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