• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_nweb/bridge/ark_web_nweb_bridge_helper.h"
17 
18 #include "base/bridge/ark_web_bridge_macros.h"
19 
20 namespace OHOS::ArkWeb {
21 
22 const std::string LIB_FILE_NAME = "libweb_engine.so";
23 
24 #if defined(webview_arm64)
25 const std::string RELATIVE_PATH_FOR_MOCK = "libs/arm64";
26 const std::string RELATIVE_PATH_FOR_BUNDLE = "nweb/libs/arm64";
27 #elif defined(webview_x86_64)
28 const std::string RELATIVE_PATH_FOR_MOCK = "libs/x86_64";
29 const std::string RELATIVE_PATH_FOR_BUNDLE = "nweb/libs/x86_64";
30 #else
31 const std::string RELATIVE_PATH_FOR_MOCK = "libs/arm";
32 const std::string RELATIVE_PATH_FOR_BUNDLE = "nweb/libs/arm";
33 #endif
34 
GetInstance()35 ArkWebNWebBridgeHelper& ArkWebNWebBridgeHelper::GetInstance()
36 {
37     static ArkWebNWebBridgeHelper helper;
38     return helper;
39 }
40 
InitArkWeb(bool runMode,const std::string & baseDir,const std::string & relativeLibPath,const std::string & arkWebEngineSo)41 bool ArkWebNWebBridgeHelper::InitArkWeb(
42     bool runMode, const std::string& baseDir,
43     const std::string& relativeLibPath, const std::string& arkWebEngineSo)
44 {
45     std::string libDirPath = baseDir + "/" + RELATIVE_PATH_FOR_MOCK;
46     if (runMode) {
47         libDirPath = baseDir + "/" + relativeLibPath;
48     }
49 #ifdef __MUSL__
50     return LoadLibFile(RTLD_NOW | RTLD_GLOBAL, "nweb_ns", libDirPath, arkWebEngineSo);
51 #else
52     std::string libFilePath = libDirPath + "/" + arkWebEngineSo;
53     return LoadLibFile(RTLD_NOW, libFilePath);
54 #endif
55 }
56 
Init(bool runMode,const std::string & baseDir)57 bool ArkWebNWebBridgeHelper::Init(bool runMode, const std::string& baseDir)
58 {
59 #ifdef __MUSL__
60     std::string libDirPath = GetDirPath(runMode, baseDir);
61     return LoadLibFile(RTLD_NOW | RTLD_GLOBAL, "nweb_ns", libDirPath, LIB_FILE_NAME);
62 #else
63     std::string dirPath = GetDirPath(runMode, baseDir);
64     std::string libFilePath = dirPath + "/" + LIB_FILE_NAME;
65     return LoadLibFile(RTLD_NOW, libFilePath);
66 #endif
67 }
68 
GetDirPath(bool runMode,const std::string & baseDir)69 std::string ArkWebNWebBridgeHelper::GetDirPath(bool runMode, const std::string& baseDir)
70 {
71     if (runMode) {
72         return baseDir + "/" + RELATIVE_PATH_FOR_BUNDLE;
73     }
74 
75     return baseDir + "/" + RELATIVE_PATH_FOR_MOCK;
76 }
77 
78 } // namespace OHOS::ArkWeb
79