• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_ADAPTER_OHOS_CPP_ACE_CONTAINER_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_CONTAINER_H
18 
19 #include <cstddef>
20 #include <list>
21 #include <memory>
22 #include <mutex>
23 
24 #include "display_manager.h"
25 #include "dm_common.h"
26 #include "interfaces/inner_api/ace/arkui_rect.h"
27 #include "native_engine/native_reference.h"
28 #include "native_engine/native_value.h"
29 
30 #include "adapter/ohos/entrance/ace_ability.h"
31 #include "adapter/ohos/entrance/platform_event_callback.h"
32 #include "base/memory/ace_type.h"
33 #include "base/resource/asset_manager.h"
34 #include "base/thread/task_executor.h"
35 #include "base/utils/noncopyable.h"
36 #include "base/utils/utils.h"
37 #include "base/view_data/view_data_wrap.h"
38 #include "base/view_data/hint_to_type_wrap.h"
39 #include "core/common/ace_view.h"
40 #include "core/common/container.h"
41 #include "core/common/display_info.h"
42 #include "core/common/font_manager.h"
43 #include "core/common/js_message_dispatcher.h"
44 #include "core/common/resource/resource_configuration.h"
45 #include "core/components/common/layout/constants.h"
46 #include "core/pipeline/pipeline_context.h"
47 
48 namespace OHOS::Accessibility {
49 class AccessibilityElementInfo;
50 }
51 
52 namespace OHOS::Ace {
53 class FontManager;
54 }
55 
56 namespace OHOS::Ace::Platform {
57 using UIEnvCallback = std::function<void(const OHOS::Ace::RefPtr<OHOS::Ace::PipelineContext>& context)>;
58 using SharePanelCallback = std::function<void(const std::string& bundleName, const std::string& abilityName)>;
59 
60 struct ParsedConfig {
61     std::string colorMode;
62     std::string deviceAccess;
63     std::string languageTag;
64     std::string direction;
65     std::string densitydpi;
66     std::string themeTag;
67     std::string fontFamily;
68     std::string fontScale;
69     std::string fontWeightScale;
70     std::string colorModeIsSetByApp;
71     std::string mcc;
72     std::string mnc;
73     std::string preferredLanguage;
IsValidParsedConfig74     bool IsValid() const
75     {
76         return !(colorMode.empty() && deviceAccess.empty() && languageTag.empty() && direction.empty() &&
77                  densitydpi.empty() && themeTag.empty() && fontScale.empty() && fontWeightScale.empty() &&
78                  colorModeIsSetByApp.empty() && mcc.empty() && mnc.empty() && fontFamily.empty() &&
79                  preferredLanguage.empty());
80     }
81 };
82 
83 using ConfigurationChangedCallback = std::function<void(const ParsedConfig& config, const std::string& configuration)>;
84 
85 class ACE_FORCE_EXPORT AceContainer : public Container, public JsMessageDispatcher {
86     DECLARE_ACE_TYPE(AceContainer, Container, JsMessageDispatcher);
87 
88 public:
89     AceContainer(int32_t instanceId, FrontendType type, std::shared_ptr<OHOS::AppExecFwk::Ability> aceAbility,
90         std::unique_ptr<PlatformEventCallback> callback, bool useCurrentEventRunner = false,
91         bool useNewPipeline = false);
92     AceContainer(int32_t instanceId, FrontendType type, std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext,
93         std::weak_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo, std::unique_ptr<PlatformEventCallback> callback,
94         bool useCurrentEventRunner = false, bool isSubContainer = false, bool useNewPipeline = false);
95 
96     AceContainer(int32_t instanceId, FrontendType type, std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext,
97         std::weak_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo, std::unique_ptr<PlatformEventCallback> callback,
98         std::shared_ptr<TaskWrapper> taskWrapper, bool useCurrentEventRunner = false, bool isSubContainer = false,
99         bool useNewPipeline = false);
100 
101     ~AceContainer() override;
102 
103     bool UpdatePopupUIExtension(const RefPtr<NG::FrameNode>& node,
104         uint32_t autoFillSessionId, bool isNative = true) override;
105 
106     bool ClosePopupUIExtension(uint32_t autoFillSessionId) override;
107 
108     void Initialize() override;
109 
110     void Destroy() override;
111 
112     bool IsKeyboard() override;
113 
114     void DestroyView() override;
115 
116     static bool Register();
117 
GetInstanceId()118     int32_t GetInstanceId() const override
119     {
120         if (aceView_) {
121             return aceView_->GetInstanceId();
122         }
123         return -1;
124     }
125 
GetFrontend()126     RefPtr<Frontend> GetFrontend() const override
127     {
128         std::lock_guard<std::mutex> lock(frontendMutex_);
129         return frontend_;
130     }
131 
SetCardFrontend(WeakPtr<Frontend> frontend,int64_t cardId)132     void SetCardFrontend(WeakPtr<Frontend> frontend, int64_t cardId) override
133     {
134         std::lock_guard<std::mutex> lock(cardFrontMutex_);
135         cardFrontendMap_.try_emplace(cardId, frontend);
136     }
137 
GetCardFrontend(int64_t cardId)138     WeakPtr<Frontend> GetCardFrontend(int64_t cardId) const override
139     {
140         std::lock_guard<std::mutex> lock(cardFrontMutex_);
141         auto it = cardFrontendMap_.find(cardId);
142         if (it != cardFrontendMap_.end()) {
143             return it->second;
144         }
145         return nullptr;
146     }
147 
SetCardPipeline(WeakPtr<PipelineBase> pipeline,int64_t cardId)148     void SetCardPipeline(WeakPtr<PipelineBase> pipeline, int64_t cardId) override
149     {
150         std::lock_guard<std::mutex> lock(cardPipelineMutex_);
151         cardPipelineMap_.try_emplace(cardId, pipeline);
152     }
153 
GetCardPipeline(int64_t cardId)154     WeakPtr<PipelineBase> GetCardPipeline(int64_t cardId) const override
155     {
156         std::lock_guard<std::mutex> lock(cardPipelineMutex_);
157         auto it = cardPipelineMap_.find(cardId);
158         if (it == cardPipelineMap_.end()) {
159             return nullptr;
160         }
161         return it->second;
162     }
163 
GetTaskExecutor()164     RefPtr<TaskExecutor> GetTaskExecutor() const override
165     {
166         return taskExecutor_;
167     }
168 
SetAssetManager(const RefPtr<AssetManager> & assetManager)169     void SetAssetManager(const RefPtr<AssetManager>& assetManager)
170     {
171         assetManager_ = assetManager;
172         if (frontend_) {
173             frontend_->SetAssetManager(assetManager);
174         }
175     }
176 
GetAssetManager()177     RefPtr<AssetManager> GetAssetManager() const override
178     {
179         return assetManager_;
180     }
181 
GetPlatformResRegister()182     RefPtr<PlatformResRegister> GetPlatformResRegister() const override
183     {
184         return resRegister_;
185     }
186 
GetPipelineContext()187     RefPtr<PipelineBase> GetPipelineContext() const override
188     {
189         std::lock_guard<std::mutex> lock(pipelineMutex_);
190         return pipelineContext_;
191     }
192 
GetViewWidth()193     int32_t GetViewWidth() const override
194     {
195         return aceView_ ? aceView_->GetWidth() : 0;
196     }
197 
GetViewHeight()198     int32_t GetViewHeight() const override
199     {
200         return aceView_ ? aceView_->GetHeight() : 0;
201     }
202 
GetViewPosX()203     int32_t GetViewPosX() const override
204     {
205         return aceView_ ? aceView_->GetPosX() : 0;
206     }
207 
GetViewPosY()208     int32_t GetViewPosY() const override
209     {
210         return aceView_ ? aceView_->GetPosY() : 0;
211     }
212 
GetAceView()213     RefPtr<AceView> GetAceView() const override
214     {
215         std::lock_guard<std::mutex> lock(viewMutex_);
216         return aceView_;
217     }
218 
GetView()219     void* GetView() const override
220     {
221         std::lock_guard<std::mutex> lock(viewMutex_);
222         return static_cast<void*>(AceType::RawPtr(aceView_));
223     }
224 
SetWindowModal(WindowModal windowModal)225     void SetWindowModal(WindowModal windowModal)
226     {
227         windowModal_ = windowModal;
228     }
229 
SetInstallationFree(bool installationFree)230     void SetInstallationFree(bool installationFree)
231     {
232         installationFree_ = installationFree;
233     }
234 
SetSharePanelCallback(SharePanelCallback && callback)235     void SetSharePanelCallback(SharePanelCallback&& callback)
236     {
237         sharePanelCallback_ = std::move(callback);
238     }
239 
SetColorScheme(ColorScheme colorScheme)240     void SetColorScheme(ColorScheme colorScheme)
241     {
242         colorScheme_ = colorScheme;
243     }
244 
GetResourceConfiguration()245     ResourceConfiguration GetResourceConfiguration() const
246     {
247         return resourceInfo_.GetResourceConfiguration();
248     }
249 
SetResourceConfiguration(const ResourceConfiguration & config)250     void SetResourceConfiguration(const ResourceConfiguration& config)
251     {
252         resourceInfo_.SetResourceConfiguration(config);
253     }
254 
GetPackagePathStr()255     std::string GetPackagePathStr() const
256     {
257         return resourceInfo_.GetPackagePath();
258     }
259 
SetPackagePathStr(const std::string & packagePath)260     void SetPackagePathStr(const std::string& packagePath)
261     {
262         resourceInfo_.SetPackagePath(packagePath);
263     }
264 
GetHapPath()265     std::string GetHapPath() const override
266     {
267         return resourceInfo_.GetHapPath();
268     }
269 
GetResourceInfo()270     const ResourceInfo& GetResourceInfo() const
271     {
272         return resourceInfo_;
273     }
274 
SetOrientation(Orientation orientation)275     void SetOrientation(Orientation orientation) override
276     {
277         CHECK_NULL_VOID(uiWindow_);
278         auto dmOrientation = static_cast<Rosen::Orientation>(static_cast<uint32_t>(orientation));
279         uiWindow_->SetRequestedOrientation(dmOrientation);
280     }
281 
GetOrientation()282     Orientation GetOrientation() override
283     {
284         CHECK_NULL_RETURN(uiWindow_, Orientation::UNSPECIFIED);
285         auto dmOrientation = uiWindow_->GetRequestedOrientation();
286         return static_cast<Orientation>(static_cast<uint32_t>(dmOrientation));
287     }
288 
289     void SetHapPath(const std::string& hapPath);
290 
291     void Dispatch(
292         const std::string& group, std::vector<uint8_t>&& data, int32_t id, bool replyToComponent) const override;
293 
DispatchSync(const std::string & group,std::vector<uint8_t> && data,uint8_t ** resData,int64_t & position)294     void DispatchSync(
295         const std::string& group, std::vector<uint8_t>&& data, uint8_t** resData, int64_t& position) const override
296     {}
297 
298     void DispatchPluginError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override;
299 
300     bool Dump(const std::vector<std::string>& params, std::vector<std::string>& info) override;
301 
302     bool DumpInfo(const std::vector<std::string>& params);
303 
304     bool OnDumpInfo(const std::vector<std::string>& params);
305 
306     void TriggerGarbageCollection() override;
307 
308     void DumpHeapSnapshot(bool isPrivate) override;
309 
310     void DestroyHeapProfiler() override;
311 
312     void ForceFullGC() override;
313 
314     void SetLocalStorage(NativeReference* storage, const std::shared_ptr<OHOS::AbilityRuntime::Context>& context);
315 
316     void CheckAndSetFontFamily();
317 
OnFinish()318     void OnFinish()
319     {
320         if (platformEventCallback_) {
321             platformEventCallback_->OnFinish();
322         }
323     }
324 
OnStartAbility(const std::string & address)325     void OnStartAbility(const std::string& address)
326     {
327         if (platformEventCallback_) {
328             platformEventCallback_->OnStartAbility(address);
329         }
330     }
331 
GeneratePageId()332     int32_t GeneratePageId()
333     {
334         return pageId_++;
335     }
336 
GetHostClassName()337     std::string GetHostClassName() const override
338     {
339         return "";
340     }
341 
SetSharedRuntime(void * runtime)342     void SetSharedRuntime(void* runtime) override
343     {
344         sharedRuntime_ = runtime;
345     }
346 
SetPageProfile(const std::string & pageProfile)347     void SetPageProfile(const std::string& pageProfile)
348     {
349         pageProfile_ = pageProfile;
350     }
351 
IsSubContainer()352     bool IsSubContainer() const override
353     {
354         return isSubContainer_;
355     }
356 
IsFormRender()357     bool IsFormRender() const override
358     {
359         return isFormRender_;
360     }
361 
GetSharedRuntime()362     void* GetSharedRuntime() override
363     {
364         return sharedRuntime_;
365     }
366 
SetParentId(int32_t parentId)367     void SetParentId(int32_t parentId)
368     {
369         parentId_ = parentId;
370     }
371 
SetWindowScale(float windowScale)372     void SetWindowScale(float windowScale) override
373     {
374         windowScale_ = windowScale;
375     }
376 
GetWindowScale()377     float GetWindowScale() const override
378     {
379         return windowScale_;
380     }
381 
GetWindowDensity()382     double GetWindowDensity() const
383     {
384         if (!uiWindow_) {
385             return 1.0;
386         }
387         return static_cast<double>(uiWindow_->GetVirtualPixelRatio());
388     }
389 
GetParentId()390     int32_t GetParentId() const
391     {
392         return parentId_;
393     }
394 
SetFocusWindowId(uint32_t focusWindowId)395     void SetFocusWindowId(uint32_t focusWindowId)
396     {
397         if (pipelineContext_) {
398             pipelineContext_->SetFocusWindowId(focusWindowId);
399         }
400     }
401 
SetRealHostWindowId(uint32_t realHostWindowId)402     void SetRealHostWindowId(uint32_t realHostWindowId)
403     {
404         if (pipelineContext_) {
405             pipelineContext_->SetRealHostWindowId(realHostWindowId);
406         }
407     }
408 
IsUseCustomBg()409     bool IsUseCustomBg() const
410     {
411         return isUseCustomBg_;
412     }
413 
SetIsUseCustomBg(bool isUseCustomBg)414     void SetIsUseCustomBg(bool isUseCustomBg)
415     {
416         isUseCustomBg_ = isUseCustomBg;
417     }
418 
419     bool IsTransparentBg() const;
420 
421     static void CreateContainer(int32_t instanceId, FrontendType type, const std::string& instanceName,
422         std::shared_ptr<OHOS::AppExecFwk::Ability> aceAbility, std::unique_ptr<PlatformEventCallback> callback,
423         bool useCurrentEventRunner = false, bool useNewPipeline = false);
424 
425     static void DestroyContainer(int32_t instanceId, const std::function<void()>& destroyCallback = nullptr);
426     static UIContentErrorCode RunPage(
427         int32_t instanceId, const std::string& content, const std::string& params, bool isNamedRouter = false);
428     static UIContentErrorCode RunPage(
429         int32_t instanceId, const std::shared_ptr<std::vector<uint8_t>>& content, const std::string& params);
430     static bool PushPage(int32_t instanceId, const std::string& content, const std::string& params);
431     static bool RunDynamicPage(
432         int32_t instanceId, const std::string& content, const std::string& params, const std::string& entryPoint);
433     static bool OnBackPressed(int32_t instanceId);
434     static void OnShow(int32_t instanceId);
435     static void OnHide(int32_t instanceId);
436     static void OnActive(int32_t instanceId);
437     static void OnInactive(int32_t instanceId);
438     static void OnNewWant(int32_t instanceId, const std::string& data);
439     static bool OnStartContinuation(int32_t instanceId);
440     static std::string OnSaveData(int32_t instanceId);
441     static bool OnRestoreData(int32_t instanceId, const std::string& data);
442     static void OnCompleteContinuation(int32_t instanceId, int result);
443     static void OnRemoteTerminated(int32_t instanceId);
444     static void OnConfigurationUpdated(int32_t instanceId, const std::string& configuration);
445     static void OnNewRequest(int32_t instanceId, const std::string& data);
446     static void AddAssetPath(int32_t instanceId, const std::string& packagePath, const std::string& hapPath,
447         const std::vector<std::string>& paths);
448     static void AddLibPath(int32_t instanceId, const std::vector<std::string>& libPath);
449     static void SetView(const RefPtr<AceView>& view, double density, int32_t width, int32_t height,
450         sptr<OHOS::Rosen::Window> rsWindow, UIEnvCallback callback = nullptr);
451     static UIContentErrorCode SetViewNew(
452         const RefPtr<AceView>& view, double density, float width, float height, sptr<OHOS::Rosen::Window> rsWindow);
453     static void SetUIWindow(int32_t instanceId, sptr<OHOS::Rosen::Window> uiWindow);
454     static sptr<OHOS::Rosen::Window> GetUIWindow(int32_t instanceId);
455     static OHOS::AppExecFwk::Ability* GetAbility(int32_t instanceId);
456     static OHOS::AbilityRuntime::Context* GetRuntimeContext(int32_t instanceId);
457     static void SetWindowStyle(int32_t instanceId, WindowModal windowModal, ColorScheme colorScheme);
458     static std::pair<std::string, UIContentErrorCode> RestoreRouterStack(
459         int32_t instanceId, const std::string& contentInfo);
460     static std::string GetContentInfo(int32_t instanceId);
461 
462     static RefPtr<AceContainer> GetContainer(int32_t instanceId);
463     static bool UpdatePage(int32_t instanceId, int32_t pageId, const std::string& content);
464     static bool RemoveOverlayBySubwindowManager(int32_t instanceId);
465 
466     // ArkTsCard
467     static std::shared_ptr<Rosen::RSSurfaceNode> GetFormSurfaceNode(int32_t instanceId);
468 
SetWindowName(const std::string & name)469     void SetWindowName(const std::string& name)
470     {
471         windowName_ = name;
472     }
473 
GetWindowName()474     std::string& GetWindowName()
475     {
476         return windowName_;
477     }
478 
SetWindowId(uint32_t windowId)479     void SetWindowId(uint32_t windowId) override
480     {
481         windowId_ = windowId;
482     }
483 
GetWindowId()484     uint32_t GetWindowId() const override
485     {
486         return windowId_;
487     }
488 
WindowIsShow()489     bool WindowIsShow() const override
490     {
491         if (!uiWindow_) {
492             return false;
493         }
494         return uiWindow_->GetWindowState() == Rosen::WindowState::STATE_SHOWN;
495     }
496 
497     void SetWindowPos(int32_t left, int32_t top);
498 
SetIsSubContainer(bool isSubContainer)499     void SetIsSubContainer(bool isSubContainer)
500     {
501         isSubContainer_ = isSubContainer;
502     }
503 
SetIsFormRender(bool isFormRender)504     void SetIsFormRender(bool isFormRender) override
505     {
506         isFormRender_ = isFormRender;
507     }
508 
509     void InitializeSubContainer(int32_t parentContainerId);
510     static void SetDialogCallback(int32_t instanceId, FrontendDialogCallback callback);
511 
512     std::shared_ptr<OHOS::AbilityRuntime::Context> GetAbilityContextByModule(
513         const std::string& bundle, const std::string& module);
514 
515     void UpdateConfiguration(const ParsedConfig& parsedConfig, const std::string& configuration);
516 
517     void NotifyConfigurationChange(
518         bool needReloadTransition, const ConfigurationChange& configurationChange = { false, false }) override;
519 
AddOnConfigurationChange(int32_t instanceId,ConfigurationChangedCallback && callback)520     void AddOnConfigurationChange(int32_t instanceId, ConfigurationChangedCallback &&callback)
521     {
522         configurationChangedCallbacks_.emplace(instanceId, std::move(callback));
523     }
524 
RemoveOnConfigurationChange(int32_t instanceId)525     void RemoveOnConfigurationChange(int32_t instanceId)
526     {
527         configurationChangedCallbacks_.erase(instanceId_);
528     }
529 
530     void HotReload() override;
531 
IsUseStageModel()532     bool IsUseStageModel() const override
533     {
534         return useStageModel_;
535     }
536 
GetCardFrontendMap(std::unordered_map<int64_t,WeakPtr<Frontend>> & cardFrontendMap)537     void GetCardFrontendMap(std::unordered_map<int64_t, WeakPtr<Frontend>>& cardFrontendMap) const override
538     {
539         cardFrontendMap = cardFrontendMap_;
540     }
541 
542     void SetToken(sptr<IRemoteObject>& token);
543     sptr<IRemoteObject> GetToken();
544     void SetParentToken(sptr<IRemoteObject>& token);
545     sptr<IRemoteObject> GetParentToken();
546     uint32_t GetParentWindowType() const;
547     uint32_t GetWindowType() const;
548 
GetWebHapPath()549     std::string GetWebHapPath() const override
550     {
551         return webHapPath_;
552     }
553 
554     NG::SafeAreaInsets GetViewSafeAreaByType(OHOS::Rosen::AvoidAreaType type);
555 
556     NG::SafeAreaInsets GetKeyboardSafeArea() override;
557 
558     Rosen::AvoidArea GetAvoidAreaByType(Rosen::AvoidAreaType type);
559 
560     // ArkTSCard
561     void UpdateFormData(const std::string& data);
562     void UpdateFormSharedImage(const std::map<std::string, sptr<OHOS::AppExecFwk::FormAshmem>>& imageDataMap);
563     void UpdateResource();
564 
565     void GetNamesOfSharedImage(std::vector<std::string>& picNameArray);
566     void UpdateSharedImage(std::vector<std::string>& picNameArray, std::vector<int32_t>& byteLenArray,
567         std::vector<int32_t>& fileDescriptorArray);
568     void GetImageDataFromAshmem(
569         const std::string& picName, Ashmem& ashmem, const RefPtr<PipelineBase>& pipelineContext, int len);
570 
571     bool IsLauncherContainer() override;
572     bool IsScenceBoardWindow() override;
573     bool IsUIExtensionWindow() override;
574     bool IsSceneBoardEnabled() override;
575     bool IsMainWindow() const override;
576     bool IsSubWindow() const override;
577     bool IsDialogWindow() const override;
578     bool IsSystemWindow() const override;
579     bool IsHostMainWindow() const override;
580     bool IsHostSubWindow() const override;
581     bool IsHostDialogWindow() const override;
582     bool IsHostSystemWindow() const override;
583     bool IsHostScenceBoardWindow() const override;
584     uint32_t GetParentMainWindowId(uint32_t currentWindowId) const override;
585 
586     void SetCurPointerEvent(const std::shared_ptr<MMI::PointerEvent>& currentEvent);
587     bool GetCurPointerEventInfo(int32_t& pointerId, int32_t& globalX, int32_t& globalY, int32_t& sourceType,
588         int32_t& sourceTool, StopDragCallback&& stopDragCallback) override;
589 
590     bool GetCurPointerEventSourceType(int32_t& sourceType) override;
591 
592     bool RequestAutoFill(const RefPtr<NG::FrameNode>& node, AceAutoFillType autoFillType,
593         bool isNewPassWord, bool& isPopup, uint32_t& autoFillSessionId, bool isNative = true) override;
594     bool IsNeedToCreatePopupWindow(const AceAutoFillType& autoFillType) override;
595     bool RequestAutoSave(const RefPtr<NG::FrameNode>& node, const std::function<void()>& onFinish,
596         const std::function<void()>& onUIExtNodeBindingCompleted, bool isNative = true,
597         int32_t instanceId = -1) override;
598     std::shared_ptr<NavigationController> GetNavigationController(const std::string& navigationId) override;
599     void OverwritePageNodeInfo(const RefPtr<NG::FrameNode>& frameNode, AbilityBase::ViewData& viewData);
600     HintToTypeWrap PlaceHolderToType(const std::string& onePlaceHolder) override;
601 
602     void SearchElementInfoByAccessibilityIdNG(
603         int64_t elementId, int32_t mode, int64_t baseParent,
604         std::list<Accessibility::AccessibilityElementInfo>& output);
605 
606     void SearchElementInfosByTextNG(
607         int64_t elementId, const std::string& text, int64_t baseParent,
608         std::list<Accessibility::AccessibilityElementInfo>& output);
609 
610     void FindFocusedElementInfoNG(
611         int64_t elementId, int32_t focusType, int64_t baseParent,
612         Accessibility::AccessibilityElementInfo& output);
613 
614     void FocusMoveSearchNG(
615         int64_t elementId, int32_t direction, int64_t baseParent,
616         Accessibility::AccessibilityElementInfo& output);
617 
618     bool NotifyExecuteAction(
619         int64_t elementId, const std::map<std::string, std::string>& actionArguments,
620         int32_t action, int64_t offset);
621 
622     void HandleAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType,
623         int32_t eventType, int64_t timeMs);
624 
625     void TerminateUIExtension() override;
626 
SetUIExtensionSubWindow(bool isUIExtensionSubWindow)627     void SetUIExtensionSubWindow(bool isUIExtensionSubWindow)
628     {
629         isUIExtensionSubWindow_ = isUIExtensionSubWindow;
630     }
631 
IsUIExtensionSubWindow()632     bool IsUIExtensionSubWindow()
633     {
634         return isUIExtensionSubWindow_;
635     }
636 
SetUIExtensionAbilityProcess(bool isUIExtensionAbilityProcess)637     void SetUIExtensionAbilityProcess(bool isUIExtensionAbilityProcess)
638     {
639         isUIExtensionAbilityProcess_ = isUIExtensionAbilityProcess;
640     }
641 
IsUIExtensionAbilityProcess()642     bool IsUIExtensionAbilityProcess()
643     {
644         return isUIExtensionAbilityProcess_;
645     }
646 
SetUIExtensionAbilityHost(bool isUIExtensionAbilityHost)647     void SetUIExtensionAbilityHost(bool isUIExtensionAbilityHost)
648     {
649         isUIExtensionAbilityHost_ = isUIExtensionAbilityHost;
650     }
651 
IsUIExtensionAbilityHost()652     bool IsUIExtensionAbilityHost()
653     {
654         return isUIExtensionAbilityHost_;
655     }
656 
RecordResAdapter(const std::string & key)657     void RecordResAdapter(const std::string& key)
658     {
659         resAdapterRecord_.emplace(key);
660     }
661 
662     std::vector<Ace::RectF> GetOverlayNodePositions();
663 
664     void RegisterOverlayNodePositionsUpdateCallback(
665         const std::function<void(std::vector<Ace::RectF>)>&& callback);
666 
667     OHOS::Rosen::WMError RegisterAvoidAreaChangeListener(sptr<OHOS::Rosen::IAvoidAreaChangedListener>& listener);
668     OHOS::Rosen::WMError UnregisterAvoidAreaChangeListener(sptr<OHOS::Rosen::IAvoidAreaChangedListener>& listener);
669 
670     bool NeedFullUpdate(uint32_t limitKey);
671     void NotifyDensityUpdate(double density);
672     void NotifyDirectionUpdate();
673 
SetRegisterComponents(const std::vector<std::string> & registerComponents)674     void SetRegisterComponents(const std::vector<std::string>& registerComponents)
675     {
676         registerComponents_ = registerComponents;
677     }
678 
GetRegisterComponents()679     std::vector<std::string> GetRegisterComponents() override
680     {
681         return registerComponents_;
682     }
683 
684     void UpdateResourceOrientation(int32_t orientation);
685     void UpdateResourceDensity(double density);
686 
IsFreeMultiWindow()687     bool IsFreeMultiWindow() const override
688     {
689         CHECK_NULL_RETURN(uiWindow_, false);
690         return uiWindow_->GetFreeMultiWindowModeEnabledState();
691     }
692 
693     void FireAccessibilityEventCallback(uint32_t eventId, int64_t parameter);
694 
695 private:
696     virtual bool MaybeRelease() override;
697     void InitializeFrontend();
698     void InitializeCallback();
699     void InitializeTask(std::shared_ptr<TaskWrapper> taskWrapper = nullptr);
700     void InitWindowCallback();
701     bool IsFontFileExistInPath(std::string path);
702     std::string GetFontFamilyName(std::string path);
703     bool endsWith(std::string str, std::string suffix);
704 
705     void AttachView(std::shared_ptr<Window> window, const RefPtr<AceView>& view, double density, float width,
706         float height, uint32_t windowId, UIEnvCallback callback = nullptr);
707     void SetUIWindowInner(sptr<OHOS::Rosen::Window> uiWindow);
708     sptr<OHOS::Rosen::Window> GetUIWindowInner() const;
709     std::weak_ptr<OHOS::AppExecFwk::Ability> GetAbilityInner() const;
710     std::weak_ptr<OHOS::AbilityRuntime::Context> GetRuntimeContextInner() const;
711 
712     void RegisterStopDragCallback(int32_t pointerId, StopDragCallback&& stopDragCallback);
713     void SetFontScaleAndWeightScale(const ParsedConfig& parsedConfig, ConfigurationChange& configurationChange);
714     void ReleaseResourceAdapter();
715     void FillAutoFillViewData(const RefPtr<NG::FrameNode> &node, RefPtr<ViewDataWrap> &viewDataWrap);
716 
717     void NotifyConfigToSubContainers(const ParsedConfig& parsedConfig, const std::string& configuration);
718 
719     int32_t instanceId_ = 0;
720     RefPtr<AceView> aceView_;
721     RefPtr<TaskExecutor> taskExecutor_;
722     RefPtr<AssetManager> assetManager_;
723     RefPtr<PlatformResRegister> resRegister_;
724     RefPtr<PipelineBase> pipelineContext_;
725     RefPtr<Frontend> frontend_;
726     std::unordered_map<int64_t, WeakPtr<Frontend>> cardFrontendMap_;
727     std::unordered_map<int64_t, WeakPtr<PipelineBase>> cardPipelineMap_;
728 
729     FrontendType type_ = FrontendType::JS;
730     std::unique_ptr<PlatformEventCallback> platformEventCallback_;
731     WindowModal windowModal_ { WindowModal::NORMAL };
732     ColorScheme colorScheme_ { ColorScheme::FIRST_VALUE };
733     ResourceInfo resourceInfo_;
734     std::weak_ptr<OHOS::AppExecFwk::Ability> aceAbility_;
735     std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext_;
736     std::weak_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo_;
737     void* sharedRuntime_ = nullptr;
738     std::string pageProfile_;
739     int32_t pageId_ = 0;
740     bool useCurrentEventRunner_ = false;
741     sptr<OHOS::Rosen::Window> uiWindow_ = nullptr;
742     std::string windowName_;
743     uint32_t windowId_ = OHOS::Rosen::INVALID_WINDOW_ID;
744     float windowScale_ = 1.0f;
745     sptr<IRemoteObject> token_;
746     sptr<IRemoteObject> parentToken_;
747 
748     bool isSubContainer_ = false;
749     bool isFormRender_ = false;
750     int32_t parentId_ = 0;
751     bool useStageModel_ = false;
752     bool isUIExtensionSubWindow_ = false;
753     bool isUIExtensionAbilityProcess_ = false;
754     bool isUIExtensionAbilityHost_ = false;
755     bool isUseCustomBg_ = false;
756 
757     DeviceOrientation orientation_ = DeviceOrientation::ORIENTATION_UNDEFINED;
758 
759     // for other AceContainer subscribe configuration from host AceContaier
760     // key is instanceId, value is callback function
761     std::unordered_map<int32_t, ConfigurationChangedCallback> configurationChangedCallbacks_;
762     std::vector<std::string> registerComponents_;
763 
764     std::unordered_set<std::string> resAdapterRecord_;
765 
766     mutable std::mutex frontendMutex_;
767     mutable std::mutex pipelineMutex_;
768     mutable std::mutex destructMutex_;
769     mutable std::mutex viewMutex_;
770 
771     mutable std::mutex cardFrontMutex_;
772     mutable std::mutex cardPipelineMutex_;
773     mutable std::mutex cardTokensMutex_;
774 
775     std::string webHapPath_;
776 
777     bool installationFree_ = false;
778     SharePanelCallback sharePanelCallback_ = nullptr;
779 
780     std::atomic_flag isDumping_ = ATOMIC_FLAG_INIT;
781 
782     // For custom drag event
783     std::mutex pointerEventMutex_;
784     std::shared_ptr<MMI::PointerEvent> currentPointerEvent_;
785     std::unordered_map<int32_t, std::list<StopDragCallback>> stopDragCallbackMap_;
786     std::map<int32_t, std::shared_ptr<MMI::PointerEvent>> currentEvents_;
787     ACE_DISALLOW_COPY_AND_MOVE(AceContainer);
788 };
789 
790 } // namespace OHOS::Ace::Platform
791 
792 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_CONTAINER_H
793