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