• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_COMMON_CONTAINER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <mutex>
22 #include <unordered_map>
23 
24 #include "interfaces/inner_api/ace/ace_forward_compatibility.h"
25 #include "interfaces/inner_api/ace/constants.h"
26 #include "interfaces/inner_api/ace/navigation_controller.h"
27 
28 #include "base/memory/ace_type.h"
29 #include "base/resource/asset_manager.h"
30 #include "base/resource/shared_image_manager.h"
31 #include "base/subwindow/subwindow_manager.h"
32 #include "base/thread/task_executor.h"
33 #include "base/utils/macros.h"
34 #include "base/utils/noncopyable.h"
35 #include "base/utils/system_properties.h"
36 #include "base/utils/utils.h"
37 #include "base/view_data/ace_auto_fill_error.h"
38 #include "base/view_data/hint_to_type_wrap.h"
39 #include "core/common/ace_application_info.h"
40 #include "core/common/container_consts.h"
41 #include "core/common/container_handler.h"
42 #include "core/common/display_info.h"
43 #include "core/common/display_info_utils.h"
44 #include "core/common/frontend.h"
45 #include "core/common/page_url_checker.h"
46 #include "core/common/platform_res_register.h"
47 #include "core/common/resource/resource_configuration.h"
48 #include "core/common/settings.h"
49 #include "core/common/window.h"
50 #include "core/components/common/layout/constants.h"
51 #include "core/components_ng/base/distributed_ui.h"
52 #include "core/components_ng/pattern/app_bar/app_bar_view.h"
53 #include "core/components_ng/pattern/navigation/navigation_route.h"
54 #include "core/components_ng/pattern/navigator/navigator_event_hub.h"
55 #include "core/event/non_pointer_event.h"
56 #include "core/event/pointer_event.h"
57 #include "core/pipeline/pipeline_base.h"
58 
59 namespace OHOS::Ace {
60 
61 using PageTask = std::function<void()>;
62 using TouchEventCallback = std::function<void(const TouchEvent&, const std::function<void()>&,
63     const RefPtr<NG::FrameNode>&)>;
64 using KeyEventCallback = std::function<bool(const KeyEvent&)>;
65 using NonPointerEventCallback = std::function<bool(const NonPointerEvent&, const std::function<void()>&)>;
66 using MouseEventCallback = std::function<void(const MouseEvent&, const std::function<void()>&,
67     const RefPtr<NG::FrameNode>&)>;
68 using AxisEventCallback = std::function<void(const AxisEvent&, const std::function<void()>&,
69     const RefPtr<NG::FrameNode>&)>;
70 using RotationEventCallBack = std::function<bool(const RotationEvent&)>;
71 using CardViewPositionCallBack = std::function<void(int id, float offsetX, float offsetY)>;
72 using DragEventCallBack = std::function<void(const DragPointerEvent&, const DragEventAction&,
73     const RefPtr<NG::FrameNode>&)>;
74 using StopDragCallback = std::function<void()>;
75 using CrownEventCallback = std::function<bool(const CrownEvent&, const std::function<void()>&)>;
76 
77 class PipelineBase;
78 
79 class ACE_FORCE_EXPORT Container : public virtual AceType {
80     DECLARE_ACE_TYPE(Container, AceType);
81 
82 public:
83     Container() = default;
84     ~Container() override = default;
85 
86     virtual void Initialize() = 0;
87 
88     virtual void Destroy() = 0;
89 
SetAppRunningUniqueId(const std::string & uniqueId)90     virtual void SetAppRunningUniqueId(const std::string& uniqueId) {};
91 
GetAppRunningUniqueId()92     virtual const std::string& GetAppRunningUniqueId() const
93     {
94         static const std::string res;
95         return res;
96     }
97 
IsKeyboard()98     virtual bool IsKeyboard()
99     {
100         return false;
101     }
102 
DestroyView()103     virtual void DestroyView() {}
104     virtual bool UpdatePopupUIExtension(const RefPtr<NG::FrameNode>& node,
105         uint32_t autoFillSessionId, bool isNative = true)
106     {
107         return false;
108     }
109 
ClosePopupUIExtension(uint32_t autoFillSessionId)110     virtual bool ClosePopupUIExtension(uint32_t autoFillSessionId)
111     {
112         return false;
113     }
114 
PlaceHolderToType(const std::string & onePlaceHolder)115     virtual HintToTypeWrap PlaceHolderToType(const std::string& onePlaceHolder)
116     {
117         HintToTypeWrap hintToTypeWrap;
118         return hintToTypeWrap;
119     }
120 
121     // Get the instance id of this container
122     virtual int32_t GetInstanceId() const = 0;
123 
124     // Get the ability name of this container
125     virtual std::string GetHostClassName() const = 0;
126 
127     // Get the frontend of container
128     virtual RefPtr<Frontend> GetFrontend() const = 0;
129 
130     // Get task executor.
131     virtual RefPtr<TaskExecutor> GetTaskExecutor() const = 0;
132 
133     // Get assert manager.
134     virtual RefPtr<AssetManager> GetAssetManager() const = 0;
135 
136     // Get platform resource register.
137     virtual RefPtr<PlatformResRegister> GetPlatformResRegister() const = 0;
138 
139     // Get the pipelineContext of container.
140     virtual RefPtr<PipelineBase> GetPipelineContext() const = 0;
141 
142     // Dump container.
143     virtual bool Dump(const std::vector<std::string>& params, std::vector<std::string>& info);
144 
145     // Get the width/height of the view
146     virtual int32_t GetViewWidth() const = 0;
147     virtual int32_t GetViewHeight() const = 0;
148     virtual int32_t GetViewPosX() const = 0;
149     virtual int32_t GetViewPosY() const = 0;
150 
151     virtual uint32_t GetWindowId() const = 0;
SetWindowId(uint32_t windowId)152     virtual void SetWindowId(uint32_t windowId) {}
WindowIsShow()153     virtual bool WindowIsShow() const
154     {
155         return false;
156     }
157 
158     virtual RefPtr<AceView> GetAceView() const = 0;
159 
160     virtual void* GetView() const = 0;
161 
162     // Trigger garbage collection
TriggerGarbageCollection()163     virtual void TriggerGarbageCollection() {}
164 
DumpHeapSnapshot(bool isPrivate)165     virtual void DumpHeapSnapshot(bool isPrivate) {}
166 
DestroyHeapProfiler()167     virtual void DestroyHeapProfiler() {}
168 
ForceFullGC()169     virtual void ForceFullGC() {}
170 
NotifyFontNodes()171     virtual void NotifyFontNodes() {}
172 
NotifyAppStorage(const std::string & key,const std::string & value)173     virtual void NotifyAppStorage(const std::string& key, const std::string& value) {}
174 
SetCardFrontend(WeakPtr<Frontend> frontend,int64_t cardId)175     virtual void SetCardFrontend(WeakPtr<Frontend> frontend, int64_t cardId) {}
176 
GetCardFrontend(int64_t cardId)177     virtual WeakPtr<Frontend> GetCardFrontend(int64_t cardId) const
178     {
179         return nullptr;
180     }
181 
SetCardPipeline(WeakPtr<PipelineBase>,int64_t cardId)182     virtual void SetCardPipeline(WeakPtr<PipelineBase>, int64_t cardId) {}
183 
GetCardPipeline(int64_t cardId)184     virtual WeakPtr<PipelineBase> GetCardPipeline(int64_t cardId) const
185     {
186         return nullptr;
187     }
188 
189     // Get MultiModal ptr.
GetMutilModalPtr()190     virtual uintptr_t GetMutilModalPtr() const
191     {
192         return 0;
193     }
194 
SetParentId(int32_t parentId)195     virtual void SetParentId(int32_t parentId) {}
196 
GetParentId()197     virtual int32_t GetParentId() const
198     {
199         return 0;
200     }
201 
ProcessScreenOnEvents()202     virtual void ProcessScreenOnEvents() {}
203 
ProcessScreenOffEvents()204     virtual void ProcessScreenOffEvents() {}
205 
SetOrientation(Orientation orientation)206     virtual void SetOrientation(Orientation orientation) {}
207 
GetOrientation()208     virtual Orientation GetOrientation()
209     {
210         return Orientation::UNSPECIFIED;
211     }
212 
213     virtual RefPtr<DisplayInfo> GetDisplayInfo();
214 
215     virtual void InitIsFoldable();
216 
217     virtual bool IsFoldable();
218 
219     virtual FoldStatus GetCurrentFoldStatus();
220 
GetFoldStatusFromListener()221     virtual FoldStatus GetFoldStatusFromListener()
222     {
223         return GetCurrentFoldStatus();
224     }
225 
InitFoldStatusFromListener()226     virtual void InitFoldStatusFromListener() {}
227 
228     virtual NG::SafeAreaInsets GetKeyboardSafeArea();
229 
GetHapPath()230     virtual std::string GetHapPath() const
231     {
232         return {};
233     }
234 
GetWebHapPath()235     virtual std::string GetWebHapPath() const
236     {
237         return {};
238     }
239 
SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)240     void SetCreateTime(std::chrono::time_point<std::chrono::high_resolution_clock> time)
241     {
242         createTime_ = time;
243     }
244 
IsFirstUpdate()245     bool IsFirstUpdate() const
246     {
247         return firstUpdateData_;
248     }
249 
AlreadyFirstUpdate()250     void AlreadyFirstUpdate()
251     {
252         firstUpdateData_ = false;
253     }
254 
SetBundleName(const std::string & bundleName)255     void SetBundleName(const std::string& bundleName)
256     {
257         bundleName_ = bundleName;
258     }
259 
GetBundleName()260     const std::string& GetBundleName() const
261     {
262         return bundleName_;
263     }
264 
SetModuleName(const std::string & moduleName)265     void SetModuleName(const std::string& moduleName)
266     {
267         moduleName_ = moduleName;
268     }
269 
GetModuleName()270     std::string GetModuleName() const
271     {
272         return moduleName_;
273     }
274 
IsMainWindow()275     virtual bool IsMainWindow() const { return false; }
IsSubWindow()276     virtual bool IsSubWindow() const { return false; }
IsDialogWindow()277     virtual bool IsDialogWindow() const { return false; }
IsSystemWindow()278     virtual bool IsSystemWindow() const { return false; }
IsHostMainWindow()279     virtual bool IsHostMainWindow() const { return false; }
IsHostSubWindow()280     virtual bool IsHostSubWindow() const { return false; }
IsHostDialogWindow()281     virtual bool IsHostDialogWindow() const { return false; }
IsHostSystemWindow()282     virtual bool IsHostSystemWindow() const { return false; }
IsHostSceneBoardWindow()283     virtual bool IsHostSceneBoardWindow() const { return false; }
IsSubContainer()284     virtual bool IsSubContainer() const { return false; }
IsFormRender()285     virtual bool IsFormRender() const { return false; }
GetParentMainWindowId(uint32_t currentWindowId)286     virtual uint32_t GetParentMainWindowId(uint32_t currentWindowId) const
287     {
288         return 0;
289     }
290 
SetIsFormRender(bool isFormRender)291     virtual void SetIsFormRender(bool isFormRender) {};
292 
GetCardHapPath()293     const std::string& GetCardHapPath() const
294     {
295         return cardHapPath_;
296     }
297 
298     bool UpdateState(const Frontend::State& state);
299 
GetSettings()300     Settings& GetSettings()
301     {
302         return settings_;
303     }
304 
SetBundlePath(const std::string & path)305     void SetBundlePath(const std::string& path)
306     {
307         bundlePath_ = path;
308     }
309 
GetBundlePath()310     const std::string& GetBundlePath() const
311     {
312         return bundlePath_;
313     }
314 
SetFilesDataPath(const std::string & path)315     void SetFilesDataPath(const std::string& path)
316     {
317         filesDataPath_ = path;
318     }
319 
GetFilesDataPath()320     const std::string& GetFilesDataPath() const
321     {
322         return filesDataPath_;
323     }
324 
SetTempDir(const std::string & path)325     void SetTempDir(const std::string& path)
326     {
327         tempDir_ = path;
328     }
329 
GetTempDir()330     const std::string& GetTempDir() const
331     {
332         return tempDir_;
333     }
334 
SetViewFirstUpdating(std::chrono::time_point<std::chrono::high_resolution_clock> time)335     virtual void SetViewFirstUpdating(std::chrono::time_point<std::chrono::high_resolution_clock> time) {}
336 
UpdateResourceConfiguration(const std::string & jsonStr)337     virtual void UpdateResourceConfiguration(const std::string& jsonStr) {}
338 
339     static int32_t SafelyId();
340     static int32_t CurrentId();
341     static int32_t CurrentIdSafely();
342     static int32_t CurrentIdSafelyWithCheck();
343     static RefPtr<Container> Current();
344     static RefPtr<Container> CurrentSafely();
345     static RefPtr<Container> CurrentSafelyWithCheck();
346     static RefPtr<Container> GetContainer(int32_t containerId);
347     static RefPtr<Container> GetActive();
348     static RefPtr<Container> GetDefault();
349     static RefPtr<Container> GetFoucsed();
350     static RefPtr<Container> GetByWindowId(uint32_t windowId);
351     static RefPtr<TaskExecutor> CurrentTaskExecutor();
352     static RefPtr<TaskExecutor> CurrentTaskExecutorSafely();
353     static RefPtr<TaskExecutor> CurrentTaskExecutorSafelyWithCheck();
354     static void UpdateCurrent(int32_t id);
355     static ColorMode CurrentColorMode();
356 
SetUseNewPipeline()357     void SetUseNewPipeline()
358     {
359         useNewPipeline_ = true;
360     }
361 
SetUsePartialUpdate()362     void SetUsePartialUpdate()
363     {
364         usePartialUpdate_ = true;
365     }
366 
IsUseNewPipeline()367     bool IsUseNewPipeline() const
368     {
369         return useNewPipeline_;
370     }
371 
IsCurrentUseNewPipeline()372     static bool IsCurrentUseNewPipeline()
373     {
374         auto container = Current();
375         return container ? container->useNewPipeline_ : AceForwardCompatibility::IsUseNG();
376     }
377 
378     // SetCurrentUsePartialUpdate is called when initial render on a page
379     // starts, see zyz_view_register loadDocument() implementation
IsCurrentUsePartialUpdate()380     static bool IsCurrentUsePartialUpdate()
381     {
382         auto container = Current();
383         return container ? container->usePartialUpdate_ : false;
384     }
385 
386     static void SetCurrentUsePartialUpdate(bool useIt = false)
387     {
388         auto container = Current();
389         if (container) {
390             container->usePartialUpdate_ = useIt;
391         }
392     }
393 
IsInFormContainer()394     static bool IsInFormContainer() {
395         auto container = Current();
396         return container ? container->isFRSCardContainer_ : false;
397     }
398 
IsInSubContainer()399     static bool IsInSubContainer()
400     {
401         auto container = Current();
402         return container ? container->IsSubContainer() : false;
403     }
404 
405     Window* GetWindow() const;
406 
GetDisplayId()407     virtual uint64_t GetDisplayId() const
408     {
409         return -1;
410     }
411 
IsUseStageModel()412     virtual bool IsUseStageModel() const
413     {
414         return false;
415     }
416 
GetCardFrontendMap(std::unordered_map<int64_t,WeakPtr<Frontend>> & cardFrontendMap)417     virtual void GetCardFrontendMap(std::unordered_map<int64_t, WeakPtr<Frontend>>& cardFrontendMap) const {}
418 
SetSharedRuntime(void * runtime)419     virtual void SetSharedRuntime(void* runtime) {}
GetSharedRuntime()420     virtual void* GetSharedRuntime()
421     {
422         return nullptr;
423     }
424 
IsFRSCardContainer()425     bool IsFRSCardContainer() const
426     {
427         return isFRSCardContainer_;
428     }
429 
SetIsFRSCardContainer(bool isFRSCardContainer)430     void SetIsFRSCardContainer(bool isFRSCardContainer)
431     {
432         isFRSCardContainer_ = isFRSCardContainer;
433     }
434 
IsDynamicRender()435     bool IsDynamicRender() const
436     {
437         return isDynamicRender_;
438     }
439 
SetIsDynamicRender(bool isDynamicRender)440     void SetIsDynamicRender(bool isDynamicRender)
441     {
442         isDynamicRender_ = isDynamicRender;
443     }
444 
GetRegisterComponents()445     virtual std::vector<std::string> GetRegisterComponents() { return {}; };
446 
SetPageUrlChecker(const RefPtr<PageUrlChecker> & pageUrlChecker)447     void SetPageUrlChecker(const RefPtr<PageUrlChecker>& pageUrlChecker)
448     {
449         pageUrlChecker_ = pageUrlChecker;
450     }
451 
GetPageUrlChecker()452     const RefPtr<PageUrlChecker>& GetPageUrlChecker()
453     {
454         return pageUrlChecker_;
455     }
456 
SetNavigationRoute(const RefPtr<NG::NavigationRoute> & navigationRoute)457     void SetNavigationRoute(const RefPtr<NG::NavigationRoute>& navigationRoute)
458     {
459         navigationRoute_ = navigationRoute;
460     }
461 
GetNavigationRoute()462     RefPtr<NG::NavigationRoute> GetNavigationRoute() const
463     {
464         return navigationRoute_;
465     }
466 
IsDialogContainer()467     virtual bool IsDialogContainer() const
468     {
469         return false;
470     }
471 
SetWindowScale(float windowScale)472     virtual void SetWindowScale(float windowScale) {}
473 
GetWindowScale()474     virtual float GetWindowScale() const
475     {
476         return 1.0f;
477     }
478 
479     virtual void NotifyConfigurationChange(bool, const ConfigurationChange& configurationChange = { false, false }) {}
480 
HotReload()481     virtual void HotReload() {}
482 
SetIsModule(bool isModule)483     void SetIsModule(bool isModule)
484     {
485         isModule_ = isModule;
486     }
487 
IsModule()488     bool IsModule() const
489     {
490         return isModule_;
491     }
492 
SetDistributedUI(std::shared_ptr<NG::DistributedUI> & distributedUI)493     void SetDistributedUI(std::shared_ptr<NG::DistributedUI>& distributedUI)
494     {
495         distributedUI_ = distributedUI;
496     }
497 
GetDistributedUI()498     std::shared_ptr<NG::DistributedUI>& GetDistributedUI()
499     {
500         return distributedUI_;
501     }
502 
IsLauncherContainer()503     virtual bool IsLauncherContainer()
504     {
505         return false;
506     }
507 
IsScenceBoardWindow()508     virtual bool IsScenceBoardWindow()
509     {
510         return false;
511     }
512 
IsCrossAxisWindow()513     virtual bool IsCrossAxisWindow()
514     {
515         return false;
516     }
517 
IsUIExtensionWindow()518     virtual bool IsUIExtensionWindow()
519     {
520         return false;
521     }
522 
IsSceneBoardEnabled()523     virtual bool IsSceneBoardEnabled()
524     {
525         return false;
526     }
527 
GetCurPointerEventInfo(DragPointerEvent & dragPointerEvent,StopDragCallback && stopDragCallback)528     virtual bool GetCurPointerEventInfo(DragPointerEvent& dragPointerEvent, StopDragCallback&& stopDragCallback)
529     {
530         return false;
531     }
532 
GetCurPointerEventSourceType(int32_t & sourceType)533     virtual bool GetCurPointerEventSourceType(int32_t& sourceType)
534     {
535         return false;
536     }
537 
538     virtual int32_t RequestAutoFill(const RefPtr<NG::FrameNode>& node, AceAutoFillType autoFillType, bool isNewPassWord,
539         bool& isPopup, uint32_t& autoFillSessionId, bool isNative = true,
540         const std::function<void()>& onFinish = nullptr,
541         const std::function<void()>& onUIExtNodeBindingCompleted = nullptr)
542     {
543         return AceAutoFillError::ACE_AUTO_FILL_DEFAULT;
544     }
545 
IsNeedToCreatePopupWindow(const AceAutoFillType & autoFillType)546     virtual bool IsNeedToCreatePopupWindow(const AceAutoFillType& autoFillType)
547     {
548         return false;
549     }
550 
551     virtual bool RequestAutoSave(const RefPtr<NG::FrameNode>& node, const std::function<void()>& onFinish = nullptr,
552         const std::function<void()>& onUIExtNodeBindingCompleted = nullptr, bool isNative = true,
553         int32_t instanceId = -1)
554     {
555         return false;
556     }
557 
558 
GetNavigationController(const std::string & navigationId)559     virtual std::shared_ptr<NavigationController> GetNavigationController(const std::string& navigationId)
560     {
561         return nullptr;
562     }
563 
564     /**
565      * @description: [Deprecated]. Compare whether the min compatible api version of the application is less than the
566      * incoming target version. This interface is just use before api12(not include api12), after api12 when you judge
567      * version, use LessThanAPITargetVersion(PlatformVersion version).
568      * @param: Target version to be isolated.
569      * @return: return the compare result.
570      */
571     static bool LessThanAPIVersion(PlatformVersion version);
572 
573     /**
574      * @description: [Deprecated]. Compare whether the min compatible api version of the application is less than the
575      * incoming target version. This interface is just use before api12(not include api12), after api12 when you judge
576      * version, use GreatOrEqualAPITargetVersion(PlatformVersion version).
577      * @param: Target version to be isolated.
578      * @return: return the compare result.
579      */
580     static bool GreatOrEqualAPIVersion(PlatformVersion version);
581 
582     /**
583      * @description: Compare whether the min compatible api version of the application is less than the incoming target
584      * version. This interface is just for when you use LessThanAPIVersion in instance does not exist situation.
585      * @param: Target version to be isolated.
586      * @return: return the compare result.
587      */
588     static bool LessThanAPIVersionWithCheck(PlatformVersion version);
589 
590     /**
591      * @description: Compare whether the min compatible api version of the application is greater than or equal to the
592      * incoming target version. This interface is just for when you use GreatOrEqualAPIVersion in instance does not
593      * exist situation.
594      * @param: Target version to be isolated.
595      * @return: return the compare result.
596      */
597     static bool GreatOrEqualAPIVersionWithCheck(PlatformVersion version);
598 
599     /**
600      * @description: Compare whether the target api version of the application is less than the incoming target
601      * version.
602      * @param: Target version to be isolated.
603      * @return: return the compare result.
604      */
LessThanAPITargetVersion(PlatformVersion version)605     static bool LessThanAPITargetVersion(PlatformVersion version)
606     {
607         auto container = Current();
608         CHECK_NULL_RETURN(container, false);
609         auto apiTargetVersion = container->GetApiTargetVersion();
610         return apiTargetVersion < static_cast<int32_t>(version);
611     }
612 
613     /**
614      * @description: Compare whether the target api version of the application is greater than or equal to the incoming
615      * target.
616      * @param: Target version to be isolated.
617      * @return: return the compare result.
618      */
GreatOrEqualAPITargetVersion(PlatformVersion version)619     static bool GreatOrEqualAPITargetVersion(PlatformVersion version)
620     {
621         auto container = Current();
622         if (!container) {
623             auto apiTargetVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion() % 1000;
624             return apiTargetVersion >= static_cast<int32_t>(version);
625         }
626         auto apiTargetVersion = container->GetApiTargetVersion();
627         return apiTargetVersion >= static_cast<int32_t>(version);
628     }
629 
GetCurrentApiTargetVersion()630     static int32_t GetCurrentApiTargetVersion()
631     {
632         auto container = Current();
633         if (!container) {
634             return AceApplicationInfo::GetInstance().GetApiTargetVersion() % 1000;
635         }
636         return container->GetApiTargetVersion();
637     }
638 
SetAppBar(const RefPtr<NG::AppBarView> & appBar)639     void SetAppBar(const RefPtr<NG::AppBarView>& appBar)
640     {
641         appBar_ = appBar;
642     }
643 
GetAppBar()644     RefPtr<NG::AppBarView> GetAppBar() const
645     {
646         return appBar_;
647     }
648 
TerminateUIExtension()649     virtual void TerminateUIExtension() {}
UIExtensionIsHalfScreen()650     virtual bool UIExtensionIsHalfScreen()
651     {
652         return false;
653     }
654     template<ContainerType type>
655     static int32_t GenerateId();
656     static void SetFontScale(int32_t instanceId, float fontScale);
657     static void SetFontWeightScale(int32_t instanceId, float fontScale);
658 
659     /**
660      * @description: Get the target api version of the application.
661      * @return: The target api version of the application.
662      */
GetApiTargetVersion()663     int32_t GetApiTargetVersion() const
664     {
665         return apiTargetVersion_;
666     }
667 
668     /**
669      * @description: Set the target api version of the application.
670      * @param: The target api version of the application.
671      */
SetApiTargetVersion(int32_t apiTargetVersion)672     void SetApiTargetVersion(int32_t apiTargetVersion)
673     {
674         apiTargetVersion_ = apiTargetVersion % 1000;
675     }
676 
GetUIContentType()677     UIContentType GetUIContentType() const
678     {
679         return uIContentType_;
680     }
681 
SetUIContentType(UIContentType uIContentType)682     void SetUIContentType(UIContentType uIContentType)
683     {
684         uIContentType_ = uIContentType;
685     }
686 
687     void DestroyToastSubwindow(int32_t instanceId);
688 
CheckAndSetFontFamily()689     virtual void CheckAndSetFontFamily() {};
690 
IsFreeMultiWindow()691     virtual bool IsFreeMultiWindow() const
692     {
693         return false;
694     }
695 
GetUIExtensionHostWindowRect(int32_t instanceId)696     virtual Rect GetUIExtensionHostWindowRect(int32_t instanceId)
697     {
698         return Rect();
699     }
700 
IsFloatingWindow()701     virtual bool IsFloatingWindow() const
702     {
703         return false;
704     }
705 
RegisterContainerHandler(const WeakPtr<ContainerHandler> & containerHandler)706     void RegisterContainerHandler(const WeakPtr<ContainerHandler>& containerHandler)
707     {
708         containerHandler_ = containerHandler;
709     }
710 
GetContainerHandler()711     WeakPtr<ContainerHandler> GetContainerHandler()
712     {
713         return containerHandler_;
714     }
715 
SetCurrentDisplayId(uint64_t displayId)716     void SetCurrentDisplayId(uint64_t displayId)
717     {
718         currentDisplayId_ = displayId;
719     }
720 
GetCurrentDisplayId()721     uint64_t GetCurrentDisplayId() const
722     {
723         return currentDisplayId_;
724     }
725 
SetColorMode(ColorMode mode)726     virtual void SetColorMode(ColorMode mode)
727     {
728         colorMode_ = mode;
729     }
730 
GetColorMode()731     virtual ColorMode GetColorMode() const
732     {
733         return colorMode_;
734     }
735 
736     virtual ResourceConfiguration GetResourceConfiguration() const = 0;
737 
738     void DestroySelectOverlaySubwindow(int32_t instanceId);
739 
740     static bool IsNodeInKeyGuardWindow(const RefPtr<NG::FrameNode>& node);
741 
GetLastMovingPointerPosition(DragPointerEvent & dragPointerEvent)742     virtual bool GetLastMovingPointerPosition(DragPointerEvent& dragPointerEvent)
743     {
744         return false;
745     }
746 
747     virtual std::vector<Rect> GetCurrentFoldCreaseRegion();
748 
GetDisplayAvailableRect()749     virtual Rect GetDisplayAvailableRect() const
750     {
751         return Rect();
752     }
753 
754     static bool CheckRunOnThreadByThreadId(int32_t currentId, bool defaultRes);
755 
756 protected:
757     bool IsFontFileExistInPath(const std::string& path);
758     std::vector<std::string> GetFontFamilyName(const std::string& path);
759     bool endsWith(std::string str, std::string suffix);
760 
761 private:
762     static bool IsIdAvailable(int32_t id);
763 
764 protected:
765     std::chrono::time_point<std::chrono::high_resolution_clock> createTime_;
766     bool firstUpdateData_ = true;
767     std::string cardHapPath_;
768     bool useNewPipeline_ = false;
769     std::mutex stateMutex_;
770     Frontend::State state_ = Frontend::State::UNDEFINE;
771     bool isFRSCardContainer_ = false;
772     bool isDynamicRender_ = false;
773     // for common handler
774     WeakPtr<ContainerHandler> containerHandler_;
775     RefPtr<DisplayInfoUtils> displayManager_ = AceType::MakeRefPtr<DisplayInfoUtils>();
776 
777 private:
778     std::string bundleName_;
779     std::string moduleName_;
780     std::string bundlePath_;
781     std::string filesDataPath_;
782     std::string tempDir_;
783     bool usePartialUpdate_ = false;
784     Settings settings_;
785     RefPtr<PageUrlChecker> pageUrlChecker_;
786     RefPtr<NG::NavigationRoute> navigationRoute_;
787     bool isModule_ = false;
788     std::shared_ptr<NG::DistributedUI> distributedUI_;
789     RefPtr<NG::AppBarView> appBar_;
790     int32_t apiTargetVersion_ = 0;
791     // Define the type of UI Content, for example, Security UIExtension.
792     UIContentType uIContentType_ = UIContentType::UNDEFINED;
793     uint64_t currentDisplayId_ = 0;
794     ColorMode colorMode_ = ColorMode::LIGHT;
795     ACE_DISALLOW_COPY_AND_MOVE(Container);
796 };
797 
798 template<ContainerType type>
GenerateId()799 int32_t Container::GenerateId()
800 {
801     static std::atomic<int32_t> gInstanceId;
802     int32_t id;
803     do {
804         id = type * CONTAINER_ID_DIVIDE_SIZE + gInstanceId.fetch_add(1) % CONTAINER_ID_DIVIDE_SIZE;
805     } while (!IsIdAvailable(id));
806     return id;
807 }
808 
809 template<>
810 int32_t Container::GenerateId<PLUGIN_SUBCONTAINER>();
811 
812 } // namespace OHOS::Ace
813 
814 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_CONTAINER_H
815