From 6d1348eb85182bbf7b0ad240937c8b5b2025748e Mon Sep 17 00:00:00 2001 From: lixingchi1 Date: Mon, 7 Mar 2022 17:18:54 +0800 Subject: [PATCH] sync the Web code. Signed-off-by: lixingchi1 --- api/@internal/component/ets/web.d.ts | 238 ++++++++++++++++++++++----- 1 file changed, 199 insertions(+), 39 deletions(-) diff --git a/api/@internal/component/ets/web.d.ts b/api/@internal/component/ets/web.d.ts index d75f2cda11..eba8d735d8 100755 --- a/api/@internal/component/ets/web.d.ts +++ b/api/@internal/component/ets/web.d.ts @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + declare enum MessageLevel { /** * Debug level. @@ -27,9 +42,13 @@ declare enum MessageLevel { * Warn level. * @since 8 */ - Warn + Warn, } +/** + * Defines the mixed mode. + * @since 8 + */ declare enum MixedMode { /** * Allows all sources. @@ -97,26 +116,37 @@ declare enum HitTestType { * Other unknown hit test. * @since 8 */ - Unknown + Unknown, } +/** + * Defines the cache mode interface. + * @since 8 + */ declare enum CacheMode { /** * load online and not cache. + * @since 8 */ None, /** * Load cache first, then online. + * @since 8 */ Online, /** * load cache and not online. + * @since 8 */ - Only + Only, } +/** + * Defines the js result. + * @since 8 + */ declare class JsResult { /** * Constructor. @@ -137,6 +167,10 @@ declare class JsResult { handleConfirm(): void; } +/** + * Defines the console message. + * @since 8 + */ declare class ConsoleMessage { /** * Constructor. @@ -177,6 +211,10 @@ declare class ConsoleMessage { getMessageLevel(): MessageLevel; } +/** + * Defines the web resource request. + * @since 8 + */ declare class WebResourceRequest { /** * Constructor. @@ -225,6 +263,70 @@ declare class WebResourceRequest { isRedirect(): boolean; } + +/** + * Defines the web resource response. + * @since 8 + */ + declare class WebResourceResponse { + /** + * Constructor. + * @since 8 + */ + constructor(); + + /** + * Get the response data. + * + * @return Return the response data. + * @since 8 + */ + getResponseData(): string; + + /** + * Get the response encoding. + * + * @return Return the response encoding. + * @since 8 + */ + getResponseEncoding(): string; + + /** + * Get the response mime type. + * + * @return Return the response mime type. + * @since 8 + */ + getResponseMimeType(): string; + + /** + * Get the reason message. + * + * @return Return the reason message. + * @since 8 + */ + getReasonMessage(): string; + + /** + * Get the response headers. + * @return Return the response headers. + * @since 8 + */ + getResponseHeader() : Map; + + /** + * Get the response code. + * + * @return Return the response code. + * @since 8 + */ + getResponseCode(): number; +} + +/** + * Defines the web resource error. + * @since 8 + */ declare class WebResourceError { /** * Constructor. @@ -249,6 +351,10 @@ declare class WebResourceError { getErrorCode(): number; } +/** + * Defines the js geolocation request. + * @since 8 + */ declare class JsGeolocation { /** * Constructor. @@ -258,7 +364,7 @@ declare class JsGeolocation { /** * Report the geolocation permission status from users. - * + * * @param origin The origin that ask for the geolocation permission. * @param allow The geolocation permission status. * @param retain Whether to allow the geolocation permission status to be saved to the system. @@ -267,6 +373,10 @@ declare class JsGeolocation { invoke(origin: string, allow: boolean, retain: boolean): void; } +/** + * Defines the js web cookie. + * @since 8 + */ declare class WebCookie { /** * Constructor. @@ -287,6 +397,10 @@ declare class WebCookie { saveCookie(); } +/** + * Defines the web controller. + * @since 8 + */ declare class WebController { /** * Constructor. @@ -306,6 +420,14 @@ declare class WebController { */ onActive(): void; + /** + * Let the Web zoom by. + * @param factor The zoom factor. + * + * @since 8 + */ + zoom(factor: number): void; + /** * Clear the history in the Web. * @since 8 @@ -316,19 +438,19 @@ declare class WebController { * Means to load a piece of code and execute JS code in the context of the currently displayed page * @since 8 */ - runJavaScript(options: { script: string, callback?: (result: string) => void }); + runJavaScript(options: { script: string; callback?: (result: string) => void }); /** * Indicates that a piece of code is loaded * @since 8 */ - loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }); + loadData(options: { data: string; mimeType: string; encoding: string; baseUrl?: string; historyUrl?: string }); /** * Load the given URL * @since 8 */ - loadUrl(options: {url: string, headers?: Array<{ key: string, value: string }> }); + loadUrl(options: { url: string; headers?: Array<{ key: string; value: string }> }); /** * refreshes the current URL. @@ -346,7 +468,7 @@ declare class WebController { * Registers the JavaScript object and method list. * @since 8 */ - registerJavaScriptProxy(options: { obj: object, name: string, methodList: Array }); + registerJavaScriptProxy(options: { obj: object; name: string; methodList: Array }); /** * Deletes a registered JavaScript object with given name. @@ -367,46 +489,57 @@ declare class WebController { requestFocus(); /** - * Check whether the web page can go back - * @since 8 - */ + * Check whether the web page can go back + * @since 8 + */ accessBackward(): boolean; /** - * Check whether the web page can go forward - * @since 8 - */ + * Check whether the web page can go forward + * @since 8 + */ accessForward(): boolean; /** - * Check whether the web page can go back or forward the given number of steps - * @since 8 - */ + * Check whether the web page can go back or forward the given number of steps + * @since 8 + */ accessStep(step: number): boolean; /** - * Go back in the history of the web - * @since 8 - */ + * Go back in the history of the web + * @since 8 + */ backward(); /** - * Go forward in the history of the web - * @since 8 - */ + * Go forward in the history of the web + * @since 8 + */ forward(); - } +/** + * Defines the web options. + * @since 8 + */ declare interface WebOptions { /** - * Set the address of the web page to be displayed + * Set the address of the web page to be displayed. * @since 8 */ src: string | Resource; + /** + * Set the controller of the web. + * @since 8 + */ controller: WebController; } +/** + * Defines the web interface. + * @since 8 + */ interface WebInterface { /** * Set Value. @@ -415,6 +548,10 @@ interface WebInterface { (value: WebOptions): WebAttribute; } +/** + * Defines the web attribute functions. + * @since 8 + */ declare class WebAttribute extends CommonMethod { /** * Set whether WebView allows JavaScript scripts to execute @@ -468,9 +605,14 @@ declare class WebAttribute extends CommonMethod { * Inject the arkUI JS object into H5 and invoke the function of the object in H5. * @since 8 */ - javaScriptProxy(javaScriptProxy: { obj: object, name: string, methodList: Array }): WebAttribute; + javaScriptProxy(javaScriptProxy: { + obj: object; + name: string; + methodList: Array; + controller: WebController; + }): WebAttribute; - /* + /** * Sets whether the Web should save the password. * @param password {@code ture} means the Web can save the password; {@code false} otherwise. * @@ -526,6 +668,14 @@ declare class WebAttribute extends CommonMethod { */ databaseAccess(databaseAccess: boolean): WebAttribute; + /** + * Sets the Web's user agent. + * @param userAgent The Web's user agent. + * + * @since 8 + */ + userAgent(userAgent: string): WebAttribute; + /** * Triggered at the end of web page loading * @since 8 @@ -558,12 +708,12 @@ declare class WebAttribute extends CommonMethod { /** * Show prompt to ask for the geolocation permission. - * + * * @param origin the origin of the resource to get geolocation. * @param geolocation callback to report geolocation. * @since 8 */ - onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocation }) => void): WebAttribute; + onGeolocationShow(callback: (event?: { origin: string; geolocation: JsGeolocation }) => void): WebAttribute; /** * Get WebView focus callback event @@ -577,7 +727,7 @@ declare class WebAttribute extends CommonMethod { * @param callback The triggered function when the web page wants to display a JavaScript alert() dialog. * @since 8 */ - onAlert(callback: (event?: { url: string, message: string, result: JsResult }) => boolean): WebAttribute; + onAlert(callback: (event?: { url: string; message: string; result: JsResult }) => boolean): WebAttribute; /** * Triggered when the web page wants to confirm navigation from JavaScript onbeforeunload. @@ -585,7 +735,7 @@ declare class WebAttribute extends CommonMethod { * @param callback The triggered function when the web page wants to confirm navigation from JavaScript onbeforeunload. * @since 8 */ - onBeforeUnload(callback: (event?: { message: string, result: JsResult }) => boolean): WebAttribute; + onBeforeUnload(callback: (event?: { message: string; result: JsResult }) => boolean): WebAttribute; /** * Triggered when the web page wants to display a JavaScript confirm() dialog. @@ -593,7 +743,7 @@ declare class WebAttribute extends CommonMethod { * @param callback The Triggered function when the web page wants to display a JavaScript confirm() dialog. * @since 8 */ - onConfirm(callback: (event?: {url: string, message: string, result: JsResult }) => boolean): WebAttribute; + onConfirm(callback: (event?: { url: string; message: string; result: JsResult }) => boolean): WebAttribute; /** * Triggered when the web page receives a JavaScript console message. @@ -601,7 +751,7 @@ declare class WebAttribute extends CommonMethod { * @param callback The triggered function when the web page receives a JavaScript console message. * @since 8 */ - onConsole(callback: (event?: {message: ConsoleMessage}) => boolean): WebAttribute; + onConsole(callback: (event?: { message: ConsoleMessage }) => boolean): WebAttribute; /** * Triggered when the web page receives a web resource loading error. @@ -609,7 +759,7 @@ declare class WebAttribute extends CommonMethod { * @param callback The triggered function when the web page receives a web resource loading error. * @since 8 */ - onErrorReceive(callback: (event?: {request: WebResourceRequest, error: WebResourceError}) => void): WebAttribute; + onErrorReceive(callback: (event?: { request: WebResourceRequest; error: WebResourceError }) => void): WebAttribute; /** * Triggered when the web page receives a web resource loading HTTP error. @@ -617,13 +767,23 @@ declare class WebAttribute extends CommonMethod { * @param callback The triggered function when the web page receives a web resource loading HTTP error. * @since 8 */ - onHttpErrorReceive(callback: (event?: {request: WebResourceRequest, error: WebResourceError}) => void): WebAttribute; + onHttpErrorReceive( + callback: (event?: { request: WebResourceRequest; response: WebResourceResponse }) => void, + ): WebAttribute; /** * Triggered when download start * @since 8 */ - onDownloadStart(callback: (event?: {url: string, userAgent: string, contentDisposition: string, mimetype: string, contentLength: number}) => void): WebAttribute; + onDownloadStart( + callback: (event?: { + url: string; + userAgent: string; + contentDisposition: string; + mimetype: string; + contentLength: number; + }) => void, + ): WebAttribute; /** * Triggered when the Web page refreshes accessed history. @@ -631,7 +791,7 @@ declare class WebAttribute extends CommonMethod { * * @since 8 */ - onRefreshAccessedHistory(callback: (event?: { url: string, refreshed: boolean }) => void): WebAttribute; + onRefreshAccessedHistory(callback: (event?: { url: string; refreshed: boolean }) => void): WebAttribute; /** * Triggered when the url is about to be loaded. @@ -648,7 +808,7 @@ declare class WebAttribute extends CommonMethod { * * @since 8 */ - onSslErrorReceive(callback: (event?: { handler: Function, error: object }) => void): WebAttribute; + onSslErrorReceive(callback: (event?: { handler: Function; error: object }) => void): WebAttribute; /** * Triggered when the render process is exited. @@ -666,7 +826,7 @@ declare class WebAttribute extends CommonMethod { * * @since 8 */ - onFileSelectorShow(callback: (event?: { callback: Function, fileSelector: object }) => void): WebAttribute; + onFileSelectorShow(callback: (event?: { callback: Function; fileSelector: object }) => void): WebAttribute; } declare const Web: WebInterface; -- Gitee