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 #include "arkweb_error_code.h" 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /** 43 * @brief Defines the javascript callback of the web component. 44 * 45 * @since 11 46 */ 47 typedef void (*NativeArkWeb_OnJavaScriptCallback)(const char*); 48 49 /** 50 * @brief Defines the javascript proxy callback of the web component. 51 * 52 * @since 11 53 */ 54 typedef char* (*NativeArkWeb_OnJavaScriptProxyCallback)(const char** argv, int32_t argc); 55 56 /** 57 * @brief Defines the valid callback of the web component. 58 * 59 * @since 11 60 */ 61 typedef void (*NativeArkWeb_OnValidCallback)(const char*); 62 63 /** 64 * @brief Defines the destroy callback of the web component. 65 * 66 * @since 11 67 */ 68 typedef void (*NativeArkWeb_OnDestroyCallback)(const char*); 69 70 /* 71 * @brief Loads a piece of code and execute JS code in the context of the currently displayed page. 72 * 73 * @param webTag The name of the web component. 74 * @param jsCode a piece of javascript code. 75 * @param callback Callbacks execute JavaScript script results. 76 * 77 * @syscap SystemCapability.Web.Webview.Core 78 * @since 11 79 */ 80 void OH_NativeArkWeb_RunJavaScript(const char* webTag, const char* jsCode, NativeArkWeb_OnJavaScriptCallback callback); 81 82 /* 83 * @brief Registers the JavaScript object and method list. 84 * 85 * @param webTag The name of the web component. 86 * @param objName The name of the registered object. 87 * @param methodList The method of the application side JavaScript object participating in the registration. 88 * @param callback The callback function registered by developer is called back when HTML side uses. 89 * @param size The size of the callback. 90 * @param needRefresh if web need refresh. 91 * 92 * @syscap SystemCapability.Web.Webview.Core 93 * @since 11 94 */ 95 void OH_NativeArkWeb_RegisterJavaScriptProxy(const char* webTag, const char* objName, const char** methodList, 96 NativeArkWeb_OnJavaScriptProxyCallback* callback, int32_t size, bool isNeedRefresh); 97 98 /* 99 * @brief Deletes the registered object which th given name. 100 * 101 * @param webTag The name of the web component. 102 * @param objName The name of the registered object. 103 * 104 * @syscap SystemCapability.Web.Webview.Core 105 * @since 11 106 */ 107 void OH_NativeArkWeb_UnregisterJavaScriptProxy(const char* webTag, const char* objName); 108 109 /* 110 * @brief Registers the valid callback. 111 * 112 * @param webTag The name of the web component. 113 * @param callback The callback in which we can register object. 114 * 115 * @syscap SystemCapability.Web.Webview.Core 116 * @since 11 117 */ 118 void OH_NativeArkWeb_SetJavaScriptProxyValidCallback(const char* webTag, NativeArkWeb_OnValidCallback callback); 119 120 /* 121 * @brief Get the valid callback. 122 * 123 * @param webTag The name of the web component. 124 * @return return the valid callback function registered. 125 * 126 * @syscap SystemCapability.Web.Webview.Core 127 * @since 11 128 */ 129 NativeArkWeb_OnValidCallback OH_NativeArkWeb_GetJavaScriptProxyValidCallback(const char* webTag); 130 131 /* 132 * @brief Registers the destroy callback. 133 * 134 * @param webTag The name of the web component. 135 * @param callback the destroy callback. 136 * 137 * @syscap SystemCapability.Web.Webview.Core 138 * @since 11 139 */ 140 void OH_NativeArkWeb_SetDestroyCallback(const char* webTag, NativeArkWeb_OnDestroyCallback callback); 141 142 /* 143 * @brief Get the destroy callback. 144 * 145 * @param webTag The name of the web component. 146 * @return return the destroy callback function registered. 147 * 148 * @syscap SystemCapability.Web.Webview.Core 149 * @since 11 150 */ 151 NativeArkWeb_OnDestroyCallback OH_NativeArkWeb_GetDestroyCallback(const char* webTag); 152 153 /** 154 * @brief Loads the data or URL. 155 * This function should be called on main thread. 156 * 157 * @param webTag The name of the web component. 158 * @param data A string encoded according to "Base64" or "URL", should not be NULL. 159 * @param mimeType Media type. For example: "text/html", should not be NULL. 160 * @param encoding Encoding type. For example: "UTF-8", should not be NULL. 161 * @param baseUrl A specified URL path ("http"/"https"/"data" protocol), 162 * which is assigned to window.origin by the Web component. 163 * @param historyUrl History URL. When it is not empty, it can be managed by 164 * history records to realize the back and forth function. 165 * @return LoadData result code. 166 * {@link ARKWEB_SUCCESS} load data success. 167 * {@link ARKWEB_INVALID_PARAM} Mandatory parameters are left unspecified or 168 * Incorrect parameter types or Parameter verification failed. 169 * {@link ARKWEB_INIT_ERROR} Initialization error, can't get a valid Web for the webTag. 170 * {@link ARKWEB_LIBRARY_OPEN_FAILURE} Failed to open the library. 171 * {@link ARKWEB_LIBRARY_SYMBOL_NOT_FOUND} The required symbol was not found in the library. 172 * 173 * @syscap SystemCapability.Web.Webview.Core 174 * @since 15 175 */ 176 ArkWeb_ErrorCode OH_NativeArkWeb_LoadData(const char* webTag, 177 const char* data, 178 const char* mimeType, 179 const char* encoding, 180 const char* baseUrl, 181 const char* historyUrl); 182 183 #ifdef __cplusplus 184 }; 185 #endif 186 #endif // NATIVE_INTERFACE_ARKWEB_H