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_LOCK, 168 CT_UNLOCK, 169 CT_MAX_VALUE, 170 }; 171 172 class NWebCursorInfo { 173 public: 174 virtual ~NWebCursorInfo() = default; 175 176 virtual int32_t GetX() = 0; 177 virtual int32_t GetY() = 0; 178 virtual uint8_t* GetBuff() = 0; 179 virtual float GetScale() = 0; 180 virtual int32_t GetWidth() = 0; 181 virtual int32_t GetHeight() = 0; 182 }; 183 184 class NWebTouchHandleHotZone { 185 public: 186 virtual ~NWebTouchHandleHotZone() = default; 187 188 virtual void SetWidth(double width) = 0; 189 virtual void SetHeight(double height) = 0; 190 }; 191 192 enum class MediaPlayingState { 193 // Media is playing 194 PLAYING, 195 196 // Media playing is paused 197 PAUSED, 198 199 // Media playing is end 200 END_OF_STREAM, 201 }; 202 203 enum class FormState { 204 kHadInteraction, 205 kNoInteraction, 206 }; 207 208 enum class ActivityType { 209 VIDEO = 0, 210 AUDIO, 211 FORM, 212 }; 213 214 enum class NativeEmbedStatus { 215 CREATE, 216 UPDATE, 217 DESTROY, 218 ENTER_BFCACHE, 219 LEAVE_BFCACHE, 220 VISIBLE, 221 HIDDEN, 222 }; 223 224 enum class NWebFocusSource { 225 FOCUS_SOURCE_DEFAULT = -1, 226 FOCUS_SOURCE_NAVIGATION = 0, 227 FOCUS_SOURCE_SYSTEM, 228 }; 229 230 class NWebNativeEmbedInfo { 231 public: 232 virtual ~NWebNativeEmbedInfo() = default; 233 234 virtual int32_t GetWidth() = 0; 235 236 virtual int32_t GetHeight() = 0; 237 238 virtual std::string GetId() = 0; 239 240 virtual std::string GetSrc() = 0; 241 242 virtual std::string GetUrl() = 0; 243 244 virtual std::string GetType() = 0; 245 246 virtual std::string GetTag() = 0; 247 248 virtual std::map<std::string, std::string> GetParams() = 0; 249 250 virtual int32_t GetX() = 0; 251 252 virtual int32_t GetY() = 0; 253 }; 254 255 class NWebNativeEmbedDataInfo { 256 public: 257 virtual ~NWebNativeEmbedDataInfo() = default; 258 259 virtual NativeEmbedStatus GetStatus() = 0; 260 261 virtual std::string GetEmbedId() = 0; 262 263 virtual std::string GetSurfaceId() = 0; 264 265 virtual std::shared_ptr<NWebNativeEmbedInfo> GetNativeEmbedInfo() = 0; 266 }; 267 268 enum class TouchType : size_t { 269 DOWN = 0, 270 UP, 271 MOVE, 272 CANCEL, 273 }; 274 275 class NWebNativeEmbedTouchEvent { 276 public: 277 virtual ~NWebNativeEmbedTouchEvent() = default; 278 279 virtual float GetX() = 0; 280 281 virtual float GetY() = 0; 282 283 virtual int32_t GetId() = 0; 284 285 virtual TouchType GetType() = 0; 286 287 virtual float GetOffsetX() = 0; 288 289 virtual float GetOffsetY() = 0; 290 291 virtual float GetScreenX() = 0; 292 293 virtual float GetScreenY() = 0; 294 295 virtual std::string GetEmbedId() = 0; 296 297 virtual std::shared_ptr<NWebGestureEventResult> GetResult() = 0; 298 }; 299 300 class OHOS_NWEB_EXPORT NWebHandler { 301 public: 302 NWebHandler() = default; 303 304 virtual ~NWebHandler() = default; 305 SetNWeb(std::shared_ptr<NWeb> nweb)306 virtual void SetNWeb(std::shared_ptr<NWeb> nweb) {} 307 OnProxyDied()308 virtual void OnProxyDied() {} 309 OnRouterPush(const std::string & param)310 virtual void OnRouterPush(const std::string& param) {} 311 OnMessage(const std::string & param)312 virtual void OnMessage(const std::string& param) {} 313 314 /** 315 * @brief Notify the SDK that a web site has finished loading. This method is 316 * called only for main frame. 317 * 318 * @param httpStatusCode The status code for the http request. 319 * @param url The url of the web site. 320 */ OnPageLoadEnd(int httpStatusCode,const std::string & url)321 virtual void OnPageLoadEnd(int httpStatusCode, const std::string& url) {} 322 323 /** 324 * @brief Notify the SDK that a web site has started loading. This method is 325 * called once for each main frame load. 326 * 327 * @param url The url to be loaded. 328 */ OnPageLoadBegin(const std::string & url)329 virtual void OnPageLoadBegin(const std::string& url) {} 330 331 /** 332 * @brief Report a load error to the SDK. 333 * 334 * @param errorCode The error code. 335 * @param description The error description. 336 * @param failingUrl The failed url. 337 */ OnPageLoadError(int errorCode,const std::string & description,const std::string & failingUrl)338 virtual void OnPageLoadError(int errorCode, const std::string& description, const std::string& failingUrl) {} 339 340 /** 341 * @brief Give the SDK a chance to decide whether to continue loading the 342 * url. 343 * 344 * @param url The url to be loaded. 345 * @return true to cancel the loading, false to continue the loading. 346 */ OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)347 virtual bool OnHandleInterceptUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request) 348 { 349 return false; 350 } 351 352 /** 353 * @brief Notify the SDK that the nweb will load the resource specified by 354 * the given url. 355 * 356 * @param url The url of the resource. 357 */ OnResource(const std::string & url)358 virtual void OnResource(const std::string& url) {} 359 360 /** 361 * @brief Notify the SDK of the changed document title. 362 * 363 * @param title The document title. 364 */ OnPageTitle(const std::string & title)365 virtual void OnPageTitle(const std::string& title) {} 366 367 /** 368 * @brief Notify the SDK the current progress of loading a web site. 369 * 370 * @param newProgress Loading progress, an integer between 0 and 100. 371 */ OnLoadingProgress(int newProgress)372 virtual void OnLoadingProgress(int newProgress) {} 373 374 /** 375 * @brief Request display and focus for a new nweb. 376 * 377 * @return Return true if request focus success, false if request focus fail. 378 */ OnFocus()379 virtual bool OnFocus() 380 { 381 return false; 382 } 383 384 /** 385 * @brief Obtains a list of all visited history items, used for link coloring 386 * 387 * @retval visited history 388 */ VisitedUrlHistory()389 virtual std::vector<std::string> VisitedUrlHistory() 390 { 391 return std::vector<std::string>(); 392 } 393 394 /** 395 * @brief Notify the host application of a resource request and allow the 396 * application to return the data. 397 * 398 * @param request request information 399 * @param response response information 400 * 401 * @retval true if handle success, otherwise false. 402 */ OnHandleInterceptRequest(std::shared_ptr<NWebUrlResourceRequest> request,std::shared_ptr<NWebUrlResourceResponse> response)403 virtual bool OnHandleInterceptRequest( 404 std::shared_ptr<NWebUrlResourceRequest> request, std::shared_ptr<NWebUrlResourceResponse> response) 405 { 406 return false; 407 } 408 409 /** 410 * @brief Report web resource loading error to the SDK. These errors usually 411 * indicate inability to connect to the server. 412 * 413 * @param request The request information. 414 * @param error The error information. 415 */ OnResourceLoadError(std::shared_ptr<NWebUrlResourceRequest> request,std::shared_ptr<NWebUrlResourceError> error)416 virtual void OnResourceLoadError( 417 std::shared_ptr<NWebUrlResourceRequest> request, std::shared_ptr<NWebUrlResourceError> error) 418 {} 419 420 /** 421 * @brief Notify the SDK that an HTTP error has been received from the server 422 * while loading a resource. 423 * 424 * @param request The request information. 425 * @param errorResponse The error occurred. 426 */ OnHttpError(std::shared_ptr<NWebUrlResourceRequest> request,std::shared_ptr<NWebUrlResourceResponse> errorResponse)427 virtual void OnHttpError( 428 std::shared_ptr<NWebUrlResourceRequest> request, std::shared_ptr<NWebUrlResourceResponse> errorResponse) 429 {} 430 431 /** 432 * @brief Notify the SDK of a new favicon for the current web site. 433 * 434 * @param data The raw image data for the icon. 435 * @param width The width of the icon in pixel. 436 * @param height The height of the icon in pixel. 437 * @param color_type The color data encoding type. 438 * @param alpha_type The alpha value of any pixel. 439 */ OnPageIcon(const void * data,size_t width,size_t height,ImageColorType color_type,ImageAlphaType alpha_type)440 virtual void OnPageIcon( 441 const void* data, size_t width, size_t height, ImageColorType color_type, ImageAlphaType alpha_type) 442 {} 443 444 /** 445 * @brief Notify the SDK of the url for a touch icon. 446 * 447 * @param icon_url The icon url. 448 * @param precomposed The touch icon type. 449 */ OnDesktopIconUrl(const std::string & icon_url,bool precomposed)450 virtual void OnDesktopIconUrl(const std::string& icon_url, bool precomposed) {} 451 452 /** 453 * @brief Report a JavaScript console message to the host application. 454 * 455 * @param console_log Details of the console message. 456 * @return Return true to stop the message from being output to the console. 457 */ OnConsoleLog(std::shared_ptr<NWebConsoleLog> console_log)458 virtual bool OnConsoleLog(std::shared_ptr<NWebConsoleLog> console_log) 459 { 460 return false; 461 } 462 463 /** 464 * @brief Show prompt to ask for the geolocation permission. 465 * 466 * @param origin String: the origin of the resource to get geolocation 467 * @param callback GeolocationCallbackInterface: callback to report 468 * geolocation 469 */ OnGeolocationShow(const std::string & origin,std::shared_ptr<NWebGeolocationCallbackInterface> callback)470 virtual void OnGeolocationShow( 471 const std::string& origin, std::shared_ptr<NWebGeolocationCallbackInterface> callback) 472 {} 473 474 /** 475 * @brief Notify the host application that the web page wants to display a 476 * JavaScript alert() dialog. 477 * 478 * @param url String: The url of the page requesting the dialog. 479 * @param message String: The message of the dialog. 480 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 481 * confirm that the user closed the window. 482 * @return To show a custom dialog, the app should return true. 483 */ OnAlertDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)484 virtual bool OnAlertDialogByJS( 485 const std::string& url, const std::string& message, std::shared_ptr<NWebJSDialogResult> result) 486 { 487 return false; 488 } 489 490 /** 491 * @brief Notify the host application that the web page wants to handle 492 * JavaScript onbeforeunload. 493 * 494 * @param url String: The url of the page requesting. 495 * @param message String: The message of the dialog. 496 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 497 * confirm that the user closed the window. 498 * @return To show a custom dialog, the app should return true. 499 */ OnBeforeUnloadByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)500 virtual bool OnBeforeUnloadByJS( 501 const std::string& url, const std::string& message, std::shared_ptr<NWebJSDialogResult> result) 502 { 503 return false; 504 } 505 506 /** 507 * @brief Notify the host application that the web page wants to display a 508 * JavaScript prompt() dialog. 509 * 510 * @param url String: The url of the page requesting the dialog. 511 * @param message String: The message of the dialog. 512 * @param defaultValue String: The default value of the input message. 513 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 514 * confirm that the user closed the window. 515 * @return To show a custom dialog, the app should return true. 516 */ OnPromptDialogByJS(const std::string & url,const std::string & message,const std::string & defaultValue,std::shared_ptr<NWebJSDialogResult> result)517 virtual bool OnPromptDialogByJS(const std::string& url, const std::string& message, const std::string& defaultValue, 518 std::shared_ptr<NWebJSDialogResult> result) 519 { 520 return false; 521 } 522 523 /** 524 * @brief Notify the host application that the web page wants to display a 525 * JavaScript Confirm() dialog. 526 * 527 * @param url String: The url of the page requesting the dialog. 528 * @param message String: The message of the dialog. 529 * @param result std::shared_ptr<NWebJSDialogResult>: A NWebJSDialogResult to 530 * confirm that the user closed the window. 531 * @return To show a custom dialog, the app should return true. 532 */ OnConfirmDialogByJS(const std::string & url,const std::string & message,std::shared_ptr<NWebJSDialogResult> result)533 virtual bool OnConfirmDialogByJS( 534 const std::string& url, const std::string& message, std::shared_ptr<NWebJSDialogResult> result) 535 { 536 return false; 537 } 538 539 /** 540 * @brief Hide prompt to ask for the geolocation permission. 541 */ OnGeolocationHide()542 virtual void OnGeolocationHide() {} 543 544 /** 545 * @brief Ask for the permission. 546 * 547 * @param request std::shared_ptr<NWebAccessRequest>: A request to ask for the 548 * permission. 549 */ OnPermissionRequest(std::shared_ptr<NWebAccessRequest> request)550 virtual void OnPermissionRequest(std::shared_ptr<NWebAccessRequest> request) {} 551 552 /** 553 * @brief Cancel the request to ask for the permission. 554 * 555 * @param request std::shared_ptr<NWebAccessRequest>: A request to ask for the 556 * permission. 557 */ OnPermissionRequestCanceled(std::shared_ptr<NWebAccessRequest> request)558 virtual void OnPermissionRequestCanceled(std::shared_ptr<NWebAccessRequest> request) {} 559 560 /** 561 * @brief called when the render process exit. 562 * 563 * @param reason the detail reason why render process exit, the implementation of this callback 564 * should attempt to clean up the specific nweb that was set by SetNWeb interface. 565 */ OnRenderExited(RenderExitReason reason)566 virtual void OnRenderExited(RenderExitReason reason) {} 567 568 /** 569 * @brief inform application to update its visited links database. 570 * 571 * @param url the url being visited. 572 * @param isReload true if the url is being reload. 573 */ OnRefreshAccessedHistory(const std::string & url,bool isReload)574 virtual void OnRefreshAccessedHistory(const std::string& url, bool isReload) {} 575 576 /** 577 * @brief inform application to show a file selector. 578 * @param callback the file list to select. 579 * @param params the params of file selector. 580 */ OnFileSelectorShow(std::shared_ptr<NWebStringVectorValueCallback> callback,std::shared_ptr<NWebFileSelectorParams> params)581 virtual bool OnFileSelectorShow( 582 std::shared_ptr<NWebStringVectorValueCallback> callback, std::shared_ptr<NWebFileSelectorParams> params) 583 { 584 return false; 585 } 586 OnScaleChanged(float oldScaleFactor,float newScaleFactor)587 virtual void OnScaleChanged(float oldScaleFactor, float newScaleFactor) {} 588 RunContextMenu(std::shared_ptr<NWebContextMenuParams> params,std::shared_ptr<NWebContextMenuCallback> callback)589 virtual bool RunContextMenu( 590 std::shared_ptr<NWebContextMenuParams> params, std::shared_ptr<NWebContextMenuCallback> callback) 591 { 592 return false; 593 } 594 OnContextMenuDismissed()595 virtual void OnContextMenuDismissed() {} 596 RunQuickMenu(std::shared_ptr<NWebQuickMenuParams> params,std::shared_ptr<NWebQuickMenuCallback> callback)597 virtual bool RunQuickMenu( 598 std::shared_ptr<NWebQuickMenuParams> params, std::shared_ptr<NWebQuickMenuCallback> callback) 599 { 600 return false; 601 } 602 OnQuickMenuDismissed()603 virtual void OnQuickMenuDismissed() {} 604 OnTouchSelectionChanged(std::shared_ptr<NWebTouchHandleState> insertHandle,std::shared_ptr<NWebTouchHandleState> startSelectionHandle,std::shared_ptr<NWebTouchHandleState> endSelectionHandle)605 virtual void OnTouchSelectionChanged(std::shared_ptr<NWebTouchHandleState> insertHandle, 606 std::shared_ptr<NWebTouchHandleState> startSelectionHandle, 607 std::shared_ptr<NWebTouchHandleState> endSelectionHandle) 608 {} 609 OnHttpAuthRequestByJS(std::shared_ptr<NWebJSHttpAuthResult> result,const std::string & host,const std::string & realm)610 virtual bool OnHttpAuthRequestByJS( 611 std::shared_ptr<NWebJSHttpAuthResult> result, const std::string& host, const std::string& realm) 612 { 613 return false; 614 } 615 OnScroll(double xOffset,double yOffset)616 virtual void OnScroll(double xOffset, double yOffset) {} 617 OnDragAndDropData(const void * data,size_t len,std::shared_ptr<NWebImageOptions> opt)618 virtual bool OnDragAndDropData(const void* data, size_t len, std::shared_ptr<NWebImageOptions> opt) 619 { 620 return false; 621 } 622 OnSslErrorRequestByJS(std::shared_ptr<NWebJSSslErrorResult> result,SslError error)623 virtual bool OnSslErrorRequestByJS(std::shared_ptr<NWebJSSslErrorResult> result, SslError error) 624 { 625 return false; 626 } 627 OnSslSelectCertRequestByJS(std::shared_ptr<NWebJSSslSelectCertResult> result,const std::string & host,int port,const std::vector<std::string> & keyTypes,const std::vector<std::string> & issuers)628 virtual bool OnSslSelectCertRequestByJS(std::shared_ptr<NWebJSSslSelectCertResult> result, const std::string& host, 629 int port, const std::vector<std::string>& keyTypes, const std::vector<std::string>& issuers) 630 { 631 return false; 632 } 633 634 /** 635 * @brief called when the page enter the full-screen mode. 636 * @param handler to exit full-screen mode. 637 */ OnFullScreenEnter(std::shared_ptr<NWebFullScreenExitHandler> handler)638 virtual void OnFullScreenEnter(std::shared_ptr<NWebFullScreenExitHandler> handler) {} 639 640 /** 641 * @brief called when the page exit the full-screen mode. 642 */ OnFullScreenExit()643 virtual void OnFullScreenExit() {} 644 645 /** 646 * @brief called when new window required. 647 * 648 * @param targetUrl URL to be loaded in the new window. 649 * @param isAlert dialog window or not. 650 * @param isUserTrigger triggered by User. 651 * @param handler set the new web object. 652 */ OnWindowNewByJS(const std::string & targetUrl,bool isAlert,bool isUserTrigger,std::shared_ptr<NWebControllerHandler> handler)653 virtual void OnWindowNewByJS( 654 const std::string& targetUrl, bool isAlert, bool isUserTrigger, std::shared_ptr<NWebControllerHandler> handler) 655 {} 656 657 /** 658 * @brief called when window exit. 659 */ OnWindowExitByJS()660 virtual void OnWindowExitByJS() {} 661 662 /** 663 * @brief called when the page being loaded is about to be made visible. 664 */ OnPageVisible(const std::string & url)665 virtual void OnPageVisible(const std::string& url) {} 666 667 /** 668 * @brief shows the repost form confirmation dialog box. 669 * @param handler sets whether to resend data. 670 */ OnDataResubmission(std::shared_ptr<NWebDataResubmissionCallback> handler)671 virtual void OnDataResubmission(std::shared_ptr<NWebDataResubmissionCallback> handler) {} 672 673 /** 674 * @brief Give the host application a chance to handle the key event synchronousl. 675 * @param event The key event. 676 * @return True if the host application wants to handle the key event itself, otherwise return false. 677 */ OnPreKeyEvent(std::shared_ptr<NWebKeyEvent> event)678 virtual bool OnPreKeyEvent(std::shared_ptr<NWebKeyEvent> event) 679 { 680 return false; 681 } 682 683 /** 684 * @brief Notify the host application that a key was not handled by the WebView. 685 * @param event The key event. 686 * @return True if the host application wants to handle the key event itself, otherwise return false. 687 */ OnUnProcessedKeyEvent(std::shared_ptr<NWebKeyEvent> event)688 virtual bool OnUnProcessedKeyEvent(std::shared_ptr<NWebKeyEvent> event) 689 { 690 return false; 691 } 692 693 /** 694 * @brief Called when the browser's cursor has changed. 695 * @param type Cursor type. 696 * @param info If |type| is CT_CUSTOM then |info| will be populated with the custom cursor information. 697 * @return True if the cursor change was handled or false for default handling. 698 */ OnCursorChange(const CursorType & type,std::shared_ptr<NWebCursorInfo> info)699 virtual bool OnCursorChange(const CursorType& type, std::shared_ptr<NWebCursorInfo> info) 700 { 701 return false; 702 } 703 OnSelectPopupMenu(std::shared_ptr<NWebSelectPopupMenuParam> params,std::shared_ptr<NWebSelectPopupMenuCallback> callback)704 virtual void OnSelectPopupMenu( 705 std::shared_ptr<NWebSelectPopupMenuParam> params, std::shared_ptr<NWebSelectPopupMenuCallback> callback) 706 {} 707 708 /** 709 * @brief Called when the audio playing state on web page changed. 710 * @param playing Whether the audio is playing or not. 711 */ OnAudioStateChanged(bool playing)712 virtual void OnAudioStateChanged(bool playing) {} 713 714 /** 715 * @brief Called when the first content rendering of web page. 716 * @param navigationStartTick Absolute navigation start time, as TimeTicks. 717 * @param firstContentfulPaintMs Time to first contentful paint from 718 * navigation start. 719 */ OnFirstContentfulPaint(int64_t navigationStartTick,int64_t firstContentfulPaintMs)720 virtual void OnFirstContentfulPaint(int64_t navigationStartTick, int64_t firstContentfulPaintMs) {} 721 722 /** 723 * @brief Called when the first meaningful paint rendering of web page. 724 * @param details represents the details of first meaningful paint. 725 */ OnFirstMeaningfulPaint(std::shared_ptr<NWebFirstMeaningfulPaintDetails> details)726 virtual void OnFirstMeaningfulPaint(std::shared_ptr<NWebFirstMeaningfulPaintDetails> details) {} 727 728 /** 729 * @brief Called when the largest contentful paint rendering of web page. 730 * @param details represents the details of largest contentful paint. 731 */ OnLargestContentfulPaint(std::shared_ptr<NWebLargestContentfulPaintDetails> details)732 virtual void OnLargestContentfulPaint(std::shared_ptr<NWebLargestContentfulPaintDetails> details) {} 733 734 /** 735 * @brief Called when swap buffer completed with new size. 736 */ OnCompleteSwapWithNewSize()737 virtual void OnCompleteSwapWithNewSize() {} 738 739 /** 740 * @brief Called when resize not work. 741 */ OnResizeNotWork()742 virtual void OnResizeNotWork() {} 743 OnGetTouchHandleHotZone(std::shared_ptr<NWebTouchHandleHotZone> hotZone)744 virtual void OnGetTouchHandleHotZone(std::shared_ptr<NWebTouchHandleHotZone> hotZone) {} 745 OnDateTimeChooserPopup(std::shared_ptr<NWebDateTimeChooser> chooser,const std::vector<std::shared_ptr<NWebDateTimeSuggestion>> & suggestions,std::shared_ptr<NWebDateTimeChooserCallback> callback)746 virtual void OnDateTimeChooserPopup(std::shared_ptr<NWebDateTimeChooser> chooser, 747 const std::vector<std::shared_ptr<NWebDateTimeSuggestion>>& suggestions, 748 std::shared_ptr<NWebDateTimeChooserCallback> callback) 749 {} 750 OnDateTimeChooserClose()751 virtual void OnDateTimeChooserClose() {} 752 OnDragAndDropDataUdmf(std::shared_ptr<NWebDragData> dragData)753 virtual bool OnDragAndDropDataUdmf(std::shared_ptr<NWebDragData> dragData) 754 { 755 return false; 756 } 757 UpdateDragCursor(NWebDragData::DragOperation op)758 virtual void UpdateDragCursor(NWebDragData::DragOperation op) {} 759 OnOverScroll(float xOffset,float yOffset)760 virtual void OnOverScroll(float xOffset, float yOffset) {} 761 762 /** 763 * @brief Ask for the screen capture permission. 764 * 765 * @param request std::shared_ptr<NWebScreenCaptureAccessRequest>: A request to ask for the 766 * screen capture permission. 767 */ OnScreenCaptureRequest(std::shared_ptr<NWebScreenCaptureAccessRequest> request)768 virtual void OnScreenCaptureRequest(std::shared_ptr<NWebScreenCaptureAccessRequest> request) {} 769 OnOverScrollFlingVelocity(float xVelocity,float yVelocity,bool isFling)770 virtual void OnOverScrollFlingVelocity(float xVelocity, float yVelocity, bool isFling) {} 771 OnOverScrollFlingEnd()772 virtual void OnOverScrollFlingEnd() {} 773 774 /** 775 * @brief Called when the media or form state on the web page changed. 776 * @param state state of the media or form. Refer to the enum class MediaPlayingState and FormState 777 * @param ActivityType it can be form, media, or audio 778 */ OnActivityStateChanged(int state,ActivityType type)779 virtual void OnActivityStateChanged(int state, ActivityType type) {} 780 OnScrollState(bool scrollState)781 virtual void OnScrollState(bool scrollState) {} 782 OnRootLayerChanged(int width,int height)783 virtual void OnRootLayerChanged(int width, int height) {} 784 FilterScrollEvent(const float x,const float y,const float xVelocity,const float yVelocity)785 virtual bool FilterScrollEvent(const float x, const float y, const float xVelocity, const float yVelocity) 786 { 787 return false; 788 } 789 790 /** 791 * @brief called when the navigation entry has been committed. 792 * @param details represents the details of a committed navigation entry. 793 */ OnNavigationEntryCommitted(std::shared_ptr<NWebLoadCommittedDetails> details)794 virtual void OnNavigationEntryCommitted(std::shared_ptr<NWebLoadCommittedDetails> details) {} 795 OnNativeEmbedLifecycleChange(std::shared_ptr<NWebNativeEmbedDataInfo> dataInfo)796 virtual void OnNativeEmbedLifecycleChange(std::shared_ptr<NWebNativeEmbedDataInfo> dataInfo) {} 797 OnNativeEmbedGestureEvent(std::shared_ptr<NWebNativeEmbedTouchEvent> event)798 virtual void OnNativeEmbedGestureEvent(std::shared_ptr<NWebNativeEmbedTouchEvent> event) {} 799 800 /** 801 * @brief Called when received website security risk check result. 802 * @param threat_type The threat_type of website. 803 */ OnSafeBrowsingCheckResult(int threat_type)804 virtual void OnSafeBrowsingCheckResult(int threat_type) {} 805 806 /** 807 * @brief Called when tracker's cookie is prevented. 808 * @param website_host The host of website url. 809 * @param tracker_host The host of tracker url. 810 */ OnIntelligentTrackingPreventionResult(const std::string & website_host,const std::string & tracker_host)811 virtual void OnIntelligentTrackingPreventionResult(const std::string& website_host, const std::string& tracker_host) 812 {} 813 814 /** 815 * @brief called when the page enter the full-screen mode. 816 * 817 * @param handler to exit full-screen mode. 818 * @param video_natural_width indicates the width of the <video> element 819 * entering full screen. 820 * @param video_natural_height indicates the height of the <video> element 821 * entering full screen. 822 */ OnFullScreenEnterWithVideoSize(std::shared_ptr<NWebFullScreenExitHandler> handler,int video_natural_width,int video_natural_height)823 virtual void OnFullScreenEnterWithVideoSize( 824 std::shared_ptr<NWebFullScreenExitHandler> handler, int video_natural_width, int video_natural_height) 825 {} 826 827 /** 828 * @brief Give the application a chance to decide whether to override loading the 829 * url. 830 * 831 * @param request The request information. 832 * @return true to abort loading the url, false to continue loading the url 833 * as usual. 834 */ OnHandleOverrideUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request)835 virtual bool OnHandleOverrideUrlLoading(std::shared_ptr<OHOS::NWeb::NWebUrlResourceRequest> request) 836 { 837 return false; 838 } 839 OnAllSslErrorRequestByJS(std::shared_ptr<NWebJSAllSslErrorResult> result,SslError error,const std::string & url,const std::string & originalUrl,const std::string & referrer,bool isFatalError,bool isMainFrame)840 virtual bool OnAllSslErrorRequestByJS(std::shared_ptr<NWebJSAllSslErrorResult> result, SslError error, 841 const std::string& url, const std::string& originalUrl, const std::string& referrer, bool isFatalError, 842 bool isMainFrame) 843 { 844 return false; 845 } 846 847 /** 848 * @brief Called when a tooltip should be presented for a component. 849 * 850 * @param tooltip The content of the tooltip. 851 */ OnTooltip(const std::string & param)852 virtual void OnTooltip(const std::string& param) {} 853 854 /** 855 * @brief called when resizehold is released. 856 */ ReleaseResizeHold()857 virtual void ReleaseResizeHold() {} 858 OnShowAutofillPopup(const float offsetX,const float offsetY,const std::vector<std::string> & menu_items)859 virtual void OnShowAutofillPopup( 860 const float offsetX, const float offsetY, const std::vector<std::string>& menu_items) 861 {} 862 OnHideAutofillPopup()863 virtual void OnHideAutofillPopup() {} 864 865 /** 866 * @brief Called when select a word. 867 * 868 * @param text The content of the text. 869 * @param offset The offset of the point. 870 */ GetWordSelection(const std::string & text,int8_t offset)871 virtual std::vector<int8_t> GetWordSelection(const std::string& text, int8_t offset) 872 { 873 return { -1, -1 }; 874 } 875 UpdateClippedSelectionBounds(int x,int y,int w,int h)876 virtual void UpdateClippedSelectionBounds(int x, int y, int w, int h) {} 877 OnOpenAppLink(const std::string & url,std::shared_ptr<NWebAppLinkCallback> callback)878 virtual bool OnOpenAppLink(const std::string& url, std::shared_ptr<NWebAppLinkCallback> callback) 879 { 880 return false; 881 } 882 883 /** 884 * @brief Called when the render process not responding. 885 * 886 * @param js_stack Javascript stack info of webpage when render process not 887 * responding. 888 * @param pid Process id of the render process not responding. 889 * @param reason Reason of the render process not responding. 890 */ 891 OnRenderProcessNotResponding(const std::string & js_stack,int pid,RenderProcessNotRespondingReason reason)892 virtual void OnRenderProcessNotResponding( 893 const std::string& js_stack, int pid, RenderProcessNotRespondingReason reason) 894 {} 895 896 /** 897 * @brief Called when the unresponding render process becomes responsive. 898 * 899 */ 900 OnRenderProcessResponding()901 virtual void OnRenderProcessResponding() {} 902 903 /** 904 * @brief Called when the viewport-fit meta is detected for web page. 905 * 906 * @param viewportFit The type of the viewport-fit. 907 */ OnViewportFitChange(ViewportFit viewportFit)908 virtual void OnViewportFitChange(ViewportFit viewportFit) {} 909 910 /** 911 * @brief called when creating overlay. 912 */ CreateOverlay(void * data,size_t len,int width,int height,int offsetX,int offsetY,int rectWidth,int rectHeight,int pointX,int pointY)913 virtual void CreateOverlay(void* data, size_t len, int width, int height, int offsetX, int offsetY, int rectWidth, 914 int rectHeight, int pointX, int pointY) 915 {} 916 917 /** 918 * @brief called when state changed. 919 */ OnOverlayStateChanged(int offsetX,int offsetY,int rectWidth,int rectHeight)920 virtual void OnOverlayStateChanged(int offsetX, int offsetY, int rectWidth, int rectHeight) {} 921 922 /** 923 * @brief Request display and focus for a new nweb. 924 * 925 * @param source The Focus Source. 926 * @return Return true if request focus success, false if request focus fail. 927 */ OnFocus(NWebFocusSource source)928 virtual bool OnFocus(NWebFocusSource source) 929 { 930 return false; 931 } 932 933 /** 934 * @brief Called when the page is over scroll. 935 * 936 * @param xOffset The offset of x axis. 937 * @param yOffset The offset of y axis. 938 * @param xVelocity The velocity of x axis. 939 * @param yVelocity The velocity of y axis. 940 * @return Return true if value is consumed, false if value is unconsumed. 941 */ OnOverScroll(float xOffset,float yOffset,float xVelocity,float yVelocity)942 virtual bool OnOverScroll(float xOffset, float yOffset, float xVelocity, float yVelocity) 943 { 944 return false; 945 } 946 947 /** 948 * @brief Called when the key board redispatch. 949 * 950 * @param event Key information. 951 * @param isUsed Whether the key is used by the kernel. 952 */ KeyboardReDispatch(std::shared_ptr<NWebKeyEvent> event,bool isUsed)953 virtual void KeyboardReDispatch(std::shared_ptr<NWebKeyEvent> event, bool isUsed) {} 954 OnInterceptKeyboardAttach(const std::shared_ptr<NWebCustomKeyboardHandler> keyboardHandler,const std::map<std::string,std::string> & attributes,bool & useSystemKeyboard,int32_t & enterKeyType)955 virtual void OnInterceptKeyboardAttach( 956 const std::shared_ptr<NWebCustomKeyboardHandler> keyboardHandler, 957 const std::map<std::string, std::string> &attributes, bool &useSystemKeyboard, int32_t &enterKeyType) { 958 useSystemKeyboard = true; 959 enterKeyType = -1; 960 } 961 OnCustomKeyboardAttach()962 virtual void OnCustomKeyboardAttach() {} 963 OnCustomKeyboardClose()964 virtual void OnCustomKeyboardClose() {} 965 /** 966 * @brief Called when received Ads blocked results. 967 * 968 * @param url The url of webpage. 969 * @param adsBlocked The ads' blocked urls. 970 * 971 */ OnAdsBlocked(const std::string & url,const std::vector<std::string> & adsBlocked)972 virtual void OnAdsBlocked(const std::string& url, const std::vector<std::string>& adsBlocked) {} 973 974 /** 975 * @brief called when the cursor info is updated. 976 * 977 * @param x, y relative coordinates within web components of the cursor 978 * @param width, height width and height of the cursor 979 */ OnCursorUpdate(double x,double y,double width,double height)980 virtual void OnCursorUpdate(double x, double y, double width, double height) {} 981 982 /** 983 * @brief Called when web occurs frame loss event. 984 * 985 * @param sceneId The id of event scene. 986 * @param isStart True if is start. 987 */ ReportDynamicFrameLossEvent(const std::string & sceneId,bool isStart)988 virtual void ReportDynamicFrameLossEvent(const std::string& sceneId, bool isStart) {} 989 990 /** 991 * @brief Called when you need to temporarily hide/restore the handle menu. 992 * 993 * @param hide hide. 994 */ HideHandleAndQuickMenuIfNecessary(bool hide)995 virtual void HideHandleAndQuickMenuIfNecessary(bool hide) {} 996 997 /** 998 * @brief Called When you click on the selected area. 999 * 1000 */ ChangeVisibilityOfQuickMenu()1001 virtual void ChangeVisibilityOfQuickMenu() {} 1002 1003 /** 1004 * @brief Called when you need to start vibrator. 1005 */ StartVibraFeedback(const std::string & vibratorType)1006 virtual void StartVibraFeedback(const std::string& vibratorType) {} 1007 1008 /** 1009 * @brief Called when a popup is shown with the given size. 1010 * 1011 * @param x The offset of the popup on the x coordinate axis. 1012 * @param y The offset of the popup on the y coordinate axis. 1013 * @param width The width of the popup. 1014 * @param height The height of the popup. 1015 * 1016 */ OnPopupSize(int x,int y,int width,int height)1017 virtual void OnPopupSize(int x, int y, int width, int height) {} 1018 1019 /** 1020 * @brief Called when the popup is shown or hidden. 1021 * 1022 * @param show Whether the popup is shown or hidden. 1023 * 1024 */ OnPopupShow(bool show)1025 virtual void OnPopupShow(bool show) {} 1026 OnNativeEmbedVisibilityChange(const std::string & embed_id,bool visibility)1027 virtual void OnNativeEmbedVisibilityChange(const std::string& embed_id, bool visibility) {} 1028 CloseImageOverlaySelection()1029 virtual bool CloseImageOverlaySelection() { return false; } 1030 OnSslErrorRequestByJSV2(std::shared_ptr<NWebJSSslErrorResult> result,SslError error,const std::vector<std::string> & certChainData)1031 virtual bool OnSslErrorRequestByJSV2(std::shared_ptr<NWebJSSslErrorResult> result, SslError error, 1032 const std::vector<std::string>& certChainData) 1033 { 1034 return false; 1035 } 1036 OnAccessibilityEvent(int64_t accessibilityId,int32_t eventType)1037 virtual void OnAccessibilityEvent(int64_t accessibilityId, int32_t eventType) {} 1038 IsCurrentFocus()1039 virtual bool IsCurrentFocus() { return false; } 1040 1041 /** 1042 * @brief Get the visible area relative to the web. 1043 */ GetVisibleRectToWeb(int & visibleX,int & visibleY,int & visibleWidth,int & visibleHeight)1044 virtual void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight) {} 1045 OnScrollStart(const float x,const float y)1046 virtual void OnScrollStart(const float x, const float y) {} 1047 OnShowAutofillPopupV2(const float offsetX,const float offsetY,const float height,const float width,const std::vector<std::string> & menu_items)1048 virtual void OnShowAutofillPopupV2( 1049 const float offsetX, const float offsetY, const float height, const float width, 1050 const std::vector<std::string>& menu_items) 1051 {} 1052 1053 /** 1054 * @brief Restore web component renderfit. 1055 */ RestoreRenderFit()1056 virtual void RestoreRenderFit() {} 1057 OnAccessibilityEventV2(int64_t accessibilityId,int32_t eventType,const std::string & argument)1058 virtual void OnAccessibilityEventV2(int64_t accessibilityId, int32_t eventType, const std::string& argument) {} 1059 }; 1060 1061 } // namespace OHOS::NWeb 1062 1063 #endif // NWEB_HANDLER_H 1064