1 /* 2 * Copyright (c) 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 #ifndef NWEB_HANDLER_H 17 #define NWEB_HANDLER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "nweb.h" 24 #include "nweb_access_request.h" 25 #include "nweb_app_link_callback.h" 26 #include "nweb_console_log.h" 27 #include "nweb_context_menu_params.h" 28 #include "nweb_controller_handler.h" 29 #include "nweb_custom_keyboard_handler.h" 30 #include "nweb_data_resubmission_callback.h" 31 #include "nweb_date_time_chooser.h" 32 #include "nweb_drag_data.h" 33 #include "nweb_file_selector_params.h" 34 #include "nweb_first_meaningful_paint_details.h" 35 #include "nweb_full_screen_exit_handler.h" 36 #include "nweb_geolocation_callback_interface.h" 37 #include "nweb_gesture_event_result.h" 38 #include "nweb_js_dialog_result.h" 39 #include "nweb_js_http_auth_result.h" 40 #include "nweb_js_ssl_error_result.h" 41 #include "nweb_js_ssl_select_cert_result.h" 42 #include "nweb_key_event.h" 43 #include "nweb_largest_contentful_paint_details.h" 44 #include "nweb_load_committed_details.h" 45 #include "nweb_select_popup_menu.h" 46 #include "nweb_touch_handle_state.h" 47 #include "nweb_url_resource_error.h" 48 #include "nweb_url_resource_request.h" 49 #include "nweb_url_resource_response.h" 50 51 namespace OHOS::NWeb { 52 53 enum class RenderExitReason { 54 // Render process non-zero exit status 55 PROCESS_ABNORMAL_TERMINATION, 56 57 // SIGKILL or task manager kill 58 PROCESS_WAS_KILLED, 59 60 // Segmentation fault 61 PROCESS_CRASHED, 62 63 // Out of memory 64 PROCESS_OOM, 65 66 // Unknown reason 67 PROCESS_EXIT_UNKNOWN, 68 }; 69 70 enum class RenderProcessNotRespondingReason { 71 // Input ack from Render process timeout 72 INPUT_TIMEOUT, 73 74 // navigation commit ack from Render process timeout 75 NAVIGATION_COMMIT_TIMEOUT, 76 }; 77 78 enum class ViewportFit { 79 // No effect - the whole web page is viewable(default) 80 AUTO, 81 82 // The initial layout viewport and the visual viewport are set to the 83 // largest rectangle which is inscribed in the display of the device. 84 CONTAIN, 85 86 // The initial layout viewport and the visual viewport are set to the 87 // circumscribed rectangle of the physical screen of the device. 88 COVER, 89 }; 90 91 class NWebImageOptions { 92 public: 93 virtual ~NWebImageOptions() = default; 94 95 virtual ImageColorType GetColorType() = 0; 96 virtual ImageAlphaType GetAlphaType() = 0; 97 virtual size_t GetWidth() = 0; 98 virtual size_t GetHeight() = 0; 99 }; 100 101 enum class SslError { 102 // General error 103 INVALID, 104 105 // Hostname mismatch 106 HOSTMISMATCH, 107 108 // The certificate date is invalid 109 DATEINVALID, 110 111 // The certificate authority is not trusted 112 UNTRUSTED, 113 }; 114 115 // Cursor type values. 116 enum class CursorType : int32_t { 117 CT_POINTER = 0, 118 CT_CROSS, 119 CT_HAND, 120 CT_IBEAM, 121 CT_WAIT, 122 CT_HELP, 123 CT_EASTRESIZE, 124 CT_NORTHRESIZE, 125 CT_NORTHEASTRESIZE, 126 CT_NORTHWESTRESIZE, 127 CT_SOUTHRESIZE, 128 CT_SOUTHEASTRESIZE, 129 CT_SOUTHWESTRESIZE, 130 CT_WESTRESIZE, 131 CT_NORTHSOUTHRESIZE, 132 CT_EASTWESTRESIZE, 133 CT_NORTHEASTSOUTHWESTRESIZE, 134 CT_NORTHWESTSOUTHEASTRESIZE, 135 CT_COLUMNRESIZE, 136 CT_ROWRESIZE, 137 CT_MIDDLEPANNING, 138 CT_EASTPANNING, 139 CT_NORTHPANNING, 140 CT_NORTHEASTPANNING, 141 CT_NORTHWESTPANNING, 142 CT_SOUTHPANNING, 143 CT_SOUTHEASTPANNING, 144 CT_SOUTHWESTPANNING, 145 CT_WESTPANNING, 146 CT_MOVE, 147 CT_VERTICALTEXT, 148 CT_CELL, 149 CT_CONTEXTMENU, 150 CT_ALIAS, 151 CT_PROGRESS, 152 CT_NODROP, 153 CT_COPY, 154 CT_NONE, 155 CT_NOTALLOWED, 156 CT_ZOOMIN, 157 CT_ZOOMOUT, 158 CT_GRAB, 159 CT_GRABBING, 160 CT_MIDDLE_PANNING_VERTICAL, 161 CT_MIDDLE_PANNING_HORIZONTAL, 162 CT_CUSTOM, 163 CT_DND_NONE, 164 CT_DND_MOVE, 165 CT_DND_COPY, 166 CT_DND_LINK, 167 CT_MAX_VALUE, 168 }; 169 170 class NWebCursorInfo { 171 public: 172 virtual ~NWebCursorInfo() = default; 173 174 virtual int32_t GetX() = 0; 175 virtual int32_t GetY() = 0; 176 virtual uint8_t* GetBuff() = 0; 177 virtual float GetScale() = 0; 178 virtual int32_t GetWidth() = 0; 179 virtual int32_t GetHeight() = 0; 180 }; 181 182 class NWebTouchHandleHotZone { 183 public: 184 virtual ~NWebTouchHandleHotZone() = default; 185 186 virtual void SetWidth(double width) = 0; 187 virtual void SetHeight(double height) = 0; 188 }; 189 190 enum class MediaPlayingState { 191 // Media is playing 192 PLAYING, 193 194 // Media playing is paused 195 PAUSED, 196 197 // Media playing is end 198 END_OF_STREAM, 199 }; 200 201 enum class FormState { 202 kHadInteraction, 203 kNoInteraction, 204 }; 205 206 enum class ActivityType { 207 VIDEO = 0, 208 AUDIO, 209 FORM, 210 }; 211 212 enum class NativeEmbedStatus { 213 CREATE, 214 UPDATE, 215 DESTROY, 216 ENTER_BFCACHE, 217 LEAVE_BFCACHE, 218 }; 219 220 enum class NWebFocusSource { 221 FOCUS_SOURCE_DEFAULT = -1, 222 FOCUS_SOURCE_NAVIGATION = 0, 223 FOCUS_SOURCE_SYSTEM, 224 }; 225 226 class NWebNativeEmbedInfo { 227 public: 228 virtual ~NWebNativeEmbedInfo() = default; 229 230 virtual int32_t GetWidth() = 0; 231 232 virtual int32_t GetHeight() = 0; 233 234 virtual std::string GetId() = 0; 235 236 virtual std::string GetSrc() = 0; 237 238 virtual std::string GetUrl() = 0; 239 240 virtual std::string GetType() = 0; 241 242 virtual std::string GetTag() = 0; 243 244 virtual std::map<std::string, std::string> GetParams() = 0; 245 246 virtual int32_t GetX() = 0; 247 248 virtual int32_t GetY() = 0; 249 }; 250 251 class NWebNativeEmbedDataInfo { 252 public: 253 virtual ~NWebNativeEmbedDataInfo() = default; 254 255 virtual NativeEmbedStatus GetStatus() = 0; 256 257 virtual std::string GetEmbedId() = 0; 258 259 virtual std::string GetSurfaceId() = 0; 260 261 virtual std::shared_ptr<NWebNativeEmbedInfo> GetNativeEmbedInfo() = 0; 262 }; 263 264 enum class TouchType : size_t { 265 DOWN = 0, 266 UP, 267 MOVE, 268 CANCEL, 269 }; 270 271 class NWebNativeEmbedTouchEvent { 272 public: 273 virtual ~NWebNativeEmbedTouchEvent() = default; 274 275 virtual float GetX() = 0; 276 277 virtual float GetY() = 0; 278 279 virtual int32_t GetId() = 0; 280 281 virtual TouchType GetType() = 0; 282 283 virtual float GetOffsetX() = 0; 284 285 virtual float GetOffsetY() = 0; 286 287 virtual float GetScreenX() = 0; 288 289 virtual float GetScreenY() = 0; 290 291 virtual std::string GetEmbedId() = 0; 292 293 virtual std::shared_ptr<NWebGestureEventResult> GetResult() = 0; 294 }; 295 296 class OHOS_NWEB_EXPORT NWebHandler { 297 public: 298 NWebHandler() = default; 299 300 virtual ~NWebHandler() = default; 301 SetNWeb(std::shared_ptr<NWeb> nweb)302 virtual void SetNWeb(std::shared_ptr<NWeb> nweb) {} 303 OnProxyDied()304 virtual void OnProxyDied() {} 305 OnRouterPush(const std::string & param)306 virtual void OnRouterPush(const std::string& param) {} 307 OnMessage(const std::string & param)308 virtual void OnMessage(const std::string& param) {} 309 310 /** 311 * @brief Notify the SDK that a web site has finished loading. This method is 312 * called only for main frame. 313 * 314 * @param httpStatusCode The status code for the http request. 315 * @param url The url of the web site. 316 */ OnPageLoadEnd(int httpStatusCode,const std::string & url)317 virtual void OnPageLoadEnd(int httpStatusCode, const std::string& url) {} 318 319 /** 320 * @brief Notify the SDK that a web site has started loading. This method is 321 * called once for each main frame load. 322 * 323 * @param url The url to be loaded. 324 */ OnPageLoadBegin(const std::string & url)325 virtual void OnPageLoadBegin(const std::string& url) {} 326 327 /** 328 * @brief Report a load error to the SDK. 329 * 330 * @param errorCode The error code. 331 * @param description The error description. 332 * @param failingUrl The failed url. 333 */ OnPageLoadError(int errorCode,const std::string & description,const std::string & failingUrl)334 virtual void OnPageLoadError(int errorCode, const std::string& description, const std::string& failingUrl) {} 335 336 /** 337 * @brief Give the SDK a chance to decide whether to continue loading the 338 * url. 339 * 340 * @param url The url to be loaded. 341 * @return true to cancel the loading, false to continue the loading. 342 */ OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)343 virtual bool OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request) 344 { 345 return false; 346 } 347 348 /** 349 * @brief Notify the SDK that the nweb will load the resource specified by 350 * the given url. 351 * 352 * @param url The url of the resource. 353 */ OnResource(const std::string & url)354 virtual void OnResource(const std::string& url) {} 355 356 /** 357 * @brief Notify the SDK of the changed document title. 358 * 359 * @param title The document title. 360 */ OnPageTitle(const std::string & title)361 virtual void OnPageTitle(const std::string& title) {} 362 363 /** 364 * @brief Notify the SDK the current progress of loading a web site. 365 * 366 * @param newProgress Loading progress, an integer between 0 and 100. 367 */ OnLoadingProgress(int newProgress)368 virtual void OnLoadingProgress(int newProgress) {} 369 370 /** 371 * @brief Request display and focus for a new nweb. 372 * 373 * @return Return true if request focus success, false if request focus fail. 374 */ OnFocus()375 virtual bool OnFocus() 376 { 377 return false; 378 } 379 380 /** 381 * @brief Obtains a list of all visited history items, used for link coloring 382 * 383 * @retval visited history 384 */ VisitedUrlHistory()385 virtual std::vector<std::string> VisitedUrlHistory() 386 { 387 return std::vector<std::string>(); 388 } 389 390 /** 391 * @brief Notify the host application of a resource request and allow the 392 * application to return the data. 393 * 394 * @param request request information 395 * @param response response information 396 * 397 * @retval true if handle success, otherwise false. 398 */ OnHandleInterceptRequest(std::shared_ptr<NWebUrlResourceRequest> request,std::shared_ptr<NWebUrlResourceResponse> response)399 virtual bool OnHandleInterceptRequest( 400 std::shared_ptr<NWebUrlResourceRequest> request, std::shared_ptr<NWebUrlResourceResponse> response) 401 { 402 return false; 403 } 404 405 /** 406 * @brief Report web resource loading error to the SDK. These errors usually 407 * indicate inability to connect to the server. 408 * 409 * @param request The request information. 410 * @param error The error information. 411 */ OnResourceLoadError(std::shared_ptr<NWebUrlResourceRequest> request,std::shared_ptr<NWebUrlResourceError> error)412 virtual void OnResourceLoadError( 413 std::shared_ptr<NWebUrlResourceRequest> request, std::shared_ptr<NWebUrlResourceError> error) 414 {} 415 416 /** 417 * @brief Notify the SDK that an HTTP error has been received from the server 418 * while loading a resource. 419 * 420 * @param request The request information. 421 * @param errorResponse The error occurred. 422 */ OnHttpError(std::shared_ptr<NWebUrlResourceRequest> request,std::shared_ptr<NWebUrlResourceResponse> errorResponse)423 virtual void OnHttpError( 424 std::shared_ptr<NWebUrlResourceRequest> request, std::shared_ptr<NWebUrlResourceResponse> errorResponse) 425 {} 426 427 /** 428 * @brief Notify the SDK of a new favicon for the current web site. 429 * 430 * @param data The raw image data for the icon. 431 * @param width The width of the icon in pixel. 432 * @param height The height of the icon in pixel. 433 * @param color_type The color data encoding type. 434 * @param alpha_type The alpha value of any pixel. 435 */ OnPageIcon(const void * data,size_t width,size_t height,ImageColorType color_type,ImageAlphaType alpha_type)436 virtual void OnPageIcon( 437 const void* data, size_t width, size_t height, ImageColorType color_type, ImageAlphaType alpha_type) 438 {} 439 440 /** 441 * @brief Notify the SDK of the url for a touch icon. 442 * 443 * @param icon_url The icon url. 444 * @param precomposed The touch icon type. 445 */ OnDesktopIconUrl(const std::string & icon_url,bool precomposed)446 virtual void OnDesktopIconUrl(const std::string& icon_url, bool precomposed) {} 447 448 /** 449 * @brief Report a JavaScript console message to the host application. 450 * 451 * @param console_log Details of the console message. 452 * @return Return true to stop the message from being output to the console. 453 */ OnConsoleLog(std::shared_ptr<NWebConsoleLog> console_log)454 virtual bool OnConsoleLog(std::shared_ptr<NWebConsoleLog> console_log) 455 { 456 return false; 457 } 458 459 /** 460 * @brief Show prompt to ask for the geolocation permission. 461 * 462 * @param origin String: the origin of the resource to get geolocation 463 * @param callback GeolocationCallbackInterface: callback to report 464 * geolocation 465 */ OnGeolocationShow(const std::string & origin,std::shared_ptr<NWebGeolocationCallbackInterface> callback)466 virtual void OnGeolocationShow( 467 const std::string& origin, std::shared_ptr<NWebGeolocationCallbackInterface> callback) 468 {} 469 470 /** 471 * @brief Notify the host application that the web page wants to display a 472 * JavaScript alert() dialog. 473 * 474 * @param url String: The url of the page requesting the dialog. 475 * @param message String: The message of the dialog. 476 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 477 * confirm that the user closed the window. 478 * @return To show a custom dialog, the app should return true. 479 */ OnAlertDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)480 virtual bool OnAlertDialogByJS( 481 const std::string& url, const std::string& message, std::shared_ptr<NWebJSDialogResult> result) 482 { 483 return false; 484 } 485 486 /** 487 * @brief Notify the host application that the web page wants to handle 488 * JavaScript onbeforeunload. 489 * 490 * @param url String: The url of the page requesting. 491 * @param message String: The message of the dialog. 492 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 493 * confirm that the user closed the window. 494 * @return To show a custom dialog, the app should return true. 495 */ OnBeforeUnloadByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)496 virtual bool OnBeforeUnloadByJS( 497 const std::string& url, const std::string& message, std::shared_ptr<NWebJSDialogResult> result) 498 { 499 return false; 500 } 501 502 /** 503 * @brief Notify the host application that the web page wants to display a 504 * JavaScript prompt() dialog. 505 * 506 * @param url String: The url of the page requesting the dialog. 507 * @param message String: The message of the dialog. 508 * @param defaultValue String: The default value of the input message. 509 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 510 * confirm that the user closed the window. 511 * @return To show a custom dialog, the app should return true. 512 */ OnPromptDialogByJS(const std::string & url,const std::string & message,const std::string & defaultValue,std::shared_ptr<NWebJSDialogResult> result)513 virtual bool OnPromptDialogByJS(const std::string& url, const std::string& message, const std::string& defaultValue, 514 std::shared_ptr<NWebJSDialogResult> result) 515 { 516 return false; 517 } 518 519 /** 520 * @brief Notify the host application that the web page wants to display a 521 * JavaScript Confirm() dialog. 522 * 523 * @param url String: The url of the page requesting the dialog. 524 * @param message String: The message of the dialog. 525 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 526 * confirm that the user closed the window. 527 * @return To show a custom dialog, the app should return true. 528 */ OnConfirmDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)529 virtual bool OnConfirmDialogByJS( 530 const std::string& url, const std::string& message, std::shared_ptr<NWebJSDialogResult> result) 531 { 532 return false; 533 } 534 535 /** 536 * @brief Hide prompt to ask for the geolocation permission. 537 */ OnGeolocationHide()538 virtual void OnGeolocationHide() {} 539 540 /** 541 * @brief Ask for the permission. 542 * 543 * @param request std::shared_ptr<NWebAccessRequest>: A request to ask for the 544 * permission. 545 */ OnPermissionRequest(std::shared_ptr<NWebAccessRequest> request)546 virtual void OnPermissionRequest(std::shared_ptr<NWebAccessRequest> request) {} 547 548 /** 549 * @brief Cancel the request to ask for the permission. 550 * 551 * @param request std::shared_ptr<NWebAccessRequest>: A request to ask for the 552 * permission. 553 */ OnPermissionRequestCanceled(std::shared_ptr<NWebAccessRequest> request)554 virtual void OnPermissionRequestCanceled(std::shared_ptr<NWebAccessRequest> request) {} 555 556 /** 557 * @brief called when the render process exit. 558 * 559 * @param reason the detail reason why render process exit, the implementation of this callback 560 * should attempt to clean up the specific nweb that was set by SetNWeb interface. 561 */ OnRenderExited(RenderExitReason reason)562 virtual void OnRenderExited(RenderExitReason reason) {} 563 564 /** 565 * @brief inform application to update its visited links database. 566 * 567 * @param url the url being visited. 568 * @param isReload true if the url is being reload. 569 */ OnRefreshAccessedHistory(const std::string & url,bool isReload)570 virtual void OnRefreshAccessedHistory(const std::string& url, bool isReload) {} 571 572 /** 573 * @brief inform application to show a file selector. 574 * @param callback the file list to select. 575 * @param params the params of file selector. 576 */ OnFileSelectorShow(std::shared_ptr<NWebStringVectorValueCallback> callback,std::shared_ptr<NWebFileSelectorParams> params)577 virtual bool OnFileSelectorShow( 578 std::shared_ptr<NWebStringVectorValueCallback> callback, std::shared_ptr<NWebFileSelectorParams> params) 579 { 580 return false; 581 } 582 OnScaleChanged(float oldScaleFactor,float newScaleFactor)583 virtual void OnScaleChanged(float oldScaleFactor, float newScaleFactor) {} 584 RunContextMenu(std::shared_ptr<NWebContextMenuParams> params,std::shared_ptr<NWebContextMenuCallback> callback)585 virtual bool RunContextMenu( 586 std::shared_ptr<NWebContextMenuParams> params, std::shared_ptr<NWebContextMenuCallback> callback) 587 { 588 return false; 589 } 590 OnContextMenuDismissed()591 virtual void OnContextMenuDismissed() {} 592 RunQuickMenu(std::shared_ptr<NWebQuickMenuParams> params,std::shared_ptr<NWebQuickMenuCallback> callback)593 virtual bool RunQuickMenu( 594 std::shared_ptr<NWebQuickMenuParams> params, std::shared_ptr<NWebQuickMenuCallback> callback) 595 { 596 return false; 597 } 598 OnQuickMenuDismissed()599 virtual void OnQuickMenuDismissed() {} 600 OnTouchSelectionChanged(std::shared_ptr<NWebTouchHandleState> insertHandle,std::shared_ptr<NWebTouchHandleState> startSelectionHandle,std::shared_ptr<NWebTouchHandleState> endSelectionHandle)601 virtual void OnTouchSelectionChanged(std::shared_ptr<NWebTouchHandleState> insertHandle, 602 std::shared_ptr<NWebTouchHandleState> startSelectionHandle, 603 std::shared_ptr<NWebTouchHandleState> endSelectionHandle) 604 {} 605 OnHttpAuthRequestByJS(std::shared_ptr<NWebJSHttpAuthResult> result,const std::string & host,const std::string & realm)606 virtual bool OnHttpAuthRequestByJS( 607 std::shared_ptr<NWebJSHttpAuthResult> result, const std::string& host, const std::string& realm) 608 { 609 return false; 610 } 611 OnScroll(double xOffset,double yOffset)612 virtual void OnScroll(double xOffset, double yOffset) {} 613 OnDragAndDropData(const void * data,size_t len,std::shared_ptr<NWebImageOptions> opt)614 virtual bool OnDragAndDropData(const void* data, size_t len, std::shared_ptr<NWebImageOptions> opt) 615 { 616 return false; 617 } 618 OnSslErrorRequestByJS(std::shared_ptr<NWebJSSslErrorResult> result,SslError error)619 virtual bool OnSslErrorRequestByJS(std::shared_ptr<NWebJSSslErrorResult> result, SslError error) 620 { 621 return false; 622 } 623 OnSslSelectCertRequestByJS(std::shared_ptr<NWebJSSslSelectCertResult> result,const std::string & host,int port,const std::vector<std::string> & keyTypes,const std::vector<std::string> & issuers)624 virtual bool OnSslSelectCertRequestByJS(std::shared_ptr<NWebJSSslSelectCertResult> result, const std::string& host, 625 int port, const std::vector<std::string>& keyTypes, const std::vector<std::string>& issuers) 626 { 627 return false; 628 } 629 630 /** 631 * @brief called when the page enter the full-screen mode. 632 * @param handler to exit full-screen mode. 633 */ OnFullScreenEnter(std::shared_ptr<NWebFullScreenExitHandler> handler)634 virtual void OnFullScreenEnter(std::shared_ptr<NWebFullScreenExitHandler> handler) {} 635 636 /** 637 * @brief called when the page exit the full-screen mode. 638 */ OnFullScreenExit()639 virtual void OnFullScreenExit() {} 640 641 /** 642 * @brief called when new window required. 643 * 644 * @param targetUrl URL to be loaded in the new window. 645 * @param isAlert dialog window or not. 646 * @param isUserTrigger triggered by User. 647 * @param handler set the new web object. 648 */ OnWindowNewByJS(const std::string & targetUrl,bool isAlert,bool isUserTrigger,std::shared_ptr<NWebControllerHandler> handler)649 virtual void OnWindowNewByJS( 650 const std::string& targetUrl, bool isAlert, bool isUserTrigger, std::shared_ptr<NWebControllerHandler> handler) 651 {} 652 653 /** 654 * @brief called when window exit. 655 */ OnWindowExitByJS()656 virtual void OnWindowExitByJS() {} 657 658 /** 659 * @brief called when the page being loaded is about to be made visible. 660 */ OnPageVisible(const std::string & url)661 virtual void OnPageVisible(const std::string& url) {} 662 663 /** 664 * @brief shows the repost form confirmation dialog box. 665 * @param handler sets whether to resend data. 666 */ OnDataResubmission(std::shared_ptr<NWebDataResubmissionCallback> handler)667 virtual void OnDataResubmission(std::shared_ptr<NWebDataResubmissionCallback> handler) {} 668 669 /** 670 * @brief Give the host application a chance to handle the key event synchronousl. 671 * @param event The key event. 672 * @return True if the host application wants to handle the key event itself, otherwise return false. 673 */ OnPreKeyEvent(std::shared_ptr<NWebKeyEvent> event)674 virtual bool OnPreKeyEvent(std::shared_ptr<NWebKeyEvent> event) 675 { 676 return false; 677 } 678 679 /** 680 * @brief Notify the host application that a key was not handled by the WebView. 681 * @param event The key event. 682 * @return True if the host application wants to handle the key event itself, otherwise return false. 683 */ OnUnProcessedKeyEvent(std::shared_ptr<NWebKeyEvent> event)684 virtual bool OnUnProcessedKeyEvent(std::shared_ptr<NWebKeyEvent> event) 685 { 686 return false; 687 } 688 689 /** 690 * @brief Called when the browser's cursor has changed. 691 * @param type Cursor type. 692 * @param info If |type| is CT_CUSTOM then |info| will be populated with the custom cursor information. 693 * @return True if the cursor change was handled or false for default handling. 694 */ OnCursorChange(const CursorType & type,std::shared_ptr<NWebCursorInfo> info)695 virtual bool OnCursorChange(const CursorType& type, std::shared_ptr<NWebCursorInfo> info) 696 { 697 return false; 698 } 699 OnSelectPopupMenu(std::shared_ptr<NWebSelectPopupMenuParam> params,std::shared_ptr<NWebSelectPopupMenuCallback> callback)700 virtual void OnSelectPopupMenu( 701 std::shared_ptr<NWebSelectPopupMenuParam> params, std::shared_ptr<NWebSelectPopupMenuCallback> callback) 702 {} 703 704 /** 705 * @brief Called when the audio playing state on web page changed. 706 * @param playing Whether the audio is playing or not. 707 */ OnAudioStateChanged(bool playing)708 virtual void OnAudioStateChanged(bool playing) {} 709 710 /** 711 * @brief Called when the first content rendering of web page. 712 * @param navigationStartTick Absolute navigation start time, as TimeTicks. 713 * @param firstContentfulPaintMs Time to first contentful paint from 714 * navigation start. 715 */ OnFirstContentfulPaint(int64_t navigationStartTick,int64_t firstContentfulPaintMs)716 virtual void OnFirstContentfulPaint(int64_t navigationStartTick, int64_t firstContentfulPaintMs) {} 717 718 /** 719 * @brief Called when the first meaningful paint rendering of web page. 720 * @param details represents the details of first meaningful paint. 721 */ OnFirstMeaningfulPaint(std::shared_ptr<NWebFirstMeaningfulPaintDetails> details)722 virtual void OnFirstMeaningfulPaint(std::shared_ptr<NWebFirstMeaningfulPaintDetails> details) {} 723 724 /** 725 * @brief Called when the largest contentful paint rendering of web page. 726 * @param details represents the details of largest contentful paint. 727 */ OnLargestContentfulPaint(std::shared_ptr<NWebLargestContentfulPaintDetails> details)728 virtual void OnLargestContentfulPaint(std::shared_ptr<NWebLargestContentfulPaintDetails> details) {} 729 730 /** 731 * @brief Called when swap buffer completed with new size. 732 */ OnCompleteSwapWithNewSize()733 virtual void OnCompleteSwapWithNewSize() {} 734 735 /** 736 * @brief Called when resize not work. 737 */ OnResizeNotWork()738 virtual void OnResizeNotWork() {} 739 OnGetTouchHandleHotZone(std::shared_ptr<NWebTouchHandleHotZone> hotZone)740 virtual void OnGetTouchHandleHotZone(std::shared_ptr<NWebTouchHandleHotZone> hotZone) {} 741 OnDateTimeChooserPopup(std::shared_ptr<NWebDateTimeChooser> chooser,const std::vector<std::shared_ptr<NWebDateTimeSuggestion>> & suggestions,std::shared_ptr<NWebDateTimeChooserCallback> callback)742 virtual void OnDateTimeChooserPopup(std::shared_ptr<NWebDateTimeChooser> chooser, 743 const std::vector<std::shared_ptr<NWebDateTimeSuggestion>>& suggestions, 744 std::shared_ptr<NWebDateTimeChooserCallback> callback) 745 {} 746 OnDateTimeChooserClose()747 virtual void OnDateTimeChooserClose() {} 748 OnDragAndDropDataUdmf(std::shared_ptr<NWebDragData> dragData)749 virtual bool OnDragAndDropDataUdmf(std::shared_ptr<NWebDragData> dragData) 750 { 751 return false; 752 } 753 UpdateDragCursor(NWebDragData::DragOperation op)754 virtual void UpdateDragCursor(NWebDragData::DragOperation op) {} 755 OnOverScroll(float xOffset,float yOffset)756 virtual void OnOverScroll(float xOffset, float yOffset) {} 757 758 /** 759 * @brief Ask for the screen capture permission. 760 * 761 * @param request std::shared_ptr<NWebScreenCaptureAccessRequest>: A request to ask for the 762 * screen capture permission. 763 */ OnScreenCaptureRequest(std::shared_ptr<NWebScreenCaptureAccessRequest> request)764 virtual void OnScreenCaptureRequest(std::shared_ptr<NWebScreenCaptureAccessRequest> request) {} 765 OnOverScrollFlingVelocity(float xVelocity,float yVelocity,bool isFling)766 virtual void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling) {} 767 OnOverScrollFlingEnd()768 virtual void OnOverScrollFlingEnd() {} 769 770 /** 771 * @brief Called when the media or form state on the web page changed. 772 * @param state state of the media or form. Refer to the enum class MediaPlayingState and FormState 773 * @param ActivityType it can be form, media, or audio 774 */ OnActivityStateChanged(int state,ActivityType type)775 virtual void OnActivityStateChanged(int state, ActivityType type) {} 776 OnScrollState(bool scrollState)777 virtual void OnScrollState(bool scrollState) {} 778 OnRootLayerChanged(int width,int height)779 virtual void OnRootLayerChanged(int width, int height) {} 780 FilterScrollEvent(const float x,const float y,const float xVelocity,const float yVelocity)781 virtual bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity) 782 { 783 return false; 784 } 785 786 /** 787 * @brief Called when received website security risk check result. 788 * @param threat_type The threat type of website. 789 */ OnSafeBrowsingCheckResult(int threat_type)790 virtual void OnSafeBrowsingCheckResult(int threat_type) {} 791 792 /** 793 * @brief called when the navigation entry has been committed. 794 * @param details represents the details of a committed navigation entry. 795 */ OnNavigationEntryCommitted(std::shared_ptr<NWebLoadCommittedDetails> details)796 virtual void OnNavigationEntryCommitted(std::shared_ptr<NWebLoadCommittedDetails> details) {} 797 OnNativeEmbedLifecycleChange(std::shared_ptr<NWebNativeEmbedDataInfo> dataInfo)798 virtual void OnNativeEmbedLifecycleChange(std::shared_ptr<NWebNativeEmbedDataInfo> dataInfo) {} 799 OnNativeEmbedGestureEvent(std::shared_ptr<NWebNativeEmbedTouchEvent> event)800 virtual void OnNativeEmbedGestureEvent(std::shared_ptr<NWebNativeEmbedTouchEvent> event) {} 801 802 /** 803 * @brief called when the page enter the full-screen mode. 804 * 805 * @param handler to exit full-screen mode. 806 * @param video_natural_width indicates the width of the <video> element 807 * entering full screen. 808 * @param video_natural_height indicates the height of the <video> element 809 * entering full screen. 810 */ OnFullScreenEnterWithVideoSize(std::shared_ptr<NWebFullScreenExitHandler> handler,int video_natural_width,int video_natural_height)811 virtual void OnFullScreenEnterWithVideoSize( 812 std::shared_ptr<NWebFullScreenExitHandler> handler, int video_natural_width, int video_natural_height) 813 {} 814 815 /** 816 * @brief Called when tracker's cookie is prevented. 817 * @param website_host The host of website url. 818 * @param tracker_host The host of tracker url. 819 */ OnIntelligentTrackingPreventionResult(const std::string & websiteHost,const std::string & trackerHost)820 virtual void OnIntelligentTrackingPreventionResult(const std::string& websiteHost, const std::string& trackerHost) 821 {} 822 823 /** 824 * @brief Give the application a chance to decide whether to override loading the 825 * url. 826 * 827 * @param request The request information. 828 * @return true to abort loading the url, false to continue loading the url 829 * as usual. 830 */ OnHandleOverrideUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)831 virtual bool OnHandleOverrideUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request) 832 { 833 return false; 834 } 835 OnAllSslErrorRequestByJS(std::shared_ptr<NWebJSAllSslErrorResult> result,SslError error,const std::string & url,const std::string & originalUrl,const std::string & referrer,bool isFatalError,bool isMainFrame)836 virtual bool OnAllSslErrorRequestByJS(std::shared_ptr<NWebJSAllSslErrorResult> result, SslError error, 837 const std::string& url, const std::string& originalUrl, const std::string& referrer, bool isFatalError, 838 bool isMainFrame) 839 { 840 return false; 841 } 842 843 /** 844 * @brief Called when a tooltip should be presented for a component. 845 * 846 * @param tooltip The content of the tooltip. 847 */ OnTooltip(const std::string & param)848 virtual void OnTooltip(const std::string& param) {} 849 850 /** 851 * @brief called when resizehold is released. 852 */ ReleaseResizeHold()853 virtual void ReleaseResizeHold() {} 854 855 /** 856 * @brief Called when select a word. 857 * 858 * @param text The content of the text. 859 * @param offset The offset of the point. 860 */ GetWordSelection(const std::string & text,int8_t offset)861 virtual std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset) 862 { 863 return { -1, -1 }; 864 } 865 UpdateClippedSelectionBounds(int x,int y,int w,int h)866 virtual void UpdateClippedSelectionBounds(int x, int y, int w, int h) {} 867 OnOpenAppLink(const std::string & url,std::shared_ptr<NWebAppLinkCallback> callback)868 virtual bool OnOpenAppLink(const std::string& url, std::shared_ptr<NWebAppLinkCallback> callback) 869 { 870 return false; 871 } 872 873 /** 874 * @brief Called when the render process not responding. 875 * 876 * @param js_stack Javascript stack info of webpage when render process not 877 * responding. 878 * @param pid Process id of the render process not responding. 879 * @param reason Reason of the render process not responding. 880 */ OnRenderProcessNotResponding(const std::string & js_stack,int pid,RenderProcessNotRespondingReason reason)881 virtual void OnRenderProcessNotResponding( 882 const std::string& js_stack, int pid, RenderProcessNotRespondingReason reason) 883 {} 884 885 /** 886 * @brief Called when the unresponding render process becomes responsive. 887 * 888 */ OnRenderProcessResponding()889 virtual void OnRenderProcessResponding() {} 890 OnShowAutofillPopup(const float offsetX,const float offsetY,const std::vector<std::string> & menu_items)891 virtual void OnShowAutofillPopup( 892 const float offsetX, const float offsetY, const std::vector<std::string>& menu_items) 893 {} 894 OnHideAutofillPopup()895 virtual void OnHideAutofillPopup() {} 896 897 /** 898 * @brief Called when the viewport-fit meta is detected for web page. 899 * 900 * @param viewportFit The type of the viewport-fit. 901 */ OnViewportFitChange(ViewportFit viewportFit)902 virtual void OnViewportFitChange(ViewportFit viewportFit) {} 903 904 /** 905 * @brief Request display and focus for a new nweb. 906 * 907 * @param source The Focus Source. 908 * @return Return true if request focus success, false if request focus fail. 909 */ OnFocus(NWebFocusSource source)910 virtual bool OnFocus(NWebFocusSource source) 911 { 912 return false; 913 } 914 915 /** 916 * @brief Called when the page is over scroll. 917 * 918 * @param xOffset The offset of x axis. 919 * @param yOffset The offset of y axis. 920 * @param xVelocity The velocity of x axis. 921 * @param yVelocity The velocity of y axis. 922 * @return Return true if value is consumed, false if value is unconsumed. 923 */ OnOverScroll(float xOffset,float yOffset,float xVelocity,float yVelocity)924 virtual bool OnOverScroll(float xOffset, float yOffset, float xVelocity, float yVelocity) 925 { 926 return false; 927 } 928 929 /** 930 * @brief called when creating overlay. 931 */ CreateOverlay(void * data,size_t len,int width,int height,int offsetX,int offsetY,int rectWidth,int rectHeight,int pointX,int pointY)932 virtual void CreateOverlay(void* data, size_t len, int width, int height, int offsetX, int offsetY, int rectWidth, 933 int rectHeight, int pointX, int pointY) 934 {} 935 936 /** 937 * @brief called when state changed. 938 */ OnOverlayStateChanged(int offsetX,int offsetY,int rectWidth,int rectHeight)939 virtual void OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight) {} 940 941 /** 942 * @brief Called when received Ads blocked results. 943 * 944 * @param url The url of webpage. 945 * @param adsBlocked The ads' blocked urls. 946 * 947 */ OnAdsBlocked(const std::string & url,const std::vector<std::string> & adsBlocked)948 virtual void OnAdsBlocked(const std::string& url, const std::vector<std::string>& adsBlocked) {} 949 OnInterceptKeyboardAttach(const std::shared_ptr<NWebCustomKeyboardHandler> keyboardHandler,const std::map<std::string,std::string> & attributes,bool & useSystemKeyboard,int32_t & enterKeyType)950 virtual void OnInterceptKeyboardAttach( 951 const std::shared_ptr<NWebCustomKeyboardHandler> keyboardHandler, 952 const std::map<std::string, std::string> &attributes, bool &useSystemKeyboard, int32_t &enterKeyType) { 953 useSystemKeyboard = true; 954 enterKeyType = -1; 955 } 956 OnCustomKeyboardAttach()957 virtual void OnCustomKeyboardAttach() {} 958 OnCustomKeyboardClose()959 virtual void OnCustomKeyboardClose() {} 960 KeyboardReDispatch(std::shared_ptr<NWebKeyEvent> event,bool isUsed)961 virtual void KeyboardReDispatch(std::shared_ptr<NWebKeyEvent> event, bool isUsed) {} 962 963 /** 964 * @brief Called when you need to temporarily hide/restore the handle menu. 965 * 966 * @param hide hide. 967 */ HideHandleAndQuickMenuIfNecessary(bool hide)968 virtual void HideHandleAndQuickMenuIfNecessary(bool hide) {} 969 970 /** 971 * @brief called when the cursor info is updated. 972 * 973 * @param x, y relative coordinates within web components of the cursor 974 * @param width, height width and height of the cursor 975 */ OnCursorUpdate(double x,double y,double width,double height)976 virtual void OnCursorUpdate(double x, double y, double width, double height) {} 977 978 /** 979 * @brief Called When you click on the selected area. 980 * 981 */ ChangeVisibilityOfQuickMenu()982 virtual void ChangeVisibilityOfQuickMenu() {} 983 984 /** 985 * @brief Called when you need to start vibrator. 986 */ StartVibraFeedback(const std::string & vibratorType)987 virtual void StartVibraFeedback(const std::string& vibratorType) {} 988 OnNativeEmbedVisibilityChange(const std::string & embed_id,bool visibility)989 virtual void OnNativeEmbedVisibilityChange(const std::string& embed_id, bool visibility) {} 990 CloseImageOverlaySelection()991 virtual bool CloseImageOverlaySelection() { return false; } 992 993 /** 994 * @brief Get the visible area relative to the web. 995 */ GetVisibleRectToWeb(int & visibleX,int & visibleY,int & visibleWidth,int & visibleHeight)996 virtual void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight) {} 997 OnScrollStart(const float x,const float y)998 virtual void OnScrollStart(const float x, const float y) {} 999 }; 1000 1001 } // namespace OHOS::NWeb 1002 1003 #endif // NWEB_HANDLER_H 1004