ArkWeb_ControllerAPI
typedef struct {...} ArkWeb_ControllerAPI
Overview
Defines a native controller API. Before calling this 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. The controller APIs must be called on the UI thread through OH_ArkWeb_GetNativeAPI.
Since: 12
Related module: Web
Header file: arkweb_type.h
Summary
Member Variables
| Name | Description |
|---|---|
| size_t size | Size of the struct. |
Member Functions
| Name | Description |
|---|---|
| void (*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject) | Injects a JavaScript script. |
| void (*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject) | Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window. |
| void (*deleteJavaScriptRegister)(const char* webTag, const char* objName) | Deletes a specific application JavaScript object that is registered with the window using registerJavaScriptProxy. |
| void (*refresh)(const char* webTag) | Refreshes the web page. The page stack is cleared during the refresh. As a result, the current page cannot be navigated forward or backward. |
| void (*registerAsyncJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject) | Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window. |
| ArkWeb_WebMessagePortPtr* (*createWebMessagePorts)(const char* webTag, size_t* size) | Creates a post message port. |
| void (*destroyWebMessagePorts)(ArkWeb_WebMessagePortPtr** ports, size_t size) | Destroys a message port. |
| ArkWeb_ErrorCode (*postWebMessage)(const char* webTag, const char* name, ArkWeb_WebMessagePortPtr* webMessagePorts, size_t size, const char* url) | Sends a message port to the HTML page. |
| const char* (*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. Since: 14 |
| void (*registerJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject,const char* permission) | 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. Since: 18 |
| void (*registerAsyncJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObject* proxyObject,const char* permission) | Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window. Since: 18 |
Member Function Description
runJavaScript()
void (*runJavaScript)(const char* webTag, const ArkWeb_JavaScriptObject* javascriptObject)
Description
Injects a JavaScript script.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const ArkWeb_JavaScriptObject* javascriptObject | JavaScript object to inject. |
registerJavaScriptProxy()
void (*registerJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)
Description
Injects a JavaScript object with the window. Synchronous APIs of this object can then be invoked in the window.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const ArkWeb_ProxyObject* proxyObject | Object to be registered. |
deleteJavaScriptRegister()
void (*deleteJavaScriptRegister)(const char* webTag, const char* objName)
Description
Deletes a specific application JavaScript object that is registered with the window using registerJavaScriptProxy.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const char* objName | Name of the JavaScript object. |
refresh()
void (*refresh)(const char* webTag)
Description
Refreshes the web page. The page stack is cleared during the refresh. As a result, the current page cannot be navigated forward or backward.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
registerAsyncJavaScriptProxy()
void (*registerAsyncJavaScriptProxy)(const char* webTag, const ArkWeb_ProxyObject* proxyObject)
Description
Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const ArkWeb_ProxyObject* proxyObject | Object to be registered. |
createWebMessagePorts()
ArkWeb_WebMessagePortPtr* (*createWebMessagePorts)(const char* webTag, size_t* size)
Description
Creates a post message port.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| size_t* size | Number of ports, which is an output parameter. |
Returns
| Type | Description |
|---|---|
| ArkWeb_WebMessagePortPtr | Pointer to the message port. |
destroyWebMessagePorts()
void (*destroyWebMessagePorts)(ArkWeb_WebMessagePortPtr** ports, size_t size)
Description
Destroys a message port.
Parameters
| Name | Description |
|---|---|
| ArkWeb_WebMessagePortPtr** ports | Double pointer to the message port struct. |
| size_t size | Number of ports. |
postWebMessage()
ArkWeb_ErrorCode (*postWebMessage)(const char* webTag, const char* name, ArkWeb_WebMessagePortPtr* webMessagePorts, size_t size, const char* url)
Description
Sends a message port to the HTML page.
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const char* name | Name of the message sent to the HTML page. |
| ArkWeb_WebMessagePortPtr* webMessagePorts | Pointer to the message port. |
| size_t size | Number of ports. |
| const char* url | URL of the page that receives the message. |
Returns
| Type | Description |
|---|---|
| Error code | ARKWEB_SUCCESS: The operation is successful. ARKWEB_INVALID_PARAM: The parameter is invalid. ARKWEB_INIT_ERROR: The initialization fails because the Web component bound to webTag is not found. |
getLastJavascriptProxyCallingFrameUrl()
const char* (*getLastJavascriptProxyCallingFrameUrl)()
Description
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.
Since: 14
Returns
| Type | Description |
|---|---|
| const char* | URL of the last frame that calls JavaScriptProxy. |
registerJavaScriptProxyEx()
void (*registerJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObjectWithResult* proxyObject,const char* permission)
Description
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.
Since: 18
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const ArkWeb_ProxyObjectWithResult* proxyObject | Object to be registered. |
| const char* permission | A JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default. |
registerAsyncJavaScriptProxyEx()
void (*registerAsyncJavaScriptProxyEx)(const char* webTag, const ArkWeb_ProxyObject* proxyObject, const char* permission)
Description
Injects a JavaScript object with the window. Asynchronous APIs of this object can then be invoked in the window.
Since: 18
Parameters
| Name | Description |
|---|---|
| const char* webTag | Name of the Web component. |
| const ArkWeb_ProxyObject* proxyObject | Object to be registered. |
| const char* permission | A JSON string used to configure the object and method levels of the JSBridge permission. This value is empty by default. |