1 /* 2 * Copyright (c) 2023 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 /** 17 * @addtogroup Web 18 * @{ 19 * 20 * @brief Provides APIs to use javascript proxy and run javascirpt code. 21 * @since 11 22 */ 23 /** 24 * @file native_interface_arkweb.h 25 * 26 * @brief Declares the APIs to use javascript proxy and run javascirpt code. 27 * @library libohweb.so 28 * @syscap SystemCapability.Web.Webview.Core 29 * @since 11 30 */ 31 #ifndef NATIVE_INTERFACE_ARKWEB_H 32 #define NATIVE_INTERFACE_ARKWEB_H 33 34 #include <cstdint> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /** 41 * @brief Defines the javascript callback of the web component. 42 * 43 * @since 11 44 */ 45 typedef void (*NativeArkWeb_OnJavaScriptCallback)(const char*); 46 47 /** 48 * @brief Defines the javascript proxy callback of the web component. 49 * 50 * @since 11 51 */ 52 typedef char* (*NativeArkWeb_OnJavaScriptProxyCallback)(const char** argv, int32_t argc); 53 54 /** 55 * @brief Defines the valid callback of the web component. 56 * 57 * @since 11 58 */ 59 typedef void (*NativeArkWeb_OnValidCallback)(const char*); 60 61 /** 62 * @brief Defines the destroy callback of the web component. 63 * 64 * @since 11 65 */ 66 typedef void (*NativeArkWeb_OnDestroyCallback)(const char*); 67 68 /* 69 * @brief Loads a piece of code and execute JS code in the context of the currently displayed page. 70 * 71 * @param webTag The name of the web component. 72 * @param jsCode a piece of javascript code. 73 * @param callback Callbacks execute JavaScript script results. 74 * 75 * @syscap SystemCapability.Web.Webview.Core 76 * @since 11 77 */ 78 void OH_NativeArkWeb_RunJavaScript(const char* webTag, const char* jsCode, NativeArkWeb_OnJavaScriptCallback callback); 79 80 /* 81 * @brief Registers the JavaScript object and method list. 82 * 83 * @param webTag The name of the web component. 84 * @param objName The name of the registered object. 85 * @param methodList The method of the application side JavaScript object participating in the registration. 86 * @param callback The callback function registered by developer is called back when HTML side uses. 87 * @param size The size of the callback. 88 * @param needRefresh if web need refresh. 89 * 90 * @syscap SystemCapability.Web.Webview.Core 91 * @since 11 92 */ 93 void OH_NativeArkWeb_RegisterJavaScriptProxy(const char* webTag, const char* objName, const char** methodList, 94 NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool isNeedRefresh); 95 96 /* 97 * @brief Deletes the registered object which th given name. 98 * 99 * @param webTag The name of the web component. 100 * @param objName The name of the registered object. 101 * 102 * @syscap SystemCapability.Web.Webview.Core 103 * @since 11 104 */ 105 void OH_NativeArkWeb_UnregisterJavaScriptProxy(const char* webTag, const char* objName); 106 107 /* 108 * @brief Registers the valid callback. 109 * 110 * @param webTag The name of the web component. 111 * @param callback The callback in which we can register object. 112 * 113 * @syscap SystemCapability.Web.Webview.Core 114 * @since 11 115 */ 116 void OH_NativeArkWeb_SetJavaScriptProxyValidCallback(const char* webTag, NativeArkWeb_OnValidCallback callback); 117 118 /* 119 * @brief Get the valid callback. 120 * 121 * @param webTag The name of the web component. 122 * @return return the valid callback function registered. 123 * 124 * @syscap SystemCapability.Web.Webview.Core 125 * @since 11 126 */ 127 NativeArkWeb_OnValidCallback OH_NativeArkWeb_GetJavaScriptProxyValidCallback(const char* webTag); 128 129 /* 130 * @brief Registers the destroy callback. 131 * 132 * @param webTag The name of the web component. 133 * @param callback the destroy callback. 134 * 135 * @syscap SystemCapability.Web.Webview.Core 136 * @since 11 137 */ 138 void OH_NativeArkWeb_SetDestroyCallback(const char* webTag, NativeArkWeb_OnDestroyCallback callback); 139 140 /* 141 * @brief Get the destroy callback. 142 * 143 * @param webTag The name of the web component. 144 * @return return the destroy callback function registered. 145 * 146 * @syscap SystemCapability.Web.Webview.Core 147 * @since 11 148 */ 149 NativeArkWeb_OnDestroyCallback OH_NativeArkWeb_GetDestroyCallback(const char* webTag); 150 151 #ifdef __cplusplus 152 }; 153 #endif 154 #endif // NATIVE_INTERFACE_ARKWEB_H