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 #ifndef ARK_WEB_BRIDGE_HELPER_H_ 17 #define ARK_WEB_BRIDGE_HELPER_H_ 18 #pragma once 19 20 #include <dlfcn.h> 21 22 #include "base/include/ark_web_bridge_types.h" 23 #include "base/include/ark_web_types.h" 24 25 namespace OHOS::ArkWeb { 26 27 extern int g_ark_web_init_addr; 28 #define ARK_WEB_INIT_ADDR &g_ark_web_init_addr 29 30 #if defined(OHOS_WEBVIEW_GLUE) 31 32 #if defined(IS_ASAN) 33 #if defined(webview_arm64) 34 const std::string WEBVIEW_RELATIVE_SANDBOX_PATH_FOR_LIBRARY = 35 "data/storage/el1/bundle/arkwebcore_asan/libs/arm64/libarkweb_engine.so"; 36 #endif 37 #endif 38 39 #endif 40 41 using ArkWebMemberCheckFunc = void* (*)(ArkWebBridgeType, const ArkWebString*); 42 43 class ArkWebBridgeHelper { 44 public: 45 virtual ~ArkWebBridgeHelper(); 46 47 void* LoadFuncSymbol(const char* funcName, bool isPrintLog = true); 48 49 void RegisterFuncMember(ArkWebBridgeType bridgeType, const std::map<std::string, void*>& funcMemberMap); 50 51 void* CheckFuncMemberForCalled(ArkWebBridgeType bridgeType, const std::string& funcName); 52 53 void* CheckFuncMemberForCaller(ArkWebBridgeType bridgeType, const std::string& funcName); 54 55 protected: 56 ArkWebBridgeHelper() = default; 57 58 bool LoadLibFile(int openMode, const std::string& libFilePath, bool isPrintLog = true); 59 60 #if defined(OHOS_WEBVIEW_GLUE) 61 bool LoadLibFile(int openMode, const std::string& libNsName, const std::string& libDirPath, 62 const std::string& libFileName, bool isPrintLog = true); 63 #endif 64 65 static void PrereadLibFile(const std::string& libFilePath, bool isPrintLog = true); 66 67 void InitFuncMemberMaps(ArkWebBridgeType init, ArkWebBridgeType butt, bool isPrintLog = true); 68 69 private: 70 void UnloadLibFile(); 71 72 protected: 73 ArkWebMemberCheckFunc memberCheckFunc_ = nullptr; 74 std::map<int, std::map<std::string, void*>> funcMemberMaps_; 75 void* libFileHandler_ = nullptr; 76 }; 77 78 } // namespace OHOS::ArkWeb 79 80 #endif // ARK_WEB_BRIDGE_HELPER_H_ 81