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