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