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 #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 needRefresh);
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. If the valid callback function
125  *         specified by the parameter webTag is not set, a null pointer is returned.
126  *
127  * @syscap SystemCapability.Web.Webview.Core
128  * @since 11
129  */
130 NativeArkWeb_OnValidCallback OH_NativeArkWeb_GetJavaScriptProxyValidCallback(const char* webTag);
131 
132 /*
133  * @brief Registers the destroy callback.
134  *
135  * @param webTag The name of the web component.
136  * @param callback the destroy callback.
137  *
138  * @syscap SystemCapability.Web.Webview.Core
139  * @since 11
140  */
141 void OH_NativeArkWeb_SetDestroyCallback(const char* webTag, NativeArkWeb_OnDestroyCallback callback);
142 
143 /*
144  * @brief Get the destroy callback.
145  *
146  * @param webTag The name of the web component.
147  * @return Return the destroy callback function registered. If the destroy callback
148  *         function specified by the parameter webTag is not set,
149  *         a null pointer is returned.
150  *
151  * @syscap SystemCapability.Web.Webview.Core
152  * @since 11
153  */
154 NativeArkWeb_OnDestroyCallback OH_NativeArkWeb_GetDestroyCallback(const char* webTag);
155 
156 #ifdef __cplusplus
157 };
158 #endif
159 #endif // NATIVE_INTERFACE_ARKWEB_H