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_adapter/bridge/ark_web_adapter_webcore_bridge_helper.h"
17
18 #include "base/bridge/ark_web_bridge_macros.h"
19 #include "base/check.h"
20
21 namespace OHOS::ArkWeb {
22
23 const std::string ADAPTER_LIB_FILE_NAME = "libohos_adapter_glue_source.z.so";
24
ArkWebAdapterWebcoreBridgeHelper()25 ArkWebAdapterWebcoreBridgeHelper::ArkWebAdapterWebcoreBridgeHelper()
26 {
27 Init();
28
29 InitFuncMemberMaps(ARK_WEB_ADAPTER_INTERFACE_INIT, ARK_WEB_ADAPTER_INTERFACE_BUTT, false);
30 }
31
Init()32 void ArkWebAdapterWebcoreBridgeHelper::Init()
33 {
34 CHECK(LoadLibFile(RTLD_LAZY, ADAPTER_LIB_FILE_NAME, false));
35
36 memberCheckFunc_ =
37 reinterpret_cast<ArkWebMemberCheckFunc>(LoadFuncSymbol("ark_web_adapter_webview_check_func_static", false));
38 }
39
GetInstance()40 ArkWebAdapterWebcoreBridgeHelper& ArkWebAdapterWebcoreBridgeHelper::GetInstance()
41 {
42 static ArkWebAdapterWebcoreBridgeHelper helper;
43 return helper;
44 }
45
46 } // namespace OHOS::ArkWeb
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif // __cplusplus
51
52 ARK_WEB_EXPORT
ark_web_adapter_webcore_check_func_static(ArkWebBridgeType bridgeType,const ArkWebString * funcName)53 void* ark_web_adapter_webcore_check_func_static(ArkWebBridgeType bridgeType, const ArkWebString* funcName)
54 {
55 if (!funcName) {
56 ARK_WEB_BRIDGE_INFO_LOG("func name is nullptr");
57 return nullptr;
58 }
59
60 return OHOS::ArkWeb::ArkWebAdapterWebcoreBridgeHelper::GetInstance().CheckFuncMemberForCalled(
61 bridgeType, ArkWebStringStructToClass(*funcName));
62 }
63
64 #ifdef __cplusplus
65 }
66 #endif // __cplusplus
67