1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_COMPONENT_H 18 19 #include <string> 20 #include <tuple> 21 #include <utility> 22 23 #include "base/geometry/size.h" 24 #include "base/log/log.h" 25 #include "base/utils/utils.h" 26 #include "core/components/box/drag_drop_event.h" 27 #include "core/components/declaration/common/declaration.h" 28 #include "core/components/declaration/web/web_client.h" 29 #include "core/components/declaration/web/web_declaration.h" 30 #include "core/components/web/resource/web_javascript_value.h" 31 #include "core/components/web/web_event.h" 32 #include "core/components/web/web_property.h" 33 #include "core/components_v2/common/common_def.h" 34 #include "core/event/key_event.h" 35 #include "core/focus/focus_node.h" 36 #include "core/pipeline/base/element.h" 37 38 namespace OHOS::Ace { 39 40 // A component can show HTML5 webpages. 41 class ACE_EXPORT WebComponent : public RenderComponent { 42 DECLARE_ACE_TYPE(WebComponent, RenderComponent); 43 44 public: 45 using CreatedCallback = std::function<void()>; 46 using ReleasedCallback = std::function<void(bool)>; 47 using ErrorCallback = std::function<void(const std::string&, const std::string&)>; 48 using MethodCall = std::function<void(const std::string&)>; 49 using Method = std::string; 50 using SetWebIdCallback = std::function<void(int32_t)>; 51 using SetHapPathCallback = std::function<void(const std::string&)>; 52 using JsProxyCallback = std::function<void()>; 53 using PreKeyEventCallback = std::function<bool(KeyEventInfo& keyEventInfo)>; 54 55 WebComponent() = default; 56 explicit WebComponent(const std::string& type); 57 ~WebComponent() override = default; 58 59 RefPtr<RenderNode> CreateRenderNode() override; 60 RefPtr<Element> CreateElement() override; 61 SetType(const std::string & type)62 void SetType(const std::string& type) 63 { 64 type_ = type; 65 } 66 GetType()67 const std::string& GetType() const 68 { 69 return type_; 70 } 71 SetIncognitoMode(const bool incognitoMode)72 void SetIncognitoMode(const bool incognitoMode) 73 { 74 incognitoMode_ = incognitoMode; 75 } 76 GetIncognitoMode()77 bool GetIncognitoMode() const 78 { 79 return incognitoMode_; 80 } 81 SetSrc(const std::string & src)82 void SetSrc(const std::string& src) 83 { 84 CHECK_NULL_VOID(declaration_); 85 declaration_->SetWebSrc(src); 86 } 87 GetSrc()88 const std::string& GetSrc() const 89 { 90 return declaration_->GetWebSrc(); 91 } 92 SetPopup(bool popup)93 void SetPopup(bool popup) 94 { 95 isPopup_ = popup; 96 } 97 SetParentNWebId(int32_t parentNWebId)98 void SetParentNWebId(int32_t parentNWebId) 99 { 100 parentNWebId_ = parentNWebId; 101 } 102 SetSharedRenderProcessToken(const std::string & sharedRenderProcessToken)103 void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken) 104 { 105 shared_render_process_token_ = sharedRenderProcessToken; 106 } 107 GetSharedRenderProcessToken()108 const std::string& GetSharedRenderProcessToken() const 109 { 110 return shared_render_process_token_; 111 } 112 SetData(const std::string & data)113 void SetData(const std::string& data) 114 { 115 CHECK_NULL_VOID(declaration_); 116 declaration_->SetWebData(data); 117 } 118 GetData()119 const std::string& GetData() const 120 { 121 return declaration_->GetWebData(); 122 } 123 SetPageStartedEventId(const EventMarker & pageStartedEventId)124 void SetPageStartedEventId(const EventMarker& pageStartedEventId) 125 { 126 CHECK_NULL_VOID(declaration_); 127 declaration_->SetPageStartedEventId(pageStartedEventId); 128 } 129 GetPageStartedEventId()130 const EventMarker& GetPageStartedEventId() const 131 { 132 return declaration_->GetPageStartedEventId(); 133 } 134 SetPageFinishedEventId(const EventMarker & pageFinishedEventId)135 void SetPageFinishedEventId(const EventMarker& pageFinishedEventId) 136 { 137 CHECK_NULL_VOID(declaration_); 138 declaration_->SetPageFinishedEventId(pageFinishedEventId); 139 } 140 GetPageFinishedEventId()141 const EventMarker& GetPageFinishedEventId() const 142 { 143 return declaration_->GetPageFinishedEventId(); 144 } 145 146 using OnProgressChangeImpl = std::function<void(const BaseEventInfo* info)>; OnProgressChange(const BaseEventInfo * info)147 void OnProgressChange(const BaseEventInfo* info) const 148 { 149 if (onProgressChangeImpl_) { 150 onProgressChangeImpl_(info); 151 } 152 } SetProgressChangeImpl(OnProgressChangeImpl && onProgressChangeImpl)153 void SetProgressChangeImpl(OnProgressChangeImpl&& onProgressChangeImpl) 154 { 155 if (onProgressChangeImpl == nullptr) { 156 return; 157 } 158 onProgressChangeImpl_ = std::move(onProgressChangeImpl); 159 } 160 SetTitleReceiveEventId(const EventMarker & titleReceiveEventId)161 void SetTitleReceiveEventId(const EventMarker& titleReceiveEventId) 162 { 163 CHECK_NULL_VOID(declaration_); 164 declaration_->SetTitleReceiveEventId(titleReceiveEventId); 165 } 166 GetTitleReceiveEventId()167 const EventMarker& GetTitleReceiveEventId() const 168 { 169 return declaration_->GetTitleReceiveEventId(); 170 } 171 SetOnFullScreenExitEventId(const EventMarker & fullScreenExitEventId)172 void SetOnFullScreenExitEventId(const EventMarker& fullScreenExitEventId) 173 { 174 CHECK_NULL_VOID(declaration_); 175 declaration_->SetOnFullScreenExitEventId(fullScreenExitEventId); 176 } 177 GetOnFullScreenExitEventId()178 const EventMarker& GetOnFullScreenExitEventId() const 179 { 180 return declaration_->GetOnFullScreenExitEventId(); 181 } 182 SetGeolocationHideEventId(const EventMarker & geolocationHideEventId)183 void SetGeolocationHideEventId(const EventMarker& geolocationHideEventId) 184 { 185 CHECK_NULL_VOID(declaration_); 186 declaration_->SetGeolocationHideEventId(geolocationHideEventId); 187 } 188 GetGeolocationHideEventId()189 const EventMarker& GetGeolocationHideEventId() const 190 { 191 return declaration_->GetGeolocationHideEventId(); 192 } 193 SetGeolocationShowEventId(const EventMarker & geolocationShowEventId)194 void SetGeolocationShowEventId(const EventMarker& geolocationShowEventId) 195 { 196 CHECK_NULL_VOID(declaration_); 197 declaration_->SetGeolocationShowEventId(geolocationShowEventId); 198 } 199 GetGeolocationShowEventId()200 const EventMarker& GetGeolocationShowEventId() const 201 { 202 return declaration_->GetGeolocationShowEventId(); 203 } 204 SetRequestFocusEventId(const EventMarker & requestFocusEventId)205 void SetRequestFocusEventId(const EventMarker& requestFocusEventId) 206 { 207 CHECK_NULL_VOID(declaration_); 208 declaration_->SetRequestFocusEventId(requestFocusEventId); 209 } 210 GetRequestFocusEventId()211 const EventMarker& GetRequestFocusEventId() const 212 { 213 return declaration_->GetRequestFocusEventId(); 214 } 215 SetDownloadStartEventId(const EventMarker & downloadStartEventId)216 void SetDownloadStartEventId(const EventMarker& downloadStartEventId) 217 { 218 CHECK_NULL_VOID(declaration_); 219 declaration_->SetDownloadStartEventId(downloadStartEventId); 220 } 221 GetDownloadStartEventId()222 const EventMarker& GetDownloadStartEventId() const 223 { 224 return declaration_->GetDownloadStartEventId(); 225 } 226 SetPageErrorEventId(const EventMarker & pageErrorEventId)227 void SetPageErrorEventId(const EventMarker& pageErrorEventId) 228 { 229 CHECK_NULL_VOID(declaration_); 230 declaration_->SetPageErrorEventId(pageErrorEventId); 231 } 232 GetPageErrorEventId()233 const EventMarker& GetPageErrorEventId() const 234 { 235 return declaration_->GetPageErrorEventId(); 236 } 237 SetHttpErrorEventId(const EventMarker & httpErrorEventId)238 void SetHttpErrorEventId(const EventMarker& httpErrorEventId) 239 { 240 CHECK_NULL_VOID(declaration_); 241 declaration_->SetHttpErrorEventId(httpErrorEventId); 242 } 243 GetHttpErrorEventId()244 const EventMarker& GetHttpErrorEventId() const 245 { 246 return declaration_->GetHttpErrorEventId(); 247 } 248 SetMessageEventId(const EventMarker & messageEventId)249 void SetMessageEventId(const EventMarker& messageEventId) 250 { 251 CHECK_NULL_VOID(declaration_); 252 declaration_->SetMessageEventId(messageEventId); 253 } 254 GetMessageEventId()255 const EventMarker& GetMessageEventId() const 256 { 257 return declaration_->GetMessageEventId(); 258 } 259 SetRenderExitedId(const EventMarker & renderExitedId)260 void SetRenderExitedId(const EventMarker& renderExitedId) 261 { 262 CHECK_NULL_VOID(declaration_); 263 declaration_->SetRenderExitedId(renderExitedId); 264 } 265 GetRenderExitedId()266 const EventMarker& GetRenderExitedId() const 267 { 268 return declaration_->GetRenderExitedId(); 269 } 270 SetRefreshAccessedHistoryId(const EventMarker & refreshAccessedHistoryId)271 void SetRefreshAccessedHistoryId(const EventMarker& refreshAccessedHistoryId) 272 { 273 CHECK_NULL_VOID(declaration_); 274 declaration_->SetRefreshAccessedHistoryId(refreshAccessedHistoryId); 275 } 276 GetRefreshAccessedHistoryId()277 const EventMarker& GetRefreshAccessedHistoryId() const 278 { 279 return declaration_->GetRefreshAccessedHistoryId(); 280 } 281 SetResourceLoadId(const EventMarker & resourceLoadId)282 void SetResourceLoadId(const EventMarker& resourceLoadId) 283 { 284 CHECK_NULL_VOID(declaration_); 285 declaration_->SetResourceLoadId(resourceLoadId); 286 } 287 GetResourceLoadId()288 const EventMarker& GetResourceLoadId() const 289 { 290 return declaration_->GetResourceLoadId(); 291 } 292 SetScaleChangeId(const EventMarker & scaleChangeId)293 void SetScaleChangeId(const EventMarker& scaleChangeId) 294 { 295 CHECK_NULL_VOID(declaration_); 296 declaration_->SetScaleChangeId(scaleChangeId); 297 } 298 GetScaleChangeId()299 const EventMarker& GetScaleChangeId() const 300 { 301 return declaration_->GetScaleChangeId(); 302 } 303 SetScrollId(const EventMarker & scrollId)304 void SetScrollId(const EventMarker& scrollId) 305 { 306 CHECK_NULL_VOID(declaration_); 307 declaration_->SetScrollId(scrollId); 308 } 309 GetScrollId()310 const EventMarker& GetScrollId() const 311 { 312 return declaration_->GetScrollId(); 313 } 314 SetPermissionRequestEventId(const EventMarker & permissionRequestEventId)315 void SetPermissionRequestEventId(const EventMarker& permissionRequestEventId) 316 { 317 CHECK_NULL_VOID(declaration_); 318 declaration_->SetPermissionRequestEventId(permissionRequestEventId); 319 } 320 GetPermissionRequestEventId()321 const EventMarker& GetPermissionRequestEventId() const 322 { 323 return declaration_->GetPermissionRequestEventId(); 324 } 325 326 using OnWindowNewImpl = std::function<void(const std::shared_ptr<BaseEventInfo>& info)>; SetWindowNewEvent(OnWindowNewImpl && onWindowNewImpl)327 void SetWindowNewEvent(OnWindowNewImpl && onWindowNewImpl) 328 { 329 if (onWindowNewImpl == nullptr) { 330 return; 331 } 332 onWindowNewImpl_ = std::move(onWindowNewImpl); 333 } 334 OnWindowNewEvent(const std::shared_ptr<BaseEventInfo> & info)335 void OnWindowNewEvent(const std::shared_ptr<BaseEventInfo>& info) const 336 { 337 if (onWindowNewImpl_) { 338 onWindowNewImpl_(info); 339 } 340 } 341 SetWindowExitEventId(const EventMarker & windowExitEventId)342 void SetWindowExitEventId(const EventMarker& windowExitEventId) 343 { 344 CHECK_NULL_VOID(declaration_); 345 declaration_->SetWindowExitEventId(windowExitEventId); 346 } 347 GetWindowExitEventId()348 const EventMarker& GetWindowExitEventId() const 349 { 350 return declaration_->GetWindowExitEventId(); 351 } 352 SetDeclaration(const RefPtr<WebDeclaration> & declaration)353 void SetDeclaration(const RefPtr<WebDeclaration>& declaration) 354 { 355 if (declaration) { 356 declaration_ = declaration; 357 } 358 } 359 GetController()360 RefPtr<WebController> GetController() const 361 { 362 return webController_; 363 } 364 SetWebController(const RefPtr<WebController> & webController)365 void SetWebController(const RefPtr<WebController>& webController) 366 { 367 webController_ = webController; 368 } 369 SetSetWebIdCallback(SetWebIdCallback && SetIdCallback)370 void SetSetWebIdCallback(SetWebIdCallback&& SetIdCallback) 371 { 372 setWebIdCallback_ = std::move(SetIdCallback); 373 } 374 GetSetWebIdCallback()375 SetWebIdCallback GetSetWebIdCallback() const 376 { 377 return setWebIdCallback_; 378 } 379 SetSetHapPathCallback(SetHapPathCallback && callback)380 void SetSetHapPathCallback(SetHapPathCallback&& callback) 381 { 382 setHapPathCallback_ = std::move(callback); 383 } 384 GetSetHapPathCallback()385 SetHapPathCallback GetSetHapPathCallback() const 386 { 387 return setHapPathCallback_; 388 } 389 GetJsEnabled()390 bool GetJsEnabled() const 391 { 392 return isJsEnabled_; 393 } 394 SetJsEnabled(bool isEnabled)395 void SetJsEnabled(bool isEnabled) 396 { 397 isJsEnabled_ = isEnabled; 398 } 399 GetUserAgent()400 std::string GetUserAgent() const 401 { 402 return userAgent_; 403 } 404 SetUserAgent(std::string userAgent)405 void SetUserAgent(std::string userAgent) 406 { 407 userAgent_ = std::move(userAgent); 408 } 409 GetCustomScheme()410 std::string GetCustomScheme() const 411 { 412 return customScheme_; 413 } 414 SetCustomScheme(std::string cmdLine)415 void SetCustomScheme(std::string cmdLine) 416 { 417 customScheme_ = std::move(cmdLine); 418 } 419 GetContentAccessEnabled()420 bool GetContentAccessEnabled() const 421 { 422 return isContentAccessEnabled_; 423 } 424 SetContentAccessEnabled(bool isEnabled)425 void SetContentAccessEnabled(bool isEnabled) 426 { 427 isContentAccessEnabled_ = isEnabled; 428 } 429 GetFileAccessEnabled()430 bool GetFileAccessEnabled() const 431 { 432 return isFileAccessEnabled_; 433 } 434 SetFileAccessEnabled(bool isEnabled)435 void SetFileAccessEnabled(bool isEnabled) 436 { 437 isFileAccessEnabled_ = isEnabled; 438 } GetOnLineImageAccessEnabled()439 bool GetOnLineImageAccessEnabled() const 440 { 441 return isOnLineImageAccessEnabled_; 442 } 443 SetOnLineImageAccessEnabled(bool isEnabled)444 void SetOnLineImageAccessEnabled(bool isEnabled) 445 { 446 isOnLineImageAccessEnabled_ = isEnabled; 447 } 448 GetDomStorageAccessEnabled()449 bool GetDomStorageAccessEnabled() const 450 { 451 return isDomStorageAccessEnabled_; 452 } 453 SetDomStorageAccessEnabled(bool isEnabled)454 void SetDomStorageAccessEnabled(bool isEnabled) 455 { 456 isDomStorageAccessEnabled_ = isEnabled; 457 } 458 GetImageAccessEnabled()459 bool GetImageAccessEnabled() const 460 { 461 return isImageAccessEnabled_; 462 } 463 SetImageAccessEnabled(bool isEnabled)464 void SetImageAccessEnabled(bool isEnabled) 465 { 466 isImageAccessEnabled_ = isEnabled; 467 } 468 GetMixedMode()469 MixedModeContent GetMixedMode() const 470 { 471 return mixedContentMode_; 472 } 473 SetMixedMode(MixedModeContent mixedModeNum)474 void SetMixedMode(MixedModeContent mixedModeNum) 475 { 476 mixedContentMode_ = mixedModeNum; 477 } 478 GetZoomAccessEnabled()479 bool GetZoomAccessEnabled() const 480 { 481 return isZoomAccessEnabled_; 482 } 483 SetZoomAccessEnabled(bool isEnabled)484 void SetZoomAccessEnabled(bool isEnabled) 485 { 486 isZoomAccessEnabled_ = isEnabled; 487 } 488 GetGeolocationAccessEnabled()489 bool GetGeolocationAccessEnabled() const 490 { 491 return isGeolocationAccessEnabled_; 492 } 493 SetGeolocationAccessEnabled(bool isEnabled)494 void SetGeolocationAccessEnabled(bool isEnabled) 495 { 496 isGeolocationAccessEnabled_ = isEnabled; 497 } 498 GetCacheMode()499 WebCacheMode GetCacheMode() 500 { 501 return cacheMode_; 502 } 503 SetCacheMode(WebCacheMode mode)504 void SetCacheMode(WebCacheMode mode) 505 { 506 cacheMode_ = mode; 507 } 508 GetOverScrollMode()509 OverScrollMode GetOverScrollMode() const 510 { 511 return OverScrollMode_; 512 } 513 SetOverScrollMode(OverScrollMode mode)514 void SetOverScrollMode(OverScrollMode mode) 515 { 516 OverScrollMode_ = mode; 517 } 518 GetCopyOptionMode()519 CopyOptions GetCopyOptionMode() const 520 { 521 return CopyOptionMode_; 522 } 523 SetCopyOptionMode(CopyOptions mode)524 void SetCopyOptionMode(CopyOptions mode) 525 { 526 CopyOptionMode_ = mode; 527 } 528 GetOverviewModeAccessEnabled()529 bool GetOverviewModeAccessEnabled() const 530 { 531 return isOverviewModeAccessEnabled_; 532 } 533 SetOverviewModeAccessEnabled(bool isEnabled)534 void SetOverviewModeAccessEnabled(bool isEnabled) 535 { 536 isOverviewModeAccessEnabled_ = isEnabled; 537 } 538 GetFileFromUrlAccessEnabled()539 bool GetFileFromUrlAccessEnabled() const 540 { 541 return isFileFromUrlAccessEnabled_; 542 } 543 SetFileFromUrlAccessEnabled(bool isEnabled)544 void SetFileFromUrlAccessEnabled(bool isEnabled) 545 { 546 isFileFromUrlAccessEnabled_ = isEnabled; 547 } 548 GetDatabaseAccessEnabled()549 bool GetDatabaseAccessEnabled() const 550 { 551 return isDatabaseAccessEnabled_; 552 } 553 SetDatabaseAccessEnabled(bool isEnabled)554 void SetDatabaseAccessEnabled(bool isEnabled) 555 { 556 isDatabaseAccessEnabled_ = isEnabled; 557 } 558 GetWebDebuggingAccessEnabled()559 bool GetWebDebuggingAccessEnabled() const 560 { 561 return isWebDebuggingAccessEnabled_; 562 } 563 SetWebDebuggingAccessEnabled(bool isEnabled)564 void SetWebDebuggingAccessEnabled(bool isEnabled) 565 { 566 isWebDebuggingAccessEnabled_ = isEnabled; 567 } 568 GetPinchSmoothModeEnabled()569 bool GetPinchSmoothModeEnabled() const 570 { 571 return isPinchSmoothModeEnabled_; 572 } 573 SetPinchSmoothModeEnabled(bool isEnabled)574 void SetPinchSmoothModeEnabled(bool isEnabled) 575 { 576 isPinchSmoothModeEnabled_ = isEnabled; 577 } 578 GetMultiWindowAccessEnabled()579 bool GetMultiWindowAccessEnabled() const 580 { 581 return isMultiWindowAccessEnabled_; 582 } 583 SetMultiWindowAccessEnabled(bool isEnabled)584 void SetMultiWindowAccessEnabled(bool isEnabled) 585 { 586 isMultiWindowAccessEnabled_ = isEnabled; 587 } 588 GetAllowWindowOpenMethod()589 bool GetAllowWindowOpenMethod() const 590 { 591 return isAllowWindowOpenMethod_; 592 } 593 SetAllowWindowOpenMethod(bool isEnabled)594 void SetAllowWindowOpenMethod(bool isEnabled) 595 { 596 isAllowWindowOpenMethod_ = isEnabled; 597 } 598 GetIsInitialScaleSet()599 bool GetIsInitialScaleSet() const 600 { 601 return isInitialScaleSet_; 602 } 603 GetInitialScale()604 float GetInitialScale() const 605 { 606 return initialScale_; 607 } 608 SetInitialScale(float scale)609 void SetInitialScale(float scale) 610 { 611 initialScale_ = scale; 612 isInitialScaleSet_ = true; 613 } 614 GetBackgroundColorEnabled()615 bool GetBackgroundColorEnabled() const 616 { 617 return isBackgroundColor_; 618 } 619 GetBackgroundColor()620 int32_t GetBackgroundColor() const 621 { 622 return backgroundColor_; 623 } 624 SetBackgroundColor(int32_t backgroundColor)625 void SetBackgroundColor(int32_t backgroundColor) 626 { 627 backgroundColor_ = backgroundColor; 628 isBackgroundColor_ = true; 629 } 630 GetTextZoomRatio()631 int32_t GetTextZoomRatio() const 632 { 633 return textZoomRatioNum_; 634 } 635 SetTextZoomRatio(int32_t ratio)636 void SetTextZoomRatio(int32_t ratio) 637 { 638 textZoomRatioNum_ = ratio; 639 } 640 SetNativeEmbedModeEnabled(bool isEnabled)641 void SetNativeEmbedModeEnabled(bool isEnabled) 642 { 643 isNativeEmbedMode_ = isEnabled; 644 } 645 RegisterNativeEmbedRule(const std::string & tag,const std::string & type)646 void RegisterNativeEmbedRule(const std::string& tag, const std::string& type) 647 { 648 tag_ = tag; 649 tag_type_ = type; 650 } 651 GetNativeVideoPlayerConfig()652 const std::tuple<bool, bool>& GetNativeVideoPlayerConfig() const 653 { 654 return native_video_player_config_; 655 } 656 SetNativeVideoPlayerConfig(bool enable,bool shouldOverlay)657 void SetNativeVideoPlayerConfig(bool enable, bool shouldOverlay) 658 { 659 native_video_player_config_ = std::make_tuple(enable, shouldOverlay); 660 } 661 662 using OnCommonDialogImpl = std::function<bool(const BaseEventInfo* info)>; OnCommonDialog(const BaseEventInfo * info,DialogEventType dialogEventType)663 bool OnCommonDialog(const BaseEventInfo* info, DialogEventType dialogEventType) const 664 { 665 if (dialogEventType == DialogEventType::DIALOG_EVENT_ALERT && onAlertImpl_) { 666 return onAlertImpl_(info); 667 } 668 if (dialogEventType == DialogEventType::DIALOG_EVENT_CONFIRM && onConfirmImpl_) { 669 return onConfirmImpl_(info); 670 } 671 if (dialogEventType == DialogEventType::DIALOG_EVENT_PROMPT && onPromptImpl_) { 672 return onPromptImpl_(info); 673 } 674 if (dialogEventType == DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD && onBeforeUnloadImpl_) { 675 return onBeforeUnloadImpl_(info); 676 } 677 return false; 678 } SetOnCommonDialogImpl(OnCommonDialogImpl && onCommonDialogImpl,DialogEventType dialogEventType)679 void SetOnCommonDialogImpl(OnCommonDialogImpl&& onCommonDialogImpl, DialogEventType dialogEventType) 680 { 681 if (onCommonDialogImpl == nullptr) { 682 return; 683 } 684 685 switch (dialogEventType) { 686 case DialogEventType::DIALOG_EVENT_ALERT: 687 onAlertImpl_ = std::move(onCommonDialogImpl); 688 break; 689 case DialogEventType::DIALOG_EVENT_CONFIRM: 690 onConfirmImpl_ = std::move(onCommonDialogImpl); 691 break; 692 case DialogEventType::DIALOG_EVENT_PROMPT: 693 onPromptImpl_ = std::move(onCommonDialogImpl); 694 break; 695 case DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD: 696 onBeforeUnloadImpl_ = std::move(onCommonDialogImpl); 697 break; 698 default: 699 break; 700 } 701 } 702 703 using OnFullScreenEnterImpl = std::function<void(const BaseEventInfo* info)>; OnFullScreenEnter(const BaseEventInfo * info)704 void OnFullScreenEnter(const BaseEventInfo* info) const 705 { 706 if (onFullScreenEnterImpl_) { 707 onFullScreenEnterImpl_(info); 708 } 709 } SetOnFullScreenEnterImpl(OnFullScreenEnterImpl && onFullScreenEnterImpl)710 void SetOnFullScreenEnterImpl(OnFullScreenEnterImpl&& onFullScreenEnterImpl) 711 { 712 onFullScreenEnterImpl_ = std::move(onFullScreenEnterImpl); 713 } 714 715 using OnHttpAuthRequestImpl = std::function<bool(const BaseEventInfo* info)>; OnHttpAuthRequest(const BaseEventInfo * info)716 bool OnHttpAuthRequest(const BaseEventInfo* info) const 717 { 718 if (onHttpAuthRequestImpl_) { 719 return onHttpAuthRequestImpl_(info); 720 } 721 return false; 722 } SetOnHttpAuthRequestImpl(OnHttpAuthRequestImpl && onHttpAuthRequestImpl)723 void SetOnHttpAuthRequestImpl(OnHttpAuthRequestImpl&& onHttpAuthRequestImpl) 724 { 725 if (onHttpAuthRequestImpl == nullptr) { 726 return; 727 } 728 onHttpAuthRequestImpl_ = std::move(onHttpAuthRequestImpl); 729 } 730 731 using OnSslErrorRequestImpl = std::function<bool(const BaseEventInfo* info)>; OnSslErrorRequest(const BaseEventInfo * info)732 bool OnSslErrorRequest(const BaseEventInfo* info) const 733 { 734 if (onSslErrorRequestImpl_) { 735 return onSslErrorRequestImpl_(info); 736 } 737 return false; 738 } SetOnSslErrorRequestImpl(OnSslErrorRequestImpl && onSslErrorRequestImpl)739 void SetOnSslErrorRequestImpl(OnSslErrorRequestImpl && onSslErrorRequestImpl) 740 { 741 if (onSslErrorRequestImpl == nullptr) { 742 return; 743 } 744 onSslErrorRequestImpl_ = std::move(onSslErrorRequestImpl); 745 } 746 747 using OnAllSslErrorRequestImpl = std::function<bool(const BaseEventInfo* info)>; OnAllSslErrorRequest(const BaseEventInfo * info)748 bool OnAllSslErrorRequest(const BaseEventInfo* info) const 749 { 750 if (onAllSslErrorRequestImpl_) { 751 return onAllSslErrorRequestImpl_(info); 752 } 753 return false; 754 } 755 SetOnAllSslErrorRequestImpl(OnAllSslErrorRequestImpl && onAllSslErrorRequestImpl)756 void SetOnAllSslErrorRequestImpl(OnAllSslErrorRequestImpl && onAllSslErrorRequestImpl) 757 { 758 if (onAllSslErrorRequestImpl == nullptr) { 759 return; 760 } 761 onAllSslErrorRequestImpl_ = std::move(onAllSslErrorRequestImpl); 762 } 763 764 using OnSslSelectCertRequestImpl = std::function<bool(const BaseEventInfo* info)>; OnSslSelectCertRequest(const BaseEventInfo * info)765 bool OnSslSelectCertRequest(const BaseEventInfo* info) const 766 { 767 if (onSslSelectCertRequestImpl_) { 768 return onSslSelectCertRequestImpl_(info); 769 } 770 return false; 771 } SetOnSslSelectCertRequestImpl(OnSslSelectCertRequestImpl && impl)772 void SetOnSslSelectCertRequestImpl(OnSslSelectCertRequestImpl && impl) 773 { 774 if (!impl) { 775 return; 776 } 777 onSslSelectCertRequestImpl_ = std::move(impl); 778 } 779 780 bool RequestFocus(); 781 782 using OnConsoleImpl = std::function<bool(const BaseEventInfo* info)>; OnConsole(const BaseEventInfo * info)783 bool OnConsole(const BaseEventInfo* info) const 784 { 785 if (consoleImpl_) { 786 return consoleImpl_(info); 787 } 788 return false; 789 } 790 SetOnConsoleImpl(OnConsoleImpl && consoleImpl)791 void SetOnConsoleImpl(OnConsoleImpl&& consoleImpl) 792 { 793 consoleImpl_ = std::move(consoleImpl); 794 } 795 SetFocusElement(const WeakPtr<FocusNode> & focusElement)796 void SetFocusElement(const WeakPtr<FocusNode>& focusElement) 797 { 798 focusElement_ = focusElement; 799 } 800 801 using OnFileSelectorShowImpl = std::function<bool(const BaseEventInfo* info)>; OnFileSelectorShow(const BaseEventInfo * info)802 bool OnFileSelectorShow(const BaseEventInfo* info) const 803 { 804 if (onFileSelectorShowImpl_) { 805 return onFileSelectorShowImpl_(info); 806 } 807 return false; 808 } SetOnFileSelectorShow(OnFileSelectorShowImpl && onFileSelectorShowImpl)809 void SetOnFileSelectorShow(OnFileSelectorShowImpl&& onFileSelectorShowImpl) 810 { 811 if (onFileSelectorShowImpl == nullptr) { 812 return; 813 } 814 815 onFileSelectorShowImpl_ = onFileSelectorShowImpl; 816 } 817 818 using OnContextMenuImpl = std::function<bool(const BaseEventInfo* info)>; OnContextMenuShow(const BaseEventInfo * info)819 bool OnContextMenuShow(const BaseEventInfo* info) const 820 { 821 if (onContextMenuImpl_) { 822 return onContextMenuImpl_(info); 823 } 824 return false; 825 } SetOnContextMenuShow(OnContextMenuImpl && onContextMenuImpl)826 void SetOnContextMenuShow(OnContextMenuImpl&& onContextMenuImpl) 827 { 828 if (onContextMenuImpl == nullptr) { 829 return; 830 } 831 onContextMenuImpl_ = std::move(onContextMenuImpl); 832 } 833 834 using OnContextMenuHideImpl = std::function<void(const BaseEventInfo* info)>; OnContextMenuHide(const BaseEventInfo * info)835 void OnContextMenuHide(const BaseEventInfo* info) const 836 { 837 if (onContextMenuHideImpl_) { 838 onContextMenuHideImpl_(info); 839 } 840 } SetOnContextMenuHide(OnContextMenuHideImpl && onContextMenuHideImpl)841 void SetOnContextMenuHide(OnContextMenuHideImpl&& onContextMenuHideImpl) 842 { 843 if (onContextMenuHideImpl == nullptr) { 844 return; 845 } 846 onContextMenuHideImpl_ = std::move(onContextMenuHideImpl); 847 } 848 849 using OnUrlLoadInterceptImpl = std::function<bool(const BaseEventInfo* info)>; OnUrlLoadIntercept(const BaseEventInfo * info)850 bool OnUrlLoadIntercept(const BaseEventInfo* info) const 851 { 852 if (onUrlLoadInterceptImpl_) { 853 return onUrlLoadInterceptImpl_(info); 854 } 855 return false; 856 } SetOnUrlLoadIntercept(OnUrlLoadInterceptImpl && onUrlLoadInterceptImpl)857 void SetOnUrlLoadIntercept(OnUrlLoadInterceptImpl&& onUrlLoadInterceptImpl) 858 { 859 if (onUrlLoadInterceptImpl == nullptr) { 860 return; 861 } 862 863 onUrlLoadInterceptImpl_ = onUrlLoadInterceptImpl; 864 } 865 866 using OnLoadInterceptImpl = std::function<bool(const BaseEventInfo* info)>; OnLoadIntercept(const BaseEventInfo * info)867 bool OnLoadIntercept(const BaseEventInfo* info) const 868 { 869 if (onLoadInterceptImpl_) { 870 return onLoadInterceptImpl_(info); 871 } 872 return false; 873 } SetOnLoadIntercept(OnLoadInterceptImpl && onLoadInterceptImpl)874 void SetOnLoadIntercept(OnLoadInterceptImpl&& onLoadInterceptImpl) 875 { 876 if (onLoadInterceptImpl == nullptr) { 877 return; 878 } 879 880 onLoadInterceptImpl_ = onLoadInterceptImpl; 881 } 882 883 using OnOverrideUrlLoadingImpl = std::function<bool(const BaseEventInfo* info)>; OnOverrideUrlLoading(const BaseEventInfo * info)884 bool OnOverrideUrlLoading(const BaseEventInfo* info) const 885 { 886 if (onOverrideUrlLoadingImpl_) { 887 return onOverrideUrlLoadingImpl_(info); 888 } 889 return false; 890 } SetOnOverrideUrlLoading(OnOverrideUrlLoadingImpl && onOverrideUrlLoadingImpl)891 void SetOnOverrideUrlLoading(OnOverrideUrlLoadingImpl&& onOverrideUrlLoadingImpl) 892 { 893 if (onOverrideUrlLoadingImpl == nullptr) { 894 return; 895 } 896 897 onOverrideUrlLoadingImpl_ = onOverrideUrlLoadingImpl; 898 } 899 900 using OnInterceptRequestImpl = std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>; OnInterceptRequest(const BaseEventInfo * info)901 RefPtr<WebResponse> OnInterceptRequest(const BaseEventInfo* info) const 902 { 903 if (onInterceptRequestImpl_) { 904 return onInterceptRequestImpl_(info); 905 } 906 return nullptr; 907 } 908 IsEmptyOnInterceptRequest()909 bool IsEmptyOnInterceptRequest() const 910 { 911 return onInterceptRequestImpl_ == nullptr; 912 } 913 SetOnInterceptRequest(OnInterceptRequestImpl && onInterceptRequestImpl)914 void SetOnInterceptRequest(OnInterceptRequestImpl&& onInterceptRequestImpl) 915 { 916 if (onInterceptRequestImpl == nullptr) { 917 return; 918 } 919 onInterceptRequestImpl_ = std::move(onInterceptRequestImpl); 920 } 921 SetOnMouseEventCallback(const OnMouseCallback & onMouseId)922 void SetOnMouseEventCallback(const OnMouseCallback& onMouseId) 923 { 924 onMouseEvent_ = onMouseId; 925 } 926 GetOnMouseEventCallback()927 OnMouseCallback GetOnMouseEventCallback() const 928 { 929 return onMouseEvent_; 930 } 931 SetOnKeyEventCallback(const OnKeyEventCallback & onKeyEventId)932 void SetOnKeyEventCallback(const OnKeyEventCallback& onKeyEventId) 933 { 934 onKeyEvent_ = onKeyEventId; 935 } 936 GetOnKeyEventCallback()937 OnKeyEventCallback GetOnKeyEventCallback() const 938 { 939 return onKeyEvent_; 940 } 941 SetSearchResultReceiveEventId(const EventMarker & searchResultReceiveEventId)942 void SetSearchResultReceiveEventId(const EventMarker& searchResultReceiveEventId) 943 { 944 CHECK_NULL_VOID(declaration_); 945 declaration_->SetSearchResultReceiveEventId(searchResultReceiveEventId); 946 } 947 GetSearchResultReceiveEventId()948 const EventMarker& GetSearchResultReceiveEventId() const 949 { 950 return declaration_->GetSearchResultReceiveEventId(); 951 } 952 SetMediaPlayGestureAccess(bool isNeedGestureAccess)953 void SetMediaPlayGestureAccess(bool isNeedGestureAccess) 954 { 955 isNeedGestureAccess_ = isNeedGestureAccess; 956 } 957 IsMediaPlayGestureAccess()958 bool IsMediaPlayGestureAccess() const 959 { 960 return isNeedGestureAccess_; 961 } 962 GetOnDragStartId()963 const OnDragFunc& GetOnDragStartId() const 964 { 965 return onDragStartId_; 966 } 967 SetOnDragStartId(const OnDragFunc & onDragStartId)968 void SetOnDragStartId(const OnDragFunc& onDragStartId) 969 { 970 onDragStartId_ = onDragStartId; 971 } 972 GetOnDragEnterId()973 const OnDropFunc& GetOnDragEnterId() const 974 { 975 return onDragEnterId_; 976 } 977 SetOnDragEnterId(const OnDropFunc & onDragEnterId)978 void SetOnDragEnterId(const OnDropFunc& onDragEnterId) 979 { 980 onDragEnterId_ = onDragEnterId; 981 } 982 GetOnDragMoveId()983 const OnDropFunc& GetOnDragMoveId() const 984 { 985 return onDragMoveId_; 986 } 987 SetOnDragMoveId(const OnDropFunc & onDragMoveId)988 void SetOnDragMoveId(const OnDropFunc& onDragMoveId) 989 { 990 onDragMoveId_ = onDragMoveId; 991 } 992 GetOnDragLeaveId()993 const OnDropFunc& GetOnDragLeaveId() const 994 { 995 return onDragLeaveId_; 996 } 997 SetOnDragLeaveId(const OnDropFunc & onDragLeaveId)998 void SetOnDragLeaveId(const OnDropFunc& onDragLeaveId) 999 { 1000 onDragLeaveId_ = onDragLeaveId; 1001 } 1002 GetOnDropId()1003 const OnDropFunc& GetOnDropId() const 1004 { 1005 return onDropId_; 1006 } 1007 SetOnDropId(const OnDropFunc & onDropId)1008 void SetOnDropId(const OnDropFunc& onDropId) 1009 { 1010 onDropId_ = onDropId; 1011 } 1012 SetJsProxyCallback(JsProxyCallback && jsProxyCallback)1013 void SetJsProxyCallback(JsProxyCallback&& jsProxyCallback) 1014 { 1015 jsProxyCallback_ = std::move(jsProxyCallback); 1016 } 1017 CallJsProxyCallback()1018 void CallJsProxyCallback() 1019 { 1020 if (jsProxyCallback_) { 1021 jsProxyCallback_(); 1022 } 1023 } 1024 SetOnInterceptKeyEventCallback(const PreKeyEventCallback & onPreKeyEventId)1025 void SetOnInterceptKeyEventCallback(const PreKeyEventCallback& onPreKeyEventId) 1026 { 1027 onPreKeyEvent_ = onPreKeyEventId; 1028 } 1029 GetOnInterceptKeyEventCallback()1030 PreKeyEventCallback GetOnInterceptKeyEventCallback() const 1031 { 1032 return onPreKeyEvent_; 1033 } 1034 SetOverScrollId(const EventMarker & overScrollId)1035 void SetOverScrollId(const EventMarker& overScrollId) 1036 { 1037 CHECK_NULL_VOID(declaration_); 1038 declaration_->SetOverScrollId(overScrollId); 1039 } 1040 GetOverScrollId()1041 const EventMarker& GetOverScrollId() const 1042 { 1043 return declaration_->GetOverScrollId(); 1044 } 1045 SetNativeEmbedLifecycleChangeId(const EventMarker & embedLifecycleChangeId)1046 void SetNativeEmbedLifecycleChangeId(const EventMarker& embedLifecycleChangeId) 1047 { 1048 CHECK_NULL_VOID(declaration_); 1049 declaration_->SetNativeEmbedLifecycleChangeId(embedLifecycleChangeId); 1050 } 1051 GetNativeEmbedLifecycleChangeId()1052 const EventMarker& GetNativeEmbedLifecycleChangeId() const 1053 { 1054 return declaration_->GetNativeEmbedLifecycleChangeId(); 1055 } 1056 SetNativeEmbedVisibilityChangeId(const EventMarker & embedVisibilityChangeId)1057 void SetNativeEmbedVisibilityChangeId(const EventMarker& embedVisibilityChangeId) 1058 { 1059 CHECK_NULL_VOID(declaration_); 1060 declaration_->SetNativeEmbedVisibilityChangeId(embedVisibilityChangeId); 1061 } 1062 GetNativeEmbedVisibilityChangeId()1063 const EventMarker& GetNativeEmbedVisibilityChangeId() const 1064 { 1065 return declaration_->GetNativeEmbedVisibilityChangeId(); 1066 } 1067 SetNativeEmbedGestureEventId(const EventMarker & embedGestureEventId)1068 void SetNativeEmbedGestureEventId(const EventMarker& embedGestureEventId) 1069 { 1070 CHECK_NULL_VOID(declaration_); 1071 declaration_->SetNativeEmbedGestureEventId(embedGestureEventId); 1072 } 1073 GetNativeEmbedGestureEventId()1074 const EventMarker& GetNativeEmbedGestureEventId() const 1075 { 1076 return declaration_->GetNativeEmbedGestureEventId(); 1077 } 1078 SetRenderProcessNotRespondingId(const EventMarker & renderNotRespondingId)1079 void SetRenderProcessNotRespondingId(const EventMarker& renderNotRespondingId) 1080 { 1081 CHECK_NULL_VOID(declaration_); 1082 declaration_->SetRenderProcessNotRespondingId(renderNotRespondingId); 1083 } 1084 GetRenderProcessNotRespondingId()1085 const EventMarker& GetRenderProcessNotRespondingId() const 1086 { 1087 return declaration_->GetRenderProcessNotRespondingId(); 1088 } 1089 SetRenderProcessRespondingId(const EventMarker & renderRespondingId)1090 void SetRenderProcessRespondingId(const EventMarker& renderRespondingId) 1091 { 1092 CHECK_NULL_VOID(declaration_); 1093 declaration_->SetRenderProcessRespondingId(renderRespondingId); 1094 } 1095 GetRenderProcessRespondingId()1096 const EventMarker& GetRenderProcessRespondingId() const 1097 { 1098 return declaration_->GetRenderProcessRespondingId(); 1099 } 1100 SetViewportFitChangedId(const EventMarker & viewportFitId)1101 void SetViewportFitChangedId(const EventMarker& viewportFitId) 1102 { 1103 CHECK_NULL_VOID(declaration_); 1104 declaration_->SetViewportFitChangedId(viewportFitId); 1105 } 1106 GetViewportFitChangedId()1107 const EventMarker& GetViewportFitChangedId() const 1108 { 1109 return declaration_->GetViewportFitChangedId(); 1110 } 1111 SetAdsBlockedEventId(const EventMarker & adsBlockedEventId)1112 void SetAdsBlockedEventId(const EventMarker& adsBlockedEventId) 1113 { 1114 CHECK_NULL_VOID(declaration_); 1115 declaration_->SetAdsBlockedEventId(adsBlockedEventId); 1116 } 1117 GetAdsBlockedEventId()1118 const EventMarker& GetAdsBlockedEventId() const 1119 { 1120 return declaration_->GetAdsBlockedEventId(); 1121 } 1122 1123 private: 1124 RefPtr<WebDeclaration> declaration_; 1125 CreatedCallback createdCallback_ = nullptr; 1126 ReleasedCallback releasedCallback_ = nullptr; 1127 ErrorCallback errorCallback_ = nullptr; 1128 SetWebIdCallback setWebIdCallback_ = nullptr; 1129 SetHapPathCallback setHapPathCallback_ = nullptr; 1130 JsProxyCallback jsProxyCallback_ = nullptr; 1131 RefPtr<WebDelegate> delegate_; 1132 RefPtr<WebController> webController_; 1133 OnCommonDialogImpl onAlertImpl_; 1134 OnCommonDialogImpl onConfirmImpl_; 1135 OnCommonDialogImpl onPromptImpl_; 1136 OnCommonDialogImpl onBeforeUnloadImpl_; 1137 OnConsoleImpl consoleImpl_; 1138 OnFileSelectorShowImpl onFileSelectorShowImpl_; 1139 OnFullScreenEnterImpl onFullScreenEnterImpl_; 1140 OnUrlLoadInterceptImpl onUrlLoadInterceptImpl_; 1141 OnLoadInterceptImpl onLoadInterceptImpl_; 1142 OnOverrideUrlLoadingImpl onOverrideUrlLoadingImpl_; 1143 OnHttpAuthRequestImpl onHttpAuthRequestImpl_; 1144 OnSslErrorRequestImpl onSslErrorRequestImpl_; 1145 OnAllSslErrorRequestImpl onAllSslErrorRequestImpl_; 1146 OnSslSelectCertRequestImpl onSslSelectCertRequestImpl_; 1147 OnContextMenuImpl onContextMenuImpl_; 1148 OnContextMenuHideImpl onContextMenuHideImpl_; 1149 OnInterceptRequestImpl onInterceptRequestImpl_ = nullptr; 1150 OnProgressChangeImpl onProgressChangeImpl_ = nullptr; 1151 OnWindowNewImpl onWindowNewImpl_ = nullptr; 1152 1153 std::string type_; 1154 bool incognitoMode_ = false; 1155 bool isJsEnabled_ = true; 1156 bool isContentAccessEnabled_ = true; 1157 bool isFileAccessEnabled_ = true; 1158 std::string userAgent_; 1159 std::string customScheme_; 1160 WeakPtr<FocusNode> focusElement_; 1161 bool isOnLineImageAccessEnabled_ = false; 1162 bool isDomStorageAccessEnabled_ = false; 1163 bool isImageAccessEnabled_ = true; 1164 MixedModeContent mixedContentMode_ = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW; 1165 bool isZoomAccessEnabled_ = true; 1166 bool isGeolocationAccessEnabled_ = true; 1167 bool isOverviewModeAccessEnabled_ = true; 1168 bool isFileFromUrlAccessEnabled_ = false; 1169 bool isDatabaseAccessEnabled_ = false; 1170 int32_t textZoomRatioNum_ = DEFAULT_TEXT_ZOOM_RATIO; 1171 WebCacheMode cacheMode_ = WebCacheMode::DEFAULT; 1172 bool isWebDebuggingAccessEnabled_ = false; 1173 bool isMultiWindowAccessEnabled_ = false; 1174 bool isAllowWindowOpenMethod_ = false; 1175 OnMouseCallback onMouseEvent_; 1176 OnKeyEventCallback onKeyEvent_; 1177 float initialScale_ = 0; 1178 bool isInitialScaleSet_ = false; 1179 int32_t backgroundColor_ = 0; 1180 bool isBackgroundColor_ = false; 1181 bool isNeedGestureAccess_ = true; 1182 bool isNativeEmbedMode_ = false; 1183 std::string tag_; 1184 std::string tag_type_; 1185 OnDragFunc onDragStartId_; 1186 OnDropFunc onDragEnterId_; 1187 OnDropFunc onDragMoveId_; 1188 OnDropFunc onDragLeaveId_; 1189 OnDropFunc onDropId_; 1190 bool isPinchSmoothModeEnabled_ = false; 1191 PreKeyEventCallback onPreKeyEvent_; 1192 bool isPopup_ = false; 1193 int32_t parentNWebId_ = -1; 1194 OverScrollMode OverScrollMode_ = OverScrollMode::NEVER; 1195 CopyOptions CopyOptionMode_ = CopyOptions::Distributed; 1196 std::tuple<bool, bool> native_video_player_config_{false, false}; 1197 std::string shared_render_process_token_; 1198 }; 1199 1200 } // namespace OHOS::Ace 1201 1202 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_COMPONENT_H 1203