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