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_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_net_proxy_event_callback_adapter_impl.h"
19
20 #include "base/bridge/ark_web_bridge_macros.h"
21
22 namespace OHOS::ArkWeb {
23
ArkNetProxyAdapterWrapper(ArkWebRefPtr<ArkNetProxyAdapter> ref)24 ArkNetProxyAdapterWrapper::ArkNetProxyAdapterWrapper(ArkWebRefPtr<ArkNetProxyAdapter> ref) : ctocpp_(ref) {}
25
RegNetProxyEvent(std::shared_ptr<OHOS::NWeb::NetProxyEventCallbackAdapter> eventCallback)26 void ArkNetProxyAdapterWrapper::RegNetProxyEvent(
27 std::shared_ptr<OHOS::NWeb::NetProxyEventCallbackAdapter> eventCallback)
28 {
29 if (!ctocpp_) {
30 return;
31 }
32 if (CHECK_SHARED_PTR_IS_NULL(eventCallback)) {
33 return ctocpp_->RegNetProxyEvent(nullptr);
34 }
35
36 ctocpp_->RegNetProxyEvent(new ArkNetProxyEventCallbackAdapterImpl(eventCallback));
37 }
38
StartListen()39 bool ArkNetProxyAdapterWrapper::StartListen()
40 {
41 if (!ctocpp_) {
42 return false;
43 }
44 return ctocpp_->StartListen();
45 }
46
StopListen()47 void ArkNetProxyAdapterWrapper::StopListen()
48 {
49 if (!ctocpp_) {
50 return;
51 }
52 return ctocpp_->StopListen();
53 }
54
GetProperty(std::string & host,uint16_t & port,std::string & pacUrl,std::string & exclusion)55 void ArkNetProxyAdapterWrapper::GetProperty(
56 std::string& host, uint16_t& port, std::string& pacUrl, std::string& exclusion)
57 {
58 if (!ctocpp_) {
59 return;
60 }
61 ArkWebString ark_host;
62 ArkWebString ark_pacUrl;
63 ArkWebString ark_exclusion;
64 ctocpp_->GetProperty(ark_host, port, ark_pacUrl, ark_exclusion);
65 host = ArkWebStringStructToClass(ark_host);
66 pacUrl = ArkWebStringStructToClass(ark_pacUrl);
67 exclusion = ArkWebStringStructToClass(ark_exclusion);
68 ArkWebStringStructRelease(ark_host);
69 ArkWebStringStructRelease(ark_pacUrl);
70 ArkWebStringStructRelease(ark_exclusion);
71 }
72
73 } // namespace OHOS::ArkWeb
74