• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_FRONTEND_DELEGATE_DECLARATIVE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_FRONTEND_DELEGATE_DECLARATIVE_H
18 
19 #include <future>
20 #include <mutex>
21 #include <unordered_map>
22 
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "base/thread/cancelable_callback.h"
26 #include "base/utils/measure_util.h"
27 #include "bridge/declarative_frontend/ng/page_router_manager.h"
28 #include "core/common/js_message_dispatcher.h"
29 #include "core/components_ng/pattern/overlay/overlay_manager.h"
30 #include "core/components_ng/render/snapshot_param.h"
31 #include "core/pipeline/pipeline_context.h"
32 #include "frameworks/bridge/common/accessibility/accessibility_node_manager.h"
33 #include "frameworks/bridge/common/manifest/manifest_parser.h"
34 #include "frameworks/bridge/js_frontend/engine/common/group_js_bridge.h"
35 #include "frameworks/bridge/js_frontend/engine/common/js_engine.h"
36 #include "frameworks/bridge/js_frontend/frontend_delegate.h"
37 #include "frameworks/bridge/js_frontend/frontend_delegate_impl.h"
38 #include "frameworks/bridge/js_frontend/js_ace_page.h"
39 
40 namespace OHOS::Ace::Framework {
41 
42 using ExternalEventCallback = std::function<void(const std::string&, const uint32_t&, const bool&)>;
43 
44 enum class RouterAction {
45     PUSH = 0,
46     REPLACE,
47     BACK,
48     CLEAR,
49 };
50 
51 struct RouterTask {
52     RouterAction action = RouterAction::PUSH;
53     PageTarget target = PageTarget("");
54     std::string params;
55     std::function<void(const std::string&, int32_t)> errorCallback;
56 };
57 
58 class FrontendDelegateDeclarative : public FrontendDelegate {
59     DECLARE_ACE_TYPE(FrontendDelegateDeclarative, FrontendDelegate);
60 
61 public:
62     FrontendDelegateDeclarative(const RefPtr<TaskExecutor>& taskExecutor, const LoadJsCallback& loadCallback,
63         const JsMessageDispatcherSetterCallback& transferCallback, const EventCallback& asyncEventCallback,
64         const EventCallback& syncEventCallback, const UpdatePageCallback& updatePageCallback,
65         const ResetStagingPageCallback& resetLoadingPageCallback, const DestroyPageCallback& destroyPageCallback,
66         const DestroyApplicationCallback& destroyApplicationCallback,
67         const UpdateApplicationStateCallback& updateApplicationStateCallback, const TimerCallback& timerCallback,
68         const MediaQueryCallback& mediaQueryCallback, const LayoutInspectorCallback& layoutInpsectorCallback,
69         const DrawInspectorCallback& drawInpsectorCallback,
70         const DrawChildrenInspectorCallback& drawChildrenInspectorCallback,
71         const RequestAnimationCallback& requestAnimationCallback,
72         const JsCallback& jsCallback, const OnWindowDisplayModeChangedCallBack& onWindowDisplayModeChangedCallBack,
73         const OnConfigurationUpdatedCallBack& onConfigurationUpdatedCallBack,
74         const OnSaveAbilityStateCallBack& onSaveAbilityStateCallBack,
75         const OnRestoreAbilityStateCallBack& onRestoreAbilityStateCallBack, const OnNewWantCallBack& onNewWantCallBack,
76         const OnMemoryLevelCallBack& onMemoryLevelCallBack,
77         const OnStartContinuationCallBack& onStartContinuationCallBack,
78         const OnCompleteContinuationCallBack& onCompleteContinuationCallBack,
79         const OnRemoteTerminatedCallBack& onRemoteTerminatedCallBack, const OnSaveDataCallBack& onSaveDataCallBack,
80         const OnRestoreDataCallBack& onRestoreDataCallBack, const ExternalEventCallback& externalEventCallback);
81     ~FrontendDelegateDeclarative() override;
82 
83     void AttachPipelineContext(const RefPtr<PipelineBase>& context) override;
84     void AttachSubPipelineContext(const RefPtr<PipelineBase>& context);
85 
86     // JSFrontend delegate functions.
87     UIContentErrorCode RunPage(
88         const std::string& url, const std::string& params, const std::string& profile, bool isNamedRouter = false);
89     void RunPage(const std::shared_ptr<std::vector<uint8_t>>& content,
90         const std::string& params, const std::string& profile);
91     void RunIntentPage();
92     void SetRouterIntentInfo(const std::string& intentInfoSerialized, bool isColdStart,
93         const std::function<void()>&& loadPageCallback);
94     std::string GetTopNavDestinationInfo(bool onlyFullScreen, bool needParam);
95 
96     void SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher>& dispatcher) const;
97     void TransferComponentResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data);
98     void TransferJsResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const;
99 #if defined(PREVIEW)
100     void TransferJsResponseDataPreview(int32_t callbackId, int32_t code, ResponseData responseData) const;
101 #endif
102     void TransferJsPluginGetError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const;
103     void TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const;
104     void LoadPluginJsCode(std::string&& jsCode) const;
105     void LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) const;
106     void OnJSCallback(const std::string& callbackId, const std::string& data);
107     bool OnPageBackPress();
108     void OnBackGround();
109     void OnForeground();
110     void OnConfigurationUpdated(const std::string& data);
111     void OnSaveAbilityState(std::string& data);
112     void OnRestoreAbilityState(const std::string& data);
113     void OnNewWant(const std::string& data);
114     bool OnStartContinuation();
115     void OnCompleteContinuation(int32_t code);
116     void OnMemoryLevel(int32_t level);
117     void OnSaveData(std::string& data);
118     void GetPluginsUsed(std::string& data);
119     bool OnRestoreData(const std::string& data);
120     void OnRemoteTerminated();
121     void OnNewRequest(const std::string& data);
122     void SetColorMode(ColorMode colorMode);
123     void CallPopPage();
124     void OnApplicationDestroy(const std::string& packageName);
125     void UpdateApplicationState(const std::string& packageName, Frontend::State state);
126     void OnWindowDisplayModeChanged(bool isShownInMultiWindow, const std::string& data);
127     void NotifyAppStorage(
128         const WeakPtr<Framework::JsEngine>& jsEngineWeak, const std::string& key, const std::string& value);
129 
130     // restore
131     std::pair<RouterRecoverRecord, UIContentErrorCode> RestoreRouterStack(
132         const std::string& contentInfo, ContentInfoType type) override;
133     std::string GetContentInfo(ContentInfoType type) override;
134 
135     // Accessibility delegate functions.
GetJSAccessibilityManager()136     RefPtr<Framework::AccessibilityNodeManager> GetJSAccessibilityManager() const
137     {
138         return jsAccessibilityManager_;
139     }
140     void FireAccessibilityEvent(const AccessibilityEvent& accessibilityEvent);
141     void InitializeAccessibilityCallback();
142 
143     void OnMediaQueryUpdate(bool isSynchronous = false) override;
144     void OnSurfaceChanged();
145     void OnLayoutCompleted(const std::string& componentId);
146     void OnDrawCompleted(const std::string& componentId);
147     void OnDrawChildrenCompleted(const std::string& componentId);
148     bool IsDrawChildrenCallbackFuncExist(const std::string& componentId);
149     // JSEventHandler delegate functions.
150     void FireAsyncEvent(const std::string& eventId, const std::string& param, const std::string& jsonArgs);
151     bool FireSyncEvent(const std::string& eventId, const std::string& param, const std::string& jsonArgs);
152     void FireSyncEvent(
153         const std::string& eventId, const std::string& param, const std::string& jsonArgs, std::string& result);
154     void FireExternalEvent(const std::string& eventId, const std::string& componentId, uint32_t nodeId, bool isDestroy);
155 
156     // FrontendDelegate overrides.
157     void Push(const PageTarget& target, const std::string& params,
158         const std::function<void(const std::string&, int32_t)>& errorCallback = nullptr);
159     void Replace(const PageTarget& target, const std::string& params,
160         const std::function<void(const std::string&, int32_t)>& errorCallback = nullptr);
161     void BackWithTarget(const PageTarget& target, const std::string& params);
162 
163     void Push(const std::string& uri, const std::string& params) override;
164     void PushWithMode(const std::string& uri, const std::string& params, uint32_t routerMode) override;
165     void PushWithCallback(const std::string& uri, const std::string& params, bool recoverable,
166         const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode = 0) override;
167     void PushNamedRoute(const std::string& uri, const std::string& params, bool recoverable,
168         const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode = 0) override;
169     void Replace(const std::string& uri, const std::string& params) override;
170     void ReplaceWithMode(const std::string& uri, const std::string& params, uint32_t routerMode) override;
171     void ReplaceWithCallback(const std::string& uri, const std::string& params, bool recoverable,
172         const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode = 0) override;
173     void ReplaceNamedRoute(const std::string& uri, const std::string& params, bool recoverable,
174         const std::function<void(const std::string&, int32_t)>& errorCallback, uint32_t routerMode = 0) override;
175     void Back(const std::string& uri, const std::string& params) override;
176     void BackToIndex(int32_t index, const std::string& params) override;
177     void Clear() override;
178     int32_t GetStackSize() const override;
179     int32_t GetCurrentPageIndex() const override;
180     void GetState(int32_t& index, std::string& name, std::string& path) override;
181     void GetRouterStateByIndex(int32_t& index, std::string& name, std::string& path, std::string& params) override;
182     bool IsUnrestoreByIndex(int32_t index);
183     void GetRouterStateByUrl(std::string& url, std::vector<StateInfo>& stateArray) override;
184     std::string GetInitParams() override;
185     std::string GetParams() override;
186     int32_t GetIndexByUrl(const std::string& url) override;
187 
188     void PostponePageTransition() override;
189     void LaunchPageTransition() override;
190     size_t GetComponentsCount() override;
191     void TriggerPageUpdate(int32_t pageId, bool directExecute = false) override;
192 
193     void PostJsTask(std::function<void()>&& task, const std::string& name) override;
194 
195     const std::string& GetAppID() const override;
196     const std::string& GetAppName() const override;
197     const std::string& GetVersionName() const override;
198     int32_t GetVersionCode() const override;
GetWindowConfig()199     WindowConfig& GetWindowConfig()
200     {
201         return manifestParser_->GetWindowConfig();
202     }
203 
204     double MeasureText(MeasureContext context) override;
205     Size MeasureTextSize(MeasureContext context) override;
206 
207     void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback = nullptr) override;
208     void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback = nullptr) override;
209     void SetToastStopListenerCallback(std::function<void()>&& stopCallback) override;
210     void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
211         bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
212         const std::set<std::string>& callbacks) override;
213     void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
214         bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
215         const std::set<std::string>& callbacks, std::function<void(bool)>&& onStatusChanged) override;
216     void ShowDialog(const PromptDialogAttr &dialogAttr, const std::vector<ButtonInfo> &buttons,
217         std::function<void(int32_t, int32_t)> &&callback, const std::set<std::string> &callbacks) override;
218     void ShowDialog(const PromptDialogAttr &dialogAttr, const std::vector<ButtonInfo> &buttons,
219         std::function<void(int32_t, int32_t)> &&callback, const std::set<std::string> &callbacks,
220         std::function<void(bool)>&& onStatusChanged) override;
221     void ShowDialogInner(DialogProperties& dialogProperties, std::function<void(int32_t, int32_t)>&& callback,
222         const std::set<std::string>& callbacks);
223     void RemoveCustomDialog(int32_t instanceId) override;
224     void OpenCustomDialog(const PromptDialogAttr &dialogAttr, std::function<void(int32_t)> &&callback) override;
225     void CloseCustomDialog(const int32_t dialogId) override;
226     void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)> &&callback) override;
227     void UpdateCustomDialog(const WeakPtr<NG::UINode>& node, const PromptDialogAttr &dialogAttr,
228         std::function<void(int32_t)> &&callback) override;
229     std::optional<double> GetTopOrder() override;
230     std::optional<double> GetBottomOrder() override;
231 
232     RefPtr<NG::ChainedTransitionEffect> GetTransitionEffect(void* value) override;
233 
234     void EnableAlertBeforeBackPage(const std::string& message, std::function<void(int32_t)>&& callback) override;
235 
236     void DisableAlertBeforeBackPage() override;
237 
238     void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
239         std::function<void(int32_t, int32_t)>&& callback) override;
240     void ShowActionMenu(const std::string& title, const std::vector<ButtonInfo>& button,
241         std::function<void(int32_t, int32_t)>&& callback, std::function<void(bool)>&& onStatusChanged) override;
242     void ShowActionMenu(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
243         std::function<void(int32_t, int32_t)>&& callback) override;
244     void ShowActionMenuInner(DialogProperties& dialogProperties, const std::vector<ButtonInfo>& button,
245         std::function<void(int32_t, int32_t)>&& callback);
246     void ShowActionMenuInnerNG(DialogProperties& dialogProperties, const std::vector<ButtonInfo>& button,
247         std::function<void(int32_t, int32_t)>&& callback);
248 
249     Rect GetBoundingRectData(NodeId nodeId) override;
250 
251     std::string GetInspector(NodeId nodeId) override;
252 
253     void PushJsCallbackToRenderNode(NodeId id, double ratio, std::function<void(bool, double)>&& callback) override;
254     // For async event.
255     void SetCallBackResult(const std::string& callBackId, const std::string& result) override;
256 
257     void WaitTimer(const std::string& callbackId, const std::string& delay, bool isInterval, bool isFirst) override;
258     void ClearTimer(const std::string& callbackId) override;
259 
260     void PostSyncTaskToPage(std::function<void()>&& task, const std::string& name) override;
261     void AddTaskObserver(std::function<void()>&& task) override;
262     void RemoveTaskObserver() override;
263 
264     bool GetAssetContent(const std::string& url, std::string& content) override;
265     bool GetAssetContent(const std::string& url, std::vector<uint8_t>& content) override;
266     std::string GetAssetPath(const std::string& url) override;
267 
268     // i18n
269     void GetI18nData(std::unique_ptr<JsonValue>& json) override;
270 
271     void GetResourceConfiguration(std::unique_ptr<JsonValue>& json) override;
272 
273     void GetConfigurationCommon(const std::string& filePath, std::unique_ptr<JsonValue>& data) override;
274 
275     int32_t GetMinPlatformVersion() override;
276 
277     void LoadResourceConfiguration(std::map<std::string, std::string>& mediaResourceFileMap,
278         std::unique_ptr<JsonValue>& currentResourceData) override;
279 
280     void ChangeLocale(const std::string& language, const std::string& countryOrRegion) override;
281 
282     void RegisterFont(const std::string& familyName, const std::string& familySrc, const std::string& bundleName = "",
283         const std::string& moduleName = "") override;
284 
285     void GetSystemFontList(std::vector<std::string>& fontList) override;
286 
287     bool GetSystemFont(const std::string& fontName, FontInfo& fontInfo) override;
288 
289     void GetUIFontConfig(FontConfigJsonInfo& fontConfigJsonInfo) override;
290 
291     void HandleImage(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& callback) override;
292 
293     void GetSnapshot(const std::string& componentId,
294         std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
295         const NG::SnapshotOptions& options) override;
296     void CreateSnapshot(std::function<void()>&& customBuilder,
297         std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
298         bool enableInspector, const NG::SnapshotParam& param) override;
299 
300     std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSyncSnapshot(
301         RefPtr<NG::FrameNode>& node, const NG::SnapshotOptions& options) override;
302 
303     std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSyncSnapshot(const std::string& componentId,
304         const NG::SnapshotOptions& options) override;
305 
306     void GetSnapshotByUniqueId(int32_t uniqueId,
307         std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
308         const NG::SnapshotOptions& options) override;
309 
310     std::pair<int32_t, std::shared_ptr<Media::PixelMap>> GetSyncSnapshotByUniqueId(int32_t uniqueId,
311         const NG::SnapshotOptions& options) override;
312 
313     void GetSnapshotWithRange(const NG::NodeIdentity& startID, const NG::NodeIdentity& endID, const bool isStartRect,
314         std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
315         const NG::SnapshotOptions& options) override;
316 
317     void CreateSnapshotFromComponent(const RefPtr<NG::UINode>& nodeWk,
318         std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
319         bool enableInspector, const NG::SnapshotParam& param) override;
320 
321     void AddFrameNodeToOverlay(
322         const RefPtr<NG::FrameNode>& node, std::optional<int32_t> index = std::nullopt) override;
323     void AddFrameNodeWithOrder(const RefPtr<NG::FrameNode>& node, std::optional<double> levelOrder) override;
324     void RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
325     void ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
326     void HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
327     void ShowAllNodesOnOverlay() override;
328     void HideAllNodesOnOverlay() override;
329     bool SetOverlayManagerOptions(const NG::OverlayManagerInfo& overlayInfo) override;
330     std::optional<NG::OverlayManagerInfo> GetOverlayManagerOptions() override;
331 
332     void RequestAnimationFrame(const std::string& callbackId) override;
333 
334     void CancelAnimationFrame(const std::string& callbackId) override;
335 
336     SingleTaskExecutor GetAnimationJsTask() override;
337 
338     SingleTaskExecutor GetUiTask() override;
339 
GetMediaQueryInfoInstance()340     const RefPtr<MediaQueryInfo>& GetMediaQueryInfoInstance() override
341     {
342         return mediaQueryInfo_;
343     }
344 
GetGroupJsBridge()345     const RefPtr<GroupJsBridge>& GetGroupJsBridge() override
346     {
347         return groupJsBridge_;
348     }
349 
350 #if defined(PREVIEW)
SetPagePath(const std::string & pagePath)351     void SetPagePath(const std::string& pagePath)
352     {
353         if (manifestParser_) {
354             manifestParser_->SetPagePath(pagePath);
355         }
356     }
357 #endif
358 
359     RefPtr<PipelineBase> GetPipelineContext() override;
360 
SetGroupJsBridge(const RefPtr<GroupJsBridge> & groupJsBridge)361     void SetGroupJsBridge(const RefPtr<GroupJsBridge>& groupJsBridge)
362     {
363         groupJsBridge_ = groupJsBridge;
364     }
365 
366     RefPtr<JsAcePage> GetPage(int32_t pageId) const override;
367 
368     void RebuildAllPages();
369 
370     std::string GetCurrentPageUrl();
371 
372     // Get the currently running JS page information in NG structure.
373     RefPtr<RevSourceMap> GetCurrentPageSourceMap();
374 
375     // Get the currently running JS page information in NG structure.
376     RefPtr<RevSourceMap> GetFaAppSourceMap();
377 
378     void GetStageSourceMap(
379         std::unordered_map<std::string, RefPtr<Framework::RevSourceMap>>& sourceMap);
380 
381 #if defined(PREVIEW)
382     void SetIsComponentPreview(NG::IsComponentPreviewCallback&& callback);
383 #endif
384 
SetPageRouterManager(const RefPtr<NG::PageRouterManager> & routerMgr)385     void SetPageRouterManager(const RefPtr<NG::PageRouterManager>& routerMgr)
386     {
387         pageRouterManager_ = routerMgr;
388     }
GetPageRouterManager()389     const RefPtr<NG::PageRouterManager>& GetPageRouterManager() const
390     {
391         return pageRouterManager_;
392     }
393 
GetTaskExecutor()394     const RefPtr<TaskExecutor>& GetTaskExecutor() const
395     {
396         return taskExecutor_;
397     }
398 
GetManifestParser()399     const RefPtr<Framework::ManifestParser>& GetManifestParser() const
400     {
401         return manifestParser_;
402     }
403 
404     std::string GetPagePathByUrl(const std::string& url) const;
405 
406 protected:
407     bool isCardDelegate_ = false;
408 
409 private:
410     int32_t GenerateNextPageId();
411     void RecyclePageId(int32_t pageId);
412 
413     UIContentErrorCode LoadPage(
414         int32_t pageId, const PageTarget& target, bool isMainPage, const std::string& params, bool isRestore = false);
415     void OnPageReady(const RefPtr<Framework::JsAcePage>& page, const std::string& url, bool isMainPage, bool isRestore);
416     void FlushPageCommand(
417         const RefPtr<Framework::JsAcePage>& page, const std::string& url, bool isMainPage, bool isRestore);
418     void AddPageLocked(const RefPtr<JsAcePage>& page);
419     void OnPrePageChange(const RefPtr<JsAcePage>& page);
420     void SetCurrentPage(int32_t pageId);
421 
422     void OnPushPageSuccess(const RefPtr<JsAcePage>& page, const std::string& url);
423     void OnPopToPageSuccess(const std::string& url);
424     void PopToPage(const std::string& url);
425     int32_t OnPopPageSuccess();
426     void PopPage();
427     void RestorePopPage(const RefPtr<JsAcePage>& page, const std::string& url);
428 
429     void PushPageTransitionListener(const TransitionEvent& event, const RefPtr<JsAcePage>& page);
430 
431     void PopPageTransitionListener(const TransitionEvent& event, int32_t destroyPageId);
432 
433     void PopToPageTransitionListener(const TransitionEvent& event, const std::string& url, int32_t pageId);
434 
435     void RestorePageTransitionListener(
436         const TransitionEvent& event, const std::string& url, const RefPtr<JsAcePage>& page);
437 
438     int32_t OnClearInvisiblePagesSuccess();
439     void ClearInvisiblePages();
440 
441     void OnReplacePageSuccess(const RefPtr<JsAcePage>& page, const std::string& url);
442     void ReplacePage(const RefPtr<JsAcePage>& page, const std::string& url);
443     void LoadReplacePage(int32_t pageId, const PageTarget& url, const std::string& params);
444 
445     void ReplacePageInSubStage(const RefPtr<JsAcePage>& page, const std::string& url);
446     std::optional<int32_t> GetEffectiveContainerId() const;
447 
448     uint64_t GetSystemRealTime();
449 
450     // Page lifecycle
451     void OnPageShow(bool isFromWindow = false);
452     void OnPageHide(bool isFromWindow = false);
453     void OnPageDestroy(int32_t pageId);
454 
455     int32_t GetRunningPageId() const;
456     std::string GetRunningPageUrl() const;
457     int32_t GetPageIdByUrl(const std::string& url, bool& isRestore);
GetPageIdByUrl(const std::string & url)458     int32_t GetPageIdByUrl(const std::string& url)
459     {
460         bool tmp = false;
461         return GetPageIdByUrl(url, tmp);
462     }
463 
464     void ResetStagingPage();
465     void FlushAnimationTasks();
466 
467     void StartPush(const PageTarget& target, const std::string& params,
468         const std::function<void(const std::string&, int32_t)>& errorCallback);
469     void StartReplace(const PageTarget& target, const std::string& params,
470         const std::function<void(const std::string&, int32_t)>& errorCallback);
471     void StartBack(const PageTarget& target, const std::string& params);
472     void BackCheckAlert(const PageTarget& target, const std::string& params);
473     void ProcessRouterTask();
474     void AddRouterTask(const RouterTask& task);
475     bool IsNavigationStage(const PageTarget& target);
476     void RecycleSinglePage();
477     void ClearAlertCallback(PageInfo pageInfo);
478     bool CheckIndexValid(int32_t index) const;
479 
480     void ParsePartialPropertiesFromAttr(DialogProperties& dialogProperties, const PromptDialogAttr& dialogAttr);
481     DialogProperties ParsePropertiesFromAttr(const PromptDialogAttr &dialogAttr);
482 
483     std::unique_ptr<JsonValue> GetNavigationJsonInfo();
484 
485     std::atomic<uint64_t> pageIdPool_ = 0;
486     int32_t callbackCnt_ = 0;
487     int32_t pageId_ = -1;
488     bool isRouteStackFull_ = false;
489     bool isStagingPageExist_ = false;
490     int32_t singlePageId_ = -1;
491     std::string mainPagePath_;
492     PageTarget backUri_ = PageTarget("");
493     std::string backParam_;
494     std::vector<PageInfo> pageRouteStack_;
495     std::unordered_map<int32_t, RefPtr<JsAcePage>> pageMap_;
496     std::unordered_map<int32_t, std::string> pageParamMap_;
497     std::unordered_map<int32_t, std::string> jsCallBackResult_;
498 
499     LoadJsCallback loadJs_;
500     ExternalEventCallback externalEvent_;
501     JsMessageDispatcherSetterCallback dispatcherCallback_;
502     EventCallback asyncEvent_;
503     EventCallback syncEvent_;
504     UpdatePageCallback updatePage_;
505     ResetStagingPageCallback resetStagingPage_;
506     DestroyPageCallback destroyPage_;
507     DestroyApplicationCallback destroyApplication_;
508     UpdateApplicationStateCallback updateApplicationState_;
509     TimerCallback timer_;
510     std::unordered_map<std::string, CancelableCallback<void()>> timeoutTaskMap_;
511     MediaQueryCallback mediaQueryCallback_;
512     LayoutInspectorCallback layoutInspectorCallback_;
513     DrawInspectorCallback drawInspectorCallback_;
514     DrawChildrenInspectorCallback drawChildrenInspectorCallback_;
515     RequestAnimationCallback requestAnimationCallback_;
516     JsCallback jsCallback_;
517     OnWindowDisplayModeChangedCallBack onWindowDisplayModeChanged_;
518     OnConfigurationUpdatedCallBack onConfigurationUpdated_;
519     OnSaveAbilityStateCallBack onSaveAbilityState_;
520     OnRestoreAbilityStateCallBack onRestoreAbilityState_;
521     OnNewWantCallBack onNewWant_;
522     OnMemoryLevelCallBack onMemoryLevel_;
523     OnStartContinuationCallBack onStartContinuationCallBack_;
524     OnCompleteContinuationCallBack onCompleteContinuationCallBack_;
525     OnRemoteTerminatedCallBack onRemoteTerminatedCallBack_;
526     OnSaveDataCallBack onSaveDataCallBack_;
527     OnRestoreDataCallBack onRestoreDataCallBack_;
528     RefPtr<Framework::ManifestParser> manifestParser_;
529     RefPtr<Framework::AccessibilityNodeManager> jsAccessibilityManager_;
530     RefPtr<MediaQueryInfo> mediaQueryInfo_;
531     RefPtr<GroupJsBridge> groupJsBridge_;
532 
533     RefPtr<TaskExecutor> taskExecutor_;
534 
535     PipelineContextHolder pipelineContextHolder_;
536 
537     BaseId::IdType pageTransitionListenerId_ = 0L;
538     std::queue<std::string> animationFrameTaskIds_;
539     std::unordered_map<std::string, CancelableCallback<void()>> animationFrameTaskMap_;
540 
541     mutable std::mutex mutex_;
542 
543     std::queue<RouterTask> routerQueue_;
544     mutable std::mutex routerQueueMutex_;
545 
546     RefPtr<RevSourceMap> appSourceMap_;
547     RefPtr<NG::PageRouterManager> pageRouterManager_;
548 };
549 
550 } // namespace OHOS::Ace::Framework
551 
552 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_FRONTEND_DELEGATE_DECLARATIVE_H
553