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