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 #ifndef NET_PROXY_ADAPTER_IMPL_H
17 #define NET_PROXY_ADAPTER_IMPL_H
18 
19 #include <string>
20 
21 #include "common_event_manager.h"
22 #include "common_event_subscriber.h"
23 #include "common_event_support.h"
24 #include "matching_skills.h"
25 #include "net_conn_client.h"
26 #include "net_proxy_adapter.h"
27 #include "want.h"
28 
29 namespace OHOS::NWeb {
30 class NetProxyAdapterImpl final : public NetProxyAdapter {
31 public:
32     NetProxyAdapterImpl() = default;
33     ~NetProxyAdapterImpl() override = default;
34 
35     static NetProxyAdapterImpl& GetInstance();
36 
37     void RegNetProxyEvent(std::shared_ptr<NetProxyEventCallbackAdapter> eventCallback) override;
38 
39     bool StartListen() override;
40 
41     void StopListen() override;
42 
43     void GetProperty(std::string& host, uint16_t& port, std::string& pacUrl, std::string& exclusion) override;
44 
45     void Changed();
46 
47 private:
48     bool listen_ = false;
49     std::shared_ptr<NetProxyEventCallbackAdapter> cb_ = nullptr;
50     uint32_t appProxyCallbackId_ = 0;
51     void StartListenAppProxy();
52     std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber_ = nullptr;
53 };
54 
55 class NetProxyEventSubscriber : public EventFwk::CommonEventSubscriber {
56 public:
57     NetProxyEventSubscriber(EventFwk::CommonEventSubscribeInfo& in, std::shared_ptr<NetProxyEventCallbackAdapter> cb);
58     ~NetProxyEventSubscriber() override = default;
59     void OnReceiveEvent(const EventFwk::CommonEventData& data) override;
60 
61 private:
62     std::shared_ptr<NetProxyEventCallbackAdapter> eventCallback_ = nullptr;
63 };
64 
65 namespace Base64 {
66 std::string Encode(const std::string& source);
67 std::string Decode(const std::string& encoded);
68 } // namespace Base64
69 
70 } // namespace OHOS::NWeb
71 
72 #endif // NET_PROXY_ADAPTER_IMPL_H
73