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/// <reference path="../component/units.d.ts" /> 17 18import { AsyncCallback } from './@ohos.base'; 19import { Callback } from './@ohos.base'; 20import { Resource } from 'GlobalResource'; 21import cert from './@ohos.security.cert'; 22import image from './@ohos.multimedia.image'; 23 24/** 25 * This module provides the capability to manage web modules. 26 * 27 * @namespace webview 28 * @syscap SystemCapability.Web.Webview.Core 29 * @since 9 30 */ 31/** 32 * This module provides the capability to manage web modules. 33 * 34 * @namespace webview 35 * @syscap SystemCapability.Web.Webview.Core 36 * @crossplatform 37 * @since 10 38 */ 39declare namespace webview { 40 /** 41 * Defines the Web's request/response header. 42 * 43 * @interface WebHeader 44 * @syscap SystemCapability.Web.Webview.Core 45 * @since 9 46 */ 47 /** 48 * Defines the Web's request/response header. 49 * 50 * @interface WebHeader 51 * @syscap SystemCapability.Web.Webview.Core 52 * @crossplatform 53 * @since 10 54 */ 55 interface WebHeader { 56 /** 57 * Gets the key of the request/response header. 58 * @syscap SystemCapability.Web.Webview.Core 59 * @since 9 60 */ 61 /** 62 * Gets the key of the request/response header. 63 * @syscap SystemCapability.Web.Webview.Core 64 * @crossplatform 65 * @since 10 66 */ 67 headerKey: string; 68 69 /** 70 * Gets the value of the request/response header. 71 * @syscap SystemCapability.Web.Webview.Core 72 * @since 9 73 */ 74 /** 75 * Gets the value of the request/response header. 76 * @syscap SystemCapability.Web.Webview.Core 77 * @crossplatform 78 * @since 9 79 */ 80 headerValue: string; 81 } 82 83 /** 84 * Enum type supplied to {@link getHitTest} for indicating the cursor node HitTest. 85 * @enum {number} 86 * @syscap SystemCapability.Web.Webview.Core 87 * @since 9 88 */ 89 enum WebHitTestType { 90 /** 91 * The edit text. 92 * @syscap SystemCapability.Web.Webview.Core 93 * @since 9 94 */ 95 EditText, 96 97 /** 98 * The email address. 99 * @syscap SystemCapability.Web.Webview.Core 100 * @since 9 101 */ 102 Email, 103 104 /** 105 * The HTML::a tag with src=http. 106 * @syscap SystemCapability.Web.Webview.Core 107 * @since 9 108 */ 109 HttpAnchor, 110 111 /** 112 * The HTML::a tag with src=http + HTML::img. 113 * @syscap SystemCapability.Web.Webview.Core 114 * @since 9 115 */ 116 HttpAnchorImg, 117 118 /** 119 * The HTML::img tag. 120 * @syscap SystemCapability.Web.Webview.Core 121 * @since 9 122 */ 123 Img, 124 125 /** 126 * The map address. 127 * @syscap SystemCapability.Web.Webview.Core 128 * @since 9 129 */ 130 Map, 131 132 /** 133 * The phone number. 134 * @syscap SystemCapability.Web.Webview.Core 135 * @since 9 136 */ 137 Phone, 138 139 /** 140 * Other unknown HitTest. 141 * @syscap SystemCapability.Web.Webview.Core 142 * @since 9 143 */ 144 Unknown 145 } 146 147 /** 148 * Defines the mode for using HttpDns. 149 * @enum {number} 150 * @syscap SystemCapability.Web.Webview.Core 151 * @since 10 152 */ 153 enum SecureDnsMode { 154 /** 155 * Do not use HttpDns, can be used to revoke previously used HttpDns configuration. 156 * @syscap SystemCapability.Web.Webview.Core 157 * @since 10 158 */ 159 OFF = 0, 160 /** 161 * By default, the user-settings of HttpDns is used for dns resolution, and if it fails, 162 * the system dns is used for resolution. 163 * @syscap SystemCapability.Web.Webview.Core 164 * @since 10 165 */ 166 AUTO = 1, 167 /** 168 * Use the user-settings of HttpDns for dns resolution. If it fails, it will not 169 * fall back to the system dns, which will directly cause the page to fail to load. 170 * @syscap SystemCapability.Web.Webview.Core 171 * @since 10 172 */ 173 SECURE_ONLY = 2, 174 } 175 176 /** 177 * Defines the hit test value, related to {@link getHitTestValue} method. 178 * 179 * @interface HitTestValue 180 * @syscap SystemCapability.Web.Webview.Core 181 * @since 9 182 */ 183 interface HitTestValue { 184 185 /** 186 * Get the hit test type. 187 * 188 * @syscap SystemCapability.Web.Webview.Core 189 * @since 9 190 */ 191 type: WebHitTestType; 192 193 /** 194 * Get the hit test extra data. 195 * 196 * @syscap SystemCapability.Web.Webview.Core 197 * @since 9 198 */ 199 extra: string; 200 } 201 202 /** 203 * Defines the configuration of web custom scheme, related to {@link customizeSchemes} method. 204 * 205 * @interface WebCustomScheme 206 * @syscap SystemCapability.Web.Webview.Core 207 * @since 9 208 */ 209 interface WebCustomScheme { 210 211 /** 212 * Name of the custom scheme. 213 * 214 * @syscap SystemCapability.Web.Webview.Core 215 * @since 9 216 */ 217 schemeName: string; 218 219 /** 220 * Whether Cross-Origin Resource Sharing is supported. 221 * 222 * @syscap SystemCapability.Web.Webview.Core 223 * @since 9 224 */ 225 isSupportCORS: boolean; 226 227 /** 228 * Whether fetch request is supported. 229 * 230 * @syscap SystemCapability.Web.Webview.Core 231 * @since 9 232 */ 233 isSupportFetch: boolean; 234 } 235 236 /** 237 * Provides basic information of web storage. 238 * 239 * @interface WebStorageOrigin 240 * @syscap SystemCapability.Web.Webview.Core 241 * @since 9 242 */ 243 interface WebStorageOrigin { 244 origin: string; 245 usage: number; 246 quota: number; 247 } 248 249 /** 250 * Subscribe to a callback of a specified type of web event once. 251 * 252 * @param {string} type Types of web event. 253 * @param {Callback<void>} callback Indicate callback used to receive the web event. 254 * 255 * @throws { BusinessError } 401 - Invalid input parameter. 256 * @syscap SystemCapability.Web.Webview.Core 257 * @since 9 258 */ 259 function once(type: string, callback: Callback<void>): void; 260 261 /** 262 * Provides methods for managing web storage.3 263 * 264 * @syscap SystemCapability.Web.Webview.Core 265 * @since 9 266 */ 267 class WebStorage { 268 /** 269 * Delete all the storage data. 270 * 271 * @syscap SystemCapability.Web.Webview.Core 272 * @since 9 273 */ 274 static deleteAllData(): void; 275 276 /** 277 * Delete the storage data with the origin. 278 * 279 * @param { string } origin - The origin which to be deleted. 280 * @throws { BusinessError } 401 - Invalid input parameter. 281 * @throws { BusinessError } 17100011 - Invalid origin. 282 * @syscap SystemCapability.Web.Webview.Core 283 * @since 9 284 */ 285 static deleteOrigin(origin: string): void; 286 287 /** 288 * Get current all the web storage origins. 289 * @returns { Promise<Array<WebStorageOrigin>> } - returns all the WebStorageOrigin. 290 * @throws { BusinessError } 401 - Invalid input parameter. 291 * @throws { BusinessError } 17100012 - Invalid web storage origin. 292 * @syscap SystemCapability.Web.Webview.Core 293 * @since 9 294 */ 295 static getOrigins(): Promise<Array<WebStorageOrigin>>; 296 297 /** 298 * Get current all the web storage origins. 299 * @param { AsyncCallback<Array<WebStorageOrigin>> } callback - callback used to return all the WebStorageOrigin. 300 * @throws { BusinessError } 401 - Invalid input parameter. 301 * @throws { BusinessError } 17100012 - Invalid web storage origin. 302 * @syscap SystemCapability.Web.Webview.Core 303 * @since 9 304 */ 305 static getOrigins(callback: AsyncCallback<Array<WebStorageOrigin>>): void; 306 307 /** 308 * Get the web storage quota with the origin. 309 * @param { string } origin - The origin which to be inquired. 310 * @returns { Promise<number> } - the promise returned by the function 311 * @throws { BusinessError } 401 - Invalid input parameter. 312 * @throws { BusinessError } 17100011 - Invalid origin. 313 * @syscap SystemCapability.Web.Webview.Core 314 * @since 9 315 */ 316 static getOriginQuota(origin: string): Promise<number>; 317 318 /** 319 * Get the web storage quota with the origin. 320 * @param { string } origin - The origin which to be inquired. 321 * @param { AsyncCallback<number> } callback - the callback of getOriginQuota. 322 * @throws { BusinessError } 401 - Invalid input parameter. 323 * @throws { BusinessError } 17100011 - Invalid origin. 324 * @syscap SystemCapability.Web.Webview.Core 325 * @since 9 326 */ 327 static getOriginQuota(origin: string, callback: AsyncCallback<number>): void; 328 329 /** 330 * Get the web storage quota with the origin. 331 * @param { string } origin - The origin which to be inquired. 332 * @returns { Promise<number> } - the promise returned by the function 333 * @throws { BusinessError } 401 - Invalid input parameter. 334 * @throws { BusinessError } 17100011 - Invalid origin. 335 * @syscap SystemCapability.Web.Webview.Core 336 * @since 9 337 */ 338 static getOriginUsage(origin: string): Promise<number>; 339 340 /** 341 * Get the web storage quota with the origin. 342 * @param { string } origin - The origin which to be inquired. 343 * @param { AsyncCallback<number> } callback - the callback of getOriginUsage. 344 * @throws { BusinessError } 401 - Invalid input parameter. 345 * @throws { BusinessError } 17100011 - Invalid origin. 346 * @syscap SystemCapability.Web.Webview.Core 347 * @since 9 348 */ 349 static getOriginUsage(origin: string, callback: AsyncCallback<number>): void; 350 } 351 352 /** 353 * Provides methods for managing web database. 354 * @syscap SystemCapability.Web.Webview.Core 355 * @since 9 356 */ 357 class WebDataBase { 358 /** 359 * Get whether instances holds any http authentication credentials. 360 * @returns { boolean } true if instances saved any http authentication credentials otherwise false. 361 * @syscap SystemCapability.Web.Webview.Core 362 * @since 9 363 */ 364 static existHttpAuthCredentials(): boolean; 365 366 /** 367 * Delete all http authentication credentials. 368 * 369 * @syscap SystemCapability.Web.Webview.Core 370 * @since 9 371 */ 372 static deleteHttpAuthCredentials(): void; 373 374 /** 375 * Get http authentication credentials. 376 * @param { string } host - The host to which the credentials apply. 377 * @param { string } realm - The realm to which the credentials apply. 378 * @returns { Array<string> } Return an array containing username and password. 379 * @throws { BusinessError } 401 - Invalid input parameter. 380 * @syscap SystemCapability.Web.Webview.Core 381 * @since 9 382 */ 383 static getHttpAuthCredentials(host: string, realm: string): Array<string>; 384 385 /** 386 * Save http authentication credentials. 387 * @param { string } host - The host to which the credentials apply. 388 * @param { string } realm - The realm to which the credentials apply. 389 * @param { string } username - The username. 390 * @param { string } password - The password. 391 * @throws { BusinessError } 401 - Invalid input parameter. 392 * @syscap SystemCapability.Web.Webview.Core 393 * @since 9 394 */ 395 static saveHttpAuthCredentials(host: string, realm: string, username: string, password: string): void; 396 } 397 398 /** 399 * Provides a method for managing web geographic location permissions. 400 * @syscap SystemCapability.Web.Webview.Core 401 * @since 9 402 */ 403 class GeolocationPermissions { 404 /** 405 * Allow geolocation permissions for specifies source. 406 * @param { string } origin - Url source. 407 * @throws { BusinessError } 401 - Invalid input parameter. 408 * @throws { BusinessError } 17100011 - Invalid origin. 409 * @syscap SystemCapability.Web.Webview.Core 410 * @since 9 411 */ 412 static allowGeolocation(origin: string): void; 413 414 /** 415 * Delete geolocation permissions for specifies source. 416 * @param { string } origin - Url source. 417 * @throws { BusinessError } 401 - Invalid input parameter. 418 * @throws { BusinessError } 17100011 - Invalid origin. 419 * @syscap SystemCapability.Web.Webview.Core 420 * @since 9 421 */ 422 static deleteGeolocation(origin: string): void; 423 424 /** 425 * Delete all geolocation permissions. 426 * 427 * @syscap SystemCapability.Web.Webview.Core 428 * @since 9 429 */ 430 static deleteAllGeolocation(): void; 431 432 /** 433 * Gets the geolocation permission status of the specified source. 434 * @param { string } origin - Url source. 435 * @returns { Promise<boolean> } Return whether there is a saved result. 436 * @throws { BusinessError } 401 - Invalid input parameter. 437 * @throws { BusinessError } 17100011 - Invalid origin. 438 * @syscap SystemCapability.Web.Webview.Core 439 * @since 9 440 */ 441 static getAccessibleGeolocation(origin: string): Promise<boolean>; 442 443 /** 444 * Gets the geolocation permission status of the specified source. 445 * @param { string } origin - Url source. 446 * @param { AsyncCallback<boolean> } callback - Return to the specified source 447 * geographic location permission status. 448 * @throws { BusinessError } 401 - Invalid input parameter. 449 * @throws { BusinessError } 17100011 - Invalid origin. 450 * @syscap SystemCapability.Web.Webview.Core 451 * @since 9 452 */ 453 static getAccessibleGeolocation(origin: string, callback: AsyncCallback<boolean>): void; 454 455 /** 456 * Get all stored geolocation permission url source. 457 * @returns { Promise<Array<string>> } Return whether there is a saved result. 458 * @throws { BusinessError } 401 - Invalid input parameter. 459 * @syscap SystemCapability.Web.Webview.Core 460 * @since 9 461 */ 462 static getStoredGeolocation(): Promise<Array<string>>; 463 464 /** 465 * Get all stored geolocation permission url source. 466 * @param { AsyncCallback<Array<string>> } callback - Return all source information of 467 * stored geographic location permission status. 468 * @throws { BusinessError } 401 - Invalid input parameter. 469 * @syscap SystemCapability.Web.Webview.Core 470 * @since 9 471 */ 472 static getStoredGeolocation(callback: AsyncCallback<Array<string>>): void; 473 } 474 475 /** 476 * Provides methods for managing the web cookies. 477 * 478 * @syscap SystemCapability.Web.Webview.Core 479 * @since 9 480 */ 481 class WebCookieManager { 482 /** 483 * Gets all cookies for the given URL. 484 * 485 * @param { string } url - The URL for which the cookies are requested. 486 * @returns { string } - The cookie value for the given URL. 487 * @throws { BusinessError } 401 - Invalid input parameter. 488 * @throws { BusinessError } 17100002 - Invalid url. 489 * @syscap SystemCapability.Web.Webview.Core 490 * @since 9 491 */ 492 static getCookie(url: string): string; 493 494 /** 495 * Set a single cookie (key-value pair) for the given URL. 496 * 497 * @param { string } url - The URL for which the cookie is to be set. 498 * @param { string } value - The cookie as a string, using the format of the 'Set-Cookie' HTTP response header. 499 * @throws { BusinessError } 401 - Invalid input parameter. 500 * @throws { BusinessError } 17100002 - Invalid url. 501 * @throws { BusinessError } 17100005 - Invalid cookie value. 502 * @syscap SystemCapability.Web.Webview.Core 503 * @since 9 504 */ 505 static setCookie(url: string, value: string): void; 506 507 /** 508 * Save the cookies Asynchronously. 509 * @returns { Promise<void> } - A promise resolved after the cookies have been saved. 510 * @throws { BusinessError } 401 - Invalid input parameter. 511 * @syscap SystemCapability.Web.Webview.Core 512 * @since 9 513 */ 514 static saveCookieAsync(): Promise<void>; 515 516 /** 517 * Save the cookies Asynchronously. 518 * @param { AsyncCallback<void> } callback - Called after the cookies have been saved. 519 * @throws { BusinessError } 401 - Invalid input parameter. 520 * @syscap SystemCapability.Web.Webview.Core 521 * @since 9 522 */ 523 static saveCookieAsync(callback: AsyncCallback<void>): void; 524 525 /** 526 * Get whether the instance can send and accept cookies. 527 * 528 * @returns { boolean } True if the instance can send and accept cookies else false. 529 * @syscap SystemCapability.Web.Webview.Core 530 * @since 9 531 */ 532 static isCookieAllowed(): boolean; 533 534 /** 535 * Set whether the instance should send and accept cookies. 536 * By default this is set to be true. 537 * 538 * @param { boolean } accept - Whether the instance should send and accept cookies. 539 * @throws { BusinessError } 401 - Invalid input parameter. 540 * @syscap SystemCapability.Web.Webview.Core 541 * @since 9 542 */ 543 static putAcceptCookieEnabled(accept: boolean): void; 544 545 /** 546 * Get whether the instance can send and accept thirdparty cookies. 547 * 548 * @returns { boolean } True if the instance can send and accept thirdparty cookies else false. 549 * @syscap SystemCapability.Web.Webview.Core 550 * @since 9 551 */ 552 static isThirdPartyCookieAllowed(): boolean; 553 554 /** 555 * Set whether the instance should send and accept thirdparty cookies. 556 * By default this is set to be false. 557 * 558 * @param { boolean } accept - Whether the instance should send and accept thirdparty cookies. 559 * @throws { BusinessError } 401 - Invalid input parameter. 560 * @syscap SystemCapability.Web.Webview.Core 561 * @since 9 562 */ 563 static putAcceptThirdPartyCookieEnabled(accept: boolean): void; 564 565 /** 566 * Check whether exists any cookies. 567 * 568 * @returns { boolean } True if exists more than one cookie else false; 569 * @syscap SystemCapability.Web.Webview.Core 570 * @since 9 571 */ 572 static existCookie(): boolean; 573 574 /** 575 * Remove all cookies. 576 * @syscap SystemCapability.Web.Webview.Core 577 * @since 9 578 */ 579 static deleteEntireCookie(): void; 580 581 /** 582 * Delete the session cookies. 583 * @syscap SystemCapability.Web.Webview.Core 584 * @since 9 585 */ 586 static deleteSessionCookie(): void; 587 } 588 589 /** 590 * Enum type supplied to {@link onMessageEventExt} for indicating the type of web message. 591 * 592 * @enum {number} 593 * @syscap SystemCapability.Web.Webview.Core 594 * @since 10 595 */ 596 enum WebMessageType { 597 /** 598 * Unsupported data type. 599 * 600 * @syscap SystemCapability.Web.Webview.Core 601 * @since 10 602 */ 603 NOT_SUPPORT, 604 605 /** 606 * The string data type. 607 * 608 * @syscap SystemCapability.Web.Webview.Core 609 * @since 10 610 */ 611 STRING, 612 613 /** 614 * The number data type. 615 * 616 * @syscap SystemCapability.Web.Webview.Core 617 * @since 10 618 */ 619 NUMBER, 620 621 /** 622 * The boolean data type. 623 * 624 * @syscap SystemCapability.Web.Webview.Core 625 * @since 10 626 */ 627 BOOLEAN, 628 629 /** 630 * The arraybuffer data type. 631 * 632 * @syscap SystemCapability.Web.Webview.Core 633 * @since 10 634 */ 635 ARRAY_BUFFER, 636 637 /** 638 * The array data type. 639 * 640 * @syscap SystemCapability.Web.Webview.Core 641 * @since 10 642 */ 643 ARRAY, 644 645 /** 646 * The error data type. 647 * 648 * @syscap SystemCapability.Web.Webview.Core 649 * @since 10 650 */ 651 ERROR 652 } 653 654 /** 655 * The message received or sent from web message port. 656 * 657 * @syscap SystemCapability.Web.Webview.Core 658 * @since 10 659 */ 660 class WebMessageExt { 661 /** 662 * Get the type of the web message. 663 * @returns { WebMessageType } - Returns data of WebMessageType type 664 * @syscap SystemCapability.Web.Webview.Core 665 * @since 10 666 */ 667 getType(): WebMessageType; 668 669 /** 670 * Get the string value of the web message. 671 * @returns { string } - Returns data of string type 672 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 673 * 674 * @syscap SystemCapability.Web.Webview.Core 675 * @since 10 676 */ 677 getString(): string; 678 679 /** 680 * Get the number value of the web message. 681 * @returns { number } - Returns data of number type 682 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 683 * 684 * @syscap SystemCapability.Web.Webview.Core 685 * @since 10 686 */ 687 getNumber(): number; 688 689 /** 690 * Get the boolean value of the web message. 691 * @returns { boolean } - Returns data of Boolean type 692 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 693 * 694 * @syscap SystemCapability.Web.Webview.Core 695 * @since 10 696 */ 697 getBoolean(): boolean; 698 699 /** 700 * Get the array buffer value of the web message. 701 * @returns { ArrayBuffer } - Returns data of ArrayBuffer type 702 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 703 * 704 * @syscap SystemCapability.Web.Webview.Core 705 * @since 10 706 */ 707 getArrayBuffer(): ArrayBuffer; 708 709 /** 710 * Get the array value of the web message. 711 * @returns { Array<string | number | boolean> } - Returns data of Array type 712 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 713 * 714 * @syscap SystemCapability.Web.Webview.Core 715 * @since 10 716 */ 717 getArray(): Array<string | number | boolean>; 718 719 /** 720 * Get the error value of the web message. 721 * @returns { Error } - Returns data of Error type 722 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 723 * 724 * @syscap SystemCapability.Web.Webview.Core 725 * @since 10 726 */ 727 getError(): Error; 728 729 /** 730 * Set the type of the web message. 731 * @param { WebMessageType } type - set WebMessageType type data 732 * @throws { BusinessError } 401 - Invalid input parameter. 733 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 734 * 735 * @syscap SystemCapability.Web.Webview.Core 736 * @since 10 737 */ 738 setType(type: WebMessageType): void; 739 740 /** 741 * Set the string value of the web message. 742 * @param { string } message - set string type data 743 * @throws { BusinessError } 401 - Invalid input parameter. 744 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 745 * 746 * @syscap SystemCapability.Web.Webview.Core 747 * @since 10 748 */ 749 setString(message: string): void; 750 751 /** 752 * Set the number value of the web message. 753 * @param { number } message - set number type data 754 * @throws { BusinessError } 401 - Invalid input parameter. 755 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 756 * 757 * @syscap SystemCapability.Web.Webview.Core 758 * @since 10 759 */ 760 setNumber(message: number): void; 761 762 /** 763 * Set the boolean value of the web message. 764 * @param { boolean } message - set boolean type data 765 * @throws { BusinessError } 401 - Invalid input parameter. 766 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 767 * 768 * @syscap SystemCapability.Web.Webview.Core 769 * @since 10 770 */ 771 setBoolean(message: boolean): void; 772 773 /** 774 * Set the array buffer value of the web message. 775 * @param { ArrayBuffer } message - set ArrayBuffer type data 776 * @throws { BusinessError } 401 - Invalid input parameter. 777 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 778 * 779 * @syscap SystemCapability.Web.Webview.Core 780 * @since 10 781 */ 782 setArrayBuffer(message: ArrayBuffer): void; 783 784 /** 785 * Set the array value of the web message. 786 * @param { Array<string | number | boolean> } message - set Array type data 787 * @throws { BusinessError } 401 - Invalid input parameter. 788 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 789 * @syscap SystemCapability.Web.Webview.Core 790 * @since 10 791 */ 792 setArray(message: Array<string | number | boolean>): void; 793 794 /** 795 * Set the error value of the web message. 796 * @param { Error } message - set Error type data 797 * @throws { BusinessError } 401 - Invalid input parameter. 798 * @throws { BusinessError } 17100014 - The type does not match with the value of the web message. 799 * 800 * @syscap SystemCapability.Web.Webview.Core 801 * @since 10 802 */ 803 setError(message: Error): void; 804 } 805 806 type WebMessage = ArrayBuffer | string; 807 /** 808 * Define html web message port. 809 * @interface WebMessagePort 810 * @syscap SystemCapability.Web.Webview.Core 811 * @since 9 812 */ 813 interface WebMessagePort { 814 /** 815 * The flag indicates whether more formats are supported than string and array buffers. 816 * 817 * @syscap SystemCapability.Web.Webview.Core 818 * @since 10 819 */ 820 isExtentionType?: boolean; 821 822 /** 823 * Close port. 824 * @syscap SystemCapability.Web.Webview.Core 825 * @since 9 826 */ 827 close(): void; 828 829 /** 830 * Post a message to other port. 831 * @param { WebMessage } message - Message to send. 832 * @throws { BusinessError } 401 - Invalid input parameter. 833 * @throws { BusinessError } 17100010 - Can not post message using this port. 834 * @syscap SystemCapability.Web.Webview.Core 835 * @since 9 836 */ 837 postMessageEvent(message: WebMessage): void; 838 839 /** 840 * Receive message from other port. 841 * @param { function } callback - Callback function for receiving messages. 842 * @throws { BusinessError } 401 - Invalid input parameter. 843 * @throws { BusinessError } 17100006 - Can not register message event using this port. 844 * @syscap SystemCapability.Web.Webview.Core 845 * @since 9 846 */ 847 onMessageEvent(callback: (result: WebMessage) => void): void; 848 849 /** 850 * Post a message to other port. 851 * @param { WebMessageExt } message - Message to send. 852 * @throws { BusinessError } 401 - Invalid input parameter. 853 * @throws { BusinessError } 17100010 - Can not post message using this port. 854 * @syscap SystemCapability.Web.Webview.Core 855 * @since 10 856 */ 857 postMessageEventExt(message: WebMessageExt): void; 858 859 /** 860 * Receive message from other port. 861 * @param { function } callback - Callback function for receiving messages. 862 * @throws { BusinessError } 401 - Invalid input parameter. 863 * @throws { BusinessError } 17100006 - Can not register message event using this port. 864 * @syscap SystemCapability.Web.Webview.Core 865 * @since 10 866 */ 867 onMessageEventExt(callback: (result: WebMessageExt) => void): void; 868 } 869 870 /** 871 * Provides information for history item in BackForwardList. 872 * @interface HistoryItem 873 * @syscap SystemCapability.Web.Webview.Core 874 * @since 9 875 */ 876 interface HistoryItem { 877 /** 878 * Pixelmap of icon. 879 * @syscap SystemCapability.Web.Webview.Core 880 * @since 9 881 */ 882 icon: image.PixelMap; 883 884 /** 885 * Url of this history item. 886 * @syscap SystemCapability.Web.Webview.Core 887 * @since 9 888 */ 889 historyUrl: string; 890 891 /** 892 * Original request url of this history item. 893 * @syscap SystemCapability.Web.Webview.Core 894 * @since 9 895 */ 896 historyRawUrl: string; 897 898 /** 899 * Title of this history item. 900 * @syscap SystemCapability.Web.Webview.Core 901 * @since 9 902 */ 903 title: string; 904 } 905 906 /** 907 * Provides back and forward history list information method. related to {@link HistoryItem}. 908 * @interface BackForwardList 909 * @syscap SystemCapability.Web.Webview.Core 910 * @since 9 911 */ 912 interface BackForwardList { 913 /** 914 * Current index in BackForwardList. 915 * @syscap SystemCapability.Web.Webview.Core 916 * @since 9 917 */ 918 currentIndex: number; 919 920 /** 921 * Size of in BackForwardList. 922 * @syscap SystemCapability.Web.Webview.Core 923 * @since 9 924 */ 925 size: number; 926 927 /** 928 * Get history entry at given index. 929 * 930 * @param { number } index Index of back forward list entry. 931 * @returns { HistoryItem } HistoryItem at given index in back forward list. 932 * @throws { BusinessError } 401 - Invalid input parameter. 933 * @syscap SystemCapability.Web.Webview.Core 934 * @since 9 935 */ 936 getItemAtIndex(index: number): HistoryItem; 937 } 938 939 /** 940 * Enum type supplied to {@link runJavaScriptExt} for indicating the result of JavaScript code execution. 941 * @enum {number} 942 * @syscap SystemCapability.Web.Webview.Core 943 * @since 10 944 */ 945 enum JsMessageType { 946 /** 947 * Unsupported data type. 948 * @syscap SystemCapability.Web.Webview.Core 949 * @since 10 950 */ 951 NOT_SUPPORT, 952 953 /** 954 * The string data type. 955 * @syscap SystemCapability.Web.Webview.Core 956 * @since 10 957 */ 958 STRING, 959 960 /** 961 * The number data type. 962 * @syscap SystemCapability.Web.Webview.Core 963 * @since 10 964 */ 965 NUMBER, 966 967 /** 968 * The boolean data type. 969 * @syscap SystemCapability.Web.Webview.Core 970 * @since 10 971 */ 972 BOOLEAN, 973 974 /** 975 * The arraybuffer data type. 976 * @syscap SystemCapability.Web.Webview.Core 977 * @since 10 978 */ 979 ARRAY_BUFFER, 980 981 /** 982 * The array data type. 983 * @syscap SystemCapability.Web.Webview.Core 984 * @since 10 985 */ 986 ARRAY 987 } 988 989 /** 990 * The message for indicating the of result of JavaScript code execution. 991 * @syscap SystemCapability.Web.Webview.Core 992 * @since 10 993 */ 994 class JsMessageExt { 995 /** 996 * Get the type of the JavaScript code execution result. 997 * @returns { JsMessageType } - Returns data of JsMessageType type 998 * @syscap SystemCapability.Web.Webview.Core 999 * @since 10 1000 */ 1001 getType(): JsMessageType; 1002 1003 /** 1004 * Get the string value of the JavaScript code execution result. 1005 * @returns { string } - Returns data of string type 1006 * @throws { BusinessError } 17100014 - The type does not match with the value of the result. 1007 * @syscap SystemCapability.Web.Webview.Core 1008 * @since 10 1009 */ 1010 getString(): string; 1011 1012 /** 1013 * Get the number value of the JavaScript code execution result. 1014 * @returns { number } - Returns data of number type 1015 * @throws { BusinessError } 17100014 - The type does not match with the value of the result. 1016 * @syscap SystemCapability.Web.Webview.Core 1017 * @since 10 1018 */ 1019 getNumber(): number; 1020 1021 /** 1022 * Get the boolean value of the JavaScript code execution result. 1023 * @returns { boolean } - Returns data of Boolean type 1024 * @throws { BusinessError } 17100014 - The type does not match with the value of the result. 1025 * @syscap SystemCapability.Web.Webview.Core 1026 * @since 10 1027 */ 1028 getBoolean(): boolean; 1029 1030 /** 1031 * Get the array buffer value of the JavaScript code execution result. 1032 * @returns { ArrayBuffer } - Returns data of ArrayBuffer 1033 * @throws { BusinessError } 17100014 - The type does not match with the value of the result. 1034 * @syscap SystemCapability.Web.Webview.Core 1035 * @since 10 1036 */ 1037 getArrayBuffer(): ArrayBuffer; 1038 1039 /** 1040 * Get the array value of the the JavaScript code execution result. 1041 * @returns { Array<string | number | boolean> } - Returns data of Array type 1042 * @throws { BusinessError } 17100014 - The type does not match with the value of the result. 1043 * @syscap SystemCapability.Web.Webview.Core 1044 * @since 10 1045 */ 1046 getArray(): Array<string | number | boolean>; 1047 } 1048 1049 /** 1050 * Provides methods for controlling the web controller. 1051 * @syscap SystemCapability.Web.Webview.Core 1052 * @since 9 1053 */ 1054 /** 1055 * Provides methods for controlling the web controller. 1056 * @syscap SystemCapability.Web.Webview.Core 1057 * @crossplatform 1058 * @since 10 1059 */ 1060 class WebviewController { 1061 /** 1062 * Initialize the web engine before loading the Web components. 1063 * This is a global static API that must be called on the UI thread, and it will have no effect if any 1064 * Web components are loaded. 1065 * @syscap SystemCapability.Web.Webview.Core 1066 * @since 9 1067 */ 1068 static initializeWebEngine(): void; 1069 1070 /** 1071 * Set web engine to use HttpDns server to resolve dns. 1072 * @param { SecureDnsMode } secureDnsMode - using HttpDns. 1073 * @param { string } secureDnsConfig - The configuration of the HttpDns server. 1074 * Must be https protocol and only allow one server to be configured. 1075 * @throws { BusinessError } 401 - Invalid input parameter. 1076 * @syscap SystemCapability.Web.Webview.Core 1077 * @since 10 1078 */ 1079 static setHttpDns(secureDnsMode: SecureDnsMode, secureDnsConfig: string): void; 1080 1081 /** 1082 * Enables debugging of web contents. 1083 * @param { boolean } webDebuggingAccess {@code true} enables debugging of web contents; {@code false} otherwise. 1084 * @throws { BusinessError } 401 - Invalid input parameter. 1085 * @syscap SystemCapability.Web.Webview.Core 1086 * @since 9 1087 */ 1088 static setWebDebuggingAccess(webDebuggingAccess: boolean): void; 1089 1090 /** 1091 * Checks whether the web page can go forward. 1092 * @returns { boolean } True if the web page can go forward else false. 1093 * @throws { BusinessError } 17100001 - Init error. 1094 * The WebviewController must be associated with a Web component. 1095 * @syscap SystemCapability.Web.Webview.Core 1096 * @since 9 1097 */ 1098 accessForward(): boolean; 1099 1100 /** 1101 * Checks whether the web page can go back. 1102 * @returns { boolean } True if the web page can go back else false. 1103 * The WebviewController must be associated with a Web component. 1104 * @throws { BusinessError } 17100001 - Init error. 1105 * @syscap SystemCapability.Web.Webview.Core 1106 * @since 9 1107 */ 1108 accessBackward(): boolean; 1109 1110 /** 1111 * Checks whether the web page can go back or forward the given number of steps. 1112 * 1113 * @param { number } step - The number of steps. 1114 * @returns { boolean } True if the web page can go back else false. 1115 * @throws { BusinessError } 401 - Invalid input parameter. 1116 * @throws { BusinessError } 17100001 - Init error. 1117 * The WebviewController must be associated with a Web component. 1118 * @syscap SystemCapability.Web.Webview.Core 1119 * @since 9 1120 */ 1121 accessStep(step: number): boolean; 1122 1123 /** 1124 * Goes forward in the history of the web page. 1125 * 1126 * @throws { BusinessError } 17100001 - Init error. 1127 * The WebviewController must be associated with a Web component. 1128 * @syscap SystemCapability.Web.Webview.Core 1129 * @since 9 1130 */ 1131 forward(): void; 1132 1133 /** 1134 * Goes back in the history of the web page. 1135 * 1136 * @throws { BusinessError } 17100001 - Init error. 1137 * The WebviewController must be associated with a Web component. 1138 * @syscap SystemCapability.Web.Webview.Core 1139 * @since 9 1140 */ 1141 backward(): void; 1142 1143 /** 1144 * Clears the history in the Web. 1145 * 1146 * @throws { BusinessError } 17100001 - Init error. 1147 * The WebviewController must be associated with a Web component. 1148 * @syscap SystemCapability.Web.Webview.Core 1149 * @since 9 1150 */ 1151 clearHistory(): void; 1152 1153 /** 1154 * Let the Web active. 1155 * 1156 * @throws { BusinessError } 17100001 - Init error. 1157 * The WebviewController must be associated with a Web component. 1158 * @syscap SystemCapability.Web.Webview.Core 1159 * @since 9 1160 */ 1161 onActive(): void; 1162 1163 /** 1164 * Let the Web inactive. 1165 * 1166 * @throws { BusinessError } 17100001 - Init error. 1167 * The WebviewController must be associated with a Web component. 1168 * @syscap SystemCapability.Web.Webview.Core 1169 * @since 9 1170 */ 1171 onInactive(): void; 1172 1173 /** 1174 * Refreshes the current URL. 1175 * 1176 * @throws { BusinessError } 17100001 - Init error. 1177 * The WebviewController must be associated with a Web component. 1178 * @syscap SystemCapability.Web.Webview.Core 1179 * @since 9 1180 */ 1181 refresh(): void; 1182 1183 /** 1184 * Loads the data or URL. 1185 * 1186 * @param { string } data - A string encoded according to "Base64" or "URL". 1187 * @param { string } mimeType - Media type. For example: "text/html". 1188 * @param { string } encoding - Encoding type. For example: "UTF-8". 1189 * @param { string } [baseUrl] - A specified URL path ("http"/"https"/"data" protocol), 1190 * which is assigned to window.origin by the Web component. 1191 * @param { string } [historyUrl] - History URL. When it is not empty, it can be managed by 1192 * history records to realize the back and forth function. 1193 * This property is invalid when baseUrl is empty. 1194 * @throws { BusinessError } 401 - Invalid input parameter. 1195 * @throws { BusinessError } 17100001 - Init error. 1196 * The WebviewController must be associated with a Web component. 1197 * @throws { BusinessError } 17100002 - Invalid url. 1198 * @syscap SystemCapability.Web.Webview.Core 1199 * @since 9 1200 */ 1201 loadData(data: string, mimeType: string, encoding: string, baseUrl?: string, historyUrl?: string): void; 1202 1203 /** 1204 * Loads the data or URL. 1205 * 1206 * @param { string | Resource } url - The URL to load. 1207 * @param { Array<WebHeader> } [headers] - Additional HTTP request header for URL. 1208 * @throws { BusinessError } 401 - Invalid input parameter. 1209 * @throws { BusinessError } 17100001 - Init error. 1210 * The WebviewController must be associated with a Web component. 1211 * @throws { BusinessError } 17100002 - Invalid url. 1212 * @throws { BusinessError } 17100003 - Invalid resource path or file type. 1213 * @syscap SystemCapability.Web.Webview.Core 1214 * @since 9 1215 */ 1216 /** 1217 * Loads the data or URL. 1218 * 1219 * @param { string | Resource } url - The URL to load. 1220 * @param { Array<WebHeader> } [headers] - Additional HTTP request header for URL. 1221 * @throws { BusinessError } 401 - Invalid input parameter. 1222 * @throws { BusinessError } 17100001 - Init error. 1223 * The WebviewController must be associated with a Web component. 1224 * @throws { BusinessError } 17100002 - Invalid url. 1225 * @throws { BusinessError } 17100003 - Invalid resource path or file type. 1226 * @syscap SystemCapability.Web.Webview.Core 1227 * @crossplatform 1228 * @since 10 1229 */ 1230 loadUrl(url: string | Resource, headers?: Array<WebHeader>): void; 1231 1232 /** 1233 * Gets the type of HitTest. 1234 * @returns { WebHitTestType } The type of HitTest. 1235 * @throws { BusinessError } 17100001 - Init error. 1236 * The WebviewController must be associated with a Web component. 1237 * @syscap SystemCapability.Web.Webview.Core 1238 * @since 9 1239 */ 1240 getHitTest(): WebHitTestType; 1241 1242 /** 1243 * Stores the current page as a web archive. 1244 * 1245 * @param { string } baseName - Where the generated offline webpage is stored, This value cannot be null. 1246 * @param { boolean } autoName - If it is false, the filename will be automatically generated according to 1247 * the url and the generated offline webpage will be stored in the directory 1248 * specified by baseName. If it is true, the offline webpage will be directly 1249 * stored in the path specified by baseName. 1250 * @returns { Promise<string> } a promise resolved after the web archive has been stored. The parameter 1251 * will either be the filename under which the file was stored, or empty 1252 * if storing the file failed. 1253 * @throws { BusinessError } 401 - Invalid input parameter. 1254 * @throws { BusinessError } 17100001 - Init error. 1255 * The WebviewController must be associated with a Web component. 1256 * @throws { BusinessError } 17100003 - Invalid resource path or file type. 1257 * @syscap SystemCapability.Web.Webview.Core 1258 * @since 9 1259 */ 1260 storeWebArchive(baseName: string, autoName: boolean): Promise<string>; 1261 1262 /** 1263 * Stores the current page as a web archive. 1264 * 1265 * @param { string } baseName - Where the generated offline webpage is stored, This value cannot be null. 1266 * @param { boolean } autoName - If it is false, the filename will be automatically generated according to 1267 * the url and the generated offline webpage will be stored in the directory 1268 * specified by baseName. If it is true, the offline webpage will be directly 1269 * stored in the path specified by baseName. 1270 * @param { AsyncCallback<string> } callback - called after the web archive has been stored. The parameter 1271 * will either be the filename under which the file was stored, 1272 * or empty if storing the file failed. 1273 * @throws { BusinessError } 401 - Invalid input parameter. 1274 * @throws { BusinessError } 17100001 - Init error. 1275 * The WebviewController must be associated with a Web component. 1276 * @throws { BusinessError } 17100003 - Invalid resource path or file type. 1277 * @syscap SystemCapability.Web.Webview.Core 1278 * @since 9 1279 */ 1280 storeWebArchive(baseName: string, autoName: boolean, callback: AsyncCallback<string>): void; 1281 1282 /** 1283 * Let the Web zoom by. 1284 * 1285 * @param { number } factor - The zoom factor. 1286 * @throws { BusinessError } 401 - Invalid input parameter. 1287 * @throws { BusinessError } 17100001 - Init error. 1288 * The WebviewController must be associated with a Web component. 1289 * @throws { BusinessError } 17100004 - Function not enable. 1290 * @syscap SystemCapability.Web.Webview.Core 1291 * @since 9 1292 */ 1293 zoom(factor: number): void; 1294 1295 /** 1296 * Let the Web zoom in. 1297 * 1298 * @throws { BusinessError } 17100001 - Init error. 1299 * The WebviewController must be associated with a Web component. 1300 * @throws { BusinessError } 17100004 - Function not enable. 1301 * @syscap SystemCapability.Web.Webview.Core 1302 * @since 9 1303 */ 1304 zoomIn(): void; 1305 1306 /** 1307 * Let the Web zoom out. 1308 * 1309 * @throws { BusinessError } 17100001 - Init error. 1310 * The WebviewController must be associated with a Web component. 1311 * @throws { BusinessError } 17100004 - Function not enable. 1312 * @syscap SystemCapability.Web.Webview.Core 1313 * @since 9 1314 */ 1315 zoomOut(): void; 1316 1317 /** 1318 * Gets the hit test value of HitTest. 1319 * @returns { HitTestValue } Return the element information of the clicked area. 1320 * @throws { BusinessError } 17100001 - Init error. 1321 * The WebviewController must be associated with a Web component. 1322 * @syscap SystemCapability.Web.Webview.Core 1323 * @since 9 1324 */ 1325 getHitTestValue(): HitTestValue; 1326 1327 /** 1328 * Gets the id for the current Web. 1329 * @returns { number } Returns the index value of the current Web component. 1330 * @throws { BusinessError } 17100001 - Init error. 1331 * The WebviewController must be associated with a Web component. 1332 * @syscap SystemCapability.Web.Webview.Core 1333 * @since 9 1334 */ 1335 getWebId(): number; 1336 1337 /** 1338 * Gets the default user agent. 1339 * @returns { string } Return user agent information. 1340 * @throws { BusinessError } 17100001 - Init error. 1341 * The WebviewController must be associated with a Web component. 1342 * @syscap SystemCapability.Web.Webview.Core 1343 * @since 9 1344 */ 1345 getUserAgent(): string; 1346 1347 /** 1348 * Gets the title of current Web page. 1349 * @returns { string } Return to File Selector Title. 1350 * @throws { BusinessError } 17100001 - Init error. 1351 * The WebviewController must be associated with a Web component. 1352 * @syscap SystemCapability.Web.Webview.Core 1353 * @since 9 1354 */ 1355 getTitle(): string; 1356 1357 /** 1358 * Gets the content height of current Web page. 1359 * @returns { number } Returns the page height of the current page. 1360 * @throws { BusinessError } 17100001 - Init error. 1361 * The WebviewController must be associated with a Web component. 1362 * @syscap SystemCapability.Web.Webview.Core 1363 * @since 9 1364 */ 1365 getPageHeight(): number; 1366 1367 /** 1368 * Goes forward or back backOrForward in the history of the web page. 1369 * 1370 * @param { number } step - Steps to go forward or backward. 1371 * @throws { BusinessError } 401 - Invalid input parameter. 1372 * @throws { BusinessError } 17100001 - Init error. 1373 * The WebviewController must be associated with a Web component. 1374 * @syscap SystemCapability.Web.Webview.Core 1375 * @since 9 1376 */ 1377 backOrForward(step: number): void; 1378 1379 /** 1380 * Gets the request focus. 1381 * 1382 * @throws { BusinessError } 17100001 - Init error. 1383 * The WebviewController must be associated with a Web component. 1384 * @syscap SystemCapability.Web.Webview.Core 1385 * @since 9 1386 */ 1387 requestFocus(): void; 1388 1389 /** 1390 * Create web message ports 1391 * @returns { Array<WebMessagePort> } An array represent 2 WebMessagePort, then can use 1392 * those ports to communication with html pages. 1393 * @throws { BusinessError } 17100001 - Init error. 1394 * The WebviewController must be associated with a Web component. 1395 * @syscap SystemCapability.Web.Webview.Core 1396 * @since 9 1397 */ 1398 /** 1399 * Create web message ports 1400 * @param { boolean } isExtentionType - Set whether the web message port supports extention type. 1401 * @returns { Array<WebMessagePort> } An array represent 2 WebMessagePort, then can use 1402 * those ports to communication with html pages. 1403 * @throws { BusinessError } 401 - Invalid input parameter. 1404 * @throws { BusinessError } 17100001 - Init error. 1405 * The WebviewController must be associated with a Web component. 1406 * @syscap SystemCapability.Web.Webview.Core 1407 * @since 10 1408 */ 1409 createWebMessagePorts(isExtentionType?: boolean): Array<WebMessagePort>; 1410 1411 /** 1412 * Post web message port to html 1413 * 1414 * @param { string } name - Data name information to send. 1415 * @param { Array<WebMessagePort> } ports - Port number array information to send. 1416 * @param { string } uri - URI to receive this information. 1417 * @throws { BusinessError } 401 - Invalid input parameter. 1418 * @throws { BusinessError } 17100001 - Init error. 1419 * The WebviewController must be associated with a Web component. 1420 * @syscap SystemCapability.Web.Webview.Core 1421 * @since 9 1422 */ 1423 postMessage(name: string, ports: Array<WebMessagePort>, uri: string): void; 1424 1425 /** 1426 * Stops the current load. 1427 * 1428 * @throws { BusinessError } 17100001 - Init error. 1429 * The WebviewController must be associated with a Web component. 1430 * @syscap SystemCapability.Web.Webview.Core 1431 * @since 9 1432 */ 1433 stop(): void; 1434 1435 /** 1436 * Registers the JavaScript object and method list. 1437 * 1438 * @param { object } object - Application side JavaScript objects participating in registration. 1439 * @param { string } name - The name of the registered object, which is consistent with the 1440 * object name called in the window. 1441 * @param { Array<string> } methodList - Thr method of the application side JavaScript object participating 1442 * in the registration. 1443 * @throws { BusinessError } 401 - Invalid input parameter. 1444 * @throws { BusinessError } 17100001 - Init error. 1445 * The WebviewController must be associated with a Web component. 1446 * @syscap SystemCapability.Web.Webview.Core 1447 * @since 9 1448 */ 1449 registerJavaScriptProxy(object: object, name: string, methodList: Array<string>): void; 1450 1451 /** 1452 * Deletes a registered JavaScript object with given name. 1453 * 1454 * @param { string } name - The name of a registered JavaScript object to be deleted. 1455 * @throws { BusinessError } 401 - Invalid input parameter. 1456 * @throws { BusinessError } 17100001 - Init error. 1457 * The WebviewController must be associated with a Web component. 1458 * @throws { BusinessError } 17100008 - Cannot delete JavaScriptProxy. 1459 * @syscap SystemCapability.Web.Webview.Core 1460 * @since 9 1461 */ 1462 deleteJavaScriptRegister(name: string): void; 1463 1464 /** 1465 * Search all instances of 'searchString' on the page and highlights them, 1466 * result will be notify through callback onSearchResultReceive. 1467 * 1468 * @param { string } searchString - String to be search. 1469 * @throws { BusinessError } 401 - Invalid input parameter. 1470 * @throws { BusinessError } 17100001 - Init error. 1471 * The WebviewController must be associated with a Web component. 1472 * @syscap SystemCapability.Web.Webview.Core 1473 * @since 9 1474 */ 1475 searchAllAsync(searchString: string): void; 1476 1477 /** 1478 * Clears the highlighting surrounding text matches created by searchAllAsync. 1479 * 1480 * @throws { BusinessError } 17100001 - Init error. 1481 * The WebviewController must be associated with a Web component. 1482 * @syscap SystemCapability.Web.Webview.Core 1483 * @since 9 1484 */ 1485 clearMatches(): void; 1486 1487 /** 1488 * Highlights and scrolls to the next match search. 1489 * 1490 * @param { boolean } forward - Step of search is back or forward. 1491 * @throws { BusinessError } 401 - Invalid input parameter. 1492 * @throws { BusinessError } 17100001 - Init error. 1493 * The WebviewController must be associated with a Web component. 1494 * @syscap SystemCapability.Web.Webview.Core 1495 * @since 9 1496 */ 1497 searchNext(forward: boolean): void; 1498 1499 /** 1500 * Clears the ssl cache in the Web. 1501 * 1502 * @throws { BusinessError } 17100001 - Init error. 1503 * The WebviewController must be associated with a Web component. 1504 * @syscap SystemCapability.Web.Webview.Core 1505 * @since 9 1506 */ 1507 clearSslCache(): void; 1508 1509 /** 1510 * Clears the client authentication certificate cache in the Web. 1511 * 1512 * @throws { BusinessError } 17100001 - Init error. 1513 * The WebviewController must be associated with a Web component. 1514 * @syscap SystemCapability.Web.Webview.Core 1515 * @since 9 1516 */ 1517 clearClientAuthenticationCache(): void; 1518 1519 /** 1520 * Loads a piece of code and execute JS code in the context of the currently displayed page. 1521 * 1522 * @param { string } script - JavaScript Script. 1523 * @returns { Promise<string> } A promise is solved after the JavaScript script is executed. 1524 * This parameter will be the result of JavaScript script execution. 1525 * If the JavaScript script fails to execute or has no return value, 1526 * null will be returned. 1527 * @throws { BusinessError } 401 - Invalid input parameter. 1528 * @throws { BusinessError } 17100001 - Init error. 1529 * The WebviewController must be associated with a Web component. 1530 * @syscap SystemCapability.Web.Webview.Core 1531 * @since 9 1532 */ 1533 runJavaScript(script: string): Promise<string>; 1534 1535 /** 1536 * Loads a piece of code and execute JS code in the context of the currently displayed page. 1537 * 1538 * @param { string } script - JavaScript Script. 1539 * @param { AsyncCallback<string> } callback - Callbacks execute JavaScript script results. 1540 * @throws { BusinessError } 401 - Invalid input parameter. 1541 * @throws { BusinessError } 17100001 - Init error. 1542 * The WebviewController must be associated with a Web component. 1543 * @syscap SystemCapability.Web.Webview.Core 1544 * @since 9 1545 */ 1546 runJavaScript(script: string, callback: AsyncCallback<string>): void; 1547 1548 /** 1549 * Execute JavaScript code in the context of the currently displayed page, and return the result. 1550 * 1551 * @param { string } script - JavaScript Script. 1552 * @returns { Promise<JsMessageExt> } A promise is solved after the JavaScript script is executed. 1553 * This parameter will be the result of JavaScript script execution. 1554 * If the JavaScript script fails to execute or has no return value, 1555 * a none type value will be returned. 1556 * @throws { BusinessError } 401 - Invalid input parameter. 1557 * @throws { BusinessError } 17100001 - Init error. 1558 * The WebviewController must be associated with a Web component. 1559 * @syscap SystemCapability.Web.Webview.Core 1560 * @since 10 1561 */ 1562 runJavaScriptExt(script: string): Promise<JsMessageExt>; 1563 1564 /** 1565 * Execute JavaScript code in the context of the currently displayed page, and return the result. 1566 * 1567 * @param { string } script - JavaScript Script. 1568 * @param { AsyncCallback<JsMessageExt> } callback - Callbacks execute JavaScript script results. 1569 * @throws { BusinessError } 401 - Invalid input parameter. 1570 * @throws { BusinessError } 17100001 - Init error. 1571 * The WebviewController must be associated with a Web component. 1572 * @syscap SystemCapability.Web.Webview.Core 1573 * @since 10 1574 */ 1575 runJavaScriptExt(script: string, callback: AsyncCallback<JsMessageExt>): void; 1576 1577 /** 1578 * Gets the url of current Web page. 1579 * @returns { string } Return the url of the current page. 1580 * @throws { BusinessError } 17100001 - Init error. 1581 * The WebviewController must be associated with a Web component. 1582 * @syscap SystemCapability.Web.Webview.Core 1583 * @since 9 1584 */ 1585 getUrl(): string; 1586 1587 /** 1588 * Scroll the contents of this Webview up by half the view size. 1589 * 1590 * @param { boolean } top - Jump to the top of the page if true. 1591 * @throws { BusinessError } 401 - Invalid input parameter. 1592 * @throws { BusinessError } 17100001 - Init error. 1593 * The WebviewController must be associated with a Web component. 1594 * @syscap SystemCapability.Web.Webview.Core 1595 * @since 9 1596 */ 1597 pageUp(top: boolean): void; 1598 1599 /** 1600 * Scroll the contents of this Webview down by half the view size. 1601 * 1602 * @param { boolean } bottom - Jump to the bottom of the page if true. 1603 * @throws { BusinessError } 401 - Invalid input parameter. 1604 * @throws { BusinessError } 17100001 - Init error. 1605 * The WebviewController must be associated with a Web component. 1606 * @syscap SystemCapability.Web.Webview.Core 1607 * @since 9 1608 */ 1609 pageDown(bottom: boolean): void; 1610 1611 /** 1612 * Gets the original url of current Web page. 1613 * @returns { string } Return the original url of the current page. 1614 * @throws { BusinessError } 17100001 - Init error. 1615 * The WebviewController must be associated with a Web component. 1616 * @syscap SystemCapability.Web.Webview.Core 1617 * @since 9 1618 */ 1619 getOriginalUrl(): string; 1620 1621 /** 1622 * Gets the favicon of current Web page. 1623 * @returns { image.PixelMap } Return the favicon bitmap of the current page. 1624 * @throws { BusinessError } 17100001 - Init error. 1625 * The WebviewController must be associated with a Web component. 1626 * @syscap SystemCapability.Web.Webview.Core 1627 * @since 9 1628 */ 1629 getFavicon(): image.PixelMap; 1630 1631 /** 1632 * Put network state for web. Which is used to set window.navigator.isOnline property in 1633 * JavaScript. 1634 * @param { boolean } enable - Whether enable window.navigator.isOnline. 1635 * @throws { BusinessError } 401 - Invalid input parameter. 1636 * @throws { BusinessError } 17100001 - Init error. 1637 * The WebviewController must be associated with a Web component. 1638 * @syscap SystemCapability.Web.Webview.Core 1639 * @since 9 1640 */ 1641 setNetworkAvailable(enable: boolean): void; 1642 1643 /** 1644 * Query if current document has image. 1645 * 1646 * @returns { Promise<boolean> } A promise resolved after query image has finished. 1647 * @throws { BusinessError } 401 - Invalid input parameter. 1648 * @throws { BusinessError } 17100001 - Init error. 1649 * The WebviewController must be associated with a Web component. 1650 * @syscap SystemCapability.Web.Webview.Core 1651 * @since 9 1652 */ 1653 hasImage(): Promise<boolean>; 1654 1655 /** 1656 * Query if current document has image. 1657 * 1658 * @param { AsyncCallback<boolean> } callback - Called after query image has finished. 1659 * @throws { BusinessError } 401 - Invalid input parameter. 1660 * @throws { BusinessError } 17100001 - Init error. 1661 * The WebviewController must be associated with a Web component. 1662 * @syscap SystemCapability.Web.Webview.Core 1663 * @since 9 1664 */ 1665 hasImage(callback: AsyncCallback<boolean>): void; 1666 1667 /** 1668 * Get back forward stack list from current webview. 1669 * @returns { BackForwardList } Back forward list for current webview. 1670 * @throws { BusinessError } 17100001 - Init error. 1671 * The WebviewController must be associated with a Web component. 1672 * @syscap SystemCapability.Web.Webview.Core 1673 * @since 9 1674 */ 1675 getBackForwardEntries(): BackForwardList; 1676 1677 /** 1678 * Remove resource cache in application. So this method will remove all cache for all web components in the 1679 * same application. 1680 * 1681 * @param { boolean } clearRom - Remove cache in both rom and ram if true. Otherwise only clear cache 1682 * in ram. 1683 * @throws { BusinessError } 401 - Invalid input parameter. 1684 * @throws { BusinessError } 17100001 - Init error. 1685 * The WebviewController must be associated with a Web component. 1686 * @syscap SystemCapability.Web.Webview.Core 1687 * @since 9 1688 */ 1689 removeCache(clearRom: boolean): void; 1690 1691 /** 1692 * Scroll to the position. 1693 * 1694 * @param { number } x - the x of the position. 1695 * @param { number } y - the y of the position. 1696 * @throws { BusinessError } 401 - Invalid input parameter. 1697 * @throws { BusinessError } 17100001 - Init error. 1698 * The WebviewController must be associated with a Web component. 1699 * @syscap SystemCapability.Web.Webview.Core 1700 * @since 9 1701 */ 1702 scrollTo(x: number, y: number): void; 1703 1704 /** 1705 * Scroll by the delta position. 1706 * 1707 * @param { number } deltaX - the delta x of the position. 1708 * @param { number } deltaY - the delta y of the position. 1709 * @throws { BusinessError } 401 - Invalid input parameter. 1710 * @throws { BusinessError } 17100001 - Init error. 1711 * The WebviewController must be associated with a Web component. 1712 * @syscap SystemCapability.Web.Webview.Core 1713 * @since 9 1714 */ 1715 scrollBy(deltaX: number, deltaY: number): void; 1716 1717 /** 1718 * Slide by the speed. 1719 * 1720 * @param { number } vx - the x speed of the speed. 1721 * @param { number } vy - the y speed of the speed. 1722 * @throws { BusinessError } 401 - Invalid input parameter. 1723 * @throws { BusinessError } 17100001 - Init error. 1724 * The WebviewController must be associated with a Web component. 1725 * @syscap SystemCapability.Web.Webview.Core 1726 * @since 9 1727 */ 1728 slideScroll(vx: number, vy: number): void; 1729 1730 /** 1731 * Serialize the access stack of the web, that is, the history of access. 1732 * @returns { Uint8Array } Web access stack after serialization. 1733 * @throws { BusinessError } 17100001 - Init error. 1734 * The WebviewController must be associated with a Web component. 1735 * @syscap SystemCapability.Web.Webview.Core 1736 * @since 9 1737 */ 1738 serializeWebState(): Uint8Array; 1739 1740 /** 1741 * Restoring the web access stack, that is, the history of access. 1742 * @param { Uint8Array } state - Web access stack after serialization. 1743 * @throws { BusinessError } 401 - Invalid input parameter. 1744 * @throws { BusinessError } 17100001 - Init error. 1745 * The WebviewController must be associated with a Web component. 1746 * @syscap SystemCapability.Web.Webview.Core 1747 * @since 9 1748 */ 1749 restoreWebState(state: Uint8Array): void; 1750 1751 /** 1752 * Set whether the Web custom scheme supports cross domain and fetch requests. 1753 * @param { Array<WebCustomScheme> } schemes - Configuration of web custom scheme. 1754 * @throws { BusinessError } 401 - Invalid input parameter. 1755 * @syscap SystemCapability.Web.Webview.Core 1756 * @since 9 1757 */ 1758 static customizeSchemes(schemes: Array<WebCustomScheme>): void; 1759 1760 /** 1761 * Get certificate for the current website. 1762 * @returns { Promise<Array<cert.X509Cert>> } the promise of the current website's certificate. 1763 * @throws { BusinessError } 17100001 - Init error. 1764 * The WebviewController must be associated with a web component. 1765 * @syscap SystemCapability.Web.Webview.Core 1766 * @since 10 1767 */ 1768 getCertificate(): Promise<Array<cert.X509Cert>>; 1769 1770 /** 1771 * Get certificate for the current website. 1772 * @param {AsyncCallback<Array<cert.X509Cert>>} callback - the callback of getCertificate. 1773 * @throws { BusinessError } 401 - Invalid input parameter. 1774 * @throws { BusinessError } 17100001 - Init error. 1775 * The WebviewController must be associated with a web component. 1776 * @syscap SystemCapability.Web.Webview.Core 1777 * @since 10 1778 */ 1779 getCertificate(callback: AsyncCallback<Array<cert.X509Cert>>): void; 1780 1781 /** 1782 * Set audio muted. 1783 * @param { boolean } mute - Set the audio muted or not. 1784 * @throws { BusinessError } 401 - Invalid input parameter. 1785 * @throws { BusinessError } 17100001 - Init error. 1786 * The WebviewController must be associated with a Web component. 1787 * @syscap SystemCapability.Web.Webview.Core 1788 * @since 10 1789 */ 1790 setAudioMuted(mute: boolean): void; 1791 1792 /** 1793 * Prefetch the resources required by the page, but will not execute js or render the page. 1794 * @param { string } url - Which url to preresolve/preconnect. 1795 * @param { Array<WebHeader> } [additionalHeaders] - Additional HTTP request header of the URL. 1796 * @throws { BusinessError } 17100001 - Init error. 1797 * The WebviewController must be associated with a Web component. 1798 * @throws { BusinessError } 17100002 - Invalid url. 1799 * @syscap SystemCapability.Web.Webview.Core 1800 * @since 10 1801 */ 1802 prefetchPage(url: string, additionalHeaders?: Array<WebHeader>): void; 1803 1804 /** 1805 * Preresolve or Preconnect the url. This API can be called before loading the url to make loading faster. 1806 * @param { string } url - Which url to preresolve/preconnect. 1807 * @param { boolean } preconnectable - Indicates whether to preconnect. 1808 * @param { number } numSockets - If preconnectable is true, this parameter indicates the number of sockets to be preconnected. 1809 * @throws { BusinessError } 17100002 - Invalid url. 1810 * @throws { BusinessError } 171000013 - The number of preconnect sockets is invalid. 1811 * @syscap SystemCapability.Web.Webview.Core 1812 * @since 10 1813 */ 1814 static prepareForPageLoad(url: string, preconnectable: boolean, numSockets: number): void; 1815 1816 /** 1817 * Set custom user agent. 1818 * @param { string } userAgent - User custom agent information. 1819 * @throws { BusinessError } 401 - Invalid input parameter. 1820 * @throws { BusinessError } 17100001 - Init error. 1821 * The WebviewController must be associated with a Web component. 1822 * @syscap SystemCapability.Web.Webview.Core 1823 * @since 10 1824 */ 1825 setCustomUserAgent(userAgent: string): void; 1826 1827 /** 1828 * Get custom user agent. 1829 * @returns { string } Get custom User agent information. 1830 * @throws { BusinessError } 17100001 - Init error. 1831 * The WebviewController must be associated with a Web component. 1832 * @syscap SystemCapability.Web.Webview.Core 1833 * @since 10 1834 */ 1835 getCustomUserAgent(): string; 1836 } 1837} 1838 1839export default webview; 1840