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