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 static void TryPreReadLib(bool isFirstTimeStartUpWeb, const std::string &bundlePath); 35 36 std::shared_ptr<NWeb> CreateNWeb(const NWebCreateInfo &create_info); 37 NWebCookieManager *GetCookieManager(); 38 NWebDataBase *GetDataBase(); 39 NWebWebStorage *GetWebStorage(); 40 std::weak_ptr<NWeb> GetNWeb(int32_t nweb_id); 41 void SetBundlePath(const std::string &path); 42 43 private: 44 NWebHelper() = default; 45 bool LoadLib(bool from_ark); 46 void UnloadLib(); 47 48 private: 49 void *libHandleWebEngine_ = nullptr; 50 std::string bundlePath_; 51 }; 52 } // namespace OHOS::NWeb 53 54 #endif // NWEB_HELPER_H 55