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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_PROPERTY_H 18 19 #include <functional> 20 #include <utility> 21 22 #include "base/geometry/size.h" 23 #include "base/utils/utils.h" 24 #include "core/components/declaration/web/web_client.h" 25 #include "core/components/web/resource/web_javascript_value.h" 26 #include "core/components/web/web_event.h" 27 #include "core/components_ng/base/view_abstract_model.h" 28 #include "core/components_ng/pattern/text/text_menu_extension.h" 29 #include "core/components_ng/pattern/text/text_model.h" 30 #include "core/components_v2/common/common_def.h" 31 #include "core/event/key_event.h" 32 #include "core/event/mouse_event.h" 33 34 namespace OHOS::Ace { 35 36 class WebDelegate; 37 using ScriptItems = std::map<std::string, std::vector<std::string>>; 38 using ScriptItemsByOrder = std::vector<std::string>; 39 using OnMouseCallback = std::function<void(MouseInfo& info)>; 40 using OnKeyEventCallback = std::function<void(KeyEventInfo& keyEventInfo)>; 41 42 enum MixedModeContent { 43 MIXED_CONTENT_ALWAYS_ALLOW = 0, 44 MIXED_CONTENT_NEVER_ALLOW = 1, 45 MIXED_CONTENT_COMPATIBILITY_MODE = 2 46 }; 47 48 enum WebAudioSessionType { 49 AUTO = 0, 50 AMBIENT = 3 51 }; 52 53 enum WebCacheMode { 54 DEFAULT = 0, 55 USE_CACHE_ELSE_NETWORK, 56 USE_NO_CACHE, 57 USE_CACHE_ONLY 58 }; 59 60 enum OverScrollMode { 61 NEVER = 0, 62 ALWAYS, 63 }; 64 65 enum BlurOnKeyboardHideMode { 66 SILENT = 0, 67 BLUR = 1, 68 }; 69 70 enum class WebDarkMode { 71 Off, 72 On, 73 Auto, 74 }; 75 76 enum class WebLayoutMode { 77 NONE, 78 FIT_CONTENT, 79 }; 80 81 enum class WebKeyboardAvoidMode : int32_t { 82 RESIZE_VISUAL = 0, 83 RESIZE_CONTENT, 84 OVERLAYS_CONTENT, 85 DEFAULT 86 }; 87 88 enum class WebElementType : int32_t { 89 TEXT = 0, 90 IMAGE, 91 LINK, 92 MIXED, 93 AILINK, 94 NONE, 95 }; 96 97 enum class WebBypassVsyncCondition : int32_t { 98 NONE = 0, 99 SCROLLBY_FROM_ZERO_OFFSET = 1 100 }; 101 102 enum class GestureFocusMode : int32_t { 103 DEFAULT = 0, 104 GESTURE_TAP_AND_LONG_PRESS = 1 105 }; 106 107 struct WebPreviewSelectionMenuParam { 108 WebElementType type; 109 ResponseType responseType; 110 std::function<void()> menuBuilder; 111 std::function<void()> previewBuilder; 112 NG::MenuParam menuParam; 113 WebPreviewSelectionMenuParamWebPreviewSelectionMenuParam114 WebPreviewSelectionMenuParam(const WebElementType& _type, const ResponseType& _responseType, 115 const std::function<void()>& _menuBuilder, const std::function<void()>& _previewBuilder, 116 const NG::MenuParam& _menuParam) 117 : type(_type), responseType(_responseType), menuBuilder(_menuBuilder), previewBuilder(_previewBuilder), 118 menuParam(_menuParam) 119 {} 120 }; 121 122 struct WebMenuOptionsParam { 123 std::vector<NG::MenuOptionsParam> menuOption; 124 bool operator==(const WebMenuOptionsParam& webMenuOption) const 125 { 126 return menuOption.data() == webMenuOption.menuOption.data(); 127 } 128 }; 129 130 constexpr int32_t DEFAULT_TEXT_ZOOM_RATIO = 100; 131 constexpr int32_t DEFAULT_FIXED_FONT_SIZE = 13; 132 constexpr int32_t DEFAULT_FONT_SIZE = 16; 133 constexpr int32_t DEFAULT_MINIMUM_FONT_SIZE = 8; 134 constexpr int32_t DEFAULT_MINIMUM_LOGICAL_FONT_SIZE = 8; 135 const std::string DEFAULT_CURSIVE_FONT_FAMILY = "cursive"; 136 const std::string DEFAULT_FANTASY_FONT_FAMILY = "fantasy"; 137 const std::string DEFAULT_FIXED_fONT_FAMILY = "monospace"; 138 const std::string DEFAULT_SANS_SERIF_FONT_FAMILY = "sans-serif"; 139 const std::string DEFAULT_SERIF_FONT_FAMILY = "serif"; 140 const std::string DEFAULT_STANDARD_FONT_FAMILY = "sans-serif"; 141 const std::string DEFAULT_SCROLLBAR_COLOR = "sys.color.ohos_id_color_foreground"; 142 143 class HitTestResult : public virtual AceType { 144 DECLARE_ACE_TYPE(HitTestResult, AceType); 145 146 public: HitTestResult(const std::string & extraData,int hitType)147 HitTestResult(const std::string& extraData, int hitType) : extraData_(extraData), hitType_(hitType) {} 148 HitTestResult() = default; 149 ~HitTestResult() = default; 150 GetExtraData()151 const std::string& GetExtraData() const 152 { 153 return extraData_; 154 } 155 SetExtraData(const std::string & extraData)156 void SetExtraData(const std::string& extraData) 157 { 158 extraData_ = extraData; 159 } 160 GetHitType()161 int GetHitType() const 162 { 163 return hitType_; 164 } 165 SetHitType(int hitType)166 void SetHitType(int hitType) 167 { 168 hitType_ = hitType; 169 } 170 171 private: 172 std::string extraData_; 173 int hitType_ = static_cast<int>(WebHitTestType::UNKNOWN); 174 }; 175 176 class WebMessagePort : public virtual AceType { 177 DECLARE_ACE_TYPE(WebMessagePort, AceType); 178 179 public: 180 WebMessagePort() = default; 181 virtual ~WebMessagePort() = default; 182 virtual void SetPortHandle(std::string& handle) = 0; 183 virtual std::string GetPortHandle() = 0; 184 virtual void Close() = 0; 185 virtual void PostMessage(std::string& data) = 0; 186 virtual void SetWebMessageCallback(std::function<void(const std::string&)>&& callback) = 0; 187 }; 188 189 class WebCookie : public virtual AceType { 190 DECLARE_ACE_TYPE(WebCookie, AceType); 191 192 public: 193 using SetCookieImpl = std::function<bool(const std::string&, const std::string&)>; 194 using GetCookieImpl = std::function<std::string(const std::string&)>; 195 using DeleteEntirelyCookieImpl = std::function<void()>; 196 using SaveCookieSyncImpl = std::function<bool()>; SetCookie(const std::string & url,const std::string & value)197 bool SetCookie(const std::string& url, const std::string& value) 198 { 199 if (setCookieImpl_) { 200 return setCookieImpl_(url, value); 201 } 202 return false; 203 } 204 GetCookie(const std::string & url)205 std::string GetCookie(const std::string& url) 206 { 207 if (getCookieImpl_) { 208 return getCookieImpl_(url); 209 } 210 return ""; 211 } 212 DeleteEntirelyCookie()213 void DeleteEntirelyCookie() 214 { 215 if (deleteEntirelyCookieImpl_) { 216 deleteEntirelyCookieImpl_(); 217 } 218 } 219 SaveCookieSync()220 bool SaveCookieSync() 221 { 222 if (saveCookieSyncImpl_) { 223 return saveCookieSyncImpl_(); 224 } 225 return false; 226 } 227 SetSetCookieImpl(SetCookieImpl && setCookieImpl)228 void SetSetCookieImpl(SetCookieImpl&& setCookieImpl) 229 { 230 setCookieImpl_ = setCookieImpl; 231 } 232 SetGetCookieImpl(GetCookieImpl && getCookieImpl)233 void SetGetCookieImpl(GetCookieImpl&& getCookieImpl) 234 { 235 getCookieImpl_ = getCookieImpl; 236 } 237 SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl && deleteEntirelyCookieImpl)238 void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl&& deleteEntirelyCookieImpl) 239 { 240 deleteEntirelyCookieImpl_ = deleteEntirelyCookieImpl; 241 } 242 SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl)243 void SetSaveCookieSyncImpl(SaveCookieSyncImpl&& saveCookieSyncImpl) 244 { 245 saveCookieSyncImpl_ = saveCookieSyncImpl; 246 } 247 248 private: 249 SetCookieImpl setCookieImpl_; 250 GetCookieImpl getCookieImpl_; 251 DeleteEntirelyCookieImpl deleteEntirelyCookieImpl_; 252 SaveCookieSyncImpl saveCookieSyncImpl_; 253 }; 254 255 class WebController : public virtual AceType { 256 DECLARE_ACE_TYPE(WebController, AceType); 257 258 public: 259 using LoadUrlImpl = std::function<void(std::string, const std::map<std::string, std::string>&)>; 260 using AccessBackwardImpl = std::function<bool()>; 261 using AccessForwardImpl = std::function<bool()>; 262 using AccessStepImpl = std::function<bool(int32_t)>; 263 using BackOrForwardImpl = std::function<void(int32_t)>; 264 using BackwardImpl = std::function<void()>; 265 using ForwardImpl = std::function<void()>; 266 using ClearHistoryImpl = std::function<void()>; 267 using ClearSslCacheImpl = std::function<void()>; 268 using ClearClientAuthenticationCacheImpl = std::function<void()>; 269 LoadUrl(std::string url,std::map<std::string,std::string> & httpHeaders)270 void LoadUrl(std::string url, std::map<std::string, std::string>& httpHeaders) const 271 { 272 if (loadUrlImpl_) { 273 loadUrlImpl_(url, httpHeaders); 274 } 275 } 276 AccessStep(int32_t step)277 bool AccessStep(int32_t step) 278 { 279 if (accessStepImpl_) { 280 return accessStepImpl_(step); 281 } 282 return false; 283 } 284 BackOrForward(int32_t step)285 void BackOrForward(int32_t step) 286 { 287 if (backOrForwardImpl_) { 288 return backOrForwardImpl_(step); 289 } 290 } 291 AccessBackward()292 bool AccessBackward() 293 { 294 if (accessBackwardImpl_) { 295 return accessBackwardImpl_(); 296 } 297 return false; 298 } 299 AccessForward()300 bool AccessForward() 301 { 302 if (accessForwardImpl_) { 303 return accessForwardImpl_(); 304 } 305 return false; 306 } 307 Backward()308 void Backward() 309 { 310 if (backwardImpl_) { 311 backwardImpl_(); 312 } 313 } 314 Forward()315 void Forward() 316 { 317 if (forwardimpl_) { 318 forwardimpl_(); 319 } 320 } 321 ClearHistory()322 void ClearHistory() 323 { 324 if (clearHistoryImpl_) { 325 clearHistoryImpl_(); 326 } 327 } 328 ClearSslCache()329 void ClearSslCache() 330 { 331 if (clearSslCacheImpl_) { 332 clearSslCacheImpl_(); 333 } 334 } 335 ClearClientAuthenticationCache()336 void ClearClientAuthenticationCache() 337 { 338 if (clearClientAuthenticationCacheImpl_) { 339 clearClientAuthenticationCacheImpl_(); 340 } 341 } 342 SetLoadUrlImpl(LoadUrlImpl && loadUrlImpl)343 void SetLoadUrlImpl(LoadUrlImpl && loadUrlImpl) 344 { 345 loadUrlImpl_ = std::move(loadUrlImpl); 346 } 347 SetAccessBackwardImpl(AccessBackwardImpl && accessBackwardImpl)348 void SetAccessBackwardImpl(AccessBackwardImpl && accessBackwardImpl) 349 { 350 accessBackwardImpl_ = std::move(accessBackwardImpl); 351 } 352 SetAccessForwardImpl(AccessForwardImpl && accessForwardImpl)353 void SetAccessForwardImpl(AccessForwardImpl && accessForwardImpl) 354 { 355 accessForwardImpl_ = std::move(accessForwardImpl); 356 } 357 SetAccessStepImpl(AccessStepImpl && accessStepImpl)358 void SetAccessStepImpl(AccessStepImpl && accessStepImpl) 359 { 360 accessStepImpl_ = std::move(accessStepImpl); 361 } 362 SetBackOrForwardImpl(BackOrForwardImpl && backOrForwardImpl)363 void SetBackOrForwardImpl(BackOrForwardImpl && backOrForwardImpl) 364 { 365 backOrForwardImpl_ = std::move(backOrForwardImpl); 366 } 367 SetBackwardImpl(BackwardImpl && backwardImpl)368 void SetBackwardImpl(BackwardImpl && backwardImpl) 369 { 370 backwardImpl_ = std::move(backwardImpl); 371 } 372 SetForwardImpl(ForwardImpl && forwardImpl)373 void SetForwardImpl(ForwardImpl && forwardImpl) 374 { 375 forwardimpl_ = std::move(forwardImpl); 376 } 377 SetClearHistoryImpl(ClearHistoryImpl && clearHistoryImpl)378 void SetClearHistoryImpl(ClearHistoryImpl && clearHistoryImpl) 379 { 380 clearHistoryImpl_ = std::move(clearHistoryImpl); 381 } 382 SetClearSslCacheImpl(ClearSslCacheImpl && clearSslCacheImpl)383 void SetClearSslCacheImpl(ClearSslCacheImpl && clearSslCacheImpl) 384 { 385 clearSslCacheImpl_ = std::move(clearSslCacheImpl); 386 } 387 SetClearClientAuthenticationCacheImpl(ClearClientAuthenticationCacheImpl && clearClientAuthenticationCacheImpl)388 void SetClearClientAuthenticationCacheImpl(ClearClientAuthenticationCacheImpl && clearClientAuthenticationCacheImpl) 389 { 390 clearClientAuthenticationCacheImpl_ = std::move(clearClientAuthenticationCacheImpl); 391 } 392 393 using ExecuteTypeScriptImpl = std::function<void(std::string, std::function<void(std::string)>&&)>; ExecuteTypeScript(std::string jscode,std::function<void (std::string)> && callback)394 void ExecuteTypeScript(std::string jscode, std::function<void(std::string)>&& callback) const 395 { 396 if (executeTypeScriptImpl_) { 397 executeTypeScriptImpl_(jscode, std::move(callback)); 398 } 399 } SetExecuteTypeScriptImpl(ExecuteTypeScriptImpl && executeTypeScriptImpl)400 void SetExecuteTypeScriptImpl(ExecuteTypeScriptImpl && executeTypeScriptImpl) 401 { 402 executeTypeScriptImpl_ = std::move(executeTypeScriptImpl); 403 } 404 405 using LoadDataWithBaseUrlImpl = std::function<void( 406 std::string, std::string, std::string, std::string, std::string)>; LoadDataWithBaseUrl(std::string baseUrl,std::string data,std::string mimeType,std::string encoding,std::string historyUrl)407 void LoadDataWithBaseUrl(std::string baseUrl, std::string data, std::string mimeType, std::string encoding, 408 std::string historyUrl) const 409 { 410 if (loadDataWithBaseUrlImpl_) { 411 loadDataWithBaseUrlImpl_(baseUrl, data, mimeType, encoding, historyUrl); 412 } 413 } 414 SetLoadDataWithBaseUrlImpl(LoadDataWithBaseUrlImpl && loadDataWithBaseUrlImpl)415 void SetLoadDataWithBaseUrlImpl(LoadDataWithBaseUrlImpl && loadDataWithBaseUrlImpl) 416 { 417 loadDataWithBaseUrlImpl_ = std::move(loadDataWithBaseUrlImpl); 418 } 419 420 using InitJavascriptInterface = std::function<void()>; LoadInitJavascriptInterface()421 void LoadInitJavascriptInterface() const 422 { 423 if (initJavascriptInterface_) { 424 initJavascriptInterface_(); 425 } 426 } SetInitJavascriptInterface(InitJavascriptInterface && initJavascriptInterface)427 void SetInitJavascriptInterface(InitJavascriptInterface&& initJavascriptInterface) 428 { 429 initJavascriptInterface_ = std::move(initJavascriptInterface); 430 } 431 432 using OnInactiveImpl = std::function<void()>; OnInactive()433 void OnInactive() const 434 { 435 if (onInactiveImpl_) { 436 onInactiveImpl_(); 437 } 438 } 439 SetOnInactiveImpl(OnInactiveImpl && onInactiveImpl)440 void SetOnInactiveImpl(OnInactiveImpl && onInactiveImpl) 441 { 442 onInactiveImpl_ = std::move(onInactiveImpl); 443 } 444 445 using OnActiveImpl = std::function<void()>; OnActive()446 void OnActive() const 447 { 448 if (onActiveImpl_) { 449 onActiveImpl_(); 450 } 451 } 452 SetOnActiveImpl(OnActiveImpl && onActiveImpl)453 void SetOnActiveImpl(OnActiveImpl && onActiveImpl) 454 { 455 onActiveImpl_ = std::move(onActiveImpl); 456 } 457 458 using ZoomImpl = std::function<void(float)>; Zoom(float factor)459 void Zoom(float factor) const 460 { 461 if (zoomImpl_) { 462 zoomImpl_(factor); 463 } 464 } 465 SetZoomImpl(ZoomImpl && zoomImpl)466 void SetZoomImpl(ZoomImpl&& zoomImpl) 467 { 468 zoomImpl_ = std::move(zoomImpl); 469 } 470 471 using ZoomInImpl = std::function<bool()>; ZoomIn()472 bool ZoomIn() const 473 { 474 if (zoomInImpl_) { 475 return zoomInImpl_(); 476 } 477 return false; 478 } 479 SetZoomInImpl(ZoomInImpl && zoomInImpl)480 void SetZoomInImpl(ZoomInImpl&& zoomInImpl) 481 { 482 zoomInImpl_ = std::move(zoomInImpl); 483 } 484 485 using ZoomOutImpl = std::function<bool()>; ZoomOut()486 bool ZoomOut() const 487 { 488 if (zoomOutImpl_) { 489 return zoomOutImpl_(); 490 } 491 return false; 492 } 493 SetZoomOutImpl(ZoomOutImpl && zoomOutImpl)494 void SetZoomOutImpl(ZoomOutImpl&& zoomOutImpl) 495 { 496 zoomOutImpl_ = std::move(zoomOutImpl); 497 } 498 499 using RefreshImpl = std::function<void()>; Refresh()500 void Refresh() const 501 { 502 if (refreshImpl_) { 503 refreshImpl_(); 504 } 505 } SetRefreshImpl(RefreshImpl && refreshImpl)506 void SetRefreshImpl(RefreshImpl && refreshImpl) 507 { 508 refreshImpl_ = std::move(refreshImpl); 509 } 510 511 using StopLoadingImpl = std::function<void()>; StopLoading()512 void StopLoading() const 513 { 514 if (stopLoadingImpl_) { 515 stopLoadingImpl_(); 516 } 517 } SetStopLoadingImpl(StopLoadingImpl && stopLoadingImpl)518 void SetStopLoadingImpl(StopLoadingImpl && stopLoadingImpl) 519 { 520 stopLoadingImpl_ = std::move(stopLoadingImpl); 521 } 522 523 using GetHitTestResultImpl = std::function<int()>; GetHitTestResult()524 int GetHitTestResult() 525 { 526 if (getHitTestResultImpl_) { 527 return getHitTestResultImpl_(); 528 } 529 return 0; 530 } SetGetHitTestResultImpl(GetHitTestResultImpl && getHitTestResultImpl)531 void SetGetHitTestResultImpl(GetHitTestResultImpl&& getHitTestResultImpl) 532 { 533 getHitTestResultImpl_ = std::move(getHitTestResultImpl); 534 } 535 536 using GetHitTestValueImpl = std::function<void(HitTestResult&)>; GetHitTestValue(HitTestResult & result)537 void GetHitTestValue(HitTestResult& result) 538 { 539 if (getHitTestValueImpl_) { 540 getHitTestValueImpl_(result); 541 } 542 } SetGetHitTestValueImpl(GetHitTestValueImpl && getHitTestValueImpl)543 void SetGetHitTestValueImpl(GetHitTestValueImpl&& getHitTestValueImpl) 544 { 545 getHitTestValueImpl_ = getHitTestValueImpl; 546 } 547 GetCookieManager()548 WebCookie* GetCookieManager() 549 { 550 if (!saveCookieSyncImpl_ || !setCookieImpl_) { 551 return nullptr; 552 } 553 if (cookieManager_ != nullptr) { 554 return cookieManager_; 555 } 556 cookieManager_ = new WebCookie(); 557 cookieManager_->SetSaveCookieSyncImpl(std::move(saveCookieSyncImpl_)); 558 cookieManager_->SetSetCookieImpl(std::move(setCookieImpl_)); 559 cookieManager_->SetGetCookieImpl(std::move(getCookieImpl_)); 560 cookieManager_->SetDeleteEntirelyCookieImpl(std::move(deleteEntirelyCookieImpl_)); 561 return cookieManager_; 562 } 563 564 using GetProgressImpl = std::function<int()>; GetProgress()565 int GetProgress() 566 { 567 return getProgressImpl_ ? getProgressImpl_() : 0; 568 } SetGetProgressImpl(GetProgressImpl && getProgressImpl)569 void SetGetProgressImpl(GetProgressImpl&& getProgressImpl) 570 { 571 getProgressImpl_ = getProgressImpl; 572 } 573 574 using GetPageHeightImpl = std::function<int()>; GetPageHeight()575 int GetPageHeight() 576 { 577 if (getPageHeightImpl_) { 578 return getPageHeightImpl_(); 579 } 580 return 0; 581 } SetGetPageHeightImpl(GetPageHeightImpl && getPageHeightImpl)582 void SetGetPageHeightImpl(GetPageHeightImpl&& getPageHeightImpl) 583 { 584 getPageHeightImpl_ = getPageHeightImpl; 585 } 586 587 using GetWebIdImpl = std::function<int()>; GetWebId()588 int GetWebId() 589 { 590 if (getWebIdImpl_) { 591 return getWebIdImpl_(); 592 } 593 return -1; 594 } SetGetWebIdImpl(GetWebIdImpl && getWebIdImpl)595 void SetGetWebIdImpl(GetWebIdImpl&& getWebIdImpl) 596 { 597 getWebIdImpl_ = getWebIdImpl; 598 } 599 600 using GetTitleImpl = std::function<std::string()>; GetTitle()601 std::string GetTitle() 602 { 603 if (getTitleImpl_) { 604 return getTitleImpl_(); 605 } 606 return ""; 607 } SetGetTitleImpl(GetTitleImpl && getTitleImpl)608 void SetGetTitleImpl(GetTitleImpl&& getTitleImpl) 609 { 610 getTitleImpl_ = getTitleImpl; 611 } 612 613 using CreateMsgPortsImpl = std::function<void(std::vector<RefPtr<WebMessagePort>>&)>; CreateMsgPorts(std::vector<RefPtr<WebMessagePort>> & ports)614 void CreateMsgPorts(std::vector<RefPtr<WebMessagePort>>& ports) 615 { 616 if (createMsgPortsImpl_) { 617 createMsgPortsImpl_(ports); 618 } 619 } SetCreateMsgPortsImpl(CreateMsgPortsImpl && createMsgPortsImpl)620 void SetCreateMsgPortsImpl(CreateMsgPortsImpl&& createMsgPortsImpl) 621 { 622 createMsgPortsImpl_ = createMsgPortsImpl; 623 } 624 625 using PostWebMessageImpl = std::function<void(std::string&, std::vector<RefPtr<WebMessagePort>>&, std::string&)>; PostWebMessage(std::string & message,std::vector<RefPtr<WebMessagePort>> & ports,std::string & uri)626 void PostWebMessage(std::string& message, std::vector<RefPtr<WebMessagePort>>& ports, std::string& uri) 627 { 628 if (postWebMessageImpl_) { 629 postWebMessageImpl_(message, ports, uri); 630 } 631 } SetPostWebMessageImpl(PostWebMessageImpl && postWebMessageImpl)632 void SetPostWebMessageImpl(PostWebMessageImpl&& postWebMessageImpl) 633 { 634 postWebMessageImpl_ = postWebMessageImpl; 635 } 636 637 using GetDefaultUserAgentImpl = std::function<std::string()>; GetDefaultUserAgent()638 std::string GetDefaultUserAgent() 639 { 640 if (getDefaultUserAgentImpl_) { 641 return getDefaultUserAgentImpl_(); 642 } 643 return ""; 644 } SetGetDefaultUserAgentImpl(GetDefaultUserAgentImpl && getDefaultUserAgentImpl)645 void SetGetDefaultUserAgentImpl(GetDefaultUserAgentImpl&& getDefaultUserAgentImpl) 646 { 647 getDefaultUserAgentImpl_ = getDefaultUserAgentImpl; 648 } 649 650 using SetCookieImpl = std::function<bool(const std::string&, const std::string&)>; SetCookie(const std::string & url,const std::string & value)651 bool SetCookie(const std::string& url, const std::string& value) 652 { 653 if (setCookieImpl_) { 654 return setCookieImpl_(url, value); 655 } 656 return false; 657 } SetSetCookieImpl(SetCookieImpl && setCookieImpl)658 void SetSetCookieImpl(SetCookieImpl&& setCookieImpl) 659 { 660 setCookieImpl_ = setCookieImpl; 661 } 662 663 using GetCookieImpl = std::function<std::string(const std::string&)>; GetCookie(const std::string & url)664 std::string GetCookie(const std::string& url) 665 { 666 if (getCookieImpl_) { 667 return getCookieImpl_(url); 668 } 669 return ""; 670 } SetGetCookieImpl(GetCookieImpl && getCookieImpl)671 void SetGetCookieImpl(GetCookieImpl&& getCookieImpl) 672 { 673 getCookieImpl_ = getCookieImpl; 674 } 675 676 using DeleteEntirelyCookieImpl = std::function<void()>; DeleteEntirelyCookie()677 void DeleteEntirelyCookie() 678 { 679 if (deleteEntirelyCookieImpl_) { 680 deleteEntirelyCookieImpl_(); 681 } 682 } SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl && deleteEntirelyCookieImpl)683 void SetDeleteEntirelyCookieImpl(DeleteEntirelyCookieImpl&& deleteEntirelyCookieImpl) 684 { 685 deleteEntirelyCookieImpl_ = deleteEntirelyCookieImpl; 686 } 687 688 using SaveCookieSyncImpl = std::function<bool()>; SaveCookieSync()689 bool SaveCookieSync() 690 { 691 if (saveCookieSyncImpl_) { 692 return saveCookieSyncImpl_(); 693 } 694 return false; 695 } SetSaveCookieSyncImpl(SaveCookieSyncImpl && saveCookieSyncImpl)696 void SetSaveCookieSyncImpl(SaveCookieSyncImpl&& saveCookieSyncImpl) 697 { 698 saveCookieSyncImpl_ = saveCookieSyncImpl; 699 } 700 701 using AddJavascriptInterfaceImpl = std::function<void( 702 const std::string&, 703 const std::vector<std::string>&)>; AddJavascriptInterface(const std::string & objectName,const std::vector<std::string> & methodList)704 void AddJavascriptInterface( 705 const std::string& objectName, 706 const std::vector<std::string>& methodList) 707 { 708 if (addJavascriptInterfaceImpl_) { 709 addJavascriptInterfaceImpl_(objectName, methodList); 710 } 711 } SetAddJavascriptInterfaceImpl(AddJavascriptInterfaceImpl && addJavascriptInterfaceImpl)712 void SetAddJavascriptInterfaceImpl(AddJavascriptInterfaceImpl && addJavascriptInterfaceImpl) 713 { 714 addJavascriptInterfaceImpl_ = std::move(addJavascriptInterfaceImpl); 715 } 716 717 using RemoveJavascriptInterfaceImpl = std::function<void(std::string, const std::vector<std::string>&)>; RemoveJavascriptInterface(std::string objectName,const std::vector<std::string> & methodList)718 void RemoveJavascriptInterface(std::string objectName, const std::vector<std::string>& methodList) 719 { 720 if (removeJavascriptInterfaceImpl_) { 721 removeJavascriptInterfaceImpl_(objectName, methodList); 722 } 723 } SetRemoveJavascriptInterfaceImpl(RemoveJavascriptInterfaceImpl && removeJavascriptInterfaceImpl)724 void SetRemoveJavascriptInterfaceImpl(RemoveJavascriptInterfaceImpl && removeJavascriptInterfaceImpl) 725 { 726 removeJavascriptInterfaceImpl_ = std::move(removeJavascriptInterfaceImpl); 727 } 728 729 using JavaScriptCallBackImpl = std::function<std::shared_ptr<WebJSValue>( 730 const std::string& objectName, 731 const std::string& objectMethod, 732 const std::vector<std::shared_ptr<WebJSValue>>& args)>; 733 using WebViewJavaScriptResultCallBackImpl = std::function<void(JavaScriptCallBackImpl&& javaScriptCallBackImpl)>; SetWebViewJavaScriptResultCallBackImpl(WebViewJavaScriptResultCallBackImpl && webViewJavaScriptResultCallBackImpl)734 void SetWebViewJavaScriptResultCallBackImpl( 735 WebViewJavaScriptResultCallBackImpl && webViewJavaScriptResultCallBackImpl) 736 { 737 webViewJavaScriptResultCallBackImpl_ = webViewJavaScriptResultCallBackImpl; 738 } SetJavaScriptCallBackImpl(JavaScriptCallBackImpl && javaScriptCallBackImpl)739 void SetJavaScriptCallBackImpl(JavaScriptCallBackImpl&& javaScriptCallBackImpl) 740 { 741 if (webViewJavaScriptResultCallBackImpl_) { 742 webViewJavaScriptResultCallBackImpl_(std::move(javaScriptCallBackImpl)); 743 } 744 } 745 746 using RequestFocusImpl = std::function<void()>; RequestFocus()747 void RequestFocus() 748 { 749 if (requestFocusImpl_) { 750 return requestFocusImpl_(); 751 } 752 } SetRequestFocusImpl(RequestFocusImpl && requestFocusImpl)753 void SetRequestFocusImpl(RequestFocusImpl && requestFocusImpl) 754 { 755 requestFocusImpl_ = std::move(requestFocusImpl); 756 } 757 758 using SearchAllAsyncImpl = std::function<void(const std::string&)>; SearchAllAsync(const std::string & searchStr)759 void SearchAllAsync(const std::string& searchStr) 760 { 761 if (searchAllAsyncImpl_) { 762 searchAllAsyncImpl_(searchStr); 763 } 764 } 765 SetSearchAllAsyncImpl(SearchAllAsyncImpl && searchAllAsyncImpl)766 void SetSearchAllAsyncImpl(SearchAllAsyncImpl&& searchAllAsyncImpl) 767 { 768 searchAllAsyncImpl_ = std::move(searchAllAsyncImpl); 769 } 770 771 using ClearMatchesImpl = std::function<void()>; ClearMatches()772 void ClearMatches() 773 { 774 if (clearMatchesImpl_) { 775 clearMatchesImpl_(); 776 } 777 } SetClearMatchesImpl(ClearMatchesImpl && clearMatchesImpl)778 void SetClearMatchesImpl(ClearMatchesImpl&& clearMatchesImpl) 779 { 780 clearMatchesImpl_ = std::move(clearMatchesImpl); 781 } 782 783 using SearchNextImpl = std::function<void(bool)>; SearchNext(bool forward)784 void SearchNext(bool forward) 785 { 786 if (searchNextImpl_) { 787 searchNextImpl_(forward); 788 } 789 } 790 SetSearchNextImpl(SearchNextImpl && searchNextImpl)791 void SetSearchNextImpl(SearchNextImpl&& searchNextImpl) 792 { 793 searchNextImpl_ = std::move(searchNextImpl); 794 } 795 Reload()796 void Reload() const 797 { 798 WebClient::GetInstance().ReloadWebview(); 799 } 800 801 using GetUrlImpl = std::function<std::string()>; GetUrl()802 std::string GetUrl() 803 { 804 if (getUrlImpl_) { 805 return getUrlImpl_(); 806 } 807 return ""; 808 } 809 SetGetUrlImpl(GetUrlImpl && getUrlImpl)810 void SetGetUrlImpl(GetUrlImpl && getUrlImpl) 811 { 812 getUrlImpl_ = std::move(getUrlImpl); 813 } 814 815 private: 816 WebCookie* cookieManager_ = nullptr; 817 LoadUrlImpl loadUrlImpl_; 818 819 // Forward and Backward 820 AccessBackwardImpl accessBackwardImpl_; 821 AccessForwardImpl accessForwardImpl_; 822 AccessStepImpl accessStepImpl_; 823 BackOrForwardImpl backOrForwardImpl_; 824 BackwardImpl backwardImpl_; 825 ForwardImpl forwardimpl_; 826 ClearHistoryImpl clearHistoryImpl_; 827 ClearSslCacheImpl clearSslCacheImpl_; 828 ClearClientAuthenticationCacheImpl clearClientAuthenticationCacheImpl_; 829 830 ExecuteTypeScriptImpl executeTypeScriptImpl_; 831 OnInactiveImpl onInactiveImpl_; 832 OnActiveImpl onActiveImpl_; 833 ZoomImpl zoomImpl_; 834 ZoomInImpl zoomInImpl_; 835 ZoomOutImpl zoomOutImpl_; 836 LoadDataWithBaseUrlImpl loadDataWithBaseUrlImpl_; 837 InitJavascriptInterface initJavascriptInterface_; 838 RefreshImpl refreshImpl_; 839 StopLoadingImpl stopLoadingImpl_; 840 GetHitTestResultImpl getHitTestResultImpl_; 841 GetHitTestValueImpl getHitTestValueImpl_; 842 GetProgressImpl getProgressImpl_; 843 GetPageHeightImpl getPageHeightImpl_; 844 GetWebIdImpl getWebIdImpl_; 845 GetTitleImpl getTitleImpl_; 846 CreateMsgPortsImpl createMsgPortsImpl_; 847 PostWebMessageImpl postWebMessageImpl_; 848 GetDefaultUserAgentImpl getDefaultUserAgentImpl_; 849 SaveCookieSyncImpl saveCookieSyncImpl_; 850 SetCookieImpl setCookieImpl_; 851 GetCookieImpl getCookieImpl_; 852 DeleteEntirelyCookieImpl deleteEntirelyCookieImpl_; 853 AddJavascriptInterfaceImpl addJavascriptInterfaceImpl_; 854 RemoveJavascriptInterfaceImpl removeJavascriptInterfaceImpl_; 855 WebViewJavaScriptResultCallBackImpl webViewJavaScriptResultCallBackImpl_; 856 RequestFocusImpl requestFocusImpl_; 857 SearchAllAsyncImpl searchAllAsyncImpl_; 858 ClearMatchesImpl clearMatchesImpl_; 859 SearchNextImpl searchNextImpl_; 860 GetUrlImpl getUrlImpl_; 861 }; 862 863 } // namespace OHOS::Ace 864 865 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_PROPERTY_H 866