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