1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * Enum type supplied to {@link getMessageLevel} for receiving the console log level of JavaScript. 18 * @since 8 19 */ 20declare enum MessageLevel { 21 /** 22 * Debug level. 23 * @since 8 24 */ 25 Debug, 26 27 /** 28 * Error level. 29 * @since 8 30 */ 31 Error, 32 33 /** 34 * Info level. 35 * @since 8 36 */ 37 Info, 38 39 /** 40 * Log level. 41 * @since 8 42 */ 43 Log, 44 45 /** 46 * Warn level. 47 * @since 8 48 */ 49 Warn, 50} 51 52/** 53 * The Web's behavior to load from HTTP or HTTPS. Defaults to MixedMode.None. 54 * @since 8 55 */ 56declare enum MixedMode { 57 /** 58 * Allows all sources. 59 * @since 8 60 */ 61 All, 62 63 /** 64 * Allows sources Compatibly. 65 * @since 8 66 */ 67 Compatible, 68 69 /** 70 * Don't allow unsecure sources from a secure origin. 71 * @since 8 72 */ 73 None, 74} 75 76/** 77 * Enum type supplied to {@link getHitTest} for indicating the cursor node HitTest. 78 * @since 8 79 */ 80declare enum HitTestType { 81 /** 82 * The edit text. 83 * @since 8 84 */ 85 EditText, 86 87 /** 88 * The email address. 89 * @since 8 90 */ 91 Email, 92 93 /** 94 * The HTML::a tag with src=http. 95 * @since 8 96 */ 97 HttpAnchor, 98 99 /** 100 * The HTML::a tag with src=http + HTML::img. 101 * @since 8 102 */ 103 HttpAnchorImg, 104 105 /** 106 * The HTML::img tag. 107 * @since 8 108 */ 109 Img, 110 111 /** 112 * The map address. 113 * @since 8 114 */ 115 Map, 116 117 /** 118 * The phone number. 119 * @since 8 120 */ 121 Phone, 122 123 /** 124 * Other unknown HitTest. 125 * @since 8 126 */ 127 Unknown, 128} 129 130/** 131 * Enum type supplied to {@link cacheMode} for setting the Web cache mode. 132 * @since 8 133 */ 134declare enum CacheMode { 135 /** 136 * load online and not cache. 137 * @since 8 138 */ 139 None, 140 141 /** 142 * Load cache first, then online. 143 * @since 8 144 */ 145 Online, 146 147 /** 148 * load cache and not online. 149 * @since 8 150 */ 151 Only, 152} 153 154/** 155 * Defines the js result. 156 * @since 8 157 */ 158declare class JsResult { 159 /** 160 * Constructor. 161 * @since 8 162 */ 163 constructor(); 164 165 /** 166 * Handle the user's JavaScript result if cancel the dialog. 167 * @since 8 168 */ 169 handleCancel(): void; 170 171 /** 172 * Handle the user's JavaScript result if confirm the dialog. 173 * @since 8 174 */ 175 handleConfirm(): void; 176} 177 178/** 179 * Encompassed message information as parameters to {@link onConsole} method. 180 * @since 8 181 */ 182declare class ConsoleMessage { 183 /** 184 * Constructor. 185 * @param message The console message. 186 * @param sourceId The Web source file's path and name. 187 * @param lineNumber The line number of the console message. 188 * @param messageLevel The console log level. 189 * 190 * @since 8 191 */ 192 constructor(message: string, sourceId: string, lineNumber: number, messageLevel: MessageLevel); 193 194 /** 195 * Gets the message of a console message. 196 * @return Return the message of a console message. 197 * 198 * @since 8 199 */ 200 getMessage(): string; 201 202 /** 203 * Gets the Web source file's path and name of a console message. 204 * @return Return the Web source file's path and name of a console message. 205 * 206 * @since 8 207 */ 208 getSourceId(): string; 209 210 /** 211 * Gets the line number of a console message. 212 * @return Return the line number of a console message. 213 * 214 * @since 8 215 */ 216 getLineNumber(): number; 217 218 /** 219 * Gets the message level of a console message. 220 * @return Return the message level of a console message, which can be {@link MessageLevel}. 221 * 222 * @since 8 223 */ 224 getMessageLevel(): MessageLevel; 225} 226 227/** 228 * Defines the Web resource request. 229 * @since 8 230 */ 231declare class WebResourceRequest { 232 /** 233 * Constructor. 234 * @since 8 235 */ 236 constructor(); 237 238 /** 239 * Gets request headers. 240 * @return Return the request headers 241 * 242 * @since 8 243 */ 244 getRequestHeader(): Array<Header>; 245 246 /** 247 * Gets the request URL. 248 * @return Return the request URL. 249 * 250 * @since 8 251 */ 252 getRequestUrl(): string; 253 254 /** 255 * Check whether the request is associated with gesture. 256 * @return Return {@code true} if the request is associated with gesture;return {@code false} otherwise. 257 * 258 * @since 8 259 */ 260 isRequestGesture(): boolean; 261 262 /** 263 * Check whether the request is for getting the main frame. 264 * @return Return {@code true} if the request is associated with gesture for getting the main frame; return {@code false} otherwise. 265 * 266 * @since 8 267 */ 268 isMainFrame(): boolean; 269 270 /** 271 * Check whether the request redirects. 272 * @return Return {@code true} if the request redirects; return {@code false} otherwise. 273 * 274 * @since 8 275 */ 276 isRedirect(): boolean; 277} 278 279/** 280 * Defines the Web resource response. 281 * @since 8 282 */ 283 declare class WebResourceResponse { 284 /** 285 * Constructor. 286 * @since 8 287 */ 288 constructor(); 289 290 /** 291 * Gets the response data. 292 * @return Return the response data. 293 * 294 * @since 8 295 */ 296 getResponseData(): string; 297 298 /** 299 * Gets the response encoding. 300 * @return Return the response encoding. 301 * 302 * @since 8 303 */ 304 getResponseEncoding(): string; 305 306 /** 307 * Gets the response MIME type. 308 * @return Return the response MIME type. 309 * 310 * @since 8 311 */ 312 getResponseMimeType(): string; 313 314 /** 315 * Gets the reason message. 316 * @return Return the reason message. 317 * 318 * @since 8 319 */ 320 getReasonMessage(): string; 321 322 /** 323 * Gets the response headers. 324 * @return Return the response headers. 325 * 326 * @since 8 327 */ 328 getResponseHeader() : Array<Header>; 329 330 /** 331 * Gets the response code. 332 * @return Return the response code. 333 * 334 * @since 8 335 */ 336 getResponseCode(): number; 337} 338 339/** 340 * Defines the Web's request/response header. 341 * @since 8 342 */ 343declare interface Header { 344 /** 345 * Gets the key of the request/response header. 346 * @since 8 347 */ 348 headerKey: string; 349 350 /** 351 * Gets the value of the request/response header. 352 * @since 8 353 */ 354 headerValue: string; 355} 356 357/** 358 * Defines the Web resource error. 359 * @since 8 360 */ 361declare class WebResourceError { 362 /** 363 * Constructor. 364 * @since 8 365 */ 366 constructor(); 367 368 /** 369 * Gets the info of the Web resource error. 370 * @return Return the info of the Web resource error. 371 * 372 * @since 8 373 */ 374 getErrorInfo(): string; 375 376 /** 377 * Gets the code of the Web resource error. 378 * @return Return the code of the Web resource error. 379 * 380 * @since 8 381 */ 382 getErrorCode(): number; 383} 384 385/** 386 * Defines the js geolocation request. 387 * @since 8 388 */ 389declare class JsGeolocation { 390 /** 391 * Constructor. 392 * @since 8 393 */ 394 constructor(); 395 396 /** 397 * Report the geolocation permission status from users. 398 * @param origin The origin that ask for the geolocation permission. 399 * @param allow The geolocation permission status. 400 * @param retain Whether to allow the geolocation permission status to be saved to the system. 401 * 402 * @since 8 403 */ 404 invoke(origin: string, allow: boolean, retain: boolean): void; 405} 406 407/** 408 * Defines the Web cookie. 409 * @since 8 410 */ 411declare class WebCookie { 412 /** 413 * Constructor. 414 * @since 8 415 */ 416 constructor(); 417 418 /** 419 * Sets the cookie. 420 * @since 8 421 */ 422 setCookie(); 423 424 /** 425 * Saves the cookies. 426 * @since 8 427 */ 428 saveCookie(); 429} 430 431/** 432 * Defines the Web controller. 433 * @since 8 434 */ 435 declare class WebController { 436 /** 437 * Constructor. 438 * @since 8 439 */ 440 constructor(); 441 442 /** 443 * Let the Web inactive. 444 * @since 8 445 */ 446 onInactive(): void; 447 448 /** 449 * Let the Web active. 450 * @since 8 451 */ 452 onActive(): void; 453 454 /** 455 * Let the Web zoom by. 456 * @param factor The zoom factor. 457 * 458 * @since 8 459 */ 460 zoom(factor: number): void; 461 462 /** 463 * Clears the history in the Web. 464 * @since 8 465 */ 466 clearHistory(): void; 467 468 /** 469 * Loads a piece of code and execute JS code in the context of the currently displayed page. 470 * @param options The options with a piece of code and a callback. 471 * 472 * @since 8 473 */ 474 runJavaScript(options: { script: string, callback?: (result: string) => void }); 475 476 /** 477 * Loads the data or URL. 478 * @param options The options with the data or URL and other information. 479 * 480 * @since 8 481 */ 482 loadData(options: { data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string }); 483 484 /** 485 * Loads the given URL. 486 * @param options The options with the URL and other information. 487 * 488 * @since 8 489 */ 490 loadUrl(options: { url: string | Resource, headers?: Array<Header> }); 491 492 /** 493 * refreshes the current URL. 494 * @since 8 495 */ 496 refresh(); 497 498 /** 499 * Stops the current load. 500 * @since 8 501 */ 502 stop(); 503 504 /** 505 * Registers the JavaScript object and method list. 506 * @param options The option with the JavaScript object and method list. 507 * 508 * @since 8 509 */ 510 registerJavaScriptProxy(options: { object: object, name: string, methodList: Array<string> }); 511 512 /** 513 * Deletes a registered JavaScript object with given name. 514 * @param name The name of a registered JavaScript object to be deleted. 515 * 516 * @since 8 517 */ 518 deleteJavaScriptRegister(name: string); 519 520 /** 521 * Gets the type of HitTest. 522 * @since 8 523 */ 524 getHitTest(): HitTestType; 525 526 /** 527 * Gets the request focus. 528 * @since 8 529 */ 530 requestFocus(); 531 532 /** 533 * Checks whether the web page can go back. 534 * @since 8 535 */ 536 accessBackward(): boolean; 537 538 /** 539 * Checks whether the web page can go forward. 540 * @since 8 541 */ 542 accessForward(): boolean; 543 544 /** 545 * Checks whether the web page can go back or forward the given number of steps. 546 * @param step The number of steps. 547 * 548 * @since 8 549 */ 550 accessStep(step: number): boolean; 551 552 /** 553 * Goes back in the history of the web page. 554 * @since 8 555 */ 556 backward(); 557 558 /** 559 * Goes forward in the history of the web page. 560 * @since 8 561 */ 562 forward(); 563} 564 565/** 566 * Defines the Web options. 567 * @since 8 568 */ 569declare interface WebOptions { 570 /** 571 * Sets the address of the web page to be displayed. 572 * @since 8 573 */ 574 src: string | Resource; 575 /** 576 * Sets the controller of the Web. 577 * @since 8 578 */ 579 controller: WebController; 580} 581 582/** 583 * Defines the Web interface. 584 * @since 8 585 */ 586interface WebInterface { 587 /** 588 * Sets Value. 589 * @since 8 590 */ 591 (value: WebOptions): WebAttribute; 592} 593 594/** 595 * Defines the Web attribute functions. 596 * @since 8 597 */ 598declare class WebAttribute extends CommonMethod<WebAttribute> { 599 /** 600 * Sets whether the Web allows JavaScript scripts to execute. 601 * @param javaScriptAccess {@code true} means the Web can allows JavaScript scripts to execute; {@code false} otherwise. 602 * 603 * @since 8 604 */ 605 javaScriptAccess(javaScriptAccess: boolean): WebAttribute; 606 607 /** 608 * Sets whether enable local file system access in Web. 609 * @param fileAccess {@code true} means enable local file system access in Web; {@code false} otherwise. 610 * 611 * @since 8 612 */ 613 fileAccess(fileAccess: boolean): WebAttribute; 614 615 /** 616 * Sets whether to allow image resources to be loaded from the network. 617 * @param onlineImageAccess {@code true} means the Web can allow image resources to be loaded from the network; 618 * {@code false} otherwise. 619 * 620 * @since 8 621 */ 622 onlineImageAccess(onlineImageAccess: boolean): WebAttribute; 623 624 /** 625 * Sets whether to enable the DOM Storage API permission. 626 * @param domStorageAccess {@code true} means enable the DOM Storage API permission in Web; {@code false} otherwise. 627 * 628 * @since 8 629 */ 630 domStorageAccess(domStorageAccess: boolean): WebAttribute; 631 632 /** 633 * Sets whether the Web can automatically load image resources. 634 * @param imageAccess {@code true} means the Web can automatically load image resources; {@code false} otherwise. 635 * 636 * @since 8 637 */ 638 imageAccess(imageAccess: boolean): WebAttribute; 639 640 /** 641 * Sets how to load HTTP and HTTPS content. 642 * @param mixedMode The mixed mode, which can be {@link MixedMode}. 643 * 644 * @since 8 645 */ 646 mixedMode(mixedMode: MixedMode): WebAttribute; 647 648 /** 649 * Sets whether the Web supports zooming using gestures. 650 * @param zoomAccess {@code true} means the Web supports zooming using gestures; {@code false} otherwise. 651 * 652 * @since 8 653 */ 654 zoomAccess(zoomAccess: boolean): WebAttribute; 655 656 /** 657 * Sets whether to allow access to geographical locations. 658 * @param geolocationAccess {@code true} means the Web allows access to geographical locations; {@code false} otherwise. 659 * 660 * @since 8 661 */ 662 geolocationAccess(geolocationAccess: boolean): WebAttribute; 663 664 /** 665 * Injects the JavaScript object into window and invoke the function in window. 666 * @param javaScriptProxy The JavaScript object to be injected. 667 * 668 * @since 8 669 */ 670 javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array<string>, 671 controller: WebController }): WebAttribute; 672 673 /** 674 * Sets whether the Web should save the password. 675 * @param password {@code true} means the Web can save the password; {@code false} otherwise. 676 * 677 * @since 8 678 */ 679 password(password: boolean): WebAttribute; 680 681 /** 682 * Sets the mode of cache in Web. 683 * @param cacheMode The cache mode, which can be {@link CacheMode}. 684 * 685 * @since 8 686 */ 687 cacheMode(cacheMode: CacheMode): WebAttribute; 688 689 /** 690 * Sets whether the Web should save the table data. 691 * @param tableData {@code true} means the Web can save the table data; {@code false} otherwise. 692 * 693 * @since 8 694 */ 695 tableData(tableData: boolean): WebAttribute; 696 697 /** 698 * Sets whether the Web access meta 'viewport' in HTML. 699 * @param wideViewModeAccess {@code true} means the Web access meta 'viewport' in HTML; {@code false} otherwise. 700 * 701 * @since 8 702 */ 703 wideViewModeAccess(wideViewModeAccess: boolean): WebAttribute; 704 705 /** 706 * Sets whether the Web access overview mode. 707 * @param overviewModeAccess {@code true} means the Web access overview mode; {@code false} otherwise. 708 * 709 * @since 8 710 */ 711 overviewModeAccess(overviewModeAccess: boolean): WebAttribute; 712 713 /** 714 * Sets the atio of the text zoom. 715 * @param textZoomAtio The atio of the text zoom. 716 * 717 * @since 8 718 */ 719 textZoomAtio(textZoomAtio: number): WebAttribute; 720 721 /** 722 * Sets whether the Web access the database. 723 * @param databaseAccess {@code true} means the Web access the database; {@code false} otherwise. 724 * 725 * @since 8 726 */ 727 databaseAccess(databaseAccess: boolean): WebAttribute; 728 729 /** 730 * Sets the Web's user agent. 731 * @param userAgent The Web's user agent. 732 * 733 * @since 8 734 */ 735 userAgent(userAgent: string): WebAttribute; 736 737 /** 738 * Triggered at the end of web page loading. 739 * @param callback The triggered function at the end of web page loading. 740 * 741 * @since 8 742 */ 743 onPageEnd(callback: (event?: { url: string }) => void): WebAttribute; 744 745 /** 746 * Triggered at the begin of web page loading. 747 * @param callback The triggered function at the begin of web page loading. 748 * 749 * @since 8 750 */ 751 onPageBegin(callback: (event?: { url: string }) => void): WebAttribute; 752 753 /** 754 * Triggered when the page loading progress changes. 755 * @param callback The triggered function when the page loading progress changes. 756 * 757 * @since 8 758 */ 759 onProgressChange(callback: (event?: { newProgress: number }) => void): WebAttribute; 760 761 /** 762 * Triggered when the title of the main application document changes. 763 * @param callback The triggered function when the title of the main application document changes. 764 * 765 * @since 8 766 */ 767 onTitleReceive(callback: (event?: { title: string }) => void): WebAttribute; 768 769 /** 770 * Triggered when requesting to hide the geolocation. 771 * @param callback The triggered function when requesting to hide the geolocation permission. 772 * 773 * @since 8 774 */ 775 onGeolocationHide(callback: () => void): WebAttribute; 776 777 /** 778 * Triggered when requesting to show the geolocation permission. 779 * @param callback The triggered function when requesting to show the geolocation permission. 780 * 781 * @since 8 782 */ 783 onGeolocationShow(callback: (event?: { origin: string, geolocation: JsGeolocation }) => void): WebAttribute; 784 785 /** 786 * Triggered when the Web gets the focus. 787 * @param callback The triggered function when the Web gets the focus. 788 * 789 * @since 8 790 */ 791 onRequestSelected(callback: () => void): WebAttribute; 792 793 /** 794 * Triggered when the Web wants to display a JavaScript alert() dialog. 795 * @param callback The triggered function when the web page wants to display a JavaScript alert() dialog. 796 * 797 * @since 8 798 */ 799 onAlert(callback: (event?: { url: string, message: string, result: JsResult }) => boolean): WebAttribute; 800 801 /** 802 * Triggered when the Web wants to confirm navigation from JavaScript onbeforeunload. 803 * @param callback The triggered function when the web page wants to confirm navigation from JavaScript onbeforeunload. 804 * 805 * @since 8 806 */ 807 onBeforeUnload(callback: (event?: { url: string, message: string, result: JsResult }) => boolean): WebAttribute; 808 809 /** 810 * Triggered when the web page wants to display a JavaScript confirm() dialog. 811 * @param callback The Triggered function when the web page wants to display a JavaScript confirm() dialog. 812 * 813 * @since 8 814 */ 815 onConfirm(callback: (event?: { url: string, message: string, result: JsResult }) => boolean): WebAttribute; 816 817 /** 818 * Triggered when the web page receives a JavaScript console message. 819 * @param callback The triggered function when the web page receives a JavaScript console message. 820 * 821 * @since 8 822 */ 823 onConsole(callback: (event?: { message: ConsoleMessage }) => boolean): WebAttribute; 824 825 /** 826 * Triggered when the web page receives a web resource loading error. 827 * @param callback The triggered function when the web page receives a web resource loading error. 828 * 829 * @since 8 830 */ 831 onErrorReceive(callback: (event?: { request: WebResourceRequest, error: WebResourceError }) => void): WebAttribute; 832 833 /** 834 * Triggered when the web page receives a web resource loading HTTP error. 835 * @param callback The triggered function when the web page receives a web resource loading HTTP error. 836 * 837 * @since 8 838 */ 839 onHttpErrorReceive(callback: (event?: { request: WebResourceRequest, 840 response: WebResourceResponse }) => void): WebAttribute; 841 842 /** 843 * Triggered when starting to download. 844 * @param callback The triggered function when starting to download. 845 * 846 * @since 8 847 */ 848 onDownloadStart(callback: (event?: { url: string, userAgent: string, contentDisposition: string, mimetype: string, 849 contentLength: number }) => void): WebAttribute; 850 851 /** 852 * Triggered when the Web page refreshes accessed history. 853 * @param callback The triggered callback when the Web page refreshes accessed history. 854 * 855 * @since 8 856 */ 857 onRefreshAccessedHistory(callback: (event?: { url: string, refreshed: boolean }) => void): WebAttribute; 858 859 /** 860 * Triggered when the URL loading is intercepted. 861 * @param callback The triggered callback when the URL loading is intercepted. 862 * 863 * @since 8 864 */ 865 onUrlLoadIntercept(callback: (event?: { data: string | WebResourceRequest }) => boolean): WebAttribute; 866 867 /** 868 * Triggered when the Web page receives an ssl Error. 869 * @param callback The triggered callback when the Web page receives an ssl Error. 870 * 871 * @since 8 872 */ 873 onSslErrorReceive(callback: (event?: { handler: Function, error: object }) => void): WebAttribute; 874 875 /** 876 * Triggered when the render process exits. 877 * @param callback The triggered when the render process exits. 878 * 879 * @since 8 880 */ 881 onRenderExited(callback: (event?: { detail: object }) => boolean): WebAttribute; 882 883 /** 884 * Triggered when the file selector shows. 885 * @param callback The triggered when the file selector shows. 886 * 887 * @since 8 888 */ 889 onFileSelectorShow(callback: (event?: { callback: Function, fileSelector: object }) => void): WebAttribute; 890} 891 892declare const Web: WebInterface; 893declare const WebInstance: WebAttribute;