• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NWEB_NAPI_PROXY_CONTROLLER_H
17 #define NWEB_NAPI_PROXY_CONTROLLER_H
18 
19 #include "napi/native_api.h"
20 #include "napi/native_common.h"
21 #include "napi/native_node_api.h"
22 #include "nweb_proxy_changed_callback.h"
23 
24 #include "proxy_config.h"
25 
26 namespace OHOS {
27 namespace NWeb {
28 
29 const std::string PROXY_CONTROLLER_CLASS_NAME = "ProxyController";
30 
31 class NapiProxyController {
32 public:
NapiProxyController()33     NapiProxyController() {}
34     ~NapiProxyController() = default;
35 
36     static napi_value Init(napi_env env, napi_value exports);
37 
38 private:
39     static napi_value JS_Constructor(napi_env env, napi_callback_info info);
40     static napi_value JS_ApplyProxyOverride(napi_env env, napi_callback_info info);
41     static napi_value JS_RemoveProxyOverride(napi_env env, napi_callback_info info);
42     static void InnerApplyProxyOverride(ProxyConfig *proxyConfig, napi_env env, napi_ref jsCallback);
43 };
44 
45 class ProxyChangedCallbackImpl : public NWebProxyChangedCallback {
46 public:
ProxyChangedCallbackImpl(napi_env env,napi_ref callback)47     ProxyChangedCallbackImpl(napi_env env, napi_ref callback)
48         : env_(env), callback_(callback) {}
49     ~ProxyChangedCallbackImpl() = default;
50 
51     void OnChanged() override;
52 
53 private:
54     napi_env env_;
55     napi_ref callback_;
56 };
57 
58 } // namespace NWeb
59 } // namespace OHOS
60 
61 #endif  // NWEB_NAPI_PROXY_CONTROLLER_H