1 /* 2 * Copyright (c) 2024 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 #ifndef ARK_WEB_NWEB_IMPL_H_ 17 #define ARK_WEB_NWEB_IMPL_H_ 18 #pragma once 19 20 #include "include/nweb.h" 21 #include "ohos_nweb/include/ark_web_nweb.h" 22 23 namespace OHOS::ArkWeb { 24 25 class ArkWebNWebImpl : public ArkWebNWeb { 26 IMPLEMENT_REFCOUNTING(ArkWebNWebImpl); 27 28 public: 29 ArkWebNWebImpl(std::shared_ptr<OHOS::NWeb::NWeb> nweb_nweb); 30 ~ArkWebNWebImpl() = default; 31 32 void Resize(uint32_t width, uint32_t height, bool is_keyboard) override; 33 34 void OnPause() override; 35 36 void OnContinue() override; 37 38 void OnDestroy() override; 39 40 void OnFocus(const int32_t& focus_reason) override; 41 42 void OnBlur(const int32_t& blur_reason) override; 43 44 void OnTouchPress(int32_t id, double x, double y, bool from_overlay) override; 45 46 void OnTouchRelease(int32_t id, double x, double y, bool from_overlay) override; 47 48 void OnTouchMove(int32_t id, double x, double y, bool from_overlay) override; 49 50 void OnTouchMove(const ArkWebTouchPointInfoVector& touch_point_infos, bool from_overlay) override; 51 52 void OnTouchCancel() override; 53 54 void OnNavigateBack() override; 55 56 bool SendKeyEvent(int32_t key_code, int32_t key_action) override; 57 58 void SendMouseWheelEvent(double x, double y, double delta_x, double delta_y) override; 59 60 void SendMouseEvent(int x, int y, int button, int action, int count) override; 61 62 /** 63 * @brief Loads the given URL. 64 * 65 * @param url: the URL of the resource to load This value cannot be null. 66 * 67 * @return title string for the current page. 68 */ 69 int Load(const ArkWebString& url) override; 70 71 /** 72 * @brief Gets whether this NWeb has a back history item. 73 * 74 * @return true if this NWeb has a back history item 75 */ 76 bool IsNavigatebackwardAllowed() override; 77 78 /** 79 * @brief Gets whether this NWeb has a forward history item. 80 * 81 * @return true if this NWeb has a forward history item 82 */ 83 bool IsNavigateForwardAllowed() override; 84 85 /** 86 * @brief Gets whether this NWeb has a back or forward history item for number 87 * of steps. 88 * 89 * @param num_steps: the negative or positive number of steps to move the 90 * history 91 * 92 * @return true if this NWeb has a forward history item 93 */ 94 bool CanNavigateBackOrForward(int num_steps) override; 95 96 /** 97 * @brief Goes back in the history of this NWeb. 98 */ 99 void NavigateBack() override; 100 101 /** 102 * @brief Goes forward in the history of this NWeb. 103 */ 104 void NavigateForward() override; 105 106 /** 107 * @brief Goes to the history item that is the number of steps away from the 108 * current item. 109 */ 110 void NavigateBackOrForward(int step) override; 111 112 /** 113 * @brief Delete back and forward history list. 114 */ 115 void DeleteNavigateHistory() override; 116 117 /** 118 * @brief Reloads the current URL. 119 */ 120 void Reload() override; 121 122 /** 123 * @brief Performs a zoom operation in this NWeb. 124 * 125 * @param zoom_factor: the zoom factor to apply. The zoom factor will be 126 * clamped to the NWeb's zoom limits. This value must be in the range 127 * 0.01 to 100.0 inclusive. 128 * 129 * @return the error id. 130 */ 131 int Zoom(float zoom_factor) override; 132 133 /** 134 * @brief Performs a zooming in operation in this NWeb. 135 * 136 * @return the error id. 137 */ 138 int ZoomIn() override; 139 140 /** 141 * @brief Performs a zooming out operation in this NWeb. 142 * 143 * @return the error id. 144 */ 145 int ZoomOut() override; 146 147 /** 148 * @brief Stops the current load. 149 * 150 * @param code string: javascript code 151 */ 152 void Stop() override; 153 154 /** 155 * @brief ExecuteJavaScript 156 */ 157 void ExecuteJavaScript(const ArkWebString& code) override; 158 159 /** 160 * @brief ExecuteJavaScript plus 161 * 162 * @param code: javascript code 163 * @param callback: javascript running result 164 */ 165 void ExecuteJavaScript( 166 const ArkWebString& code, ArkWebRefPtr<ArkWebMessageValueCallback> callback, bool extention) override; 167 168 /** 169 * @brief Gets the NWebPreference object used to control the settings for this 170 * NWeb. 171 * 172 * @return a NWebPreference object that can be used to control this NWeb's 173 * settings This value cannot be null. 174 */ 175 ArkWebRefPtr<ArkWebPreference> GetPreference() override; 176 177 /** 178 * @brief Gets the web id. 179 * 180 * @return the web id 181 */ 182 unsigned int GetWebId() override; 183 184 /** 185 * @brief Gets the last hit test result. 186 * 187 * @return the last HitTestResult 188 */ 189 ArkWebRefPtr<ArkWebHitTestResult> GetHitTestResult() override; 190 191 /** 192 * @brief Sets the background color for this view. 193 * 194 * @param color: the color of the background 195 */ 196 void PutBackgroundColor(int color) override; 197 198 /** 199 * @brief Sets the initla scale for the page. 200 * 201 * @param scale: the initla scale of the page. 202 */ 203 void InitialScale(float scale) override; 204 205 /** 206 * @brief Sets the NWebDownloadCallback that will receive download event. This 207 * will replace the current handler. 208 * 209 * @param download_listener: download listener 210 */ 211 void PutDownloadCallback(ArkWebRefPtr<ArkWebDownloadCallback> download_listener) override; 212 213 /** 214 * @brief Set the NWebAccessibilityEventCallback that will receive 215 * accessibility event. This will replace the current handler. 216 * 217 * @param accessibility_event_listener: accessibility event listener 218 */ 219 void PutAccessibilityEventCallback( 220 ArkWebRefPtr<ArkWebAccessibilityEventCallback> accessibility_event_listener) override; 221 222 /** 223 * @brief Set the accessibility id generator that will generate accessibility 224 * id for accessibility nodes in the web. This will replace the current 225 * handler. 226 * 227 * @param accessibility_id_generator: Accessibility id generator. 228 */ 229 void PutAccessibilityIdGenerator(AccessibilityIdGenerateFunc accessibility_id_generator) override; 230 231 /** 232 * @brief Set the NWebHandler that will receive various notifications and 233 * requests. This will replace the current handler. 234 * 235 * @param handler: an implementation of NWebHandler This value cannot be null. 236 */ 237 void SetNWebHandler(ArkWebRefPtr<ArkWebHandler> handler) override; 238 239 /** 240 * @brief Gets the title for the current page. 241 * 242 * @return title string for the current page. 243 */ 244 ArkWebString Title() override; 245 246 /** 247 * @brief Gets the progress for the current page. 248 * 249 * @return progress for the current page. 250 */ 251 int PageLoadProgress() override; 252 253 /** 254 * @brief Gets the height of the HTML content. 255 * 256 * @return the height of the HTML content. 257 */ 258 int ContentHeight() override; 259 260 /** 261 * @brief Gets the current scale of this NWeb. 262 * 263 * @return the current scale 264 */ 265 float Scale() override; 266 267 /** 268 * @brief Loads the given URL with additional HTTP headers, specified as a map 269 * from name to value. Note that if this map contains any of the 270 * headers that are set by default by this NWeb, such as those 271 * controlling caching, accept types or the User-Agent, their values 272 * may be overridden by this NWeb's defaults. 273 * 274 * @param url: the URL of the resource to load This value cannot be null. 275 * @param additional_http_headers: additional http headers 276 */ 277 int Load(const ArkWebString& url, const ArkWebStringMap& additional_http_headers) override; 278 279 /** 280 * @brief Loads the given data into this NWeb, using baseUrl as the base URL 281 * for the content. The base URL is used both to resolve relative URLs 282 * and when applying JavaScript's same origin policy. The historyUrl is 283 * used for the history entry. 284 * 285 * @param base_url: the URL to use as the page's base URL. If null defaults to 286 * 'about:blank'. This value may be null. 287 * @param data: the URL to use as the page's base URL. If null defaults to 288 * 'about:blank'. This value may be null. 289 * @param mime_type: the MIME type of the data, e.g. 'text/html'. This value 290 * may be null. 291 * @param encoding: the encoding of the data This value may be null. 292 * @param history_url: the URL to use as the history entry. If null defaults 293 * to 'about:blank'. If non-null, this must be a valid URL. This value 294 * may be null. 295 */ 296 int LoadWithDataAndBaseUrl(const ArkWebString& base_url, const ArkWebString& data, const ArkWebString& mime_type, 297 const ArkWebString& encoding, const ArkWebString& history_url) override; 298 299 /** 300 * @brief Loads the given data into this NWeb. 301 * 302 * @param data: the URL to use as the page's base URL. If null defaults to 303 * 'about:blank'. This value may be null. 304 * @param mime_type: the MIME type of the data, e.g. 'text/html'. This value 305 * may be null. 306 * @param encoding: the encoding of the data This value may be null. 307 */ 308 int LoadWithData(const ArkWebString& data, const ArkWebString& mime_type, const ArkWebString& encoding) override; 309 310 /** 311 * @brief RegisterArkJSfunction 312 * 313 * @param object_name String: objector name 314 * @param method_list vector<String>: vector list ,method list 315 * @param object_id int32_t: object id 316 */ 317 void RegisterArkJSfunction( 318 const ArkWebString& object_name, const ArkWebStringVector& method_list, const int32_t object_id) override; 319 320 /** 321 * @brief UnregisterArkJSfunction 322 * 323 * @param object_name: objector name 324 * @param method_list: vector list ,method list 325 */ 326 void UnregisterArkJSfunction(const ArkWebString& object_name, const ArkWebStringVector& method_list) override; 327 328 /** 329 * @brief SetNWebJavaScriptResultCallBack 330 * 331 * @param callback: callback client 332 */ 333 void SetNWebJavaScriptResultCallBack(ArkWebRefPtr<ArkWebJsResultCallback> callback) override; 334 335 /** 336 * @brief Set the NWebFindCallback that will receive find event. This will 337 * replace the current handler. 338 * 339 * @param find_listener: find callback 340 */ 341 void PutFindCallback(ArkWebRefPtr<ArkWebFindCallback> find_listener) override; 342 343 /** 344 * @brief Finds all instances of find on the page and highlights them, 345 * asynchronously. 346 * 347 * @param search_str: target string to find. 348 */ 349 void FindAllAsync(const ArkWebString& search_str) override; 350 351 /** 352 * @brief Clears the highlighting surrounding text matches created by 353 * findAllAsync 354 */ 355 void ClearMatches() override; 356 357 /** 358 * @brief Highlights and scrolls to the next match found by 359 * findAllAsync(String), wrapping around page boundaries as necessary. 360 * 361 * @param forward: find back or forward: 362 */ 363 void FindNext(const bool forward) override; 364 365 /** 366 * @brief Saves the current view as a web archive. 367 * 368 * @param base_name: the filename where the archive should be placed This 369 * value cannot be null. 370 * @param auto_name: if false, takes basename to be a file. If true, basename 371 * is assumed to be a directory in which a filename will be chosen 372 * according to the URL of the current page. 373 */ 374 void StoreWebArchive( 375 const ArkWebString& base_name, bool auto_name, ArkWebRefPtr<ArkWebStringValueCallback> callback) override; 376 377 /** 378 * @brief creating two ends of a message channel. 379 * 380 * @return the web message ports get from nweb. 381 */ 382 ArkWebStringVector CreateWebMessagePorts() override; 383 384 /** 385 * @brief Posts MessageEvent to the main frame. 386 * 387 * @param message: message send to mmain frame. 388 * @param ports: the web message ports send to main frame. 389 * @param target_uri: the uri which can received the ports. 390 */ 391 void PostWebMessage( 392 const ArkWebString& message, const ArkWebStringVector& ports, const ArkWebString& target_uri) override; 393 394 /** 395 * @brief close the message port. 396 * 397 * @param port_handle: the port to close. 398 */ 399 void ClosePort(const ArkWebString& port_handle) override; 400 401 /** 402 * @brief use the port to send message. 403 * 404 * @param port_handle: the port to send message. 405 * @param data: the message to send. 406 */ 407 void PostPortMessage(const ArkWebString& port_handle, const ArkWebMessage& data) override; 408 409 /** 410 * @brief set the callback of the message port. 411 * 412 * @param port_handle: the port to set callback. 413 * @param callback: to reveive the result when the other port post message. 414 */ 415 void SetPortMessageCallback( 416 const ArkWebString& port_handle, ArkWebRefPtr<ArkWebMessageValueCallback> callback) override; 417 418 void SendDragEvent(ArkWebRefPtr<ArkWebDragEvent> drag_event) override; 419 420 /** 421 * @brief Clear ssl cache. 422 */ 423 void ClearSslCache() override; 424 425 /** 426 * @brief get web page url. 427 * 428 * @return web page url. 429 */ 430 ArkWebString GetUrl() override; 431 432 /** 433 * @brief Clears the client authentication certificate Cache in the Web. 434 */ 435 void ClearClientAuthenticationCache() override; 436 437 /** 438 * @brief set the locale name of current system setting.. 439 * 440 * @param region: the locale name of current system setting. 441 */ 442 void UpdateLocale(const ArkWebString& language, const ArkWebString& region) override; 443 444 /** 445 * @brief get original url of the request. 446 * 447 * @return original url. 448 */ 449 const ArkWebString GetOriginalUrl() override; 450 451 /** 452 * @brief get original url of the request. 453 * 454 * @param data: raw image data of the icon. 455 * @param width: width of the icon. 456 * @param height: height of the icon. 457 * @param color_type: the color type of the icon. 458 * @param alpha_type: the alpha type of the icon. 459 * 460 * @return the result of get favicon. 461 */ 462 bool GetFavicon(const void** data, size_t& width, size_t& height, int& color_type, int& alpha_type) override; 463 464 /** 465 * @brief set the network status, just notify the webview to change the JS 466 * navigatoer.online. 467 * 468 * @param available: width of the icon. 469 */ 470 void PutNetworkAvailable(bool available) override; 471 472 /** 473 * @brief web has image or not. 474 * 475 * @param callback: has image or not 476 */ 477 void HasImages(ArkWebRefPtr<ArkWebBoolValueCallback> callback) override; 478 479 /** 480 * @brief web remove cache. 481 * 482 * @param include_disk_files: if false, only the RAM cache is removed 483 */ 484 void RemoveCache(bool include_disk_files) override; 485 486 /** 487 * @brief web has image or not. 488 */ 489 ArkWebRefPtr<ArkWebHistoryList> GetHistoryList() override; 490 491 /** 492 * @brief Set the NWebReleaseSurfaceCallback that will receive release surface 493 * event. This will replace the current handler. 494 * 495 * @param release_surface_listener: release surface listener 496 */ 497 void PutReleaseSurfaceCallback(ArkWebRefPtr<ArkWebReleaseSurfaceCallback> release_surface_listener) override; 498 499 /** 500 * @brief Get web back forward state. 501 * 502 * @return web back forward state. 503 */ 504 ArkWebUint8Vector SerializeWebState() override; 505 506 /** 507 * @brief Restore web back forward state. 508 * 509 * @param state: web back forward state. 510 */ 511 bool RestoreWebState(const ArkWebUint8Vector& state) override; 512 513 /** 514 * @brief Move page up. 515 * 516 * @param top: whether move to the top. 517 */ 518 void PageUp(bool top) override; 519 520 /** 521 * @brief Move page down. 522 * 523 * @param bottom: whether move to the bottom. 524 */ 525 void PageDown(bool bottom) override; 526 527 /** 528 * @brief Scroll to the position. 529 * 530 * @param x: horizontal coordinate. 531 * @param y: vertical coordinate. 532 */ 533 void ScrollTo(float x, float y) override; 534 535 /** 536 * @brief Scroll by the delta distance. 537 * 538 * @param delta_x: horizontal offset. 539 * @param delta_y: vertical offset. 540 */ 541 void ScrollBy(float delta_x, float delta_y) override; 542 543 /** 544 * @brief Slide scroll by the speed. 545 * 546 * @param vx: horizontal slide speed. 547 * @param vy: vertical slide speed. 548 */ 549 void SlideScroll(float vx, float vy) override; 550 551 /** 552 * @brief Get current website certificate. 553 * 554 * @param cert_chain_data: current website certificate array. 555 * @param is_single_cert: true if only get one certificate of current website, 556 * false if get certificate chain of the website. 557 * 558 * @return true if get certificate successfully, otherwise false. 559 */ 560 bool GetCertChainDerData(ArkWebStringVector& cert_chain_data, bool is_single_cert) override; 561 562 /** 563 * @brief Set screen offset. 564 * 565 * @param x: the offset in x direction. 566 * @param y: the offset in y direction. 567 */ 568 void SetScreenOffSet(double x, double y) override; 569 570 /** 571 * @brief Set audio muted. 572 * 573 * @param muted: Aduio mute state. 574 */ 575 void SetAudioMuted(bool muted) override; 576 577 /** 578 * @brief Set should frame submission before draw. 579 * 580 * @param should: whether wait render frame submission. 581 */ 582 void SetShouldFrameSubmissionBeforeDraw(bool should) override; 583 584 /** 585 * @brief Notify whether the popup window is initialized successfully. 586 * 587 * @param result: whether success. 588 */ 589 void NotifyPopupWindowResult(bool result) override; 590 591 /** 592 * @brief Set audio resume interval. 593 * 594 * @param resume_interval: Aduio resume interval. 595 */ 596 void SetAudioResumeInterval(int32_t resume_interval) override; 597 598 /** 599 * @brief Set audio exclusive state. 600 * 601 * @param audio_exclusive: Aduio exclusive state. 602 */ 603 void SetAudioExclusive(bool audio_exclusive) override; 604 605 /** 606 * @brief Rigest the keep srceen on interface. 607 * 608 * @param window_id: the window id. 609 * @param callback the screenon handle callback. 610 */ 611 void RegisterScreenLockFunction(int32_t window_id, ArkWebRefPtr<ArkWebScreenLockCallback> callback) override; 612 613 /** 614 * @brief UnRigest the keep srceen on interface. 615 * 616 * @param window_id: the window id. 617 */ 618 void UnRegisterScreenLockFunction(int32_t window_id) override; 619 620 /** 621 * @brief Notify memory level. 622 * 623 * @param level: the memory level. 624 */ 625 void NotifyMemoryLevel(int32_t level) override; 626 627 /** 628 * @brief Notify webview window status. 629 */ 630 void OnWebviewHide() override; 631 632 void OnWebviewShow() override; 633 634 /** 635 * @brief Get drag data. 636 * 637 * @return the drag data. 638 */ 639 ArkWebRefPtr<ArkWebDragData> GetOrCreateDragData() override; 640 641 /** 642 * @brief Prefetch the resources required by the page, but will not execute js 643 * or render the page. 644 * 645 * @param url: Which url to preresolve/preconnect. 646 * @param additional_http_headers: Additional HTTP request header of the URL. 647 */ 648 void PrefetchPage(const ArkWebString& url, const ArkWebStringMap& additional_http_headers) override; 649 650 /** 651 * @brief Set the window id. 652 */ 653 void SetWindowId(uint32_t window_id) override; 654 655 /** 656 * @brief Notify that browser was occluded by other windows. 657 */ 658 void OnOccluded() override; 659 660 /** 661 * @brief Notify that browser was unoccluded by other windows. 662 */ 663 void OnUnoccluded() override; 664 665 /** 666 * @brief Set the token. 667 */ 668 void SetToken(void* token) override; 669 670 /** 671 * @brief Set the nested scroll mode. 672 */ 673 void SetNestedScrollMode(const int32_t& nested_scroll_mode) override; 674 675 /** 676 * @brief Set enable lower the frame rate. 677 */ 678 void SetEnableLowerFrameRate(bool enabled) override; 679 680 /** 681 * @brief Set the property values for width, height, and keyboard height. 682 */ 683 void SetVirtualKeyBoardArg(int32_t width, int32_t height, double keyboard) override; 684 685 /** 686 * @brief Set the virtual keyboard to override the web status. 687 */ 688 bool ShouldVirtualKeyboardOverlay() override; 689 690 /** 691 * @brief Set draw rect. 692 */ 693 void SetDrawRect(int32_t x, int32_t y, int32_t width, int32_t height) override; 694 695 /** 696 * @brief Set draw mode. 697 */ 698 void SetDrawMode(int32_t mode) override; 699 700 /** 701 * @brief Create web print document adapter. 702 */ 703 void* CreateWebPrintDocumentAdapter(const ArkWebString& job_name) override; 704 705 /** 706 * @brief Loads the URL with postData using "POST" method into this WebView. 707 * If url is not a network URL, it will be loaded with loadUrl(String) 708 * instead. 709 * 710 * @param url: the URL of the resource to load This value cannot be null. 711 * @param post_data: the data will be passed to "POST" request, whilch must be 712 * "application/x-www-form-urlencoded" encoded. 713 * 714 * @return title string for the current page. 715 */ 716 int PostUrl(const ArkWebString& url, const ArkWebCharVector& post_data) override; 717 718 /** 719 * @brief Inject the JavaScript before WebView load the DOM tree. 720 */ 721 void JavaScriptOnDocumentStart(const ArkWebStringVectorMap& script_items) override; 722 723 /** 724 * @brief Execute an accessibility action on an accessibility node in the 725 * browser. 726 * 727 * @param accessibility_id: The id of the accessibility node. 728 * @param action: The action to be performed on the accessibility node. 729 */ 730 void ExecuteAction(int64_t accessibility_id, uint32_t action) override; 731 732 /** 733 * @brief Get the information of the focused accessibility node on the given 734 * accessibility node in the browser. 735 * 736 * @param accessibility_id: Indicate the accessibility id of the parent node 737 * of the focused accessibility node. 738 * @param is_accessibility_focus: Indicate whether the focused accessibility 739 * node is accessibility focused or input focused. 740 * 741 * @return The obtained information of the accessibility node. 742 */ 743 ArkWebRefPtr<ArkWebAccessibilityNodeInfo> GetFocusedAccessibilityNodeInfo( 744 int64_t accessibility_id, bool is_accessibility_focus) override; 745 746 /** 747 * @brief Get the information of the accessibility node by its accessibility 748 * id in the browser. 749 * 750 * @param accessibility_id: The accessibility id of the accessibility node. 751 * 752 * @return The obtained information of the accessibility node. 753 */ 754 ArkWebRefPtr<ArkWebAccessibilityNodeInfo> GetAccessibilityNodeInfoById(int64_t accessibility_id) override; 755 756 /** 757 * @brief Get the information of the accessibility node by focus move in the 758 * browser. 759 * 760 * @param accessibility_id: The accessibility id of the original accessibility 761 * node. 762 * @param direction: The focus move direction of the original accessibility 763 * node. 764 * 765 * @return The obtained information of the accessibility node. 766 */ 767 ArkWebRefPtr<ArkWebAccessibilityNodeInfo> GetAccessibilityNodeInfoByFocusMove( 768 int64_t accessibility_id, int32_t direction) override; 769 770 /** 771 * @brief Set the accessibility state in the browser. 772 * 773 * @param state: Indicate whether the accessibility state is enabled or 774 * disabled. 775 */ 776 void SetAccessibilityState(bool state) override; 777 778 /** 779 * @brief Get whether need soft keyboard. 780 * 781 * @return true if need soft keyboard, otherwise false. 782 */ 783 bool NeedSoftKeyboard() override; 784 785 /** 786 * @brief Discard the webview window. 787 * 788 * @return true if the discarding success, otherwise false. 789 */ 790 bool Discard() override; 791 792 /** 793 * @brief Reload the webview window that has been discarded before. 794 * 795 * @return true if the discarded window reload success, otherwise false. 796 */ 797 bool Restore() override; 798 799 /** 800 * @brief Get the security level of current page. 801 * 802 * @return security level for current page. 803 */ 804 int GetSecurityLevel() override; 805 806 /** 807 * @brief CallH5Function 808 * 809 * @param routingId int32_t: the h5 frame routing id 810 * @param h5ObjectId int32_t: the h5 side object id 811 * @param h5MethodName string: the h5 side object method name 812 * @param args vector<shared_ptr<NWebValue>>: the call args 813 */ 814 void CallH5Function(int32_t routingId, int32_t h5ObjectId, const ArkWebString& h5MethodName, 815 const ArkWebValueVector& args) override; 816 817 /** 818 * @brief Get web weather has been set incognito mode. 819 * 820 * @return true if web is in incognito mode; otherwise fase. 821 */ 822 bool IsIncognitoMode() override; 823 824 /** 825 * @brief Register native function. 826 */ 827 void RegisterNativeArkJSFunction(const char* objName, const ArkWebJsProxyCallbackVector& callbacks) override; 828 829 /** 830 * @brief Unregister native function. 831 */ 832 void UnRegisterNativeArkJSFunction(const char* objName) override; 833 834 /** 835 * @brief Register native valide callback function. 836 */ 837 void RegisterNativeValideCallback(const char* webName, const NativeArkWebOnValidCallback callback) override; 838 839 /** 840 * @brief Register native destroy callback function. 841 */ 842 void RegisterNativeDestroyCallback(const char* webName, const NativeArkWebOnValidCallback callback) override; 843 844 /** 845 * @brief Inject the JavaScript after WebView loads the DOM tree and run 846 * JavaScripts. 847 */ 848 void JavaScriptOnDocumentEnd(const ArkWebStringVectorMap& script_items) override; 849 850 /** 851 * @brief Enable the ability to check website security risks.Illegal and 852 * fraudulent websites are mandatory enabled and cann't be disabled by 853 * this function. 854 */ 855 void EnableSafeBrowsing(bool enable) override; 856 857 /** 858 * @brief Get whether checking website security risks is enabled. 859 * 860 * @return true if enable the ability to check website security risks else 861 * false. 862 */ 863 bool IsSafeBrowsingEnabled() override; 864 865 /** 866 * @brief Set the ability to print web page background. 867 * 868 * @param enable Indicate whether the ability is enabled or disabled. 869 */ 870 void SetPrintBackground(bool enable) override; 871 872 /** 873 * @brief Obtains whether to print the background of a web page. 874 * 875 * @return true if enable print web page background, otherwise false. 876 */ 877 bool GetPrintBackground() override; 878 879 /** 880 * @brief Close fullScreen video. 881 */ 882 void CloseAllMediaPresentations() override; 883 884 /** 885 * @brief Stop all audio and video playback on the web page. 886 */ 887 void StopAllMedia() override; 888 889 /** 890 * @brief Restart playback of all audio and video on the web page. 891 */ 892 void ResumeAllMedia() override; 893 894 /** 895 * @brief Pause all audio and video playback on the web page. 896 */ 897 void PauseAllMedia() override; 898 899 /** 900 * @brief View the playback status of all audio and video on the web page. 901 * 902 * @return The playback status of all audio and video. 903 */ 904 int GetMediaPlaybackState() override; 905 906 /** 907 * @brief Obtains the last javascript proxy calling frame url. 908 * 909 * @return the url of last calling frame url. 910 */ 911 /*--ark web()--*/ 912 ArkWebString GetLastJavascriptProxyCallingFrameUrl() override; 913 914 /** 915 * @brief Enable the ability to intelligent tracking prevention, default 916 * disabled. 917 * 918 * @param enable Indicate whether the abilitiy is enabled or disabled. 919 */ 920 void EnableIntelligentTrackingPrevention(bool enable) override; 921 922 /** 923 * @brief Get whether intelligent tracking prevention is enabled. 924 * @return true if enable the ability intelligent tracking prevention; else 925 * false. 926 */ 927 bool IsIntelligentTrackingPreventionEnabled() override; 928 929 /** 930 * @brief Start current camera. 931 */ 932 /*--ark web()--*/ 933 void StartCamera() override; 934 935 /** 936 * @brief Stop current camera. 937 */ 938 /*--ark web()--*/ 939 void StopCamera() override; 940 941 /** 942 * @brief Close current camera. 943 */ 944 /*--ark web()--*/ 945 void CloseCamera() override; 946 947 /** 948 * @brief get pendingsize status. 949 * 950 * @return the result of last pendingsize status. 951 */ 952 bool GetPendingSizeStatus() override; 953 954 /** 955 * Scroll by the delta distance or velocity takes the screen as a reference. 956 * 957 * @param delta_x horizontal offset in physical pixel. 958 * @param delta_y vertical offset in physical pixel. 959 * @param vx horizontal velocity in physical pixel. 960 * @param vx vertical velocity in physical pixel. 961 */ 962 /*--ark web()--*/ 963 void ScrollByRefScreen(float delta_x, float delta_y, float vx, float vy) override; 964 965 /** 966 * ExecuteJavaScript with ashmem 967 * 968 * @param fd fd of the ashmem 969 * @param scriptLength javascript code length 970 * @param callback NWebValueCallback: javascript running result 971 * @param extention true if is extention 972 */ 973 void ExecuteJavaScriptExt(const int fd, const size_t scriptLength, 974 ArkWebRefPtr<ArkWebMessageValueCallback> callback, bool extention) override; 975 976 /** 977 * @brief Render process switch to background. 978 */ 979 /*--ark web()--*/ 980 void OnRenderToBackground() override; 981 982 /** 983 * @brief Render process switch to foreground. 984 */ 985 /*--ark web()--*/ 986 void OnRenderToForeground() override; 987 988 /** 989 * @brief Compile javascript and generate code cache. 990 * 991 * @param url url of javascript. 992 * @param script javascript text content. 993 * @param cacheOptions compile options and info. 994 * @param callback callback will be called on getting the result of compiling 995 * javascript. 996 */ 997 void PrecompileJavaScript(const ArkWebString& url, const ArkWebString& script, 998 ArkWebRefPtr<ArkWebCacheOptions>& cacheOptions, ArkWebRefPtr<ArkWebMessageValueCallback> callback) override; 999 1000 void OnCreateNativeMediaPlayer(ArkWebRefPtr<ArkWebCreateNativeMediaPlayerCallback> callback) override; 1001 1002 /** 1003 * @brief Set the params when the scale of WebView changed by pinch gestrue. 1004 * 1005 * @param scale: the scale factor to apply. The scale will be 1006 * clamped to the pinch limits. This value must be in the range 1007 * 0.01 to 8.0 inclusive. 1008 * @param centerX: X-coordinate of the pinch center 1009 * @param centerX: Y-coordinate of the pinch center 1010 * 1011 * @return the error id. 1012 */ 1013 /*--ark web()--*/ 1014 int ScaleGestureChange(double scale, double centerX, double centerY) override; 1015 1016 /** 1017 * @brief Inject offline resource into MemoryCache. 1018 * 1019 * @param url url of resource. 1020 * @param origin origin of resource. 1021 * @param resource data of resource. 1022 * @param response_headers response headers of resource. 1023 * @param type resource type. 1024 */ 1025 /*--ark web()--*/ 1026 void InjectOfflineResource(const ArkWebString& url, const ArkWebString& origin, const ArkWebUint8Vector& resource, 1027 const ArkWebStringMap& responseHeaders, const int type) override; 1028 1029 /** 1030 * Get value of Autofill index. 1031 * @param index index value. 1032 */ 1033 /*--ark web()--*/ 1034 void SuggestionSelected(int32_t index) override; 1035 1036 /** 1037 * @brief Send touchpad fling event. 1038 * 1039 * @param x location of x. 1040 * @param y location of y. 1041 * @param vx velocity of x. 1042 * @param vy velocity of y. 1043 */ 1044 /*--ark web()--*/ 1045 void SendTouchpadFlingEvent(double x, double y, double vx, double vy) override; 1046 1047 /* 1048 * @brief Terminate render process 1049 * 1050 * @return true if it was possible to terminate this render process, false 1051 * otherwise. 1052 */ 1053 /*--ark web()--*/ 1054 bool TerminateRenderProcess() override; 1055 1056 /** 1057 * @brief RegisterArkJSfunction 1058 * 1059 * @param object_name String: object name 1060 * @param method_list vector<String>: vector list, method list 1061 * @param async_method_list vector<String>: vector list, async method list 1062 * @param object_id int32_t: object id 1063 */ 1064 void RegisterArkJSfunction(const ArkWebString& object_name, const ArkWebStringVector& method_list, 1065 const ArkWebStringVector& async_method_list, const int32_t object_id) override; 1066 1067 /** 1068 * @brief Set fit content mode. 1069 */ 1070 void SetFitContentMode(int32_t mode) override; 1071 1072 /** 1073 * @brief Get select info. 1074 */ 1075 ArkWebString GetSelectInfo() override; 1076 1077 /** 1078 * @brief Notify that safe insets change. 1079 * 1080 */ 1081 void OnSafeInsetsChange(int left, int top, int right, int bottom) override; 1082 1083 /** 1084 * @brief Render process switch to foreground. 1085 */ 1086 /*--ark web()--*/ 1087 void OnOnlineRenderToForeground() override; 1088 1089 /** 1090 * @brief Called when text is selected in image. 1091 */ 1092 /*--ark web()--*/ 1093 void OnTextSelected() override; 1094 1095 /** 1096 * @brief Enable the ability to block Ads, default disabled. 1097 */ 1098 /*--ark web()--*/ 1099 void EnableAdsBlock(bool enable) override; 1100 1101 /** 1102 * @brief Get whether Ads block is enabled. 1103 */ 1104 /*--ark web()--*/ 1105 bool IsAdsBlockEnabled() override; 1106 1107 /** 1108 * @brief Get whether Ads block is enabled for current Webpage. 1109 */ 1110 /*--ark web()--*/ 1111 bool IsAdsBlockEnabledForCurPage() override; 1112 1113 /** 1114 * @brief Notify for next touch move event. 1115 */ 1116 /*--ark web()--*/ 1117 void NotifyForNextTouchEvent() override; 1118 1119 /** 1120 * @brief Get Web page snapshot 1121 * 1122 * @param id Request id. 1123 * @param type Request snapshot pixel unit. 1124 * @param width Request SnapShot width. 1125 * @param height Request SnapShot height. 1126 * @param callback SnapShot result callback. 1127 * @return ture if succuess request snapshot to renderer. 1128 */ 1129 /*--ark web()--*/ 1130 bool WebPageSnapshot(const char* id, 1131 int type, 1132 int width, 1133 int height, 1134 const WebSnapshotCallback callback) override; 1135 1136 /** 1137 * @brief Notify that system configuration changed. 1138 * 1139 * @param configuration system configuration. 1140 */ 1141 /*--ark web()--*/ 1142 void OnConfigurationUpdated( 1143 ArkWebRefPtr<ArkWebSystemConfiguration> configuration) override; 1144 1145 /** 1146 * @brief Set url trust list. 1147 * 1148 * @param urlTrustList The url trust list. 1149 */ 1150 /*--ark web()--*/ 1151 int SetUrlTrustList(const ArkWebString& urlTrustList) override; 1152 1153 /** 1154 * @brief Put the callback for convert spanstring to html. 1155 * 1156 * @param callback will convert spanstring to html. 1157 */ 1158 /*--ark web()--*/ 1159 void PutSpanstringConvertHtmlCallback( 1160 ArkWebRefPtr<ArkWebSpanstringConvertHtmlCallback> callback) override; 1161 1162 /** 1163 * Web send key event. 1164 * @param key_code code value. 1165 * @param key_action action value. 1166 * @param pressedCodes pressedCodes value. 1167 */ 1168 /*--ark web()--*/ 1169 bool WebSendKeyEvent(int32_t key_code, int32_t key_action, const ArkWebInt32Vector& pressedCodes) override; 1170 1171 /** 1172 * @brief Set grant file access dirs. 1173 */ 1174 /*--ark web()--*/ 1175 void SetPathAllowingUniversalAccess(const ArkWebStringVector& dirs, 1176 const ArkWebStringVector& moduleName, ArkWebString& errorPath) override; 1177 1178 /** 1179 * @brief Send mouse wheel event. 1180 */ 1181 /*--ark web()--*/ 1182 void WebSendMouseWheelEvent(double x, 1183 double y, 1184 double delta_x, 1185 double delta_y, 1186 const ArkWebInt32Vector& pressedCodes) override; 1187 1188 /** 1189 * @brief Send touchpad fling event. 1190 * 1191 * @param x location of x. 1192 * @param y location of y. 1193 * @param vx velocity of x. 1194 * @param vy velocity of y. 1195 * @param pressedCodes pressed codes. 1196 */ 1197 /*--ark web()--*/ 1198 void WebSendTouchpadFlingEvent(double x, 1199 double y, 1200 double vx, 1201 double vy, 1202 const ArkWebInt32Vector& pressedCodes) override; 1203 1204 /** 1205 * @brief Set url trust list with error message. 1206 * 1207 * @param urlTrustList The url trust list. 1208 * @param detailErrMsg The detail error message. 1209 */ 1210 /*--ark web()--*/ 1211 int SetUrlTrustListWithErrMsg(const ArkWebString& urlTrustList, ArkWebString& detailErrMsg) override; 1212 1213 /** 1214 * @brief resize visual viewport. 1215 * 1216 * @param width width. 1217 * @param height height. 1218 * @param iskeyboard from keybord. 1219 */ 1220 /*--ark web()--*/ 1221 void ResizeVisibleViewport(uint32_t width, uint32_t height, bool isKeyboard) override; 1222 1223 /** 1224 * @brief set backforward cache options. 1225 * @param size The size of the back forward cache could saved. 1226 * @param timeToLive The time of the back forward cache page could stay. 1227 */ 1228 /*--ark web()--*/ 1229 void SetBackForwardCacheOptions(int32_t size, int32_t timeToLive) override; 1230 1231 /** 1232 * @brief RegisterArkJSfunctionV2 1233 * 1234 * @param object_name String: object name 1235 * @param method_list vector<String>: vector list, method list 1236 * @param async_method_list vector<String>: vector list, async method list 1237 * @param object_id int32_t: object id 1238 * @param permission String: allowlist 1239 */ 1240 void RegisterArkJSfunctionV2(const ArkWebString& object_name, const ArkWebStringVector& method_list, 1241 const ArkWebStringVector& async_method_list, const int32_t object_id, const ArkWebString& permission) override; 1242 1243 /** 1244 * @brief set the callback of the autofill event. 1245 * @param callback callback. 1246 */ 1247 /*--ark web()--*/ 1248 void SetAutofillCallback(ArkWebRefPtr<ArkWebMessageValueCallback> callback) override; 1249 1250 /** 1251 * @brief fill autofill data. 1252 * @param data data. 1253 */ 1254 /*--ark web()--*/ 1255 void FillAutofillData(const ArkWebMessage& data) override; 1256 1257 /** 1258 * @brief on autofill cancel. 1259 * @param fillContent fillContent 1260 */ 1261 /*--ark web()--*/ 1262 void OnAutofillCancel(const ArkWebString& fillContent) override; 1263 1264 /** 1265 * @brief Execute an accessibility action on an accessibility node in the 1266 * browser. 1267 * 1268 * @param accessibility_id: The id of the accessibility node. 1269 * @param action: The action to be performed on the accessibility node. 1270 * @param actionArguments Data related to the current action. 1271 */ 1272 /*--ark web()--*/ 1273 void PerformAction(int64_t accessibility_id, uint32_t action, 1274 const ArkWebStringMap& actionArguments) override; 1275 1276 /** 1277 * @brief Send the accessibility hover event coordinate. 1278 * 1279 * @param x horizontal location of coordinate. 1280 * @param y vertical location of coordinate. 1281 */ 1282 /*--ark web()--*/ 1283 void SendAccessibilityHoverEvent(int32_t x, int32_t y) override; 1284 1285 /** 1286 * Scroll by the delta distance if web is not foucsed. 1287 * 1288 * @param delta_x horizontal offset. 1289 * @param delta_y vertical offset. 1290 * @return false if web is focused. 1291 */ 1292 /*--ark web()--*/ 1293 bool ScrollByWithResult(float delta_x, float delta_y) override; 1294 1295 /** 1296 * @brief Called when image analyzer is destory. 1297 */ 1298 /*--ark web()--*/ 1299 void OnDestroyImageAnalyzerOverlay() override; 1300 1301 /** 1302 * @brief Get the current scroll offset of the webpage. 1303 * @param offset_x The current horizontal scroll offset of the webpage. 1304 * @param offset_y The current vertical scroll offset of the webpage. 1305 */ 1306 /*--ark web()--*/ 1307 void GetScrollOffset(float* offset_x, float* offset_y) override; 1308 1309 /** 1310 * @brief set DPI when DPI changes. 1311 * @param density The new density value. 1312 */ 1313 /*--ark web()--*/ 1314 void SetSurfaceDensity(const double& density) override; 1315 1316 /** 1317 * @Description: Get the accessibility visibility of the accessibility node by its accessibility id in the browser. 1318 * @Input accessibility_id: The accessibility id of the accessibility node. 1319 * @Return: The accessibility visibility of the accessibility node. 1320 */ 1321 /*--ark web()--*/ 1322 bool GetAccessibilityVisible(int64_t accessibility_id) override; 1323 1324 /** 1325 * @brief Web components blur when the keyboard is hidden by gesture back. 1326 */ 1327 void WebComponentsBlur() override; 1328 1329 /** 1330 * Scroll to the position. 1331 * 1332 * @param x horizontal coordinate. 1333 * @param y vertical coordinate. 1334 * @param duration: anime duration. 1335 */ 1336 /*--ark web()--*/ 1337 void ScrollToWithAnime(float x, float y, int32_t duration) override; 1338 1339 /** 1340 * Scroll by the delta distance. 1341 * 1342 * @param delta_x: horizontal offset. 1343 * @param delta_y: vertical offset. 1344 * @param duration: anime duration. 1345 */ 1346 /*--ark web()--*/ 1347 void ScrollByWithAnime(float delta_x, float delta_y, int32_t duration) override; 1348 1349 /** 1350 * @brief ExecuteCreatePDF 1351 * 1352 * @param pdfConfig The current configuration when creating pdf. 1353 * @param callback NWebArrayBufferValueCallback: CreatePDF running result. 1354 */ 1355 /*--ark web()--*/ 1356 void ExecuteCreatePDFExt( 1357 ArkWebRefPtr<ArkWebPDFConfigArgs> pdfConfig, ArkWebRefPtr<ArkWebArrayBufferValueCallback> callback) override; 1358 private: 1359 std::shared_ptr<OHOS::NWeb::NWeb> nweb_nweb_; 1360 }; 1361 1362 } // namespace OHOS::ArkWeb 1363 1364 #endif // ARK_WEB_NWEB_IMPL_H_ 1365