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