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