diff --git a/api/@internal/component/ets/web.d.ts b/api/@internal/component/ets/web.d.ts index 195a5345bce5968eb33c9458cd4abd4d6d15223d..f2f95f0b131670d91cec917c3ca18d6d6f13279d 100644 --- a/api/@internal/component/ets/web.d.ts +++ b/api/@internal/component/ets/web.d.ts @@ -13,6 +13,9 @@ * limitations under the License. */ +declare type WebviewController = import('../api/@ohos.web.webview').default.WebviewController; +declare type WebHeader = import('../api/@ohos.web.webview').default.WebHeader; + /** * Enum type supplied to {@link getMessageLevel} for receiving the console log level of JavaScript. * @since 8 @@ -76,6 +79,7 @@ declare enum MixedMode { /** * Enum type supplied to {@link getHitTest} for indicating the cursor node HitTest. * @since 8 + * @deprecated since 9 */ declare enum HitTestType { /** @@ -689,6 +693,7 @@ declare class ConsoleMessage { * @param messageLevel The console log level. * * @since 8 + * @deprecated since 9 */ constructor(message: string, sourceId: string, lineNumber: number, messageLevel: MessageLevel); @@ -955,6 +960,7 @@ declare class JsGeolocation { * @param retain Whether to allow the geolocation permission status to be saved to the system. * * @since 8 + * @deprecated since 9 */ invoke(origin: string, allow: boolean, retain: boolean): void; } @@ -1091,18 +1097,21 @@ declare class WebCookie { /** * Constructor. * @since 8 + * @deprecated since 9 */ constructor(); /** * Let the Web inactive. * @since 8 + * @deprecated since 9 */ onInactive(): void; /** * Let the Web active. * @since 8 + * @deprecated since 9 */ onActive(): void; @@ -1111,6 +1120,7 @@ declare class WebCookie { * @param factor The zoom factor. * * @since 8 + * @deprecated since 9 */ zoom(factor: number): void; @@ -1129,6 +1139,7 @@ declare class WebCookie { /** * Clears the history in the Web. * @since 8 + * @deprecated since 9 */ clearHistory(): void; @@ -1137,6 +1148,7 @@ declare class WebCookie { * @param options The options with a piece of code and a callback. * * @since 8 + * @deprecated since 9 */ runJavaScript(options: { script: string, callback?: (result: string) => void }); @@ -1160,6 +1172,7 @@ declare class WebCookie { * @param options The options with the data or URL and other information. * * @since 8 + * @deprecated since 9 */ loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }); @@ -1168,18 +1181,21 @@ declare class WebCookie { * @param options The options with the URL and other information. * * @since 8 + * @deprecated since 9 */ loadUrl(options: { url: string | Resource, headers?: Array
}); /** * refreshes the current URL. * @since 8 + * @deprecated since 9 */ refresh(); /** * Stops the current load. * @since 8 + * @deprecated since 9 */ stop(); @@ -1188,6 +1204,7 @@ declare class WebCookie { * @param options The option with the JavaScript object and method list. * * @since 8 + * @deprecated since 9 */ registerJavaScriptProxy(options: { object: object, name: string, methodList: Array }); @@ -1196,12 +1213,14 @@ declare class WebCookie { * @param name The name of a registered JavaScript object to be deleted. * * @since 8 + * @deprecated since 9 */ deleteJavaScriptRegister(name: string); /** * Gets the type of HitTest. * @since 8 + * @deprecated since 9 */ getHitTest(): HitTestType; @@ -1238,18 +1257,21 @@ declare class WebCookie { /** * Gets the request focus. * @since 8 + * @deprecated since 9 */ requestFocus(); /** * Checks whether the web page can go back. * @since 8 + * @deprecated since 9 */ accessBackward(): boolean; /** * Checks whether the web page can go forward. * @since 8 + * @deprecated since 9 */ accessForward(): boolean; @@ -1258,18 +1280,21 @@ declare class WebCookie { * @param step The number of steps. * * @since 8 + * @deprecated since 9 */ accessStep(step: number): boolean; /** * Goes back in the history of the web page. * @since 8 + * @deprecated since 9 */ backward(); /** * Goes forward in the history of the web page. * @since 8 + * @deprecated since 9 */ forward(); @@ -1322,6 +1347,7 @@ declare class WebCookie { /** * Defines the Web options. * @since 8 + * @deprecated since 9 */ declare interface WebOptions { /** @@ -1333,12 +1359,13 @@ declare interface WebOptions { * Sets the controller of the Web. * @since 8 */ - controller: WebController; + controller: WebController | WebviewController; } /** * Defines the Web interface. * @since 8 + * @deprecated since 9 */ interface WebInterface { /** diff --git a/api/@ohos.web.webview.d.ts b/api/@ohos.web.webview.d.ts index 0b01063a094c741014465ea2d2b61741ba18874d..5be1c6e71f7d9cbeba1c47229e3b5cf69a33ea5b 100644 --- a/api/@ohos.web.webview.d.ts +++ b/api/@ohos.web.webview.d.ts @@ -13,7 +13,115 @@ * limitations under the License. */ +/// + import {AsyncCallback} from "./basic"; +import {Resource} from 'GlobalResource'; + +/** + * Defines the Web's request/response header. + * + * @since 8 + */ + declare interface Header { + /** + * Gets the key of the request/response header. + * + * @since 8 + */ + headerKey: string; + + /** + * Gets the value of the request/response header. + * + * @since 8 + */ + headerValue: string; +} + +/** + * Enum type supplied to {@link getHitTest} for indicating the cursor node HitTest. + * + * @since 8 + */ + declare enum HitTestTypeV9 { + /** + * The edit text. + * + * @since 8 + */ + EditText, + + /** + * The email address. + * + * @since 8 + */ + Email, + + /** + * The HTML::a tag with src=http. + * + * @since 8 + */ + HttpAnchor, + + /** + * The HTML::a tag with src=http + HTML::img. + * + * @since 8 + */ + HttpAnchorImg, + + /** + * The HTML::img tag. + * + * @since 8 + */ + Img, + + /** + * The map address. + * + * @since 8 + */ + Map, + + /** + * The phone number. + * + * @since 8 + */ + Phone, + + /** + * Other unknown HitTest. + * + * @since 8 + */ + Unknown, +} + +/** + * Defines the hit test value, related to {@link getHitTestValue} method. + * @since 9 + */ +declare interface HitTestValue { + + /** + * get the hit test type. + * + * @since 9 + */ + type: HitTestTypeV9; + + /** + * get the hit test extra data. + * + * @since 9 + */ + extra: string; +} /** * This module provides the capability to manage web modules. @@ -47,10 +155,12 @@ declare namespace webview { * @since 9 */ static deleteAllData() : void; - + /** * delete the storage data with the origin. * @param 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,6 +168,8 @@ declare namespace webview { /** * Get current all the web storage origins. * + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100015 - Invaild web storage origin. * @since 9 */ static getOrigins() : Promise>; @@ -66,6 +178,8 @@ declare namespace webview { /** * Get the web storage quota with the origin. * @param 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; @@ -74,6 +188,8 @@ declare namespace webview { /** * Get the web storage quota with the origin. * @param 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 ; @@ -94,29 +210,31 @@ declare namespace webview { * @since 9 */ static existHttpAuthCredentials(): boolean; - + /** * 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. + * @throws {BusinessError} 401 - Invaild input parameter. * @return 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. + * @throws {BusinessError} 401 - Invaild input parameter. * * @since 9 */ @@ -180,6 +298,8 @@ declare namespace webview { /** * Allow geolocation permissions for specifies source. * @param origin url source. + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100011 - Invaild permission origin. * * @since 9 */ @@ -188,6 +308,8 @@ declare namespace webview { /** * Delete geolocation permissions for specifies source. * @param origin url source. + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100011 - Invaild permission origin. * * @since 9 */ @@ -203,6 +325,8 @@ declare namespace webview { /** * Gets the geolocation permission status of the specified source. * @param origin url source. + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100011 - Invaild permission origin. * @return Return whether there is a saved result. * * @since 9 @@ -212,6 +336,7 @@ declare namespace webview { /** * Get all stored geolocation permission url source. + * @throws {BusinessError} 401 - Invaild input parameter. * @return Return whether there is a saved result. * * @since 9 @@ -230,6 +355,8 @@ declare namespace webview { * Gets all cookies for the given URL. * * @param 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 @@ -241,20 +368,20 @@ declare namespace webview { * * @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. + * @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. @@ -271,6 +398,7 @@ declare namespace webview { * * @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. + * @throws {BusinessError} 401 - Invaild input parameter. * * @since 9 */ @@ -290,6 +418,7 @@ declare namespace webview { * By default this is set to be true. * * @param accept Whether the instance should send and accept cookies. + * @throws {BusinessError} 401 - Invaild input parameter. * * @since 9 */ @@ -309,6 +438,7 @@ declare namespace webview { * By default this is set to be true. * * @param accept Whether the instance should send and accept thirdparty cookies. + * @throws {BusinessError} 401 - Invaild input parameter. * * @since 9 */ @@ -332,11 +462,353 @@ 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. + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100010 - Can not post message using this port. + * + * @since 9 + */ + postMessageEvent(message: WebMessageEvent): void; + + /** + * Receive message from other port. + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100010 - Can not post message using this port. + * + * @since 9 + */ + onMessageEvent(callback: (result: string) => void): void; + } + + /** + * Provides methods for controlling the web controller. + * + * @since 9 + */ + class WebviewController { + /** + * Constructor. + * + * @since 8 + */ + constructor(); + + /** + * Checks whether the web page can go forward. + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @returns True if the web page can go forward else false. + * + * @since 8 + */ + 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 True if the web page can go back else false. + * + * @since 8 + */ + accessBackward(): boolean; + + /** + * Checks whether the web page can go back or forward the given number of steps. + * + * @param 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 True if the web page can go back else false. + * + * @since 8 + */ + 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} 17100016 - Invalid back or forward operation. + * + * @since 8 + */ + 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} 17100016 - Invalid back or forward operation. + * + * @since 8 + */ + backward(): void; + + /** + * Clears the history in the Web. + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 8 + */ + clearHistory(): void; + + /** + * Let the Web active. + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 8 + */ + onActive(): void; + + /** + * Let the Web inactive. + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 8 + */ + onInactive(): void; + + /** + * Refreshes the current URL. + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @since 8 + */ + refresh(): void; + + /** + * Loads the data or URL. + * + * @param data A string encoded according to "Base64" or "URL". + * @param mimeType Media type. For example: "text/html". + * @param encoding Encoding type. For example: "UTF-8". + * @param baseUrl A specified URL path ("http"/"https"/"data" protocol), + * which is assigned to window.origin by the Web component. + * @param 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 8 + */ + loadData(data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string): void; + + /** + * Loads the data or URL. + * + * @param url The URL to load. + * @param 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 8 + */ + 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 The type of HitTest. + * + * @since 8 + */ + getHitTest(): HitTestTypeV9; + + /** + * 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. + * @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 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; + + /** + * 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. + * @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. + * + * @since 9 + */ + storeWebArchive(baseName: string, autoName: boolean, callback : AsyncCallback): 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. + * + * @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. + * + * @since 9 + */ + getWebId(): number; + + /** + * Gets the default user agent. + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @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. + * + * @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. + * + * @since 9 + */ + getPageHeight(): number; + + /** + * Goes forward or back backOrForward in the history of the web page. + * + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws {BusinessError} 17100016 - 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 8 + */ + requestFocus(): void; + + /** + * Create web message ports + * + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * @throws {BusinessError} 17100028 - Create message port failed. + * @returns 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 options The options with a message event and a uri. + * @throws {BusinessError} 401 - Invaild input parameter. + * @throws {BusinessError} 17100001 - Init error. + * The WebviewController must be associted with a Web component. + * + * @since 9 + */ + postMessage(options: { message: WebMessageEvent, uri: string}): void; + } } export default webview;