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