• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_COMPONENT_H
18 
19 #include <string>
20 #include <utility>
21 
22 #include "base/geometry/size.h"
23 #include "base/log/log.h"
24 #include "base/utils/utils.h"
25 #include "core/components/box/drag_drop_event.h"
26 #include "core/components/declaration/common/declaration.h"
27 #include "core/components/declaration/web/web_client.h"
28 #include "core/components/declaration/web/web_declaration.h"
29 #include "core/components/web/resource/web_javascript_value.h"
30 #include "core/components/web/web_event.h"
31 #include "core/components/web/web_property.h"
32 #include "core/components_v2/common/common_def.h"
33 #include "core/event/key_event.h"
34 #include "core/focus/focus_node.h"
35 #include "core/pipeline/base/element.h"
36 
37 namespace OHOS::Ace {
38 
39 // A component can show HTML5 webpages.
40 class ACE_EXPORT WebComponent : public RenderComponent {
41     DECLARE_ACE_TYPE(WebComponent, RenderComponent);
42 
43 public:
44     using CreatedCallback = std::function<void()>;
45     using ReleasedCallback = std::function<void(bool)>;
46     using ErrorCallback = std::function<void(const std::string&, const std::string&)>;
47     using MethodCall = std::function<void(const std::string&)>;
48     using Method = std::string;
49     using SetWebIdCallback = std::function<void(int32_t)>;
50     using SetHapPathCallback = std::function<void(const std::string&)>;
51     using JsProxyCallback = std::function<void()>;
52     using PreKeyEventCallback = std::function<bool(KeyEventInfo& keyEventInfo)>;
53 
54     WebComponent() = default;
55     explicit WebComponent(const std::string& type);
56     ~WebComponent() override = default;
57 
58     RefPtr<RenderNode> CreateRenderNode() override;
59     RefPtr<Element> CreateElement() override;
60 
SetType(const std::string & type)61     void SetType(const std::string& type)
62     {
63         type_ = type;
64     }
65 
GetType()66     const std::string& GetType() const
67     {
68         return type_;
69     }
70 
SetSrc(const std::string & src)71     void SetSrc(const std::string& src)
72     {
73         CHECK_NULL_VOID(declaration_);
74         declaration_->SetWebSrc(src);
75     }
76 
GetSrc()77     const std::string& GetSrc() const
78     {
79         return declaration_->GetWebSrc();
80     }
81 
SetPopup(bool popup)82     void SetPopup(bool popup)
83     {
84         isPopup_ = popup;
85     }
86 
SetParentNWebId(int32_t parentNWebId)87     void SetParentNWebId(int32_t parentNWebId)
88     {
89         parentNWebId_ = parentNWebId;
90     }
91 
SetData(const std::string & data)92     void SetData(const std::string& data)
93     {
94         CHECK_NULL_VOID(declaration_);
95         declaration_->SetWebData(data);
96     }
97 
GetData()98     const std::string& GetData() const
99     {
100         return declaration_->GetWebData();
101     }
102 
SetPageStartedEventId(const EventMarker & pageStartedEventId)103     void SetPageStartedEventId(const EventMarker& pageStartedEventId)
104     {
105         CHECK_NULL_VOID(declaration_);
106         declaration_->SetPageStartedEventId(pageStartedEventId);
107     }
108 
GetPageStartedEventId()109     const EventMarker& GetPageStartedEventId() const
110     {
111         return declaration_->GetPageStartedEventId();
112     }
113 
SetPageFinishedEventId(const EventMarker & pageFinishedEventId)114     void SetPageFinishedEventId(const EventMarker& pageFinishedEventId)
115     {
116         CHECK_NULL_VOID(declaration_);
117         declaration_->SetPageFinishedEventId(pageFinishedEventId);
118     }
119 
GetPageFinishedEventId()120     const EventMarker& GetPageFinishedEventId() const
121     {
122         return declaration_->GetPageFinishedEventId();
123     }
124 
125     using OnProgressChangeImpl = std::function<void(const BaseEventInfo* info)>;
OnProgressChange(const BaseEventInfo * info)126     void OnProgressChange(const BaseEventInfo* info) const
127     {
128         if (onProgressChangeImpl_) {
129             onProgressChangeImpl_(info);
130         }
131     }
SetProgressChangeImpl(OnProgressChangeImpl && onProgressChangeImpl)132     void SetProgressChangeImpl(OnProgressChangeImpl&& onProgressChangeImpl)
133     {
134         if (onProgressChangeImpl == nullptr) {
135             return;
136         }
137         onProgressChangeImpl_ = std::move(onProgressChangeImpl);
138     }
139 
SetTitleReceiveEventId(const EventMarker & titleReceiveEventId)140     void SetTitleReceiveEventId(const EventMarker& titleReceiveEventId)
141     {
142         CHECK_NULL_VOID(declaration_);
143         declaration_->SetTitleReceiveEventId(titleReceiveEventId);
144     }
145 
GetTitleReceiveEventId()146     const EventMarker& GetTitleReceiveEventId() const
147     {
148         return declaration_->GetTitleReceiveEventId();
149     }
150 
SetOnFullScreenExitEventId(const EventMarker & fullScreenExitEventId)151     void SetOnFullScreenExitEventId(const EventMarker& fullScreenExitEventId)
152     {
153         CHECK_NULL_VOID(declaration_);
154         declaration_->SetOnFullScreenExitEventId(fullScreenExitEventId);
155     }
156 
GetOnFullScreenExitEventId()157     const EventMarker& GetOnFullScreenExitEventId() const
158     {
159         return declaration_->GetOnFullScreenExitEventId();
160     }
161 
SetGeolocationHideEventId(const EventMarker & geolocationHideEventId)162     void SetGeolocationHideEventId(const EventMarker& geolocationHideEventId)
163     {
164         CHECK_NULL_VOID(declaration_);
165         declaration_->SetGeolocationHideEventId(geolocationHideEventId);
166     }
167 
GetGeolocationHideEventId()168     const EventMarker& GetGeolocationHideEventId() const
169     {
170         return declaration_->GetGeolocationHideEventId();
171     }
172 
SetGeolocationShowEventId(const EventMarker & geolocationShowEventId)173     void SetGeolocationShowEventId(const EventMarker& geolocationShowEventId)
174     {
175         CHECK_NULL_VOID(declaration_);
176         declaration_->SetGeolocationShowEventId(geolocationShowEventId);
177     }
178 
GetGeolocationShowEventId()179     const EventMarker& GetGeolocationShowEventId() const
180     {
181         return declaration_->GetGeolocationShowEventId();
182     }
183 
SetRequestFocusEventId(const EventMarker & requestFocusEventId)184     void SetRequestFocusEventId(const EventMarker& requestFocusEventId)
185     {
186         CHECK_NULL_VOID(declaration_);
187         declaration_->SetRequestFocusEventId(requestFocusEventId);
188     }
189 
GetRequestFocusEventId()190     const EventMarker& GetRequestFocusEventId() const
191     {
192         return declaration_->GetRequestFocusEventId();
193     }
194 
SetDownloadStartEventId(const EventMarker & downloadStartEventId)195     void SetDownloadStartEventId(const EventMarker& downloadStartEventId)
196     {
197         CHECK_NULL_VOID(declaration_);
198         declaration_->SetDownloadStartEventId(downloadStartEventId);
199     }
200 
GetDownloadStartEventId()201     const EventMarker& GetDownloadStartEventId() const
202     {
203         return declaration_->GetDownloadStartEventId();
204     }
205 
SetPageErrorEventId(const EventMarker & pageErrorEventId)206     void SetPageErrorEventId(const EventMarker& pageErrorEventId)
207     {
208         CHECK_NULL_VOID(declaration_);
209         declaration_->SetPageErrorEventId(pageErrorEventId);
210     }
211 
GetPageErrorEventId()212     const EventMarker& GetPageErrorEventId() const
213     {
214         return declaration_->GetPageErrorEventId();
215     }
216 
SetHttpErrorEventId(const EventMarker & httpErrorEventId)217     void SetHttpErrorEventId(const EventMarker& httpErrorEventId)
218     {
219         CHECK_NULL_VOID(declaration_);
220         declaration_->SetHttpErrorEventId(httpErrorEventId);
221     }
222 
GetHttpErrorEventId()223     const EventMarker& GetHttpErrorEventId() const
224     {
225         return declaration_->GetHttpErrorEventId();
226     }
227 
SetMessageEventId(const EventMarker & messageEventId)228     void SetMessageEventId(const EventMarker& messageEventId)
229     {
230         CHECK_NULL_VOID(declaration_);
231         declaration_->SetMessageEventId(messageEventId);
232     }
233 
GetMessageEventId()234     const EventMarker& GetMessageEventId() const
235     {
236         return declaration_->GetMessageEventId();
237     }
238 
SetRenderExitedId(const EventMarker & renderExitedId)239     void SetRenderExitedId(const EventMarker& renderExitedId)
240     {
241         CHECK_NULL_VOID(declaration_);
242         declaration_->SetRenderExitedId(renderExitedId);
243     }
244 
GetRenderExitedId()245     const EventMarker& GetRenderExitedId() const
246     {
247         return declaration_->GetRenderExitedId();
248     }
249 
SetRefreshAccessedHistoryId(const EventMarker & refreshAccessedHistoryId)250     void SetRefreshAccessedHistoryId(const EventMarker& refreshAccessedHistoryId)
251     {
252         CHECK_NULL_VOID(declaration_);
253         declaration_->SetRefreshAccessedHistoryId(refreshAccessedHistoryId);
254     }
255 
GetRefreshAccessedHistoryId()256     const EventMarker& GetRefreshAccessedHistoryId() const
257     {
258         return declaration_->GetRefreshAccessedHistoryId();
259     }
260 
SetResourceLoadId(const EventMarker & resourceLoadId)261     void SetResourceLoadId(const EventMarker& resourceLoadId)
262     {
263         CHECK_NULL_VOID(declaration_);
264         declaration_->SetResourceLoadId(resourceLoadId);
265     }
266 
GetResourceLoadId()267     const EventMarker& GetResourceLoadId() const
268     {
269         return declaration_->GetResourceLoadId();
270     }
271 
SetScaleChangeId(const EventMarker & scaleChangeId)272     void SetScaleChangeId(const EventMarker& scaleChangeId)
273     {
274         CHECK_NULL_VOID(declaration_);
275         declaration_->SetScaleChangeId(scaleChangeId);
276     }
277 
GetScaleChangeId()278     const EventMarker& GetScaleChangeId() const
279     {
280         return declaration_->GetScaleChangeId();
281     }
282 
SetScrollId(const EventMarker & scrollId)283     void SetScrollId(const EventMarker& scrollId)
284     {
285         CHECK_NULL_VOID(declaration_);
286         declaration_->SetScrollId(scrollId);
287     }
288 
GetScrollId()289     const EventMarker& GetScrollId() const
290     {
291         return declaration_->GetScrollId();
292     }
293 
SetPermissionRequestEventId(const EventMarker & permissionRequestEventId)294     void SetPermissionRequestEventId(const EventMarker& permissionRequestEventId)
295     {
296         CHECK_NULL_VOID(declaration_);
297         declaration_->SetPermissionRequestEventId(permissionRequestEventId);
298     }
299 
GetPermissionRequestEventId()300     const EventMarker& GetPermissionRequestEventId() const
301     {
302         return declaration_->GetPermissionRequestEventId();
303     }
304 
305     using OnWindowNewImpl = std::function<void(const std::shared_ptr<BaseEventInfo>& info)>;
SetWindowNewEvent(OnWindowNewImpl && onWindowNewImpl)306     void SetWindowNewEvent(OnWindowNewImpl && onWindowNewImpl)
307     {
308         if (onWindowNewImpl == nullptr) {
309             return;
310         }
311         onWindowNewImpl_ = std::move(onWindowNewImpl);
312     }
313 
OnWindowNewEvent(const std::shared_ptr<BaseEventInfo> & info)314     void OnWindowNewEvent(const std::shared_ptr<BaseEventInfo>& info) const
315     {
316         if (onWindowNewImpl_) {
317             onWindowNewImpl_(info);
318         }
319     }
320 
SetWindowExitEventId(const EventMarker & windowExitEventId)321     void SetWindowExitEventId(const EventMarker& windowExitEventId)
322     {
323         CHECK_NULL_VOID(declaration_);
324         declaration_->SetWindowExitEventId(windowExitEventId);
325     }
326 
GetWindowExitEventId()327     const EventMarker& GetWindowExitEventId() const
328     {
329         return declaration_->GetWindowExitEventId();
330     }
331 
SetDeclaration(const RefPtr<WebDeclaration> & declaration)332     void SetDeclaration(const RefPtr<WebDeclaration>& declaration)
333     {
334         if (declaration) {
335             declaration_ = declaration;
336         }
337     }
338 
GetController()339     RefPtr<WebController> GetController() const
340     {
341         return webController_;
342     }
343 
SetWebController(const RefPtr<WebController> & webController)344     void SetWebController(const RefPtr<WebController>& webController)
345     {
346         webController_ = webController;
347     }
348 
SetSetWebIdCallback(SetWebIdCallback && SetIdCallback)349     void SetSetWebIdCallback(SetWebIdCallback&& SetIdCallback)
350     {
351         setWebIdCallback_ = std::move(SetIdCallback);
352     }
353 
GetSetWebIdCallback()354     SetWebIdCallback GetSetWebIdCallback() const
355     {
356         return setWebIdCallback_;
357     }
358 
SetSetHapPathCallback(SetHapPathCallback && callback)359     void SetSetHapPathCallback(SetHapPathCallback&& callback)
360     {
361         setHapPathCallback_ = std::move(callback);
362     }
363 
GetSetHapPathCallback()364     SetHapPathCallback GetSetHapPathCallback() const
365     {
366         return setHapPathCallback_;
367     }
368 
GetJsEnabled()369     bool GetJsEnabled() const
370     {
371         return isJsEnabled_;
372     }
373 
SetJsEnabled(bool isEnabled)374     void SetJsEnabled(bool isEnabled)
375     {
376         isJsEnabled_ = isEnabled;
377     }
378 
GetUserAgent()379     std::string GetUserAgent() const
380     {
381         return userAgent_;
382     }
383 
SetUserAgent(std::string userAgent)384     void SetUserAgent(std::string userAgent)
385     {
386         userAgent_ = std::move(userAgent);
387     }
388 
GetCustomScheme()389     std::string GetCustomScheme() const
390     {
391         return customScheme_;
392     }
393 
SetCustomScheme(std::string cmdLine)394     void SetCustomScheme(std::string cmdLine)
395     {
396         customScheme_ = std::move(cmdLine);
397     }
398 
GetContentAccessEnabled()399     bool GetContentAccessEnabled() const
400     {
401         return isContentAccessEnabled_;
402     }
403 
SetContentAccessEnabled(bool isEnabled)404     void SetContentAccessEnabled(bool isEnabled)
405     {
406         isContentAccessEnabled_ = isEnabled;
407     }
408 
GetFileAccessEnabled()409     bool GetFileAccessEnabled() const
410     {
411         return isFileAccessEnabled_;
412     }
413 
SetFileAccessEnabled(bool isEnabled)414     void SetFileAccessEnabled(bool isEnabled)
415     {
416         isFileAccessEnabled_ = isEnabled;
417     }
GetOnLineImageAccessEnabled()418     bool GetOnLineImageAccessEnabled() const
419     {
420         return isOnLineImageAccessEnabled_;
421     }
422 
SetOnLineImageAccessEnabled(bool isEnabled)423     void SetOnLineImageAccessEnabled(bool isEnabled)
424     {
425         isOnLineImageAccessEnabled_ = isEnabled;
426     }
427 
GetDomStorageAccessEnabled()428     bool GetDomStorageAccessEnabled() const
429     {
430         return isDomStorageAccessEnabled_;
431     }
432 
SetDomStorageAccessEnabled(bool isEnabled)433     void SetDomStorageAccessEnabled(bool isEnabled)
434     {
435         isDomStorageAccessEnabled_ = isEnabled;
436     }
437 
GetImageAccessEnabled()438     bool GetImageAccessEnabled() const
439     {
440         return isImageAccessEnabled_;
441     }
442 
SetImageAccessEnabled(bool isEnabled)443     void SetImageAccessEnabled(bool isEnabled)
444     {
445         isImageAccessEnabled_ = isEnabled;
446     }
447 
GetMixedMode()448     MixedModeContent GetMixedMode() const
449     {
450         return mixedContentMode_;
451     }
452 
SetMixedMode(MixedModeContent mixedModeNum)453     void SetMixedMode(MixedModeContent mixedModeNum)
454     {
455         mixedContentMode_ = mixedModeNum;
456     }
457 
GetZoomAccessEnabled()458     bool GetZoomAccessEnabled() const
459     {
460         return isZoomAccessEnabled_;
461     }
462 
SetZoomAccessEnabled(bool isEnabled)463     void SetZoomAccessEnabled(bool isEnabled)
464     {
465         isZoomAccessEnabled_ = isEnabled;
466     }
467 
GetGeolocationAccessEnabled()468     bool GetGeolocationAccessEnabled() const
469     {
470         return isGeolocationAccessEnabled_;
471     }
472 
SetGeolocationAccessEnabled(bool isEnabled)473     void SetGeolocationAccessEnabled(bool isEnabled)
474     {
475         isGeolocationAccessEnabled_ = isEnabled;
476     }
477 
GetCacheMode()478     WebCacheMode GetCacheMode()
479     {
480         return cacheMode_;
481     }
482 
SetCacheMode(WebCacheMode mode)483     void SetCacheMode(WebCacheMode mode)
484     {
485         cacheMode_ = mode;
486     }
487 
GetOverviewModeAccessEnabled()488     bool GetOverviewModeAccessEnabled() const
489     {
490         return isOverviewModeAccessEnabled_;
491     }
492 
SetOverviewModeAccessEnabled(bool isEnabled)493     void SetOverviewModeAccessEnabled(bool isEnabled)
494     {
495         isOverviewModeAccessEnabled_ = isEnabled;
496     }
497 
GetFileFromUrlAccessEnabled()498     bool GetFileFromUrlAccessEnabled() const
499     {
500         return isFileFromUrlAccessEnabled_;
501     }
502 
SetFileFromUrlAccessEnabled(bool isEnabled)503     void SetFileFromUrlAccessEnabled(bool isEnabled)
504     {
505         isFileFromUrlAccessEnabled_ = isEnabled;
506     }
507 
GetDatabaseAccessEnabled()508     bool GetDatabaseAccessEnabled() const
509     {
510         return isDatabaseAccessEnabled_;
511     }
512 
SetDatabaseAccessEnabled(bool isEnabled)513     void SetDatabaseAccessEnabled(bool isEnabled)
514     {
515         isDatabaseAccessEnabled_ = isEnabled;
516     }
517 
GetWebDebuggingAccessEnabled()518     bool GetWebDebuggingAccessEnabled() const
519     {
520         return isWebDebuggingAccessEnabled_;
521     }
522 
SetWebDebuggingAccessEnabled(bool isEnabled)523     void SetWebDebuggingAccessEnabled(bool isEnabled)
524     {
525         isWebDebuggingAccessEnabled_ = isEnabled;
526     }
527 
GetPinchSmoothModeEnabled()528     bool GetPinchSmoothModeEnabled() const
529     {
530         return isPinchSmoothModeEnabled_;
531     }
532 
SetPinchSmoothModeEnabled(bool isEnabled)533     void SetPinchSmoothModeEnabled(bool isEnabled)
534     {
535         isPinchSmoothModeEnabled_ = isEnabled;
536     }
537 
GetMultiWindowAccessEnabled()538     bool GetMultiWindowAccessEnabled() const
539     {
540         return isMultiWindowAccessEnabled_;
541     }
542 
SetMultiWindowAccessEnabled(bool isEnabled)543     void SetMultiWindowAccessEnabled(bool isEnabled)
544     {
545         isMultiWindowAccessEnabled_ = isEnabled;
546     }
547 
GetAllowWindowOpenMethod()548     bool GetAllowWindowOpenMethod() const
549     {
550         return isAllowWindowOpenMethod_;
551     }
552 
SetAllowWindowOpenMethod(bool isEnabled)553     void SetAllowWindowOpenMethod(bool isEnabled)
554     {
555         isAllowWindowOpenMethod_ = isEnabled;
556     }
557 
GetIsInitialScaleSet()558     bool GetIsInitialScaleSet() const
559     {
560         return isInitialScaleSet_;
561     }
562 
GetInitialScale()563     float GetInitialScale() const
564     {
565         return initialScale_;
566     }
567 
SetInitialScale(float scale)568     void SetInitialScale(float scale)
569     {
570         initialScale_ = scale;
571         isInitialScaleSet_ = true;
572     }
573 
GetBackgroundColorEnabled()574     bool GetBackgroundColorEnabled() const
575     {
576         return isBackgroundColor_;
577     }
578 
GetBackgroundColor()579     int32_t GetBackgroundColor() const
580     {
581         return backgroundColor_;
582     }
583 
SetBackgroundColor(int32_t backgroundColor)584     void SetBackgroundColor(int32_t backgroundColor)
585     {
586         backgroundColor_ = backgroundColor;
587         isBackgroundColor_ = true;
588     }
589 
GetTextZoomRatio()590     int32_t GetTextZoomRatio() const
591     {
592         return textZoomRatioNum_;
593     }
594 
SetTextZoomRatio(int32_t ratio)595     void SetTextZoomRatio(int32_t ratio)
596     {
597         textZoomRatioNum_ = ratio;
598     }
599 
600     using OnCommonDialogImpl = std::function<bool(const BaseEventInfo* info)>;
OnCommonDialog(const BaseEventInfo * info,DialogEventType dialogEventType)601     bool OnCommonDialog(const BaseEventInfo* info, DialogEventType dialogEventType) const
602     {
603         if (dialogEventType == DialogEventType::DIALOG_EVENT_ALERT && onAlertImpl_) {
604             return onAlertImpl_(info);
605         }
606         if (dialogEventType == DialogEventType::DIALOG_EVENT_CONFIRM && onConfirmImpl_) {
607             return onConfirmImpl_(info);
608         }
609         if (dialogEventType == DialogEventType::DIALOG_EVENT_PROMPT && onPromptImpl_) {
610             return onPromptImpl_(info);
611         }
612         if (dialogEventType == DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD && onBeforeUnloadImpl_) {
613             return onBeforeUnloadImpl_(info);
614         }
615         return false;
616     }
SetOnCommonDialogImpl(OnCommonDialogImpl && onCommonDialogImpl,DialogEventType dialogEventType)617     void SetOnCommonDialogImpl(OnCommonDialogImpl&& onCommonDialogImpl, DialogEventType dialogEventType)
618     {
619         if (onCommonDialogImpl == nullptr) {
620             return;
621         }
622 
623         switch (dialogEventType) {
624             case DialogEventType::DIALOG_EVENT_ALERT:
625                 onAlertImpl_ = std::move(onCommonDialogImpl);
626                 break;
627             case DialogEventType::DIALOG_EVENT_CONFIRM:
628                 onConfirmImpl_ = std::move(onCommonDialogImpl);
629                 break;
630             case DialogEventType::DIALOG_EVENT_PROMPT:
631                 onPromptImpl_ = std::move(onCommonDialogImpl);
632                 break;
633             case DialogEventType::DIALOG_EVENT_BEFORE_UNLOAD:
634                 onBeforeUnloadImpl_ = std::move(onCommonDialogImpl);
635                 break;
636             default:
637                 break;
638         }
639     }
640 
641     using OnFullScreenEnterImpl = std::function<void(const BaseEventInfo* info)>;
OnFullScreenEnter(const BaseEventInfo * info)642     void OnFullScreenEnter(const BaseEventInfo* info) const
643     {
644         if (onFullScreenEnterImpl_) {
645             onFullScreenEnterImpl_(info);
646         }
647     }
SetOnFullScreenEnterImpl(OnFullScreenEnterImpl && onFullScreenEnterImpl)648     void SetOnFullScreenEnterImpl(OnFullScreenEnterImpl&& onFullScreenEnterImpl)
649     {
650         onFullScreenEnterImpl_ = std::move(onFullScreenEnterImpl);
651     }
652 
653     using OnHttpAuthRequestImpl = std::function<bool(const BaseEventInfo* info)>;
OnHttpAuthRequest(const BaseEventInfo * info)654     bool OnHttpAuthRequest(const BaseEventInfo* info) const
655     {
656         if (onHttpAuthRequestImpl_) {
657             return onHttpAuthRequestImpl_(info);
658         }
659         return false;
660     }
SetOnHttpAuthRequestImpl(OnHttpAuthRequestImpl && onHttpAuthRequestImpl)661     void SetOnHttpAuthRequestImpl(OnHttpAuthRequestImpl&& onHttpAuthRequestImpl)
662     {
663         if (onHttpAuthRequestImpl == nullptr) {
664             return;
665         }
666         onHttpAuthRequestImpl_ = std::move(onHttpAuthRequestImpl);
667     }
668 
669     using OnSslErrorRequestImpl = std::function<bool(const BaseEventInfo* info)>;
OnSslErrorRequest(const BaseEventInfo * info)670     bool OnSslErrorRequest(const BaseEventInfo* info) const
671     {
672         if (onSslErrorRequestImpl_) {
673             return onSslErrorRequestImpl_(info);
674         }
675         return false;
676     }
SetOnSslErrorRequestImpl(OnSslErrorRequestImpl && onSslErrorRequestImpl)677     void SetOnSslErrorRequestImpl(OnSslErrorRequestImpl && onSslErrorRequestImpl)
678     {
679         if (onSslErrorRequestImpl == nullptr) {
680             return;
681         }
682         onSslErrorRequestImpl_ = std::move(onSslErrorRequestImpl);
683     }
684 
685     using OnSslSelectCertRequestImpl = std::function<bool(const BaseEventInfo* info)>;
OnSslSelectCertRequest(const BaseEventInfo * info)686     bool OnSslSelectCertRequest(const BaseEventInfo* info) const
687     {
688         if (onSslSelectCertRequestImpl_) {
689             return onSslSelectCertRequestImpl_(info);
690         }
691         return false;
692     }
SetOnSslSelectCertRequestImpl(OnSslSelectCertRequestImpl && impl)693     void SetOnSslSelectCertRequestImpl(OnSslSelectCertRequestImpl && impl)
694     {
695         if (!impl) {
696             return;
697         }
698         onSslSelectCertRequestImpl_ = std::move(impl);
699     }
700 
701     void RequestFocus();
702 
703     using OnConsoleImpl = std::function<bool(const BaseEventInfo* info)>;
OnConsole(const BaseEventInfo * info)704     bool OnConsole(const BaseEventInfo* info) const
705     {
706         if (consoleImpl_) {
707             return consoleImpl_(info);
708         }
709         return false;
710     }
711 
SetOnConsoleImpl(OnConsoleImpl && consoleImpl)712     void SetOnConsoleImpl(OnConsoleImpl&& consoleImpl)
713     {
714         consoleImpl_ = std::move(consoleImpl);
715     }
716 
SetFocusElement(const WeakPtr<FocusNode> & focusElement)717     void SetFocusElement(const WeakPtr<FocusNode>& focusElement)
718     {
719         focusElement_ = focusElement;
720     }
721 
722     using OnFileSelectorShowImpl = std::function<bool(const BaseEventInfo* info)>;
OnFileSelectorShow(const BaseEventInfo * info)723     bool OnFileSelectorShow(const BaseEventInfo* info) const
724     {
725         if (onFileSelectorShowImpl_) {
726             return onFileSelectorShowImpl_(info);
727         }
728         return false;
729     }
SetOnFileSelectorShow(OnFileSelectorShowImpl && onFileSelectorShowImpl)730     void SetOnFileSelectorShow(OnFileSelectorShowImpl&& onFileSelectorShowImpl)
731     {
732         if (onFileSelectorShowImpl == nullptr) {
733             return;
734         }
735 
736         onFileSelectorShowImpl_ = onFileSelectorShowImpl;
737     }
738 
739     using OnContextMenuImpl = std::function<bool(const BaseEventInfo* info)>;
OnContextMenuShow(const BaseEventInfo * info)740     bool OnContextMenuShow(const BaseEventInfo* info) const
741     {
742         if (onContextMenuImpl_) {
743             return onContextMenuImpl_(info);
744         }
745         return false;
746     }
SetOnContextMenuShow(OnContextMenuImpl && onContextMenuImpl)747     void SetOnContextMenuShow(OnContextMenuImpl&& onContextMenuImpl)
748     {
749         if (onContextMenuImpl == nullptr) {
750             return;
751         }
752         onContextMenuImpl_ = std::move(onContextMenuImpl);
753     }
754 
755     using OnContextMenuHideImpl = std::function<void(const BaseEventInfo* info)>;
OnContextMenuHide(const BaseEventInfo * info)756     void OnContextMenuHide(const BaseEventInfo* info) const
757     {
758         if (onContextMenuHideImpl_) {
759             onContextMenuHideImpl_(info);
760         }
761     }
SetOnContextMenuHide(OnContextMenuHideImpl && onContextMenuHideImpl)762     void SetOnContextMenuHide(OnContextMenuHideImpl&& onContextMenuHideImpl)
763     {
764         if (onContextMenuHideImpl == nullptr) {
765             return;
766         }
767         onContextMenuHideImpl_ = std::move(onContextMenuHideImpl);
768     }
769 
770     using OnUrlLoadInterceptImpl = std::function<bool(const BaseEventInfo* info)>;
OnUrlLoadIntercept(const BaseEventInfo * info)771     bool OnUrlLoadIntercept(const BaseEventInfo* info) const
772     {
773         if (onUrlLoadInterceptImpl_) {
774             return onUrlLoadInterceptImpl_(info);
775         }
776         return false;
777     }
SetOnUrlLoadIntercept(OnUrlLoadInterceptImpl && onUrlLoadInterceptImpl)778     void SetOnUrlLoadIntercept(OnUrlLoadInterceptImpl&& onUrlLoadInterceptImpl)
779     {
780         if (onUrlLoadInterceptImpl == nullptr) {
781             return;
782         }
783 
784         onUrlLoadInterceptImpl_ = onUrlLoadInterceptImpl;
785     }
786 
787     using OnLoadInterceptImpl = std::function<bool(const BaseEventInfo* info)>;
OnLoadIntercept(const BaseEventInfo * info)788     bool OnLoadIntercept(const BaseEventInfo* info) const
789     {
790         if (onLoadInterceptImpl_) {
791             return onLoadInterceptImpl_(info);
792         }
793         return false;
794     }
SetOnLoadIntercept(OnLoadInterceptImpl && onLoadInterceptImpl)795     void SetOnLoadIntercept(OnLoadInterceptImpl&& onLoadInterceptImpl)
796     {
797         if (onLoadInterceptImpl == nullptr) {
798             return;
799         }
800 
801         onLoadInterceptImpl_ = onLoadInterceptImpl;
802     }
803 
804     using OnInterceptRequestImpl = std::function<RefPtr<WebResponse>(const BaseEventInfo* info)>;
OnInterceptRequest(const BaseEventInfo * info)805     RefPtr<WebResponse> OnInterceptRequest(const BaseEventInfo* info) const
806     {
807         if (onInterceptRequestImpl_) {
808             return onInterceptRequestImpl_(info);
809         }
810         return nullptr;
811     }
812 
IsEmptyOnInterceptRequest()813     bool IsEmptyOnInterceptRequest() const
814     {
815         return onInterceptRequestImpl_ == nullptr;
816     }
817 
SetOnInterceptRequest(OnInterceptRequestImpl && onInterceptRequestImpl)818     void SetOnInterceptRequest(OnInterceptRequestImpl&& onInterceptRequestImpl)
819     {
820         if (onInterceptRequestImpl == nullptr) {
821             return;
822         }
823         onInterceptRequestImpl_ = std::move(onInterceptRequestImpl);
824     }
825 
SetOnMouseEventCallback(const OnMouseCallback & onMouseId)826     void SetOnMouseEventCallback(const OnMouseCallback& onMouseId)
827     {
828         onMouseEvent_ = onMouseId;
829     }
830 
GetOnMouseEventCallback()831     OnMouseCallback GetOnMouseEventCallback() const
832     {
833         return onMouseEvent_;
834     }
835 
SetOnKeyEventCallback(const OnKeyEventCallback & onKeyEventId)836     void SetOnKeyEventCallback(const OnKeyEventCallback& onKeyEventId)
837     {
838         onKeyEvent_ = onKeyEventId;
839     }
840 
GetOnKeyEventCallback()841     OnKeyEventCallback GetOnKeyEventCallback() const
842     {
843         return onKeyEvent_;
844     }
845 
SetSearchResultReceiveEventId(const EventMarker & searchResultReceiveEventId)846     void SetSearchResultReceiveEventId(const EventMarker& searchResultReceiveEventId)
847     {
848         CHECK_NULL_VOID(declaration_);
849         declaration_->SetSearchResultReceiveEventId(searchResultReceiveEventId);
850     }
851 
GetSearchResultReceiveEventId()852     const EventMarker& GetSearchResultReceiveEventId() const
853     {
854         return declaration_->GetSearchResultReceiveEventId();
855     }
856 
SetMediaPlayGestureAccess(bool isNeedGestureAccess)857     void SetMediaPlayGestureAccess(bool isNeedGestureAccess)
858     {
859         isNeedGestureAccess_ = isNeedGestureAccess;
860     }
861 
IsMediaPlayGestureAccess()862     bool IsMediaPlayGestureAccess() const
863     {
864         return isNeedGestureAccess_;
865     }
866 
GetOnDragStartId()867     const OnDragFunc& GetOnDragStartId() const
868     {
869         return onDragStartId_;
870     }
871 
SetOnDragStartId(const OnDragFunc & onDragStartId)872     void SetOnDragStartId(const OnDragFunc& onDragStartId)
873     {
874         onDragStartId_ = onDragStartId;
875     }
876 
GetOnDragEnterId()877     const OnDropFunc& GetOnDragEnterId() const
878     {
879         return onDragEnterId_;
880     }
881 
SetOnDragEnterId(const OnDropFunc & onDragEnterId)882     void SetOnDragEnterId(const OnDropFunc& onDragEnterId)
883     {
884         onDragEnterId_ = onDragEnterId;
885     }
886 
GetOnDragMoveId()887     const OnDropFunc& GetOnDragMoveId() const
888     {
889         return onDragMoveId_;
890     }
891 
SetOnDragMoveId(const OnDropFunc & onDragMoveId)892     void SetOnDragMoveId(const OnDropFunc& onDragMoveId)
893     {
894         onDragMoveId_ = onDragMoveId;
895     }
896 
GetOnDragLeaveId()897     const OnDropFunc& GetOnDragLeaveId() const
898     {
899         return onDragLeaveId_;
900     }
901 
SetOnDragLeaveId(const OnDropFunc & onDragLeaveId)902     void SetOnDragLeaveId(const OnDropFunc& onDragLeaveId)
903     {
904         onDragLeaveId_ = onDragLeaveId;
905     }
906 
GetOnDropId()907     const OnDropFunc& GetOnDropId() const
908     {
909         return onDropId_;
910     }
911 
SetOnDropId(const OnDropFunc & onDropId)912     void SetOnDropId(const OnDropFunc& onDropId)
913     {
914         onDropId_ = onDropId;
915     }
916 
SetJsProxyCallback(JsProxyCallback && jsProxyCallback)917     void SetJsProxyCallback(JsProxyCallback&& jsProxyCallback)
918     {
919         jsProxyCallback_ = std::move(jsProxyCallback);
920     }
921 
CallJsProxyCallback()922     void CallJsProxyCallback()
923     {
924         if (jsProxyCallback_) {
925             jsProxyCallback_();
926         }
927     }
928 
SetOnInterceptKeyEventCallback(const PreKeyEventCallback & onPreKeyEventId)929     void SetOnInterceptKeyEventCallback(const PreKeyEventCallback& onPreKeyEventId)
930     {
931         onPreKeyEvent_ = onPreKeyEventId;
932     }
933 
GetOnInterceptKeyEventCallback()934     PreKeyEventCallback GetOnInterceptKeyEventCallback() const
935     {
936         return onPreKeyEvent_;
937     }
938 
SetOverScrollId(const EventMarker & overScrollId)939     void SetOverScrollId(const EventMarker& overScrollId)
940     {
941         CHECK_NULL_VOID(declaration_);
942         declaration_->SetOverScrollId(overScrollId);
943     }
944 
GetOverScrollId()945     const EventMarker& GetOverScrollId() const
946     {
947         return declaration_->GetOverScrollId();
948     }
949 
950 private:
951     RefPtr<WebDeclaration> declaration_;
952     CreatedCallback createdCallback_ = nullptr;
953     ReleasedCallback releasedCallback_ = nullptr;
954     ErrorCallback errorCallback_ = nullptr;
955     SetWebIdCallback setWebIdCallback_ = nullptr;
956     SetHapPathCallback setHapPathCallback_ = nullptr;
957     JsProxyCallback jsProxyCallback_ = nullptr;
958     RefPtr<WebDelegate> delegate_;
959     RefPtr<WebController> webController_;
960     OnCommonDialogImpl onAlertImpl_;
961     OnCommonDialogImpl onConfirmImpl_;
962     OnCommonDialogImpl onPromptImpl_;
963     OnCommonDialogImpl onBeforeUnloadImpl_;
964     OnConsoleImpl consoleImpl_;
965     OnFileSelectorShowImpl onFileSelectorShowImpl_;
966     OnFullScreenEnterImpl onFullScreenEnterImpl_;
967     OnUrlLoadInterceptImpl onUrlLoadInterceptImpl_;
968     OnLoadInterceptImpl onLoadInterceptImpl_;
969     OnHttpAuthRequestImpl onHttpAuthRequestImpl_;
970     OnSslErrorRequestImpl onSslErrorRequestImpl_;
971     OnSslSelectCertRequestImpl onSslSelectCertRequestImpl_;
972     OnContextMenuImpl onContextMenuImpl_;
973     OnContextMenuHideImpl onContextMenuHideImpl_;
974     OnInterceptRequestImpl onInterceptRequestImpl_ = nullptr;
975     OnProgressChangeImpl onProgressChangeImpl_ = nullptr;
976     OnWindowNewImpl onWindowNewImpl_ = nullptr;
977 
978     std::string type_;
979     bool isJsEnabled_ = true;
980     bool isContentAccessEnabled_ = true;
981     bool isFileAccessEnabled_ = true;
982     std::string userAgent_;
983     std::string customScheme_;
984     WeakPtr<FocusNode> focusElement_;
985     bool isOnLineImageAccessEnabled_ = false;
986     bool isDomStorageAccessEnabled_ = false;
987     bool isImageAccessEnabled_ = true;
988     MixedModeContent mixedContentMode_ = MixedModeContent::MIXED_CONTENT_NEVER_ALLOW;
989     bool isZoomAccessEnabled_ = true;
990     bool isGeolocationAccessEnabled_ = true;
991     bool isOverviewModeAccessEnabled_ = true;
992     bool isFileFromUrlAccessEnabled_ = false;
993     bool isDatabaseAccessEnabled_ = false;
994     int32_t textZoomRatioNum_ = DEFAULT_TEXT_ZOOM_RATIO;
995     WebCacheMode cacheMode_ = WebCacheMode::DEFAULT;
996     bool isWebDebuggingAccessEnabled_ = false;
997     bool isMultiWindowAccessEnabled_ = false;
998     bool isAllowWindowOpenMethod_ = false;
999     OnMouseCallback onMouseEvent_;
1000     OnKeyEventCallback onKeyEvent_;
1001     float initialScale_;
1002     bool isInitialScaleSet_ = false;
1003     int32_t backgroundColor_;
1004     bool isBackgroundColor_ = false;
1005     bool isNeedGestureAccess_ = true;
1006     OnDragFunc onDragStartId_;
1007     OnDropFunc onDragEnterId_;
1008     OnDropFunc onDragMoveId_;
1009     OnDropFunc onDragLeaveId_;
1010     OnDropFunc onDropId_;
1011     bool isPinchSmoothModeEnabled_ = false;
1012     PreKeyEventCallback onPreKeyEvent_;
1013     bool isPopup_ = false;
1014     int32_t parentNWebId_ = -1;
1015 };
1016 
1017 } // namespace OHOS::Ace
1018 
1019 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_COMPONENT_H
1020