• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #include "frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.h"
17 
18 #include "base/subwindow/subwindow_manager.h"
19 #include "core/components_ng/base/view_stack_model.h"
20 #include "core/components_ng/pattern/stage/page_pattern.h"
21 #include "core/components_ng/pattern/overlay/dialog_manager.h"
22 #include "core/components_ng/render/adapter/component_snapshot.h"
23 #include "frameworks/core/common/ace_engine.h"
24 
25 namespace OHOS::Ace::Framework {
26 
27 namespace {
28 
29 const char MANIFEST_JSON[] = "manifest.json";
30 const char PAGES_JSON[] = "main_pages.json";
31 constexpr int32_t TOAST_TIME_MAX = 10000;    // ms
32 constexpr int32_t TOAST_TIME_DEFAULT = 1500; // ms
33 constexpr int32_t CALLBACK_ERRORCODE_CANCEL = 1;
34 constexpr int32_t CALLBACK_DATACODE_ZERO = 0;
35 
36 // helper function to run OverlayManager task
37 // ensures that the task runs in subwindow instead of main Window
MainWindowOverlay(std::function<void (RefPtr<NG::OverlayManager>)> && task,const std::string & name,const RefPtr<NG::OverlayManager> & overlay)38 void MainWindowOverlay(std::function<void(RefPtr<NG::OverlayManager>)>&& task, const std::string& name,
39     const RefPtr<NG::OverlayManager>& overlay)
40 {
41     auto currentId = Container::CurrentId();
42     ContainerScope scope(currentId);
43     auto context = NG::PipelineContext::GetCurrentContext();
44     CHECK_NULL_VOID(context);
45     auto overlayManager = context->GetOverlayManager();
46     if (overlay) {
47         overlayManager = overlay;
48     }
49     context->GetTaskExecutor()->PostTask(
50         [task = std::move(task), weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
51             auto overlayManager = weak.Upgrade();
52             task(overlayManager);
53         },
54         TaskExecutor::TaskType::UI, name);
55 }
56 } // namespace
57 
FrontendDelegateDeclarativeNG(const RefPtr<TaskExecutor> & taskExecutor)58 FrontendDelegateDeclarativeNG::FrontendDelegateDeclarativeNG(const RefPtr<TaskExecutor>& taskExecutor)
59     : taskExecutor_(taskExecutor), manifestParser_(AceType::MakeRefPtr<Framework::ManifestParser>()),
60       mediaQueryInfo_(AceType::MakeRefPtr<MediaQueryInfo>()),
61       jsAccessibilityManager_(AccessibilityNodeManager::Create())
62 {}
63 
SetMediaQueryCallback(MediaQueryCallback && mediaQueryCallback)64 void FrontendDelegateDeclarativeNG::SetMediaQueryCallback(MediaQueryCallback&& mediaQueryCallback)
65 {
66     mediaQueryCallback_ = mediaQueryCallback;
67 }
68 
SetLayoutInspectorCallback(const LayoutInspectorCallback & layoutInspectorCallback)69 void FrontendDelegateDeclarativeNG::SetLayoutInspectorCallback(const LayoutInspectorCallback& layoutInspectorCallback)
70 {
71     layoutInspectorCallback_ = layoutInspectorCallback;
72 }
73 
SetDrawInspectorCallback(const DrawInspectorCallback & drawInspectorCallback)74 void FrontendDelegateDeclarativeNG::SetDrawInspectorCallback(const DrawInspectorCallback& drawInspectorCallback)
75 {
76     drawInspectorCallback_ = drawInspectorCallback;
77 }
78 
SetOnStartContinuationCallBack(OnStartContinuationCallBack && onStartContinuationCallBack)79 void FrontendDelegateDeclarativeNG::SetOnStartContinuationCallBack(
80     OnStartContinuationCallBack&& onStartContinuationCallBack)
81 {
82     onStartContinuationCallBack_ = onStartContinuationCallBack;
83 }
84 
SetOnCompleteContinuationCallBack(OnCompleteContinuationCallBack && onCompleteContinuationCallBack)85 void FrontendDelegateDeclarativeNG::SetOnCompleteContinuationCallBack(
86     OnCompleteContinuationCallBack&& onCompleteContinuationCallBack)
87 {
88     onCompleteContinuationCallBack_ = onCompleteContinuationCallBack;
89 }
90 
SetOnSaveDataCallBack(OnSaveDataCallBack && onSaveDataCallBack)91 void FrontendDelegateDeclarativeNG::SetOnSaveDataCallBack(OnSaveDataCallBack&& onSaveDataCallBack)
92 {
93     onSaveDataCallBack_ = onSaveDataCallBack;
94 }
95 
SetOnRemoteTerminatedCallBack(OnRemoteTerminatedCallBack && onRemoteTerminatedCallBack)96 void FrontendDelegateDeclarativeNG::SetOnRemoteTerminatedCallBack(
97     OnRemoteTerminatedCallBack&& onRemoteTerminatedCallBack)
98 {
99     onRemoteTerminatedCallBack_ = onRemoteTerminatedCallBack;
100 }
101 
SetOnRestoreDataCallBack(OnRestoreDataCallBack && onRestoreDataCallBack)102 void FrontendDelegateDeclarativeNG::SetOnRestoreDataCallBack(OnRestoreDataCallBack&& onRestoreDataCallBack)
103 {
104     onRestoreDataCallBack_ = onRestoreDataCallBack;
105 }
106 
SetDestroyApplicationCallback(DestroyApplicationCallback && destroyApplicationCallback)107 void FrontendDelegateDeclarativeNG::SetDestroyApplicationCallback(
108     DestroyApplicationCallback&& destroyApplicationCallback)
109 {
110     destroyApplication_ = destroyApplicationCallback;
111 }
112 
SetUpdateApplicationStateCallback(UpdateApplicationStateCallback && updateApplicationStateCallback)113 void FrontendDelegateDeclarativeNG::SetUpdateApplicationStateCallback(
114     UpdateApplicationStateCallback&& updateApplicationStateCallback)
115 {
116     updateApplicationState_ = updateApplicationStateCallback;
117 }
118 
SetOnWindowDisplayModeChangedCallback(OnWindowDisplayModeChangedCallBack && onWindowDisplayModeChangedCallBack)119 void FrontendDelegateDeclarativeNG::SetOnWindowDisplayModeChangedCallback(
120     OnWindowDisplayModeChangedCallBack&& onWindowDisplayModeChangedCallBack)
121 {
122     onWindowDisplayModeChanged_ = onWindowDisplayModeChangedCallBack;
123 }
124 
SetExternalEventCallback(ExternalEventCallback && externalEventCallback)125 void FrontendDelegateDeclarativeNG::SetExternalEventCallback(ExternalEventCallback&& externalEventCallback)
126 {
127     externalEvent_ = externalEventCallback;
128 }
129 
SetTimerCallback(TimerCallback && timerCallback)130 void FrontendDelegateDeclarativeNG::SetTimerCallback(TimerCallback&& timerCallback)
131 {
132     timer_ = timerCallback;
133 }
134 
AttachPipelineContext(const RefPtr<PipelineBase> & context)135 void FrontendDelegateDeclarativeNG::AttachPipelineContext(const RefPtr<PipelineBase>& context)
136 {
137     if (!context) {
138         return;
139     }
140     context->SetOnPageShow([weak = AceType::WeakClaim(this)] {
141         auto delegate = weak.Upgrade();
142         if (delegate) {
143             delegate->OnPageShow();
144         }
145     });
146 
147     pipelineContextHolder_.Attach(context);
148     jsAccessibilityManager_->SetPipelineContext(context);
149     jsAccessibilityManager_->InitializeCallback();
150 }
151 
AttachSubPipelineContext(const RefPtr<PipelineBase> & context)152 void FrontendDelegateDeclarativeNG::AttachSubPipelineContext(const RefPtr<PipelineBase>& context)
153 {
154     if (!context) {
155         return;
156     }
157     jsAccessibilityManager_->AddSubPipelineContext(context);
158     jsAccessibilityManager_->RegisterSubWindowInteractionOperation(context->GetWindowId());
159 }
160 
RunPage(const std::string & url,const std::string & params,const std::string & profile,bool isNamedRouter)161 void FrontendDelegateDeclarativeNG::RunPage(
162     const std::string& url, const std::string& params, const std::string& profile, bool isNamedRouter)
163 {
164     ACE_SCOPED_TRACE("FrontendDelegateDeclarativeNG::RunPage");
165 
166     LOGI("Frontend delegate declarative run page, url=%{public}s", url.c_str());
167     std::string jsonContent;
168     if (GetAssetContent(MANIFEST_JSON, jsonContent)) {
169         manifestParser_->Parse(jsonContent);
170         manifestParser_->Printer();
171     } else if (!profile.empty() && GetAssetContent(profile, jsonContent)) {
172         manifestParser_->Parse(jsonContent);
173     } else if (GetAssetContent(PAGES_JSON, jsonContent)) {
174         manifestParser_->Parse(jsonContent);
175     }
176     std::string mainPagePath;
177     if (!url.empty()) {
178         mainPagePath = manifestParser_->GetRouter()->GetPagePath(url);
179     } else {
180         mainPagePath = manifestParser_->GetRouter()->GetEntry();
181     }
182     taskExecutor_->PostTask(
183         [manifestParser = manifestParser_, delegate = Claim(this),
184             weakPtr = WeakPtr<NG::PageRouterManager>(pageRouterManager_), url, params, isNamedRouter]() {
185             auto pageRouterManager = weakPtr.Upgrade();
186             CHECK_NULL_VOID(pageRouterManager);
187             pageRouterManager->SetManifestParser(manifestParser);
188             if (isNamedRouter) {
189                 pageRouterManager->RunPageByNamedRouter(url, params);
190             } else {
191                 pageRouterManager->RunPage(url, params);
192             }
193             auto pipeline = delegate->GetPipelineContext();
194             // TODO: get platform version from context, and should stored in AceApplicationInfo.
195             if (manifestParser->GetMinPlatformVersion() > 0) {
196                 pipeline->SetMinPlatformVersion(manifestParser->GetMinPlatformVersion());
197             }
198         },
199         TaskExecutor::TaskType::JS, "ArkUIRunPageUrl");
200 }
201 
RunPage(const std::shared_ptr<std::vector<uint8_t>> & content,const std::string & params,const std::string & profile)202 void FrontendDelegateDeclarativeNG::RunPage(
203     const std::shared_ptr<std::vector<uint8_t>>& content, const std::string& params, const std::string& profile)
204 {
205     ACE_SCOPED_TRACE("FrontendDelegateDeclarativeNG::RunPage %zu", content->size());
206     taskExecutor_->PostTask(
207         [delegate = Claim(this), weakPtr = WeakPtr<NG::PageRouterManager>(pageRouterManager_), content, params]() {
208             auto pageRouterManager = weakPtr.Upgrade();
209             CHECK_NULL_VOID(pageRouterManager);
210             pageRouterManager->RunPage(content, params);
211             auto pipeline = delegate->GetPipelineContext();
212         },
213         TaskExecutor::TaskType::JS, "ArkUIRunPageContent");
214 }
215 
OnConfigurationUpdated(const std::string & data)216 void FrontendDelegateDeclarativeNG::OnConfigurationUpdated(const std::string& data)
217 {
218     // only support mediaQueryUpdate
219     OnMediaQueryUpdate();
220 }
221 
OnStartContinuation()222 bool FrontendDelegateDeclarativeNG::OnStartContinuation()
223 {
224     bool ret = false;
225     taskExecutor_->PostSyncTask(
226         [weak = AceType::WeakClaim(this), &ret] {
227             auto delegate = weak.Upgrade();
228             if (delegate && delegate->onStartContinuationCallBack_) {
229                 ret = delegate->onStartContinuationCallBack_();
230             }
231         },
232         TaskExecutor::TaskType::JS, "ArkUIStartContinuation");
233     return ret;
234 }
235 
OnCompleteContinuation(int32_t code)236 void FrontendDelegateDeclarativeNG::OnCompleteContinuation(int32_t code)
237 {
238     taskExecutor_->PostSyncTask(
239         [weak = AceType::WeakClaim(this), code] {
240             auto delegate = weak.Upgrade();
241             if (delegate && delegate->onCompleteContinuationCallBack_) {
242                 delegate->onCompleteContinuationCallBack_(code);
243             }
244         },
245         TaskExecutor::TaskType::JS, "ArkUICompleteContinuation");
246 }
247 
OnRemoteTerminated()248 void FrontendDelegateDeclarativeNG::OnRemoteTerminated()
249 {
250     taskExecutor_->PostSyncTask(
251         [weak = AceType::WeakClaim(this)] {
252             auto delegate = weak.Upgrade();
253             if (delegate && delegate->onRemoteTerminatedCallBack_) {
254                 delegate->onRemoteTerminatedCallBack_();
255             }
256         },
257         TaskExecutor::TaskType::JS, "ArkUIRemoteTerminated");
258 }
259 
OnSaveData(std::string & data)260 void FrontendDelegateDeclarativeNG::OnSaveData(std::string& data)
261 {
262     std::string savedData;
263     taskExecutor_->PostSyncTask(
264         [weak = AceType::WeakClaim(this), &savedData] {
265             auto delegate = weak.Upgrade();
266             if (delegate && delegate->onSaveDataCallBack_) {
267                 delegate->onSaveDataCallBack_(savedData);
268             }
269         },
270         TaskExecutor::TaskType::JS, "ArkUISaveData");
271     std::string pageUri = GetCurrentPageUrl();
272     data = std::string("{\"url\":\"").append(pageUri).append("\",\"__remoteData\":").append(savedData).append("}");
273 }
274 
OnRestoreData(const std::string & data)275 bool FrontendDelegateDeclarativeNG::OnRestoreData(const std::string& data)
276 {
277     bool ret = false;
278     taskExecutor_->PostSyncTask(
279         [weak = AceType::WeakClaim(this), &data, &ret] {
280             auto delegate = weak.Upgrade();
281             if (delegate && delegate->onRestoreDataCallBack_) {
282                 ret = delegate->onRestoreDataCallBack_(data);
283             }
284         },
285         TaskExecutor::TaskType::JS, "ArkUIRestoreData");
286     return ret;
287 }
288 
OnApplicationDestroy(const std::string & packageName)289 void FrontendDelegateDeclarativeNG::OnApplicationDestroy(const std::string& packageName)
290 {
291     taskExecutor_->PostSyncTask(
292         [destroyApplication = destroyApplication_, packageName] { destroyApplication(packageName); },
293         TaskExecutor::TaskType::JS, "ArkUIApplicationDestroy");
294 }
295 
UpdateApplicationState(const std::string & packageName,Frontend::State state)296 void FrontendDelegateDeclarativeNG::UpdateApplicationState(const std::string& packageName, Frontend::State state)
297 {
298     taskExecutor_->PostTask([updateApplicationState = updateApplicationState_, packageName,
299                                 state] { updateApplicationState(packageName, state); },
300         TaskExecutor::TaskType::JS, "ArkUIUpdateApplicationState");
301 }
302 
OnWindowDisplayModeChanged(bool isShownInMultiWindow,const std::string & data)303 void FrontendDelegateDeclarativeNG::OnWindowDisplayModeChanged(bool isShownInMultiWindow, const std::string& data)
304 {
305     taskExecutor_->PostTask([onWindowDisplayModeChanged = onWindowDisplayModeChanged_, isShownInMultiWindow,
306                                 data] { onWindowDisplayModeChanged(isShownInMultiWindow, data); },
307         TaskExecutor::TaskType::JS, "ArkUIWindowDisplayModeChanged");
308 }
309 
NotifyAppStorage(const WeakPtr<Framework::JsEngine> & jsEngineWeak,const std::string & key,const std::string & value)310 void FrontendDelegateDeclarativeNG::NotifyAppStorage(
311     const WeakPtr<Framework::JsEngine>& jsEngineWeak, const std::string& key, const std::string& value)
312 {
313     taskExecutor_->PostTask(
314         [jsEngineWeak, key, value] {
315             auto jsEngine = jsEngineWeak.Upgrade();
316             if (!jsEngine) {
317                 return;
318             }
319             jsEngine->NotifyAppStorage(key, value);
320         },
321         TaskExecutor::TaskType::JS, "ArkUINotifyAppStorage");
322 }
323 
FireAccessibilityEvent(const AccessibilityEvent & accessibilityEvent)324 void FrontendDelegateDeclarativeNG::FireAccessibilityEvent(const AccessibilityEvent& accessibilityEvent)
325 {
326     jsAccessibilityManager_->SendAccessibilityAsyncEvent(accessibilityEvent);
327 }
328 
InitializeAccessibilityCallback()329 void FrontendDelegateDeclarativeNG::InitializeAccessibilityCallback()
330 {
331     jsAccessibilityManager_->InitializeCallback();
332 }
333 
FireExternalEvent(const std::string &,const std::string & componentId,const uint32_t nodeId,const bool isDestroy)334 void FrontendDelegateDeclarativeNG::FireExternalEvent(
335     const std::string& /* eventId */, const std::string& componentId, const uint32_t nodeId, const bool isDestroy)
336 {
337     taskExecutor_->PostSyncTask(
338         [weak = AceType::WeakClaim(this), componentId, nodeId, isDestroy] {
339             auto delegate = weak.Upgrade();
340             if (delegate) {
341                 delegate->externalEvent_(componentId, nodeId, isDestroy);
342             }
343         },
344         TaskExecutor::TaskType::JS, "ArkUIFireExternalEvent");
345 }
346 
WaitTimer(const std::string & callbackId,const std::string & delay,bool isInterval,bool isFirst)347 void FrontendDelegateDeclarativeNG::WaitTimer(
348     const std::string& callbackId, const std::string& delay, bool isInterval, bool isFirst)
349 {
350     if (!isFirst) {
351         auto timeoutTaskIter = timeoutTaskMap_.find(callbackId);
352         // If not find the callbackId in map, means this timer already was removed,
353         // no need create a new cancelableTimer again.
354         if (timeoutTaskIter == timeoutTaskMap_.end()) {
355             return;
356         }
357     }
358 
359     int32_t delayTime = StringToInt(delay);
360     // CancelableCallback class can only be executed once.
361     CancelableCallback<void()> cancelableTimer;
362     cancelableTimer.Reset([callbackId, delay, isInterval, call = timer_] { call(callbackId, delay, isInterval); });
363     auto result = timeoutTaskMap_.try_emplace(callbackId, cancelableTimer);
364     if (!result.second) {
365         result.first->second = cancelableTimer;
366     }
367     taskExecutor_->PostDelayedTask(cancelableTimer, TaskExecutor::TaskType::JS, delayTime, "ArkUIWaitTimer");
368 }
369 
ClearTimer(const std::string & callbackId)370 void FrontendDelegateDeclarativeNG::ClearTimer(const std::string& callbackId)
371 {
372     auto timeoutTaskIter = timeoutTaskMap_.find(callbackId);
373     if (timeoutTaskIter != timeoutTaskMap_.end()) {
374         timeoutTaskIter->second.Cancel();
375         timeoutTaskMap_.erase(timeoutTaskIter);
376     }
377 }
378 
Push(const std::string & uri,const std::string & params)379 void FrontendDelegateDeclarativeNG::Push(const std::string& uri, const std::string& params)
380 {
381     CHECK_NULL_VOID(pageRouterManager_);
382     NG::RouterPageInfo routerPageInfo;
383     routerPageInfo.url = uri;
384     routerPageInfo.params = params;
385     routerPageInfo.recoverable = true;
386     pageRouterManager_->Push(routerPageInfo);
387     OnMediaQueryUpdate();
388 }
389 
PushWithMode(const std::string & uri,const std::string & params,uint32_t routerMode)390 void FrontendDelegateDeclarativeNG::PushWithMode(const std::string& uri, const std::string& params, uint32_t routerMode)
391 {
392     CHECK_NULL_VOID(pageRouterManager_);
393     NG::RouterPageInfo routerPageInfo;
394     routerPageInfo.url = uri;
395     routerPageInfo.params = params;
396     routerPageInfo.recoverable = true;
397     routerPageInfo.routerMode = static_cast<NG::RouterMode>(routerMode);
398     pageRouterManager_->Push(routerPageInfo);
399     OnMediaQueryUpdate();
400 }
401 
PushWithCallback(const std::string & uri,const std::string & params,bool recoverable,const std::function<void (const std::string &,int32_t)> & errorCallback,uint32_t routerMode)402 void FrontendDelegateDeclarativeNG::PushWithCallback(const std::string& uri, const std::string& params,
403     bool recoverable, const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode)
404 {
405     CHECK_NULL_VOID(pageRouterManager_);
406     NG::RouterPageInfo routerPageInfo;
407     routerPageInfo.url = uri;
408     routerPageInfo.params = params;
409     routerPageInfo.recoverable = recoverable;
410     routerPageInfo.routerMode = static_cast<NG::RouterMode>(routerMode);
411     routerPageInfo.errorCallback = errorCallback;
412     pageRouterManager_->Push(routerPageInfo);
413     OnMediaQueryUpdate();
414 }
415 
PushNamedRoute(const std::string & uri,const std::string & params,bool recoverable,const std::function<void (const std::string &,int32_t)> & errorCallback,uint32_t routerMode)416 void FrontendDelegateDeclarativeNG::PushNamedRoute(const std::string& uri, const std::string& params,
417     bool recoverable, const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode)
418 {
419     CHECK_NULL_VOID(pageRouterManager_);
420     NG::RouterPageInfo routerPageInfo;
421     routerPageInfo.url = uri;
422     routerPageInfo.params = params;
423     routerPageInfo.recoverable = recoverable;
424     routerPageInfo.routerMode = static_cast<NG::RouterMode>(routerMode);
425     routerPageInfo.errorCallback = errorCallback;
426     pageRouterManager_->PushNamedRoute(routerPageInfo);
427     OnMediaQueryUpdate();
428 }
429 
Replace(const std::string & uri,const std::string & params)430 void FrontendDelegateDeclarativeNG::Replace(const std::string& uri, const std::string& params)
431 {
432     CHECK_NULL_VOID(pageRouterManager_);
433     NG::RouterPageInfo routerPageInfo;
434     routerPageInfo.url = uri;
435     routerPageInfo.params = params;
436     routerPageInfo.recoverable = true;
437     pageRouterManager_->Replace(routerPageInfo);
438 }
439 
ReplaceWithMode(const std::string & uri,const std::string & params,uint32_t routerMode)440 void FrontendDelegateDeclarativeNG::ReplaceWithMode(
441     const std::string& uri, const std::string& params, uint32_t routerMode)
442 {
443     CHECK_NULL_VOID(pageRouterManager_);
444     NG::RouterPageInfo routerPageInfo;
445     routerPageInfo.url = uri;
446     routerPageInfo.params = params;
447     routerPageInfo.recoverable = true;
448     routerPageInfo.routerMode = static_cast<NG::RouterMode>(routerMode);
449     pageRouterManager_->Replace(routerPageInfo);
450     OnMediaQueryUpdate();
451 }
452 
ReplaceWithCallback(const std::string & uri,const std::string & params,bool recoverable,const std::function<void (const std::string &,int32_t)> & errorCallback,uint32_t routerMode)453 void FrontendDelegateDeclarativeNG::ReplaceWithCallback(const std::string& uri, const std::string& params,
454     bool recoverable, const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode)
455 {
456     CHECK_NULL_VOID(pageRouterManager_);
457     NG::RouterPageInfo routerPageInfo;
458     routerPageInfo.url = uri;
459     routerPageInfo.params = params;
460     routerPageInfo.recoverable = recoverable;
461     routerPageInfo.routerMode = static_cast<NG::RouterMode>(routerMode);
462     routerPageInfo.errorCallback = errorCallback;
463     pageRouterManager_->Replace(routerPageInfo);
464     OnMediaQueryUpdate();
465 }
466 
ReplaceNamedRoute(const std::string & uri,const std::string & params,bool recoverable,const std::function<void (const std::string &,int32_t)> & errorCallback,uint32_t routerMode)467 void FrontendDelegateDeclarativeNG::ReplaceNamedRoute(const std::string& uri, const std::string& params,
468     bool recoverable, const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode)
469 {
470     CHECK_NULL_VOID(pageRouterManager_);
471     NG::RouterPageInfo routerPageInfo;
472     routerPageInfo.url = uri;
473     routerPageInfo.params = params;
474     routerPageInfo.recoverable = recoverable;
475     routerPageInfo.routerMode = static_cast<NG::RouterMode>(routerMode);
476     routerPageInfo.errorCallback = errorCallback;
477     pageRouterManager_->ReplaceNamedRoute(routerPageInfo);
478     OnMediaQueryUpdate();
479 }
480 
Back(const std::string & uri,const std::string & params)481 void FrontendDelegateDeclarativeNG::Back(const std::string& uri, const std::string& params)
482 {
483     CHECK_NULL_VOID(pageRouterManager_);
484     NG::RouterPageInfo routerPageInfo;
485     routerPageInfo.url = uri;
486     routerPageInfo.params = params;
487     pageRouterManager_->BackWithTarget(routerPageInfo);
488 }
489 
BackToIndex(int32_t index,const std::string & params)490 void FrontendDelegateDeclarativeNG::BackToIndex(int32_t index, const std::string& params)
491 {
492     CHECK_NULL_VOID(pageRouterManager_);
493     pageRouterManager_->BackToIndexWithTarget(index, params);
494 }
495 
Clear()496 void FrontendDelegateDeclarativeNG::Clear()
497 {
498     CHECK_NULL_VOID(pageRouterManager_);
499     pageRouterManager_->Clear();
500 }
501 
GetStackSize() const502 int32_t FrontendDelegateDeclarativeNG::GetStackSize() const
503 {
504     CHECK_NULL_RETURN(pageRouterManager_, 0);
505     return pageRouterManager_->GetStackSize();
506 }
507 
GetState(int32_t & index,std::string & name,std::string & path)508 void FrontendDelegateDeclarativeNG::GetState(int32_t& index, std::string& name, std::string& path)
509 {
510     CHECK_NULL_VOID(pageRouterManager_);
511     pageRouterManager_->GetState(index, name, path);
512 }
513 
GetRouterStateByIndex(int32_t & index,std::string & name,std::string & path,std::string & params)514 void FrontendDelegateDeclarativeNG::GetRouterStateByIndex(int32_t& index, std::string& name,
515     std::string& path, std::string& params)
516 {
517     CHECK_NULL_VOID(pageRouterManager_);
518     pageRouterManager_->GetStateByIndex(index, name, path, params);
519 }
520 
GetRouterStateByUrl(std::string & url,std::vector<StateInfo> & stateArray)521 void FrontendDelegateDeclarativeNG::GetRouterStateByUrl(std::string& url, std::vector<StateInfo>& stateArray)
522 {
523     CHECK_NULL_VOID(pageRouterManager_);
524     pageRouterManager_->GetStateByUrl(url, stateArray);
525 }
526 
GetParams()527 std::string FrontendDelegateDeclarativeNG::GetParams()
528 {
529     CHECK_NULL_RETURN(pageRouterManager_, "");
530     return pageRouterManager_->GetParams();
531 }
532 
NavigatePage(uint8_t type,const PageTarget & target,const std::string & params)533 void FrontendDelegateDeclarativeNG::NavigatePage(uint8_t type, const PageTarget& target, const std::string& params)
534 {
535     switch (static_cast<NavigatorType>(type)) {
536         case NavigatorType::PUSH:
537             Push(target.url, params);
538             break;
539         case NavigatorType::REPLACE:
540             Replace(target.url, params);
541             break;
542         case NavigatorType::BACK:
543             Back(target.url, params);
544             break;
545         default:
546             Back(target.url, params);
547     }
548 }
549 
PostJsTask(std::function<void ()> && task,const std::string & name)550 void FrontendDelegateDeclarativeNG::PostJsTask(std::function<void()>&& task, const std::string& name)
551 {
552     taskExecutor_->PostTask(task, TaskExecutor::TaskType::JS, name);
553 }
554 
GetAppID() const555 const std::string& FrontendDelegateDeclarativeNG::GetAppID() const
556 {
557     return manifestParser_->GetAppInfo()->GetAppID();
558 }
559 
GetAppName() const560 const std::string& FrontendDelegateDeclarativeNG::GetAppName() const
561 {
562     return manifestParser_->GetAppInfo()->GetAppName();
563 }
564 
GetVersionName() const565 const std::string& FrontendDelegateDeclarativeNG::GetVersionName() const
566 {
567     return manifestParser_->GetAppInfo()->GetVersionName();
568 }
569 
GetVersionCode() const570 int32_t FrontendDelegateDeclarativeNG::GetVersionCode() const
571 {
572     return manifestParser_->GetAppInfo()->GetVersionCode();
573 }
574 
PostSyncTaskToPage(std::function<void ()> && task,const std::string & name)575 void FrontendDelegateDeclarativeNG::PostSyncTaskToPage(std::function<void()>&& task, const std::string& name)
576 {
577     pipelineContextHolder_.Get(); // Wait until Pipeline Context is attached.
578     taskExecutor_->PostSyncTask(task, TaskExecutor::TaskType::UI, name);
579 }
580 
GetAssetContent(const std::string & url,std::string & content)581 bool FrontendDelegateDeclarativeNG::GetAssetContent(const std::string& url, std::string& content)
582 {
583     return GetAssetContentImpl(assetManager_, url, content);
584 }
585 
GetAssetContent(const std::string & url,std::vector<uint8_t> & content)586 bool FrontendDelegateDeclarativeNG::GetAssetContent(const std::string& url, std::vector<uint8_t>& content)
587 {
588     return GetAssetContentImpl(assetManager_, url, content);
589 }
590 
GetAssetPath(const std::string & url)591 std::string FrontendDelegateDeclarativeNG::GetAssetPath(const std::string& url)
592 {
593     return GetAssetPathImpl(assetManager_, url);
594 }
595 
ChangeLocale(const std::string & language,const std::string & countryOrRegion)596 void FrontendDelegateDeclarativeNG::ChangeLocale(const std::string& language, const std::string& countryOrRegion)
597 {
598     taskExecutor_->PostTask(
599         [language, countryOrRegion]() { AceApplicationInfo::GetInstance().ChangeLocale(language, countryOrRegion); },
600         TaskExecutor::TaskType::PLATFORM, "ArkUIChangeLocale");
601 }
602 
RegisterFont(const std::string & familyName,const std::string & familySrc,const std::string & bundleName,const std::string & moduleName)603 void FrontendDelegateDeclarativeNG::RegisterFont(const std::string& familyName, const std::string& familySrc,
604     const std::string& bundleName, const std::string& moduleName)
605 {
606     pipelineContextHolder_.Get()->RegisterFont(familyName, familySrc, bundleName, moduleName);
607 }
608 
GetSystemFontList(std::vector<std::string> & fontList)609 void FrontendDelegateDeclarativeNG::GetSystemFontList(std::vector<std::string>& fontList)
610 {
611     pipelineContextHolder_.Get()->GetSystemFontList(fontList);
612 }
613 
GetSystemFont(const std::string & fontName,FontInfo & fontInfo)614 bool FrontendDelegateDeclarativeNG::GetSystemFont(const std::string& fontName, FontInfo& fontInfo)
615 {
616     return pipelineContextHolder_.Get()->GetSystemFont(fontName, fontInfo);
617 }
618 
GetUIFontConfig(FontConfigJsonInfo & fontConfigJsonInfo)619 void FrontendDelegateDeclarativeNG::GetUIFontConfig(FontConfigJsonInfo& fontConfigJsonInfo)
620 {
621     pipelineContextHolder_.Get()->GetUIFontConfig(fontConfigJsonInfo);
622 }
623 
MeasureText(MeasureContext context)624 double FrontendDelegateDeclarativeNG::MeasureText(MeasureContext context)
625 {
626     if (context.isFontSizeUseDefaultUnit && context.fontSize.has_value() &&
627         !AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
628         context.fontSize = Dimension(context.fontSize->Value(), DimensionUnit::VP);
629     }
630     return MeasureUtil::MeasureText(context);
631 }
632 
MeasureTextSize(MeasureContext context)633 Size FrontendDelegateDeclarativeNG::MeasureTextSize(MeasureContext context)
634 {
635     if (context.isFontSizeUseDefaultUnit && context.fontSize.has_value() &&
636         !AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
637         context.fontSize = Dimension(context.fontSize->Value(), DimensionUnit::VP);
638     }
639     return MeasureUtil::MeasureTextSize(context);
640 }
641 
GetAnimationJsTask()642 SingleTaskExecutor FrontendDelegateDeclarativeNG::GetAnimationJsTask()
643 {
644     return SingleTaskExecutor::Make(taskExecutor_, TaskExecutor::TaskType::JS);
645 }
646 
GetUiTask()647 SingleTaskExecutor FrontendDelegateDeclarativeNG::GetUiTask()
648 {
649     return SingleTaskExecutor::Make(taskExecutor_, TaskExecutor::TaskType::UI);
650 }
651 
GetPipelineContext()652 RefPtr<PipelineBase> FrontendDelegateDeclarativeNG::GetPipelineContext()
653 {
654     return pipelineContextHolder_.Get();
655 }
656 
OnPageBackPress()657 bool FrontendDelegateDeclarativeNG::OnPageBackPress()
658 {
659     CHECK_NULL_RETURN(pageRouterManager_, false);
660     auto pageNode = pageRouterManager_->GetCurrentPageNode();
661     CHECK_NULL_RETURN(pageNode, false);
662     auto pagePattern = pageNode->GetPattern<NG::PagePattern>();
663     CHECK_NULL_RETURN(pagePattern, false);
664     if (pagePattern->OnBackPressed()) {
665         return true;
666     }
667     return pageRouterManager_->Pop();
668 }
669 
OnSurfaceChanged()670 void FrontendDelegateDeclarativeNG::OnSurfaceChanged()
671 {
672     if (mediaQueryInfo_->GetIsInit()) {
673         mediaQueryInfo_->SetIsInit(false);
674     }
675     mediaQueryInfo_->EnsureListenerIdValid();
676     OnMediaQueryUpdate();
677 }
678 
ShowDialog(const std::string & title,const std::string & message,const std::vector<ButtonInfo> & buttons,bool autoCancel,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)679 void FrontendDelegateDeclarativeNG::ShowDialog(const std::string& title, const std::string& message,
680     const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
681     const std::set<std::string>& callbacks)
682 {
683     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter");
684     DialogProperties dialogProperties = {
685         .type = DialogType::ALERT_DIALOG,
686         .title = title,
687         .content = message,
688         .autoCancel = autoCancel,
689         .buttons = buttons,
690     };
691     ShowDialogInner(dialogProperties, std::move(callback), callbacks);
692 }
693 
ShowDialog(const std::string & title,const std::string & message,const std::vector<ButtonInfo> & buttons,bool autoCancel,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks,std::function<void (bool)> && onStatusChanged)694 void FrontendDelegateDeclarativeNG::ShowDialog(const std::string& title, const std::string& message,
695     const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
696     const std::set<std::string>& callbacks, std::function<void(bool)>&& onStatusChanged)
697 {
698     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter");
699     DialogProperties dialogProperties = {
700         .type = DialogType::ALERT_DIALOG,
701         .title = title,
702         .content = message,
703         .autoCancel = autoCancel,
704         .buttons = buttons,
705         .onStatusChanged = std::move(onStatusChanged),
706     };
707     ShowDialogInner(dialogProperties, std::move(callback), callbacks);
708 }
709 
ShowDialog(const PromptDialogAttr & dialogAttr,const std::vector<ButtonInfo> & buttons,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)710 void FrontendDelegateDeclarativeNG::ShowDialog(const PromptDialogAttr& dialogAttr,
711     const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback,
712     const std::set<std::string>& callbacks)
713 {
714     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter");
715     DialogProperties dialogProperties = {
716         .type = DialogType::ALERT_DIALOG,
717         .title = dialogAttr.title,
718         .content = dialogAttr.message,
719         .autoCancel = dialogAttr.autoCancel,
720         .buttons = buttons,
721         .isShowInSubWindow = dialogAttr.showInSubWindow,
722         .isModal = dialogAttr.isModal,
723         .enableHoverMode = dialogAttr.enableHoverMode,
724         .maskRect = dialogAttr.maskRect,
725         .levelOrder = dialogAttr.levelOrder,
726         .dialogLevelMode = dialogAttr.dialogLevelMode,
727         .dialogLevelUniqueId = dialogAttr.dialogLevelUniqueId,
728         .dialogImmersiveMode = dialogAttr.dialogImmersiveMode,
729     };
730     if (dialogAttr.alignment.has_value()) {
731         dialogProperties.alignment = dialogAttr.alignment.value();
732     }
733     if (dialogAttr.offset.has_value()) {
734         dialogProperties.offset = dialogAttr.offset.value();
735     }
736     if (dialogAttr.shadow.has_value()) {
737         dialogProperties.shadow = dialogAttr.shadow.value();
738     }
739     if (dialogAttr.backgroundColor.has_value()) {
740         dialogProperties.backgroundColor = dialogAttr.backgroundColor.value();
741     }
742     if (dialogAttr.backgroundBlurStyle.has_value()) {
743         dialogProperties.backgroundBlurStyle = dialogAttr.backgroundBlurStyle.value();
744     }
745     if (dialogAttr.blurStyleOption.has_value()) {
746         dialogProperties.blurStyleOption = dialogAttr.blurStyleOption.value();
747     }
748     if (dialogAttr.effectOption.has_value()) {
749         dialogProperties.effectOption = dialogAttr.effectOption.value();
750     }
751     if (dialogAttr.hoverModeArea.has_value()) {
752         dialogProperties.hoverModeArea = dialogAttr.hoverModeArea.value();
753     }
754     ShowDialogInner(dialogProperties, std::move(callback), callbacks);
755 }
756 
ShowDialog(const PromptDialogAttr & dialogAttr,const std::vector<ButtonInfo> & buttons,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks,std::function<void (bool)> && onStatusChanged)757 void FrontendDelegateDeclarativeNG::ShowDialog(const PromptDialogAttr& dialogAttr,
758     const std::vector<ButtonInfo>& buttons, std::function<void(int32_t, int32_t)>&& callback,
759     const std::set<std::string>& callbacks, std::function<void(bool)>&& onStatusChanged)
760 {
761     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter");
762     DialogProperties dialogProperties = {
763         .type = DialogType::ALERT_DIALOG,
764         .title = dialogAttr.title,
765         .content = dialogAttr.message,
766         .autoCancel = dialogAttr.autoCancel,
767         .buttons = buttons,
768         .isShowInSubWindow = dialogAttr.showInSubWindow,
769         .isModal = dialogAttr.isModal,
770         .onStatusChanged = std::move(onStatusChanged),
771         .maskRect = dialogAttr.maskRect,
772         .levelOrder = dialogAttr.levelOrder,
773     };
774     if (dialogAttr.alignment.has_value()) {
775         dialogProperties.alignment = dialogAttr.alignment.value();
776     }
777     if (dialogAttr.offset.has_value()) {
778         dialogProperties.offset = dialogAttr.offset.value();
779     }
780     ShowDialogInner(dialogProperties, std::move(callback), callbacks);
781 }
782 
ParsePropertiesFromAttr(const PromptDialogAttr & dialogAttr)783 DialogProperties FrontendDelegateDeclarativeNG::ParsePropertiesFromAttr(const PromptDialogAttr &dialogAttr)
784 {
785     DialogProperties dialogProperties = {
786         .autoCancel = dialogAttr.autoCancel, .customStyle = dialogAttr.customStyle,
787         .onWillDismiss = dialogAttr.customOnWillDismiss, .maskColor = dialogAttr.maskColor,
788         .backgroundColor = dialogAttr.backgroundColor, .borderRadius = dialogAttr.borderRadius,
789         .isShowInSubWindow = dialogAttr.showInSubWindow, .isModal = dialogAttr.isModal,
790         .enableHoverMode = dialogAttr.enableHoverMode, .customBuilder = dialogAttr.customBuilder,
791         .customBuilderWithId = dialogAttr.customBuilderWithId,
792         .blurStyleOption = dialogAttr.blurStyleOption,
793         .effectOption = dialogAttr.effectOption,
794         .borderWidth = dialogAttr.borderWidth,
795         .borderColor = dialogAttr.borderColor, .borderStyle = dialogAttr.borderStyle, .shadow = dialogAttr.shadow,
796         .width = dialogAttr.width, .height = dialogAttr.height,
797         .isUserCreatedDialog = dialogAttr.isUserCreatedDialog,
798         .maskRect = dialogAttr.maskRect,
799         .transitionEffect = dialogAttr.transitionEffect, .contentNode = dialogAttr.contentNode,
800         .onDidAppear = dialogAttr.onDidAppear, .onDidDisappear = dialogAttr.onDidDisappear,
801         .onWillAppear = dialogAttr.onWillAppear, .onWillDisappear = dialogAttr.onWillDisappear,
802         .keyboardAvoidMode = dialogAttr.keyboardAvoidMode, .dialogCallback = dialogAttr.dialogCallback,
803         .keyboardAvoidDistance = dialogAttr.keyboardAvoidDistance,
804         .levelOrder = dialogAttr.levelOrder,
805         .focusable = dialogAttr.focusable,
806         .dialogLevelMode = dialogAttr.dialogLevelMode,
807         .dialogLevelUniqueId = dialogAttr.dialogLevelUniqueId,
808         .dialogImmersiveMode = dialogAttr.dialogImmersiveMode
809     };
810 #if defined(PREVIEW)
811     if (dialogProperties.isShowInSubWindow) {
812         LOGW("[Engine Log] Unable to use the SubWindow in the Previewer. Perform this operation on the "
813              "emulator or a real device instead.");
814         dialogProperties.isShowInSubWindow = false;
815     }
816 #endif
817     if (dialogAttr.alignment.has_value()) {
818         dialogProperties.alignment = dialogAttr.alignment.value();
819     }
820     if (dialogAttr.offset.has_value()) {
821         dialogProperties.offset = dialogAttr.offset.value();
822     }
823     if (dialogAttr.hoverModeArea.has_value()) {
824         dialogProperties.hoverModeArea = dialogAttr.hoverModeArea.value();
825     }
826     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWELVE)) {
827         dialogProperties.isSysBlurStyle = false;
828     } else {
829         if (dialogAttr.backgroundBlurStyle.has_value()) {
830             dialogProperties.backgroundBlurStyle = dialogAttr.backgroundBlurStyle.value();
831         }
832     }
833     return dialogProperties;
834 }
835 
OpenCustomDialog(const PromptDialogAttr & dialogAttr,std::function<void (int32_t)> && callback)836 void FrontendDelegateDeclarativeNG::OpenCustomDialog(const PromptDialogAttr &dialogAttr,
837     std::function<void(int32_t)> &&callback)
838 {
839     DialogProperties dialogProperties = ParsePropertiesFromAttr(dialogAttr);
840     if (Container::IsCurrentUseNewPipeline()) {
841         auto task = [dialogAttr, dialogProperties, callback](const RefPtr<NG::OverlayManager>& overlayManager) mutable {
842             CHECK_NULL_VOID(overlayManager);
843             TAG_LOGD(AceLogTag::ACE_OVERLAY, "Begin to open custom dialog ");
844             if (dialogProperties.isShowInSubWindow) {
845                 SubwindowManager::GetInstance()->OpenCustomDialogNG(dialogProperties, std::move(callback));
846                 if (dialogProperties.isModal) {
847                     TAG_LOGW(AceLogTag::ACE_OVERLAY, "temporary not support isShowInSubWindow and isModal");
848                 }
849             } else {
850                 overlayManager->OpenCustomDialog(dialogProperties, std::move(callback));
851             }
852         };
853         if (dialogProperties.dialogLevelMode == LevelMode::EMBEDDED) {
854             NG::DialogManager::ShowInEmbeddedOverlay(
855                 std::move(task), "ArkUIOverlayShowDialog", dialogProperties.dialogLevelUniqueId);
856         } else {
857             MainWindowOverlay(std::move(task), "ArkUIOverlayOpenCustomDialog", nullptr);
858         }
859         return;
860     } else {
861         TAG_LOGW(AceLogTag::ACE_OVERLAY, "not support old pipeline");
862     }
863 }
864 
CloseCustomDialog(const int32_t dialogId)865 void FrontendDelegateDeclarativeNG::CloseCustomDialog(const int32_t dialogId)
866 {
867     auto task = [dialogId](const RefPtr<NG::OverlayManager>& overlayManager) {
868         CHECK_NULL_VOID(overlayManager);
869         TAG_LOGD(AceLogTag::ACE_OVERLAY, "begin to close custom dialog.");
870         overlayManager->CloseCustomDialog(dialogId);
871         SubwindowManager::GetInstance()->CloseCustomDialogNG(dialogId);
872     };
873     auto dialogNode = NG::FrameNode::GetFrameNodeOnly(V2::DIALOG_ETS_TAG, dialogId);
874     auto currentOverlay = NG::DialogManager::GetInstance().GetEmbeddedOverlayWithNode(dialogNode);
875     MainWindowOverlay(std::move(task), "ArkUIOverlayCloseCustomDialog", currentOverlay);
876     return;
877 }
878 
CloseCustomDialog(const WeakPtr<NG::UINode> & node,std::function<void (int32_t)> && callback)879 void FrontendDelegateDeclarativeNG::CloseCustomDialog(const WeakPtr<NG::UINode>& node,
880     std::function<void(int32_t)> &&callback)
881 {
882     auto nodePtr = node.Upgrade();
883     CHECK_NULL_VOID(nodePtr);
884     auto context = nodePtr->GetContextWithCheck();
885     CHECK_NULL_VOID(context);
886     auto overlayManager = context->GetOverlayManager();
887     auto parent = NG::DialogManager::GetInstance().GetDialogNodeByContentNode(nodePtr);
888     if (parent) {
889         auto currentOverlay = NG::DialogManager::GetInstance().GetEmbeddedOverlayWithNode(parent);
890         if (currentOverlay) {
891             overlayManager = currentOverlay;
892         }
893     }
894     context->GetTaskExecutor()->PostTask(
895         [node, callback, weak = WeakPtr<NG::OverlayManager>(overlayManager)]() mutable {
896             auto overlayManager = weak.Upgrade();
897             CHECK_NULL_VOID(overlayManager);
898             TAG_LOGI(AceLogTag::ACE_OVERLAY, "begin to close custom dialog.");
899             overlayManager->CloseCustomDialog(node, std::move(callback));
900         },
901         TaskExecutor::TaskType::UI, "ArkUIOverlayCloseCustomDialog");
902 }
903 
UpdateCustomDialog(const WeakPtr<NG::UINode> & node,const PromptDialogAttr & dialogAttr,std::function<void (int32_t)> && callback)904 void FrontendDelegateDeclarativeNG::UpdateCustomDialog(
905     const WeakPtr<NG::UINode>& node, const PromptDialogAttr &dialogAttr, std::function<void(int32_t)> &&callback)
906 {
907     DialogProperties dialogProperties = {
908         .autoCancel = dialogAttr.autoCancel,
909         .maskColor = dialogAttr.maskColor,
910         .isSysBlurStyle = false
911     };
912     if (dialogAttr.alignment.has_value()) {
913         dialogProperties.alignment = dialogAttr.alignment.value();
914     }
915     if (dialogAttr.offset.has_value()) {
916         dialogProperties.offset = dialogAttr.offset.value();
917     }
918 
919     auto nodePtr = node.Upgrade();
920     CHECK_NULL_VOID(nodePtr);
921     auto context = nodePtr->GetContextWithCheck();
922     CHECK_NULL_VOID(context);
923     auto overlayManager = context->GetOverlayManager();
924     context->GetTaskExecutor()->PostTask(
925         [dialogProperties, node, callback, weak = WeakPtr<NG::OverlayManager>(overlayManager)]() mutable {
926             auto overlayManager = weak.Upgrade();
927             CHECK_NULL_VOID(overlayManager);
928             TAG_LOGI(AceLogTag::ACE_OVERLAY, "begin to update custom dialog.");
929             overlayManager->UpdateCustomDialog(node, dialogProperties, std::move(callback));
930         },
931         TaskExecutor::TaskType::UI, "ArkUIOverlayUpdateCustomDialog");
932 }
933 
GetTopOrder()934 std::optional<double> FrontendDelegateDeclarativeNG::GetTopOrder()
935 {
936     auto currentId = Container::CurrentId();
937     ContainerScope scope(currentId);
938     auto context = NG::PipelineContext::GetCurrentContext();
939     CHECK_NULL_RETURN(context, std::nullopt);
940     auto overlayManager = context->GetOverlayManager();
941     CHECK_NULL_RETURN(overlayManager, std::nullopt);
942     return overlayManager->GetTopOrder();
943 }
944 
GetBottomOrder()945 std::optional<double> FrontendDelegateDeclarativeNG::GetBottomOrder()
946 {
947     auto currentId = Container::CurrentId();
948     ContainerScope scope(currentId);
949     auto context = NG::PipelineContext::GetCurrentContext();
950     CHECK_NULL_RETURN(context, std::nullopt);
951     auto overlayManager = context->GetOverlayManager();
952     CHECK_NULL_RETURN(overlayManager, std::nullopt);
953     return overlayManager->GetBottomOrder();
954 }
955 
ShowActionMenu(const std::string & title,const std::vector<ButtonInfo> & button,std::function<void (int32_t,int32_t)> && callback)956 void FrontendDelegateDeclarativeNG::ShowActionMenu(
957     const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback)
958 {
959     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show action menu enter");
960     DialogProperties dialogProperties = {
961         .title = title,
962         .autoCancel = true,
963         .isMenu = true,
964         .buttons = button,
965     };
966     ShowActionMenuInner(dialogProperties, button, std::move(callback));
967 }
968 
ShowActionMenu(const std::string & title,const std::vector<ButtonInfo> & button,std::function<void (int32_t,int32_t)> && callback,std::function<void (bool)> && onStatusChanged)969 void FrontendDelegateDeclarativeNG::ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
970     std::function<void(int32_t, int32_t)>&& callback, std::function<void(bool)>&& onStatusChanged)
971 {
972     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show action menu enter");
973     DialogProperties dialogProperties = {
974         .title = title,
975         .autoCancel = true,
976         .isMenu = true,
977         .buttons = button,
978         .onStatusChanged = std::move(onStatusChanged),
979     };
980     ShowActionMenuInner(dialogProperties, button, std::move(callback));
981 }
982 
OnMediaQueryUpdate(bool isSynchronous)983 void FrontendDelegateDeclarativeNG::OnMediaQueryUpdate(bool isSynchronous)
984 {
985     auto containerId = Container::CurrentId();
986     if (containerId < 0) {
987         auto container = Container::GetActive();
988         if (container) {
989             containerId = container->GetInstanceId();
990         }
991     }
992     bool isInSubwindow = containerId >= 1000000;
993     if (isInSubwindow) {
994         return;
995     }
996     if (mediaQueryInfo_->GetIsInit()) {
997         return;
998     }
999 
1000     taskExecutor_->PostTask(
1001         [weak = AceType::WeakClaim(this)] {
1002             auto delegate = weak.Upgrade();
1003             if (!delegate) {
1004                 return;
1005             }
1006             const auto& info = delegate->mediaQueryInfo_->GetMediaQueryInfo();
1007 
1008             // request js media query
1009             const auto& listenerId = delegate->mediaQueryInfo_->GetListenerId();
1010             delegate->mediaQueryCallback_(listenerId, info);
1011             delegate->mediaQueryInfo_->ResetListenerId();
1012         },
1013         TaskExecutor::TaskType::JS, "ArkUIMediaQueryUpdate");
1014 }
1015 
OnLayoutCompleted(const std::string & componentId)1016 void FrontendDelegateDeclarativeNG::OnLayoutCompleted(const std::string& componentId)
1017 {
1018     taskExecutor_->PostTask(
1019         [weak = AceType::WeakClaim(this), componentId] {
1020             auto delegate = weak.Upgrade();
1021             if (!delegate) {
1022                 return;
1023             }
1024             delegate->layoutInspectorCallback_(componentId);
1025         },
1026         TaskExecutor::TaskType::JS, "ArkUILayoutCompleted");
1027 }
1028 
OnDrawCompleted(const std::string & componentId)1029 void FrontendDelegateDeclarativeNG::OnDrawCompleted(const std::string& componentId)
1030 {
1031     taskExecutor_->PostTask(
1032         [weak = AceType::WeakClaim(this), componentId] {
1033             auto delegate = weak.Upgrade();
1034             if (!delegate) {
1035                 return;
1036             }
1037             delegate->drawInspectorCallback_(componentId);
1038         },
1039         TaskExecutor::TaskType::JS, "ArkUIDrawCompleted");
1040 }
1041 
SetColorMode(ColorMode colorMode)1042 void FrontendDelegateDeclarativeNG::SetColorMode(ColorMode colorMode)
1043 {
1044     OnMediaQueryUpdate();
1045 }
1046 
OnForeground()1047 void FrontendDelegateDeclarativeNG::OnForeground()
1048 {
1049     if (!isFirstNotifyShow_) {
1050         OnPageShow();
1051     }
1052     isFirstNotifyShow_ = false;
1053 }
1054 
GetCurrentPageUrl()1055 std::string FrontendDelegateDeclarativeNG::GetCurrentPageUrl()
1056 {
1057     CHECK_NULL_RETURN(pageRouterManager_, "");
1058     return pageRouterManager_->GetCurrentPageUrl();
1059 }
1060 
1061 // Get the currently running JS page information in NG structure.
GetCurrentPageSourceMap()1062 RefPtr<RevSourceMap> FrontendDelegateDeclarativeNG::GetCurrentPageSourceMap()
1063 {
1064     CHECK_NULL_RETURN(pageRouterManager_, nullptr);
1065     return pageRouterManager_->GetCurrentPageSourceMap(assetManager_);
1066 }
1067 
1068 // Get the currently running JS page information in NG structure.
GetFaAppSourceMap()1069 RefPtr<RevSourceMap> FrontendDelegateDeclarativeNG::GetFaAppSourceMap()
1070 {
1071     if (appSourceMap_) {
1072         return appSourceMap_;
1073     }
1074     std::string appMap;
1075     if (GetAssetContent("app.js.map", appMap)) {
1076         appSourceMap_ = AceType::MakeRefPtr<RevSourceMap>();
1077         appSourceMap_->Init(appMap);
1078     }
1079     return appSourceMap_;
1080 }
1081 
GetStageSourceMap(std::unordered_map<std::string,RefPtr<Framework::RevSourceMap>> & sourceMaps)1082 void FrontendDelegateDeclarativeNG::GetStageSourceMap(
1083     std::unordered_map<std::string, RefPtr<Framework::RevSourceMap>>& sourceMaps)
1084 {
1085     std::string maps;
1086     if (GetAssetContent(MERGE_SOURCEMAPS_PATH, maps)) {
1087         auto SourceMap = AceType::MakeRefPtr<RevSourceMap>();
1088         SourceMap->StageModeSourceMapSplit(maps, sourceMaps);
1089     }
1090 }
1091 
CallPopPage()1092 void FrontendDelegateDeclarativeNG::CallPopPage()
1093 {
1094     Back("", "");
1095 }
1096 
PostponePageTransition()1097 void FrontendDelegateDeclarativeNG::PostponePageTransition()
1098 {
1099     taskExecutor_->PostTask(
1100         [weak = AceType::WeakClaim(this)] {
1101             auto delegate = weak.Upgrade();
1102             if (!delegate) {
1103                 return;
1104             }
1105             auto pipelineContext = delegate->pipelineContextHolder_.Get();
1106             pipelineContext->PostponePageTransition();
1107         },
1108         TaskExecutor::TaskType::UI, "ArkUIPostponePageTransition");
1109 }
1110 
LaunchPageTransition()1111 void FrontendDelegateDeclarativeNG::LaunchPageTransition()
1112 {
1113     taskExecutor_->PostTask(
1114         [weak = AceType::WeakClaim(this)] {
1115             auto delegate = weak.Upgrade();
1116             if (!delegate) {
1117                 return;
1118             }
1119             auto pipelineContext = delegate->pipelineContextHolder_.Get();
1120             pipelineContext->LaunchPageTransition();
1121         },
1122         TaskExecutor::TaskType::UI, "ArkUILaunchPageTransition");
1123 }
1124 
GetComponentsCount()1125 size_t FrontendDelegateDeclarativeNG::GetComponentsCount()
1126 {
1127     CHECK_NULL_RETURN(pageRouterManager_, 0);
1128     auto pageNode = pageRouterManager_->GetCurrentPageNode();
1129     CHECK_NULL_RETURN(pageNode, 0);
1130     return pageNode->GetAllDepthChildrenCount();
1131 }
1132 
ShowToast(const NG::ToastInfo & toastInfo,std::function<void (int32_t)> && callback)1133 void FrontendDelegateDeclarativeNG::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
1134 {
1135     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show toast enter");
1136     NG::ToastInfo updatedToastInfo = toastInfo;
1137     updatedToastInfo.duration = std::clamp(toastInfo.duration, TOAST_TIME_DEFAULT, TOAST_TIME_MAX);
1138     updatedToastInfo.isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
1139     auto task = [updatedToastInfo, callbackParam = std::move(callback), containerId = Container::CurrentId()](
1140                     const RefPtr<NG::OverlayManager>& overlayManager) {
1141         CHECK_NULL_VOID(overlayManager);
1142         ContainerScope scope(containerId);
1143         overlayManager->ShowToast(
1144             updatedToastInfo, std::move(const_cast<std::function<void(int32_t)>&&>(callbackParam)));
1145     };
1146     MainWindowOverlay(std::move(task), "ArkUIOverlayShowToast", nullptr);
1147 }
1148 
CloseToast(const int32_t toastId,std::function<void (int32_t)> && callback)1149 void FrontendDelegateDeclarativeNG::CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback)
1150 {
1151     TAG_LOGD(AceLogTag::ACE_OVERLAY, "close toast enter");
1152     auto currentId = Container::CurrentId();
1153     ContainerScope scope(currentId);
1154     auto context = NG::PipelineContext::GetCurrentContext();
1155     CHECK_NULL_VOID(context);
1156     auto overlayManager = context->GetOverlayManager();
1157     CHECK_NULL_VOID(overlayManager);
1158     overlayManager->CloseToast(toastId, std::move(callback));
1159 }
1160 
ShowDialogInner(DialogProperties & dialogProperties,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)1161 void FrontendDelegateDeclarativeNG::ShowDialogInner(DialogProperties& dialogProperties,
1162     std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks)
1163 {
1164     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog inner enter");
1165     dialogProperties.onSuccess = std::move(callback);
1166     dialogProperties.onCancel = [callback, taskExecutor = taskExecutor_] {
1167         taskExecutor->PostTask(
1168             [callback]() { callback(CALLBACK_ERRORCODE_CANCEL, CALLBACK_DATACODE_ZERO); },
1169             TaskExecutor::TaskType::JS, "ArkUIOverlayShowDialogCancel");
1170     };
1171     auto task = [dialogProperties](const RefPtr<NG::OverlayManager>& overlayManager) {
1172         LOGI("Begin to show dialog ");
1173         CHECK_NULL_VOID(overlayManager);
1174         auto container = Container::Current();
1175         CHECK_NULL_VOID(container);
1176         if (container->IsSubContainer()) {
1177             auto currentId = SubwindowManager::GetInstance()->GetParentContainerId(Container::CurrentId());
1178             container = AceEngine::Get().GetContainer(currentId);
1179             CHECK_NULL_VOID(container);
1180         }
1181         RefPtr<NG::FrameNode> dialog;
1182         if (dialogProperties.isShowInSubWindow) {
1183             dialog = SubwindowManager::GetInstance()->ShowDialogNG(dialogProperties, nullptr);
1184             CHECK_NULL_VOID(dialog);
1185             if (dialogProperties.isModal && !container->IsUIExtensionWindow()) {
1186                 DialogProperties Maskarg;
1187                 Maskarg.isMask = true;
1188                 Maskarg.autoCancel = dialogProperties.autoCancel;
1189                 auto mask = overlayManager->ShowDialog(Maskarg, nullptr, false);
1190                 CHECK_NULL_VOID(mask);
1191                 overlayManager->SetMaskNodeId(dialog->GetId(), mask->GetId());
1192             }
1193         } else {
1194             dialog = overlayManager->ShowDialog(
1195                 dialogProperties, nullptr, AceApplicationInfo::GetInstance().IsRightToLeft());
1196             CHECK_NULL_VOID(dialog);
1197         }
1198     };
1199     if (dialogProperties.dialogLevelMode == LevelMode::EMBEDDED) {
1200         NG::DialogManager::ShowInEmbeddedOverlay(
1201             std::move(task), "ArkUIOverlayShowDialog", dialogProperties.dialogLevelUniqueId);
1202     } else {
1203         MainWindowOverlay(std::move(task), "ArkUIOverlayShowDialog", nullptr);
1204     }
1205     return;
1206 }
1207 
ShowActionMenuInner(DialogProperties & dialogProperties,const std::vector<ButtonInfo> & button,std::function<void (int32_t,int32_t)> && callback)1208 void FrontendDelegateDeclarativeNG::ShowActionMenuInner(DialogProperties& dialogProperties,
1209     const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback)
1210 {
1211     TAG_LOGD(AceLogTag::ACE_OVERLAY, "show action menu inner enter");
1212     dialogProperties.onSuccess = std::move(callback);
1213     dialogProperties.onCancel = [callback, taskExecutor = taskExecutor_] {
1214         taskExecutor->PostTask(
1215             [callback]() { callback(CALLBACK_ERRORCODE_CANCEL, CALLBACK_DATACODE_ZERO); },
1216             TaskExecutor::TaskType::JS, "ArkUIOverlayShowActionMenuCancel");
1217     };
1218     auto context = DynamicCast<NG::PipelineContext>(pipelineContextHolder_.Get());
1219     auto overlayManager = context ? context->GetOverlayManager() : nullptr;
1220     taskExecutor_->PostTask(
1221         [dialogProperties, weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
1222             auto overlayManager = weak.Upgrade();
1223             CHECK_NULL_VOID(overlayManager);
1224             overlayManager->ShowDialog(dialogProperties, nullptr, AceApplicationInfo::GetInstance().IsRightToLeft());
1225         },
1226         TaskExecutor::TaskType::UI, "ArkUIOverlayShowActionMenu");
1227     return;
1228 }
1229 
EnableAlertBeforeBackPage(const std::string & message,std::function<void (int32_t)> && callback)1230 void FrontendDelegateDeclarativeNG::EnableAlertBeforeBackPage(
1231     const std::string& message, std::function<void(int32_t)>&& callback)
1232 {
1233     CHECK_NULL_VOID(pageRouterManager_);
1234     pageRouterManager_->EnableAlertBeforeBackPage(message, std::move(callback));
1235     return;
1236 }
1237 
DisableAlertBeforeBackPage()1238 void FrontendDelegateDeclarativeNG::DisableAlertBeforeBackPage()
1239 {
1240     CHECK_NULL_VOID(pageRouterManager_);
1241     pageRouterManager_->DisableAlertBeforeBackPage();
1242     return;
1243 }
1244 
RebuildAllPages()1245 void FrontendDelegateDeclarativeNG::RebuildAllPages()
1246 {
1247     CHECK_NULL_VOID(pageRouterManager_);
1248     auto url = pageRouterManager_->GetCurrentPageUrl();
1249     pageRouterManager_->Clear();
1250     pageRouterManager_->RunPage(url, "");
1251     return;
1252 }
1253 
OnPageShow()1254 void FrontendDelegateDeclarativeNG::OnPageShow()
1255 {
1256     CHECK_NULL_VOID(pageRouterManager_);
1257     auto pageNode = pageRouterManager_->GetCurrentPageNode();
1258     CHECK_NULL_VOID(pageNode);
1259     auto pagePattern = pageNode->GetPattern<NG::PagePattern>();
1260     CHECK_NULL_VOID(pagePattern);
1261     pagePattern->OnShow();
1262 }
1263 
OnPageHide()1264 void FrontendDelegateDeclarativeNG::OnPageHide()
1265 {
1266     CHECK_NULL_VOID(pageRouterManager_);
1267     auto pageNode = pageRouterManager_->GetCurrentPageNode();
1268     CHECK_NULL_VOID(pageNode);
1269     auto pagePattern = pageNode->GetPattern<NG::PagePattern>();
1270     CHECK_NULL_VOID(pagePattern);
1271     pagePattern->OnHide();
1272 }
1273 
GetSnapshot(const std::string & componentId,NG::ComponentSnapshot::JsCallback && callback,const NG::SnapshotOptions & options)1274 void FrontendDelegateDeclarativeNG::GetSnapshot(
1275     const std::string& componentId, NG::ComponentSnapshot::JsCallback&& callback, const NG::SnapshotOptions& options)
1276 {
1277 #ifdef ENABLE_ROSEN_BACKEND
1278     NG::ComponentSnapshot::Get(componentId, std::move(callback), options);
1279 #endif
1280 }
1281 
GetSyncSnapshot(RefPtr<NG::FrameNode> & node,const NG::SnapshotOptions & options)1282 std::pair<int32_t, std::shared_ptr<Media::PixelMap>> FrontendDelegateDeclarativeNG::GetSyncSnapshot(
1283     RefPtr<NG::FrameNode>& node, const NG::SnapshotOptions& options)
1284 {
1285 #ifdef ENABLE_ROSEN_BACKEND
1286     return NG::ComponentSnapshot::GetSync(node, options);
1287 #endif
1288     return { ERROR_CODE_INTERNAL_ERROR, nullptr };
1289 }
1290 
GetSyncSnapshot(const std::string & componentId,const NG::SnapshotOptions & options)1291 std::pair<int32_t, std::shared_ptr<Media::PixelMap>> FrontendDelegateDeclarativeNG::GetSyncSnapshot(
1292     const std::string& componentId, const NG::SnapshotOptions& options)
1293 {
1294 #ifdef ENABLE_ROSEN_BACKEND
1295     return NG::ComponentSnapshot::GetSync(componentId, options);
1296 #endif
1297     return {ERROR_CODE_INTERNAL_ERROR, nullptr};
1298 }
1299 
GetSnapshotByUniqueId(int32_t uniqueId,std::function<void (std::shared_ptr<Media::PixelMap>,int32_t,std::function<void ()>)> && callback,const NG::SnapshotOptions & options)1300 void FrontendDelegateDeclarativeNG::GetSnapshotByUniqueId(int32_t uniqueId,
1301     std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
1302     const NG::SnapshotOptions& options)
1303 {
1304 #ifdef ENABLE_ROSEN_BACKEND
1305     NG::ComponentSnapshot::GetByUniqueId(uniqueId, std::move(callback), options);
1306 #endif
1307 }
1308 
GetSyncSnapshotByUniqueId(int32_t uniqueId,const NG::SnapshotOptions & options)1309 std::pair<int32_t, std::shared_ptr<Media::PixelMap>> FrontendDelegateDeclarativeNG::GetSyncSnapshotByUniqueId(
1310     int32_t uniqueId, const NG::SnapshotOptions& options)
1311 {
1312 #ifdef ENABLE_ROSEN_BACKEND
1313     return NG::ComponentSnapshot::GetSyncByUniqueId(uniqueId, options);
1314 #endif
1315     return {ERROR_CODE_INTERNAL_ERROR, nullptr};
1316 }
1317 
CreateSnapshotFromComponent(const RefPtr<NG::UINode> & nodeWk,NG::ComponentSnapshot::JsCallback && callback,bool enableInspector,const NG::SnapshotParam & param)1318 void FrontendDelegateDeclarativeNG::CreateSnapshotFromComponent(const RefPtr<NG::UINode>& nodeWk,
1319     NG::ComponentSnapshot::JsCallback&& callback, bool enableInspector, const NG::SnapshotParam& param)
1320 {
1321 #ifdef ENABLE_ROSEN_BACKEND
1322     ViewStackModel::GetInstance()->NewScope();
1323     NG::ComponentSnapshot::Create(nodeWk, std::move(callback), enableInspector, param);
1324 #endif
1325 }
1326 
GetContentInfo(ContentInfoType type)1327 std::string FrontendDelegateDeclarativeNG::GetContentInfo(ContentInfoType type)
1328 {
1329     auto jsonContentInfo = JsonUtil::Create(true);
1330 
1331     CHECK_NULL_RETURN(pageRouterManager_, "");
1332     jsonContentInfo->Put("stackInfo", pageRouterManager_->GetStackInfo(type));
1333     if (type == ContentInfoType::RESOURCESCHEDULE_RECOVERY) {
1334         auto namedRouterInfo = pageRouterManager_->GetNamedRouterInfo();
1335         if (namedRouterInfo) {
1336             jsonContentInfo->Put("namedRouterInfo", std::move(namedRouterInfo));
1337         }
1338     }
1339 
1340     if (type == ContentInfoType::CONTINUATION || type == ContentInfoType::APP_RECOVERY) {
1341         auto pipelineContext = pipelineContextHolder_.Get();
1342         CHECK_NULL_RETURN(pipelineContext, jsonContentInfo->ToString());
1343         jsonContentInfo->Put("nodeInfo", pipelineContext->GetStoredNodeInfo());
1344     }
1345 
1346     return jsonContentInfo->ToString();
1347 }
1348 
CreateSnapshot(std::function<void ()> && customBuilder,NG::ComponentSnapshot::JsCallback && callback,bool enableInspector,const NG::SnapshotParam & param)1349 void FrontendDelegateDeclarativeNG::CreateSnapshot(
1350     std::function<void()>&& customBuilder, NG::ComponentSnapshot::JsCallback&& callback, bool enableInspector,
1351     const NG::SnapshotParam& param)
1352 {
1353 #ifdef ENABLE_ROSEN_BACKEND
1354     ViewStackModel::GetInstance()->NewScope();
1355     CHECK_NULL_VOID(customBuilder);
1356     customBuilder();
1357     auto customNode = ViewStackModel::GetInstance()->Finish();
1358 
1359     NG::ComponentSnapshot::Create(customNode, std::move(callback), enableInspector, param);
1360 #endif
1361 }
1362 
AddFrameNodeToOverlay(const RefPtr<NG::FrameNode> & node,std::optional<int32_t> index)1363 void FrontendDelegateDeclarativeNG::AddFrameNodeToOverlay(
1364     const RefPtr<NG::FrameNode>& node, std::optional<int32_t> index)
1365 {
1366     auto task = [node, index, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
1367         CHECK_NULL_VOID(overlayManager);
1368         ContainerScope scope(containerId);
1369         overlayManager->AddFrameNodeToOverlay(node, index);
1370     };
1371     MainWindowOverlay(std::move(task), "ArkUIOverlayAddFrameNode", nullptr);
1372 }
1373 
AddFrameNodeWithOrder(const RefPtr<NG::FrameNode> & node,std::optional<double> levelOrder)1374 void FrontendDelegateDeclarativeNG::AddFrameNodeWithOrder(
1375     const RefPtr<NG::FrameNode>& node, std::optional<double> levelOrder)
1376 {
1377     CHECK_NULL_VOID(node);
1378     auto pipelineContext = node->GetContext();
1379     CHECK_NULL_VOID(pipelineContext);
1380     auto overlayManager = pipelineContext->GetOverlayManager();
1381     CHECK_NULL_VOID(overlayManager);
1382     overlayManager->AddFrameNodeWithOrder(node, levelOrder);
1383 }
1384 
RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode> & node)1385 void FrontendDelegateDeclarativeNG::RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
1386 {
1387     auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
1388         CHECK_NULL_VOID(overlayManager);
1389         ContainerScope scope(containerId);
1390         overlayManager->RemoveFrameNodeOnOverlay(node);
1391     };
1392     MainWindowOverlay(std::move(task), "ArkUIOverlayRemoveFrameNode", nullptr);
1393 }
1394 
ShowNodeOnOverlay(const RefPtr<NG::FrameNode> & node)1395 void FrontendDelegateDeclarativeNG::ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
1396 {
1397     auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
1398         CHECK_NULL_VOID(overlayManager);
1399         ContainerScope scope(containerId);
1400         overlayManager->ShowNodeOnOverlay(node);
1401     };
1402     MainWindowOverlay(std::move(task), "ArkUIOverlayShowNode", nullptr);
1403 }
1404 
HideNodeOnOverlay(const RefPtr<NG::FrameNode> & node)1405 void FrontendDelegateDeclarativeNG::HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
1406 {
1407     auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
1408         CHECK_NULL_VOID(overlayManager);
1409         ContainerScope scope(containerId);
1410         overlayManager->HideNodeOnOverlay(node);
1411     };
1412     MainWindowOverlay(std::move(task), "ArkUIOverlayHideNode", nullptr);
1413 }
1414 
ShowAllNodesOnOverlay()1415 void FrontendDelegateDeclarativeNG::ShowAllNodesOnOverlay()
1416 {
1417     auto task = [containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
1418         CHECK_NULL_VOID(overlayManager);
1419         ContainerScope scope(containerId);
1420         overlayManager->ShowAllNodesOnOverlay();
1421     };
1422     MainWindowOverlay(std::move(task), "ArkUIOverlayShowAllNodes", nullptr);
1423 }
1424 
HideAllNodesOnOverlay()1425 void FrontendDelegateDeclarativeNG::HideAllNodesOnOverlay()
1426 {
1427     auto task = [containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
1428         CHECK_NULL_VOID(overlayManager);
1429         ContainerScope scope(containerId);
1430         overlayManager->HideAllNodesOnOverlay();
1431     };
1432     MainWindowOverlay(std::move(task), "ArkUIOverlayHideAllNodes", nullptr);
1433 }
1434 
SetOverlayManagerOptions(const NG::OverlayManagerInfo & overlayInfo)1435 bool FrontendDelegateDeclarativeNG::SetOverlayManagerOptions(const NG::OverlayManagerInfo& overlayInfo)
1436 {
1437     auto context = NG::PipelineContext::GetCurrentContext();
1438     CHECK_NULL_RETURN(context, false);
1439     auto overlayManager = context->GetOverlayManager();
1440     CHECK_NULL_RETURN(overlayManager, false);
1441     return overlayManager->SetOverlayManagerOptions(overlayInfo);
1442 };
GetOverlayManagerOptions()1443 std::optional<NG::OverlayManagerInfo> FrontendDelegateDeclarativeNG::GetOverlayManagerOptions()
1444 {
1445     auto context = NG::PipelineContext::GetCurrentContext();
1446     CHECK_NULL_RETURN(context, std::nullopt);
1447     auto overlayManager = context->GetOverlayManager();
1448     CHECK_NULL_RETURN(context, std::nullopt);
1449     return overlayManager->GetOverlayManagerOptions();
1450 };
1451 } // namespace OHOS::Ace::Framework
1452