From c8ae9b588f6ba5f836c380be2f9c9395f34f1f4d Mon Sep 17 00:00:00 2001 From: zhufenghao Date: Sun, 9 Oct 2022 11:10:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?web.d.ts=E7=9B=B8=E5=85=B3api8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=BA=9F=E5=BC=83=EF=BC=8Cweb.webview.d.ts=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=BC=82=E5=B8=B8=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhufenghao --- api/@internal/component/ets/web.d.ts | 69 ++- api/@ohos.web.webview.d.ts | 659 ++++++++++++++++++++++++--- 2 files changed, 654 insertions(+), 74 deletions(-) diff --git a/api/@internal/component/ets/web.d.ts b/api/@internal/component/ets/web.d.ts index 587cc8463f..3893030d93 100644 --- a/api/@internal/component/ets/web.d.ts +++ b/api/@internal/component/ets/web.d.ts @@ -13,6 +13,8 @@ * limitations under the License. */ +declare type WebviewController = import('../api/@ohos.web.webview').default.WebviewController; + /** * Enum type supplied to {@link getMessageLevel} for receiving the console log level of JavaScript. * @since 8 @@ -689,9 +691,17 @@ declare class ConsoleMessage { * @param messageLevel The console log level. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.ConsoleMessage#constructor */ constructor(message: string, sourceId: string, lineNumber: number, messageLevel: MessageLevel); + /** + * Constructor. + * @since 9 + */ + constructor(); + /** * Gets the message of a console message. * @return Return the message of a console message. @@ -1021,6 +1031,7 @@ declare class WebCookie { * Sets the cookie. * @since 8 * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebCookieManager#setCookie */ setCookie(); @@ -1034,6 +1045,7 @@ declare class WebCookie { * Saves the cookies. * @since 8 * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebCookieManager#saveCookieAsync */ saveCookie(); @@ -1086,23 +1098,30 @@ declare class WebCookie { /** * Defines the Web controller. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController */ declare class WebController { /** * Constructor. * @since 8 + * @deprecated since 9 */ constructor(); /** * Let the Web inactive. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#onInactive */ onInactive(): void; /** * Let the Web active. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#onActive */ onActive(): void; @@ -1111,6 +1130,8 @@ declare class WebCookie { * @param factor The zoom factor. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#zoom */ zoom(factor: number): void; @@ -1129,6 +1150,8 @@ declare class WebCookie { /** * Clears the history in the Web. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#clearHistory */ clearHistory(): void; @@ -1137,6 +1160,8 @@ declare class WebCookie { * @param options The options with a piece of code and a callback. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#runJavaScript */ runJavaScript(options: { script: string, callback?: (result: string) => void }); @@ -1160,6 +1185,8 @@ declare class WebCookie { * @param options The options with the data or URL and other information. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#loadData */ loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }); @@ -1168,18 +1195,24 @@ declare class WebCookie { * @param options The options with the URL and other information. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#loadUrl */ loadUrl(options: { url: string | Resource, headers?: Array
}); /** * refreshes the current URL. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#refresh */ refresh(); /** * Stops the current load. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#stop */ stop(); @@ -1188,6 +1221,8 @@ declare class WebCookie { * @param options The option with the JavaScript object and method list. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#registerJavaScriptProxy */ registerJavaScriptProxy(options: { object: object, name: string, methodList: Array }); @@ -1196,12 +1231,16 @@ declare class WebCookie { * @param name The name of a registered JavaScript object to be deleted. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#deleteJavaScriptRegister */ deleteJavaScriptRegister(name: string); /** * Gets the type of HitTest. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#getHitTest */ getHitTest(): HitTestType; @@ -1238,18 +1277,24 @@ declare class WebCookie { /** * Gets the request focus. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#requestFocus */ requestFocus(); /** * Checks whether the web page can go back. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#accessBackward */ accessBackward(): boolean; /** * Checks whether the web page can go forward. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#accessForward */ accessForward(): boolean; @@ -1258,18 +1303,24 @@ declare class WebCookie { * @param step The number of steps. * * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#accessStep */ accessStep(step: number): boolean; /** * Goes back in the history of the web page. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#backward */ backward(); /** * Goes forward in the history of the web page. * @since 8 + * @deprecated since 9 + * @useinstead ohos.web.webview.webview.WebviewController#forward */ forward(); @@ -1331,9 +1382,15 @@ declare interface WebOptions { src: string | Resource; /** * Sets the controller of the Web. + * @type { (WebController) } * @since 8 */ - controller: WebController; + /** + * Sets the controller of the Web. + * @type { (WebController | WebviewController) } + * @since 9 + */ + controller: WebController | WebviewController; } /** @@ -1422,10 +1479,18 @@ declare class WebAttribute extends CommonMethod { * Injects the JavaScript object into window and invoke the function in window. * @param javaScriptProxy The JavaScript object to be injected. * + * @type {controller : WebController} * @since 8 + */ + /** + * Injects the JavaScript object into window and invoke the function in window. + * @param javaScriptProxy The JavaScript object to be injected. + * + * @type {controller : WebController | WebviewController} + * @since 9 */ javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array, - controller: WebController }): WebAttribute; + controller: WebController | WebviewController }): WebAttribute; /** * Sets whether the Web should save the password. diff --git a/api/@ohos.web.webview.d.ts b/api/@ohos.web.webview.d.ts index 0b01063a09..84a791c039 100644 --- a/api/@ohos.web.webview.d.ts +++ b/api/@ohos.web.webview.d.ts @@ -13,7 +13,31 @@ * limitations under the License. */ +/// + import {AsyncCallback} from "./basic"; +import {Resource} from 'GlobalResource'; + +/** + * Defines the hit test value, related to {@link getHitTestValue} method. + * @since 9 + */ +declare interface HitTestValue { + + /** + * Get the hit test type. + * + * @since 9 + */ + type: HitTestType; + + /** + * Get the hit test extra data. + * + * @since 9 + */ + extra: string; +} /** * This module provides the capability to manage web modules. @@ -42,15 +66,18 @@ declare namespace webview { */ class WebStorage { /** - * delete all the storage data. + * Delete all the storage data. * * @since 9 */ static deleteAllData() : void; - + /** - * delete the storage data with the origin. - * @param origin the origin which to be deleted. + * Delete the storage data with the origin. + * + * @param { string } origin - The origin which to be deleted. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100011 - Invaild permission origin. * @since 9 */ static deleteOrigin(origin : string): void; @@ -58,22 +85,28 @@ declare namespace webview { /** * Get current all the web storage origins. * + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100012 - Invaild web storage origin. * @since 9 */ static getOrigins() : Promise>; static getOrigins(callback: AsyncCallback>) : void; /** - * Get the web storage quota with the origin. - * @param origin the origin which to be inquired. + * Get the web storage quota with the origin. + * @param { string } origin - The origin which to be inquired. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100011 - Invaild permission origin. * @since 9 */ static getOriginQuota(origin : string) : Promise; static getOriginQuota(origin : string, callback : AsyncCallback) : void; /** - * Get the web storage quota with the origin. - * @param origin the origin which to be inquired. + * Get the web storage quota with the origin. + * @param { string } origin - The origin which to be inquired. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100011 - Invaild permission origin. * @since 9 */ static getOriginUsage(origin : string) : Promise ; @@ -89,34 +122,36 @@ declare namespace webview { class WebDataBase { /** * Get whether instances holds any http authentication credentials. - * @return true if instances saved any http authentication credentials otherwise false. + * @return { boolean } true if instances saved any http authentication credentials otherwise false. * * @since 9 */ static existHttpAuthCredentials(): boolean; - + /** - * delete all http authentication credentials. + * Delete all http authentication credentials. * * @since 9 */ static deleteHttpAuthCredentials(): void; - + /** - * get http authentication credentials. - * @param host the host to which the credentials apply. - * @param realm the realm to which the credentials apply. - * @return Return an array containing username and password. + * Get http authentication credentials. + * @param { string } host - The host to which the credentials apply. + * @param { string } realm - The realm to which the credentials apply. + * @throws { BusinessError } 401 - Invaild input parameter. + * @return { Array } Return an array containing username and password. * @since 9 */ static getHttpAuthCredentials(host: string, realm: string): Array; - + /** - * save http authentication credentials. - * @param host the host to which the credentials apply. - * @param realm the realm to which the credentials apply. - * @param username the username. - * @param password the password. + * Save http authentication credentials. + * @param { string } host - The host to which the credentials apply. + * @param { string } realm - The realm to which the credentials apply. + * @param { string } username - The username. + * @param { string } password - The password. + * @throws { BusinessError } 401 - Invaild input parameter. * * @since 9 */ @@ -132,7 +167,8 @@ declare namespace webview { /** * Constructor. * - * @param controller WebAsyncController needs a WebController to associate with corresponding nweb. + * @param { WebController } controller WebAsyncController needs a WebController + * to associate with corresponding nweb. * * @since 9 */ @@ -141,13 +177,14 @@ declare namespace webview { /** * Stores the current page as a web archive. * - * @param baseName Where the generated offline webpage is stored, This value cannot be null. - * @param autoName If it is false, the filename will be automatically generated according to - * the url and the generated offline webpage will be stored in the directory - * specified by baseName. If it is true, the offline webpage will be directly - * stored in the path specified by baseName. - * @returns a promise resolved after the web archive has been stored. The parameter will either - * be the filename under which the file was stored, or empty if storing the file failed. + * @param { string } baseName - Where the generated offline webpage is stored, This value cannot be null. + * @param { boolean } autoName - If it is false, the filename will be automatically generated according to + * the url and the generated offline webpage will be stored in the directory + * specified by baseName. If it is true, the offline webpage will be directly + * stored in the path specified by baseName. + * @returns { Promise } A promise resolved after the web archive has been stored. + * The parameter will either be the filename under which the file was stored, + * or empty if storing the file failed. * * @since 9 */ @@ -156,14 +193,14 @@ declare namespace webview { /** * Stores the current page as a web archive. * - * @param baseName Where the generated offline webpage is stored, This value cannot be null. - * @param autoName If it is false, the filename will be automatically generated according to - * the url and the generated offline webpage will be stored in the directory - * specified by baseName. If it is true, the offline webpage will be directly - * stored in the path specified by baseName. - * @param callback called after the web archive has been stored. The parameter will either be - * the filename under which the file was stored, or empty if storing - * the file failed. + * @param { string } baseName - Where the generated offline webpage is stored, This value cannot be null. + * @param { boolean } autoName - If it is false, the filename will be automatically generated according to + * the url and the generated offline webpage will be stored in the directory + * specified by baseName. If it is true, the offline webpage will be directly + * stored in the path specified by baseName. + * @param { AsyncCallback } callback - Called after the web archive has been stored. + * The parameter will either be the filename under which the file + * was stored, or empty if storing the file failed. * * @since 9 */ @@ -179,7 +216,9 @@ declare namespace webview { class GeolocationPermissions { /** * Allow geolocation permissions for specifies source. - * @param origin url source. + * @param { string } origin - Url source. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100011 - Invaild permission origin. * * @since 9 */ @@ -187,7 +226,9 @@ declare namespace webview { /** * Delete geolocation permissions for specifies source. - * @param origin url source. + * @param { string } origin - Url source. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100011 - Invaild permission origin. * * @since 9 */ @@ -202,8 +243,12 @@ declare namespace webview { /** * Gets the geolocation permission status of the specified source. - * @param origin url source. - * @return Return whether there is a saved result. + * @param { string } origin - Url source. + * @param { AsyncCallback } callback - Return to the specified source + * geographic location permission status. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100011 - Invaild permission origin. + * @return { Promise } Return whether there is a saved result. * * @since 9 */ @@ -212,7 +257,10 @@ declare namespace webview { /** * Get all stored geolocation permission url source. - * @return Return whether there is a saved result. + * @param { AsyncCallback } callback - Return all source information of + * stored geographic location permission status. + * @throws { BusinessError } 401 - Invaild input parameter. + * @return { Promise> } Return whether there is a saved result. * * @since 9 */ @@ -229,7 +277,9 @@ declare namespace webview { /** * Gets all cookies for the given URL. * - * @param url The URL for which the cookies are requested. + * @param { string } url - The URL for which the cookies are requested. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100002 - Invaild url. * @returns The cookie value for the given URL. * * @since 9 @@ -239,47 +289,43 @@ declare namespace webview { /** * Set a single cookie (key-value pair) for the given URL. * - * @param url The URL for which the cookie is to be set. - * @param value The cookie as a string, using the format of the 'Set-Cookie' HTTP response header. - * @returns True if the cookie was successfully set else false. + * @param { string } url - The URL for which the cookie is to be set. + * @param { string } value - The cookie as a string, using the format of the 'Set-Cookie' HTTP response header. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100002 - Invaild url. + * @throws { BusinessError } 17100005 - Invaild cookie value. * * @since 9 */ - static setCookie(url: string, value: string): boolean; + static setCookie(url: string, value: string): void; /** - * Save the cookies Synchronously . - * - * @return True if the cookies have been successfully saved else false. - * + * Save the cookies Synchronously. + * * @since 9 */ - static saveCookieSync(): boolean; + static saveCookieSync(): void; /** * Save the cookies Asynchronously. - * - * @return A promise resolved after the cookies have been saved.The parameter will either - * be true if the cookies have been successfully saved, or false if failed. - * + * + * @param { AsyncCallback } callback - Called after the cookies have been saved. + * The parameter will either be true if the cookies + * have been successfully saved, or false if failed. + * @throws { BusinessError } 401 - Invaild input parameter. + * @return { Promise } A promise resolved after the cookies have been saved. + * The parameter will either be true if the cookies have + * been successfully saved, or false if failed. + * * @since 9 */ static saveCookieAsync(): Promise; - - /** - * Save the cookies Asynchronously. - * - * @param callback Called after the cookies have been saved. The parameter will either be - * true if the cookies have been successfully saved, or false if failed. - * - * @since 9 - */ static saveCookieAsync(callback: AsyncCallback): void; /** * Get whether the instance can send and accept cookies. * - * @returns True if the instance can send and accept cookies else false. + * @returns { boolean } True if the instance can send and accept cookies else false. * * @since 9 */ @@ -289,7 +335,8 @@ declare namespace webview { * Set whether the instance should send and accept cookies. * By default this is set to be true. * - * @param accept Whether the instance should send and accept cookies. + * @param { boolean } accept - Whether the instance should send and accept cookies. + * @throws { BusinessError } 401 - Invaild input parameter. * * @since 9 */ @@ -298,7 +345,7 @@ declare namespace webview { /** * Get whether the instance can send and accept thirdparty cookies. * - * @returns True if the instance can send and accept thirdparty cookies else false. + * @returns { boolean } True if the instance can send and accept thirdparty cookies else false. * * @since 9 */ @@ -308,7 +355,8 @@ declare namespace webview { * Set whether the instance should send and accept thirdparty cookies. * By default this is set to be true. * - * @param accept Whether the instance should send and accept thirdparty cookies. + * @param { boolean } accept - Whether the instance should send and accept thirdparty cookies. + * @throws { BusinessError } 401 - Invaild input parameter. * * @since 9 */ @@ -317,7 +365,7 @@ declare namespace webview { /** * Check whether exists any cookies. * - * @returns True if exists more than one cookie else false; + * @returns { boolean } True if exists more than one cookie else false; * * @since 9 */ @@ -332,11 +380,478 @@ declare namespace webview { /** * Delete the session cookies. - * + * * @since 9 */ static deleteSessionCookie(): void; } + + /** + * Define html web message port. + * @since 9 + */ + interface WebMessagePort { + /** + * Close port. + * @since 9 + */ + close(): void; + + /** + * Post a message to other port. + * @param { string } message - Message to send. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100010 - Can not post message using this port. + * + * @since 9 + */ + postMessageEvent(message: string): void; + + /** + * Receive message from other port. + * @param { (result: string) => void } callback - Callback function for receiving messages. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100006 - Can not register message event using this port. + * + * @since 9 + */ + onMessageEvent(callback: (result: string) => void): void; + } + + /** + * Provides methods for controlling the web controller. + * + * @since 9 + */ + class WebviewController { + /** + * Checks whether the web page can go forward. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { boolean } True if the web page can go forward else false. + * + * @since 9 + */ + accessForward(): boolean; + + /** + * Checks whether the web page can go back. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { boolean } True if the web page can go back else false. + * + * @since 9 + */ + accessBackward(): boolean; + + /** + * Checks whether the web page can go back or forward the given number of steps. + * + * @param { number } step - The number of steps. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { boolean } True if the web page can go back else false. + * + * @since 9 + */ + accessStep(step: number): boolean; + + /** + * Goes forward in the history of the web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100007 - Invalid back or forward operation. + * + * @since 9 + */ + forward(): void; + + /** + * Goes back in the history of the web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100007 - Invalid back or forward operation. + * + * @since 9 + */ + backward(): void; + + /** + * Clears the history in the Web. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 9 + */ + clearHistory(): void; + + /** + * Let the Web active. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 9 + */ + onActive(): void; + + /** + * Let the Web inactive. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 9 + */ + onInactive(): void; + + /** + * Refreshes the current URL. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 9 + */ + refresh(): void; + + /** + * Loads the data or URL. + * + * @param { string } data - A string encoded according to "Base64" or "URL". + * @param { string } mimeType - Media type. For example: "text/html". + * @param { string } encoding - Encoding type. For example: "UTF-8". + * @param { string } [baseUrl] - A specified URL path ("http"/"https"/"data" protocol), + * which is assigned to window.origin by the Web component. + * @param { string } [historyUrl] - History URL. When it is not empty, it can be managed by + * history records to realize the back and forth function. + * This property is invalid when baseUrl is empty. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100002 - Invaild url. + * + * @since 9 + */ + loadData(data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string): void; + + /** + * Loads the data or URL. + * + * @param { string | Resource } url - The URL to load. + * @param { Array
} [headers] - Additional HTTP request header for URL. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100002 - Invaild url. + * @throws { BusinessError } 17100003 - Invalid resource path or file type. + * + * @since 9 + */ + loadUrl(url: string | Resource, headers?: Array
): void; + + /** + * Gets the type of HitTest. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { HitTestType } The type of HitTest. + * + * @since 9 + */ + getHitTest(): HitTestType; + + /** + * Stores the current page as a web archive. + * + * @param { string } baseName - Where the generated offline webpage is stored, This value cannot be null. + * @param { boolean } autoName - If it is false, the filename will be automatically generated according to + * the url and the generated offline webpage will be stored in the directory + * specified by baseName. If it is true, the offline webpage will be directly + * stored in the path specified by baseName. + * @param { AsyncCallback } callback - called after the web archive has been stored. The parameter + * will either be the filename under which the file was stored, + * or empty if storing the file failed. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100003 - Invalid resource path or file type. + * @returns { Promise } a promise resolved after the web archive has been stored. The parameter + * will either be the filename under which the file was stored, or empty + * if storing the file failed. + * + * @since 9 + */ + storeWebArchive(baseName: string, autoName: boolean): Promise; + storeWebArchive(baseName: string, autoName: boolean, callback : AsyncCallback): void; + + /** + * Let the Web zoom by. + * + * @param { number } factor - The zoom factor. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100004 - Function not enable. + * @throws { BusinessError } 17100009 - Cannot zoom in or zoom out. + * + * @since 9 + */ + zoom(factor: number): void; + + /** + * Let the Web zoom in. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100004 - Function not enable. + * @throws { BusinessError } 17100009 - Cannot zoom in or zoom out. + * + * @since 9 + */ + zoomIn(): void; + + /** + * Let the Web zoom out. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100004 - Function not enable. + * @throws { BusinessError } 17100009 - Cannot zoom in or zoom out. + * + * @since 9 + */ + zoomOut(): void; + + /** + * Gets the hit test value of HitTest. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { HitTestValue } Return the element information of the clicked area. + * + * @since 9 + */ + getHitTestValue(): HitTestValue; + + /** + * Gets the id for the current Web. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { number } Returns the index value of the current Web component. + * + * @since 9 + */ + getWebId(): number; + + /** + * Gets the default user agent. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { string } Return user agent information. + * + * @since 9 + */ + getUserAgent(): string; + + /** + * Gets the title of current Web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { string } Return to File Selector Title. + * + * @since 9 + */ + getTitle(): string; + + /** + * Gets the content height of current Web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { number } Returns the page height of the current page. + * + * @since 9 + */ + getPageHeight(): number; + + /** + * Goes forward or back backOrForward in the history of the web page. + * + * @param { number } step - Steps to go forward or backward. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100007 - Invalid back or forward operation. + * + * @since 9 + */ + backOrForward(step: number): void; + + /** + * Gets the request focus. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + requestFocus(): void; + + /** + * Create web message ports + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { Array } An array represent 2 WebMessagePort, then can use + * those ports to communication with html pages. + * + * @since 9 + */ + createWebMessagePorts(): Array; + + /** + * Post web message port to html + * + * @param { string } name - Data name information to send. + * @param { Array } ports - Port number array information to send. + * @param { string } uri - URI to receive this information. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + postMessage(name: string, ports: Array, uri: string): void; + + /** + * Stops the current load. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + stop(); + + /** + * Registers the JavaScript object and method list. + * + * @param { object } object - Application side JavaScript objects participating in registration. + * @param { string } name - The name of the registered object, which is consistent with the + * object name called in the window. + * @param { Array } methodList - Thr method of the application side JavaScript object participating + * in the registration. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + registerJavaScriptProxy(object: object, name: string, methodList: Array): void; + + /** + * Deletes a registered JavaScript object with given name. + * + * @param { string } name - The name of a registered JavaScript object to be deleted. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws { BusinessError } 17100008 - Cannot delete JavaScriptProxy. + * + * @since 9 + */ + deleteJavaScriptRegister(name: string): void; + + /** + * Search all instances of 'searchString' on the page and highlights them, + * result will be notify through callback onSearchResultReceive. + * + * @param { string } searchString - String to be search. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + searchAllAsync(searchString: string): void; + + /** + * Clears the highlighting surrounding text matches created by searchAllAsync. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + clearMatches(): void; + + /** + * Highlights and scrolls to the next match search. + * + * @param { boolean } forward - Step of search is back or forward. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + searchNext(forward: boolean): void; + + /** + * Clears the ssl cache in the Web. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + clearSslCache(): void; + + /** + * Clears the client authentication certificate cache in the Web. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + clearClientAuthenticationCache(): void; + + /** + * Loads a piece of code and execute JS code in the context of the currently displayed page. + * + * @param { string } script - JavaScript Script. + * @param { AsyncCallback } callback - Callbacks execute JavaScript script results. + * @throws { BusinessError } 401 - Invaild input parameter. + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { Promise } A promise is solved after the JavaScript script is executed. + * This parameter will be the result of JavaScript script execution. + * If the JavaScript script fails to execute or has no return value, + * null will be returned. + * + * @since 9 + */ + runJavaScript(script: string): Promise; + runJavaScript(script: string, callback : AsyncCallback): void; + + /** + * Gets the url of current Web page. + * + * @throws { BusinessError } 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns { string } Return the url of the current page. + * + * @since 9 + */ + getUrl(): string; + } } export default webview; -- Gitee From 3f9097f2fbcbd2d7d2c60ee1e79302c19a8d1064 Mon Sep 17 00:00:00 2001 From: zhufenghao Date: Tue, 11 Oct 2022 14:40:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?web.d.ts=E7=9B=B8=E5=85=B3api8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=BA=9F=E5=BC=83=EF=BC=8Cweb.webview.d.ts=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=8E=A5=E5=8F=A3=E5=8F=8A=E5=BC=82=E5=B8=B8=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhufenghao --- api/@ohos.web.webview.d.ts | 78 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/api/@ohos.web.webview.d.ts b/api/@ohos.web.webview.d.ts index 84a791c039..6b51682423 100644 --- a/api/@ohos.web.webview.d.ts +++ b/api/@ohos.web.webview.d.ts @@ -18,6 +18,78 @@ import {AsyncCallback} from "./basic"; import {Resource} from 'GlobalResource'; +/** + * Defines the Web's request/response header. + * @since 9 + */ + declare interface Header { + /** + * Gets the key of the request/response header. + * @since 9 + */ + headerKey: string; + + /** + * Gets the value of the request/response header. + * @since 9 + */ + headerValue: string; + } + +/** + * Enum type supplied to {@link getHitTest} for indicating the cursor node HitTest. + * @since 9 + */ + declare enum HitTestTypeV9 { + /** + * The edit text. + * @since 9 + */ + EditText, + + /** + * The email address. + * @since 9 + */ + Email, + + /** + * The HTML::a tag with src=http. + * @since 9 + */ + HttpAnchor, + + /** + * The HTML::a tag with src=http + HTML::img. + * @since 9 + */ + HttpAnchorImg, + + /** + * The HTML::img tag. + * @since 9 + */ + Img, + + /** + * The map address. + * @since 9 + */ + Map, + + /** + * The phone number. + * @since 9 + */ + Phone, + + /** + * Other unknown HitTest. + * @since 9 + */ + Unknown, + } + /** * Defines the hit test value, related to {@link getHitTestValue} method. * @since 9 @@ -29,7 +101,7 @@ declare interface HitTestValue { * * @since 9 */ - type: HitTestType; + type: HitTestTypeV9; /** * Get the hit test extra data. @@ -557,11 +629,11 @@ declare namespace webview { * * @throws { BusinessError } 17100001 - Init error. * The WebviewController must be associted with a Web component. - * @returns { HitTestType } The type of HitTest. + * @returns { HitTestTypeV9 } The type of HitTest. * * @since 9 */ - getHitTest(): HitTestType; + getHitTest(): HitTestTypeV9; /** * Stores the current page as a web archive. -- Gitee