• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_HELPER_H
17 #define NWEB_HELPER_H
18 
19 #include <iosfwd>
20 #include <memory>
21 #include <string>
22 #include "nweb.h"
23 #include "nweb_cookie_manager.h"
24 #include "nweb_data_base.h"
25 #include "nweb_export.h"
26 #include "nweb_web_storage.h"
27 
28 namespace OHOS::NWeb {
29 class OHOS_NWEB_EXPORT NWebHelper {
30 public:
31     static NWebHelper &Instance();
32     ~NWebHelper();
33     bool Init(bool from_ark = true);
34     bool InitAndRun(bool from_ark = true);
35     static void TryPreReadLib(bool isFirstTimeStartUpWeb, const std::string &bundlePath);
36 
37     std::shared_ptr<NWeb> CreateNWeb(const NWebCreateInfo &create_info);
38     NWebCookieManager *GetCookieManager();
39     NWebDataBase *GetDataBase();
40     NWebWebStorage *GetWebStorage();
41     std::weak_ptr<NWeb> GetNWeb(int32_t nweb_id);
42     void SetBundlePath(const std::string &path);
43     void SetHttpDns(const NWebDOHConfig& config);
44     void SetWebTag(int32_t nwebId, const char* webTag);
45     void PrepareForPageLoad(std::string url, bool preconnectable, int32_t numSockets);
46     bool LoadNWebSDK();
47     void* GetWebEngineHandler();
48     void SetConnectionTimeout(const int32_t& timeout);
49     void SetWebDebuggingAccess(bool isEnableDebug);
50 
51 private:
52     NWebHelper() = default;
53     bool LoadLib(bool from_ark);
54     void UnloadLib();
55 
56 private:
57     void *libHandleWebEngine_ = nullptr;
58     std::string bundlePath_;
59 };
60 } // namespace OHOS::NWeb
61 
62 #endif // NWEB_HELPER_H
63