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