提交 7cc3fd9f 编写于 作者: E ester.zhou

Update docs (17170)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 0f9e797c
...@@ -234,7 +234,7 @@ Sends a message. For the complete sample code, see [onMessageEventExt](#onmessag ...@@ -234,7 +234,7 @@ Sends a message. For the complete sample code, see [onMessageEventExt](#onmessag
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | :------------- | | ------- | ------ | ---- | :------------- |
| message | [WebMessageExt](#webmessageext) | Yes | Message to send.| | message | [WebMessageExt](#webmessageext10) | Yes | Message to send.|
**Error codes** **Error codes**
...@@ -491,7 +491,7 @@ Sets how the \<Web> component uses HTTPDNS for DNS resolution. ...@@ -491,7 +491,7 @@ Sets how the \<Web> component uses HTTPDNS for DNS resolution.
| Name | Type | Mandatory | Description| | Name | Type | Mandatory | Description|
| ------------------ | ------- | ---- | ------------- | | ------------------ | ------- | ---- | ------------- |
| secureDnsMode | [SecureDnsMode](#securednsmode) | Yes | Mode in which HTTPDNS is used.| | secureDnsMode | [SecureDnsMode](#securednsmode10) | Yes | Mode in which HTTPDNS is used.|
| secureDnsConfig | string | Yes| Information about the HTTPDNS server to use, which must use HTTPS. Only one HTTPDNS server can be configured.| | secureDnsConfig | string | Yes| Information about the HTTPDNS server to use, which must use HTTPS. Only one HTTPDNS server can be configured.|
**Example** **Example**
...@@ -504,7 +504,6 @@ import web_webview from '@ohos.web.webview'; ...@@ -504,7 +504,6 @@ import web_webview from '@ohos.web.webview';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
console.log("EntryAbility onCreate") console.log("EntryAbility onCreate")
web_webview.WebviewController.initializeWebEngine()
try { try {
web_webview.WebviewController.setHttpDns(web_webview.SecureDnsMode.Auto, "https://example1.test") web_webview.WebviewController.setHttpDns(web_webview.SecureDnsMode.Auto, "https://example1.test")
} catch(error) { } catch(error) {
...@@ -1420,7 +1419,7 @@ Executes a JavaScript script. This API uses a promise to return the script execu ...@@ -1420,7 +1419,7 @@ Executes a JavaScript script. This API uses a promise to return the script execu
| Type | Description | | Type | Description |
| --------------- | --------------------------------------------------- | | --------------- | --------------------------------------------------- |
| Promise\<string> | Promise used to return the result. Returns **null** if the JavaScript script fails to be executed| | Promise\<string> | Promise used to return the result if the operation is successful and null otherwise.|
**Error codes** **Error codes**
...@@ -2637,7 +2636,7 @@ Stores this web page. This API uses an asynchronous callback to return the resul ...@@ -2637,7 +2636,7 @@ Stores this web page. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------- | ---- | ------------------------------------------------------------ |
| baseName | string | Yes | Save path. The value cannot be null. | | baseName | string | Yes | Save path. The value cannot be null. |
| autoName | boolean | Yes | Whether to automatically generate a file name. The value **false** means not to automatically generate a file name. The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.| | autoName | boolean | Yes | Whether to automatically generate a file name. The value **false** means not to automatically generate a file name. The value **true** means to automatically generate a file name based on the URL of the current page and the **baseName** value. In this case, **baseName** is regarded as a directory.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the save path if the operation is successful and null otherwise. | | callback | AsyncCallback\<string> | Yes | Callback used to return the save path if the operation is successful and null otherwise. |
**Error codes** **Error codes**
...@@ -2662,7 +2661,7 @@ struct WebComponent { ...@@ -2662,7 +2661,7 @@ struct WebComponent {
build() { build() {
Column() { Column() {
Button('saveWebArchive') Button('storeWebArchive')
.onClick(() => { .onClick(() => {
try { try {
this.controller.storeWebArchive("/data/storage/el2/base/", true, (error, filename) => { this.controller.storeWebArchive("/data/storage/el2/base/", true, (error, filename) => {
...@@ -2697,7 +2696,7 @@ Stores this web page. This API uses a promise to return the result. ...@@ -2697,7 +2696,7 @@ Stores this web page. This API uses a promise to return the result.
| Name | Type| Mandatory| Description | | Name | Type| Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| baseName | string | Yes | Save path. The value cannot be null. | | baseName | string | Yes | Save path. The value cannot be null. |
| autoName | boolean | Yes | Whether to automatically generate a file name. The value **false** means not to automatically generate a file name. The value **true** means to automatically generate a file name based on the URL of current page and the **baseName** value. In this case, **baseName** is regarded as a directory.| | autoName | boolean | Yes | Whether to automatically generate a file name. The value **false** means not to automatically generate a file name. The value **true** means to automatically generate a file name based on the URL of the current page and the **baseName** value. In this case, **baseName** is regarded as a directory.|
**Return value** **Return value**
...@@ -2727,7 +2726,7 @@ struct WebComponent { ...@@ -2727,7 +2726,7 @@ struct WebComponent {
build() { build() {
Column() { Column() {
Button('saveWebArchive') Button('storeWebArchive')
.onClick(() => { .onClick(() => {
try { try {
this.controller.storeWebArchive("/data/storage/el2/base/", true) this.controller.storeWebArchive("/data/storage/el2/base/", true)
...@@ -2848,6 +2847,8 @@ backOrForward(step: number): void ...@@ -2848,6 +2847,8 @@ backOrForward(step: number): void
Performs a specific number of steps forward or backward on the current page based on the history stack. No redirection will be performed if the corresponding page does not exist in the history stack. Performs a specific number of steps forward or backward on the current page based on the history stack. No redirection will be performed if the corresponding page does not exist in the history stack.
Because the previously loaded web pages are used for the operation, no page reloading is involved.
**System capability**: SystemCapability.Web.Webview.Core **System capability**: SystemCapability.Web.Webview.Core
**Parameters** **Parameters**
...@@ -3586,10 +3587,11 @@ For details about the error codes, see [Webview Error Codes](../errorcodes/error ...@@ -3586,10 +3587,11 @@ For details about the error codes, see [Webview Error Codes](../errorcodes/error
**Example** **Example**
1. To perform operations on files, you must import the file management module. For details, see [File Management](./js-apis-file-fs.md).
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio'; import fs from '@ohos.file.fs';
@Entry @Entry
@Component @Component
...@@ -3602,11 +3604,13 @@ struct WebComponent { ...@@ -3602,11 +3604,13 @@ struct WebComponent {
.onClick(() => { .onClick(() => {
try { try {
let state = this.controller.serializeWebState(); let state = this.controller.serializeWebState();
let path = globalThis.AbilityContext.cacheDir; // Obtain the value of globalThis.cacheDir from MainAbility.ts.
let path = globalThis.cacheDir;
path += '/WebState'; path += '/WebState';
let fd = fileio.openSync(path, 0o2 | 0o100, 0o666); // Synchronously open a file.
fileio.writeSync(fd, state.buffer); let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
fileio.closeSync(fd); fs.writeSync(file.fd, state.buffer);
fs.closeSync(file.fd);
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
} }
...@@ -3617,6 +3621,21 @@ struct WebComponent { ...@@ -3617,6 +3621,21 @@ struct WebComponent {
} }
``` ```
2. Modify **MainAbility.ts**.
Obtain the path of the application cache file.
```ts
// xxx.ts
import UIAbility from '@ohos.app.ability.UIAbility';
import web_webview from '@ohos.web.webview';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
// Bind cacheDir to the globalThis object to implement data synchronization between the UIAbility component and the page.
globalThis.cacheDir = this.context.cacheDir;
}
}
```
### restoreWebState ### restoreWebState
restoreWebState(state: Uint8Array): void restoreWebState(state: Uint8Array): void
...@@ -3641,10 +3660,11 @@ For details about the error codes, see [Webview Error Codes](../errorcodes/error ...@@ -3641,10 +3660,11 @@ For details about the error codes, see [Webview Error Codes](../errorcodes/error
**Example** **Example**
1. To perform operations on files, you must import the file management module. For details, see [File Management](./js-apis-file-fs.md).
```ts ```ts
// xxx.ets // xxx.ets
import web_webview from '@ohos.web.webview'; import web_webview from '@ohos.web.webview';
import fileio from '@ohos.fileio'; import fs from '@ohos.file.fs';
@Entry @Entry
@Component @Component
...@@ -3656,17 +3676,22 @@ struct WebComponent { ...@@ -3656,17 +3676,22 @@ struct WebComponent {
Button('RestoreWebState') Button('RestoreWebState')
.onClick(() => { .onClick(() => {
try { try {
let path = globalThis.AbilityContext.cacheDir; // Obtain the value of globalThis.cacheDir from MainAbility.ts.
let path = globalThis.cacheDir;
path += '/WebState'; path += '/WebState';
let fd = fileio.openSync(path, 0o002, 0o666); // Synchronously open a file.
let stat = fileio.fstatSync(fd); let file = fs.openSync(path, fs.OpenMode.READ_WRITE);
let stat = fs.statSync(path);
let size = stat.size; let size = stat.size;
let buf = new ArrayBuffer(size); let buf = new ArrayBuffer(size);
fileio.read(fd, buf, (err, data) => { fs.read(file.fd, buf, (err, readLen) => {
if (data) { if (err) {
this.controller.restoreWebState(new Uint8Array(data.buffer)); console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("read file data succeed");
this.controller.restoreWebState(new Uint8Array(buf.slice(0, readLen)));
fs.closeSync(file);
} }
fileio.closeSync(fd);
}); });
} catch (error) { } catch (error) {
console.error(`ErrorCode: ${error.code}, Message: ${error.message}`); console.error(`ErrorCode: ${error.code}, Message: ${error.message}`);
...@@ -3678,6 +3703,21 @@ struct WebComponent { ...@@ -3678,6 +3703,21 @@ struct WebComponent {
} }
``` ```
2. Modify **MainAbility.ts**.
Obtain the path of the application cache file.
```ts
// xxx.ts
import UIAbility from '@ohos.app.ability.UIAbility';
import web_webview from '@ohos.web.webview';
export default class MainAbility extends UIAbility {
onCreate(want, launchParam) {
// Bind cacheDir to the globalThis object to implement data synchronization between the UIAbility component and the page.
globalThis.cacheDir = this.context.cacheDir;
}
}
```
### customizeSchemes ### customizeSchemes
static customizeSchemes(schemes: Array\<WebCustomScheme\>): void static customizeSchemes(schemes: Array\<WebCustomScheme\>): void
......
...@@ -537,7 +537,7 @@ multiWindowAccess(multiWindow: boolean) ...@@ -537,7 +537,7 @@ multiWindowAccess(multiWindow: boolean)
Sets whether to enable the multi-window permission. Sets whether to enable the multi-window permission.
Enabling the multi-window permission requires implementation of the **onWindowNew** event. For details about the sample code, see [onWindowNew](#onwindownew9). Enabling the multi-window permission requires implementation of the **onWindowNew** event. For the sample code, see [onWindowNew](#onwindownew9).
**Parameters** **Parameters**
...@@ -703,6 +703,40 @@ Sets the cache mode. ...@@ -703,6 +703,40 @@ Sets the cache mode.
} }
``` ```
### textZoomAtio<sup>(deprecated)</sup>
textZoomAtio(textZoomAtio: number)
Sets the text zoom ratio of the page. The default value is **100**, which indicates 100%.
This API is deprecated since API version 9. You are advised to use [textZoomRatio<sup>9+</sup>](#textzoomratio9) instead.
**Parameters**
| Name | Type | Mandatory | Default Value | Description |
| ------------- | ------ | ---- | ---- | --------------- |
| textZoomAtio | number | Yes | 100 | Text zoom ratio to set.|
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: WebController = new WebController()
@State atio: number = 150
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.textZoomAtio(this.atio)
}
}
}
```
### textZoomRatio<sup>9+</sup> ### textZoomRatio<sup>9+</sup>
textZoomRatio(textZoomRatio: number) textZoomRatio(textZoomRatio: number)
...@@ -1937,7 +1971,7 @@ Called when loading of the web page is complete. This API is used by an applicat ...@@ -1937,7 +1971,7 @@ Called when loading of the web page is complete. This API is used by an applicat
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------- | ---------------------------------------- | | ----------- | ------- | ---------------------------------------- |
| url | string | URL to be accessed. | | url | string | URL to be accessed. |
| isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh](#refresh) API, and **false** means the opposite.| | isRefreshed | boolean | Whether the page is reloaded. The value **true** means that the page is reloaded by invoking the [refresh<sup>9+</sup>](../apis/js-apis-webview.md#refresh) API, and **false** means the opposite.|
**Example** **Example**
...@@ -3099,7 +3133,7 @@ Called when this web page receives a new favicon. ...@@ -3099,7 +3133,7 @@ Called when this web page receives a new favicon.
Column() { Column() {
Web({ src:'www.example.com', controller: this.controller }) Web({ src:'www.example.com', controller: this.controller })
.onFaviconReceived((event) => { .onFaviconReceived((event) => {
console.log('onFaviconReceived:' + JSON.stringify(event)) console.log('onFaviconReceived');
this.icon = event.favicon; this.icon = event.favicon;
}) })
} }
...@@ -3221,6 +3255,34 @@ Called when the **\<Web>** component is about to access a URL. This API is used ...@@ -3221,6 +3255,34 @@ Called when the **\<Web>** component is about to access a URL. This API is used
} }
``` ```
### onRequestSelected
onRequestSelected(callback: () => void)
Called when the **\<Web>** component obtains the focus.
**Example**
```ts
// xxx.ets
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
.onRequestSelected(() => {
console.log('onRequestSelected')
})
}
}
}
```
## ConsoleMessage ## ConsoleMessage
Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole). Implements the **ConsoleMessage** object. For the sample code, see [onConsole](#onconsole).
...@@ -4145,7 +4207,7 @@ Describes the web-based media playback policy. ...@@ -4145,7 +4207,7 @@ Describes the web-based media playback policy.
| Name | Type | Readable| Writable| Mandatory| Description | | Name | Type | Readable| Writable| Mandatory| Description |
| -------------- | --------- | ---- | ---- | --- | ---------------------------- | | -------------- | --------- | ---- | ---- | --- | ---------------------------- |
| resumeInterval | number | Yes | Yes | No |Validity period for automatically resuming a paused web audio, in seconds. The maximum validity period is 60 seconds.| | resumeInterval | number | Yes | Yes | No |Validity period for automatically resuming a paused web audio, in seconds. The maximum validity period is 60 seconds. Due to the approximate value, the validity period may have a deviation of less than 1 second.|
| audioExclusive | boolean | Yes | Yes | No | Whether the audio of multiple **\<Web>** instances in an application is exclusive. | | audioExclusive | boolean | Yes | Yes | No | Whether the audio of multiple **\<Web>** instances in an application is exclusive. |
## DataResubmissionHandler<sup>9+</sup> ## DataResubmissionHandler<sup>9+</sup>
...@@ -4228,7 +4290,7 @@ Obtains the cookie management object of the **\<Web>** component. ...@@ -4228,7 +4290,7 @@ Obtains the cookie management object of the **\<Web>** component.
| Type | Description | | Type | Description |
| --------- | ---------------------------------------- | | --------- | ---------------------------------------- |
| WebCookie | Cookie management object. For details, see [WebCookie](#webcookie).| | WebCookie | Cookie management object. For details, see [WebCookie](#webcookiedeprecated).|
**Example** **Example**
...@@ -4457,7 +4519,7 @@ This API is deprecated since API version 9. You are advised to use [forward<sup> ...@@ -4457,7 +4519,7 @@ This API is deprecated since API version 9. You are advised to use [forward<sup>
deleteJavaScriptRegister(name: string) deleteJavaScriptRegister(name: string)
Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the [refresh](#refresh) API. Deletes a specific application JavaScript object that is registered with the window through **registerJavaScriptProxy**. The deletion takes effect immediately, with no need for invoking the[refresh](#refreshdeprecated) API.
This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](../apis/js-apis-webview.md#deletejavascriptregister). This API is deprecated since API version 9. You are advised to use [deleteJavaScriptRegister<sup>9+</sup>](../apis/js-apis-webview.md#deletejavascriptregister).
...@@ -4738,7 +4800,7 @@ This API is deprecated since API version 9. You are advised to use [refresh<sup> ...@@ -4738,7 +4800,7 @@ This API is deprecated since API version 9. You are advised to use [refresh<sup>
registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> }) registerJavaScriptProxy(options: { object: object, name: string, methodList: Array\<string\> })
Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. You must invoke the [refresh](#refresh) API for the registration to take effect. Registers a JavaScript object with the window. APIs of this object can then be invoked in the window. You must invoke the [refresh](#refreshdeprecated) API for the registration to take effect.
This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](../apis/js-apis-webview.md#registerjavascriptproxy). This API is deprecated since API version 9. You are advised to use [registerJavaScriptProxy<sup>9+</sup>](../apis/js-apis-webview.md#registerjavascriptproxy).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册