1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ohos_adapter/bridge/ark_net_proxy_adapter_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_net_proxy_event_callback_adapter_wrapper.h"
19 
20 #include "base/bridge/ark_web_bridge_macros.h"
21 
22 namespace OHOS::ArkWeb {
23 
ArkNetProxyAdapterImpl(NWeb::NetProxyAdapter & ref)24 ArkNetProxyAdapterImpl::ArkNetProxyAdapterImpl(NWeb::NetProxyAdapter& ref) : real_(ref) {}
25 
RegNetProxyEvent(ArkWebRefPtr<ArkNetProxyEventCallbackAdapter> eventCallback)26 void ArkNetProxyAdapterImpl::RegNetProxyEvent(ArkWebRefPtr<ArkNetProxyEventCallbackAdapter> eventCallback)
27 {
28     if (CHECK_REF_PTR_IS_NULL(eventCallback)) {
29         return real_.RegNetProxyEvent(nullptr);
30     }
31 
32     real_.RegNetProxyEvent(std::make_shared<ArkNetProxyEventCallbackAdapterWrapper>(eventCallback));
33 }
34 
StartListen()35 bool ArkNetProxyAdapterImpl::StartListen()
36 {
37     return real_.StartListen();
38 }
39 
StopListen()40 void ArkNetProxyAdapterImpl::StopListen()
41 {
42     return real_.StopListen();
43 }
44 
GetProperty(ArkWebString & host,uint16_t & port,ArkWebString & pacUrl,ArkWebString & exclusion)45 void ArkNetProxyAdapterImpl::GetProperty(
46     ArkWebString& host, uint16_t& port, ArkWebString& pacUrl, ArkWebString& exclusion)
47 {
48     std::string s_host;
49     std::string s_pacUrl;
50     std::string s_exclusion;
51 
52     real_.GetProperty(s_host, port, s_pacUrl, s_exclusion);
53     host = ArkWebStringClassToStruct(s_host);
54     pacUrl = ArkWebStringClassToStruct(s_pacUrl);
55     exclusion = ArkWebStringClassToStruct(s_exclusion);
56 }
57 
58 } // namespace OHOS::ArkWeb
59