• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkWeb_ControllerAPI
2
3## Overview
4
5Defines a native controller API. Before calling the API, you are advised to use **ARKWEB_MEMBER_MISSING** to check whether the function struct has the corresponding pointer to avoid crash caused by mismatch between the SDK and the device ROM.
6
7**Since**: 12
8
9**Related module**: [Web](capi-web.md)
10
11**Header file**: [arkweb_type.h](capi-arkweb-type-h.md)
12
13## Summary
14
15### Member Variables
16
17| Name| Description|
18| -- | -- |
19| size_t size | Size of the struct.|
20
21
22### Member Functions
23
24| Name| Description|
25| -- | -- |
26| [void (\*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject)](#runjavascript) | Injects a JavaScript script.|
27| [void (\*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)](#registerjavascriptproxy) | Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window.|
28| [void (\*deleteJavaScriptRegister)(const char* webTag, const char* objName)](#deletejavascriptregister) | Deletes a specific application JavaScript object that is registered with the window using **registerJavaScriptProxy**.|
29| [void (\*refresh)(const char* webTag)](#refresh) | Refreshes the web page. The page stack is cleared during the refresh. As a result, the current page cannot be navigated forward or backward.|
30| [void (\*registerAsyncJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)](#registerasyncjavascriptproxy) | Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.|
31| [ArkWeb_WebMessagePortPtr* (\*createWebMessagePorts)(const char* webTag, size_t* size)](#createwebmessageports) | Creates a post message port.|
32| [void (\*destroyWebMessagePorts)(ArkWeb_WebMessagePortPtr** ports, size_t size)](#destroywebmessageports) | Destroys a message port.|
33| [ArkWeb_ErrorCode (\*postWebMessage)(const char* webTag, const char* name, ArkWeb_WebMessagePortPtr* webMessagePorts, size_t size, const char* url)](#postwebmessage) | Sends a message port to the HTML page.|
34| [const char* (\*getLastJavascriptProxyCallingFrameUrl)()](#getlastjavascriptproxycallingframeurl) | Obtains the URL of the last frame that calls **JavaScriptProxy**. This function is invoked on the thread invoked by **JavaScriptProxy**. You can use **registerJavaScriptProxy** or **JavaScriptProxy** to inject a JavaScript object to a window object. This API can be used to obtain the URL of the last frame calls the injected object. You need to save the URL obtained from the invoked function.<br>**Since**: 14|
35| [void (\*registerJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject,const char* permission)](#registerjavascriptproxyex) | Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window. The synchronization method of this object can contain return values.<br>**Since**: 18|
36
37## Member Function Description
38
39### runJavaScript()
40
41```
42void (*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject)
43```
44
45**Description**
46
47Injects a JavaScript script.
48
49### registerJavaScriptProxy()
50
51```
52void (*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)
53```
54
55**Description**
56
57Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window.
58
59### deleteJavaScriptRegister()
60
61```
62void (*deleteJavaScriptRegister)(const char* webTag, const char* objName)
63```
64
65**Description**
66
67Deletes a specific application JavaScript object that is registered with the window using **registerJavaScriptProxy**.
68
69
70### refresh()
71
72```
73void (*refresh)(const char* webTag)
74```
75
76**Description**
77
78Refreshes the web page. The page stack is cleared during the refresh. As a result, the current page cannot be navigated forward or backward.
79
80### registerAsyncJavaScriptProxy()
81
82```
83void (*registerAsyncJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)
84```
85
86**Description**
87
88Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.
89
90### createWebMessagePorts()
91
92```
93ArkWeb_WebMessagePortPtr* (*createWebMessagePorts)(const char* webTag, size_t* size)
94```
95
96**Description**
97
98Creates a post message port.
99
100**Parameters**
101
102| Name| Description|
103| -- | -- |
104| const char* webTag | Name of the **Web** component.|
105|  size_t* size | Number of ports, which is an output parameter.|
106
107**Returns**
108
109| Type                          | Description|
110|------------------------------|----|
111| [ArkWeb_WebMessagePortPtr](capi-web-arkweb-webmessageport8h.md) | Pointer to the message port.  |
112
113### destroyWebMessagePorts()
114
115```
116void (*destroyWebMessagePorts)(ArkWeb_WebMessagePortPtr** ports, size_t size)
117```
118
119**Description**
120
121Destroys a message port.
122
123**Parameters**
124
125| Name          | Description               |
126|---------------|--------------------|
127| [ArkWeb_WebMessagePortPtr](capi-web-arkweb-webmessageport8h.md)** ports | Double pointer to the message port struct.|
128| size_t size   | Number of ports.             |
129
130### postWebMessage()
131
132```
133ArkWeb_ErrorCode (*postWebMessage)(const char* webTag, const char* name, ArkWeb_WebMessagePortPtr* webMessagePorts, size_t size, const char* url)
134```
135
136**Description**
137
138Sends a message port to the HTML page.
139
140**Parameters**
141
142| Name| Description|
143| -- | -- |
144| const char* webTag | Name of the **Web** component.|
145|  const char* name | Name of the message sent to the HTML page.|
146|  [ArkWeb_WebMessagePortPtr](capi-web-arkweb-webmessageport8h.md)* webMessagePorts | Pointer to the message port.|
147|  size_t size | Number of ports.|
148|  const char* url | URL of the page that receives the message.|
149
150**Returns**
151
152| Type| Description                                                                                                                                                        |
153|----|------------------------------------------------------------------------------------------------------------------------------------------------------------|
154| Error code  | [ARKWEB_SUCCESS](capi-arkweb-error-code-h.md#arkweb_errorcode): The operation is successful.<br>[ARKWEB_INVALID_PARAM](capi-arkweb-error-code-h.md#arkweb_errorcode): The parameter is invalid.<br>[ARKWEB_INIT_ERROR](capi-arkweb-error-code-h.md#arkweb_errorcode): The initialization fails because the **Web** component bound to **webTag** is not found.|
155
156### getLastJavascriptProxyCallingFrameUrl()
157
158```
159const char* (*getLastJavascriptProxyCallingFrameUrl)()
160```
161
162**Description**
163
164Obtains the URL of the last frame that calls **JavaScriptProxy**. This function is invoked on the thread invoked by **JavaScriptProxy**. You can use **registerJavaScriptProxy** or **JavaScriptProxy** to inject a JavaScript object to a window object. This API can be used to obtain the URL of the last frame calls the injected object. You need to save the URL obtained from the invoked function.
165
166**Since**: 14
167
168**Returns**
169
170| Type| Description|
171| -- | -- |
172| const char* | URL of the last frame that calls **JavaScriptProxy**.|
173
174### registerJavaScriptProxyEx()
175
176```
177void (*registerJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject,const char* permission)
178```
179
180**Description**
181
182Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window. The synchronization method of this object can contain return values.
183
184**Since**: 18
185
186**Parameters**
187
188| Name| Description|
189| -- | -- |
190| const char* webTag | Name of the **Web** component.|
191|  const [ArkWeb_ProxyObjectWithResult](capi-web-arkweb-proxyobjectwithresult.md)* proxyObject | Object to be registered.|
192| const char* permission |  A JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default.|
193
194### registerAsyncJavaScriptProxyEx()
195
196```
197void (*registerAsyncJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObject* proxyObject, const char* permission)
198```
199
200**Description**
201
202Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.
203
204**Since**: 18
205
206**Parameters**
207
208**Parameters**
209
210| Name| Description|
211| -------- | -------- |
212| webTag | Name of the **Web** component. |
213| proxyObject | Object to be registered. |
214| permission |  A JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default.|
215