• 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 #include "frameworks/bridge/declarative_frontend/declarative_frontend.h"
17 
18 #include <memory>
19 
20 #include "base/log/dump_log.h"
21 #include "base/log/event_report.h"
22 #include "base/utils/utils.h"
23 #include "core/common/ace_page.h"
24 #include "core/common/container.h"
25 #include "core/common/thread_checker.h"
26 #include "core/components/navigator/navigator_component.h"
27 #include "frameworks/bridge/card_frontend/form_frontend_delegate_declarative.h"
28 namespace OHOS::Ace {
29 namespace {
30 
31 /*
32  * NOTE:
33  * This function is needed to copy the values from BaseEventInfo
34  * It is observed, that the owner of BaseEventInfo will delete the pointer before it is ultimately
35  * processed by the EventMarker callback. In order to avoid this, a copy of all data needs to be made.
36  */
CopyEventInfo(const BaseEventInfo & info)37 std::shared_ptr<BaseEventInfo> CopyEventInfo(const BaseEventInfo& info)
38 {
39     const auto* touchInfo = TypeInfoHelper::DynamicCast<TouchEventInfo>(&info);
40     if (touchInfo != nullptr) {
41         return std::make_shared<TouchEventInfo>(*touchInfo);
42     }
43 
44     const auto* dragStartInfo = TypeInfoHelper::DynamicCast<DragStartInfo>(&info);
45     if (dragStartInfo != nullptr) {
46         return std::make_shared<DragStartInfo>(*dragStartInfo);
47     }
48 
49     const auto* dragUpdateInfo = TypeInfoHelper::DynamicCast<DragUpdateInfo>(&info);
50     if (dragUpdateInfo != nullptr) {
51         return std::make_shared<DragUpdateInfo>(*dragUpdateInfo);
52     }
53 
54     const auto* dragEndInfo = TypeInfoHelper::DynamicCast<DragEndInfo>(&info);
55     if (dragEndInfo != nullptr) {
56         return std::make_shared<DragEndInfo>(*dragEndInfo);
57     }
58 
59     const auto* clickInfo = TypeInfoHelper::DynamicCast<ClickInfo>(&info);
60     if (clickInfo != nullptr) {
61         return std::make_shared<ClickInfo>(*clickInfo);
62     }
63     return nullptr;
64 }
65 
TouchInfoToString(const BaseEventInfo & info,std::string & eventParam)66 void TouchInfoToString(const BaseEventInfo& info, std::string& eventParam)
67 {
68     eventParam.append("{\"touches\":[{");
69     const auto touchInfo = TypeInfoHelper::DynamicCast<TouchEventInfo>(&info);
70     if (touchInfo) {
71         auto touchList = touchInfo->GetTouches();
72         for (const auto& location : touchList) {
73             auto globalLocation = location.GetGlobalLocation();
74             eventParam.append("\"globalX\":")
75                 .append(std::to_string(globalLocation.GetX()))
76                 .append(",\"globalY\":")
77                 .append(std::to_string(globalLocation.GetY()))
78                 .append(",");
79             auto localLocation = location.GetLocalLocation();
80             eventParam.append("\"localX\":")
81                 .append(std::to_string(localLocation.GetX()))
82                 .append(",\"localY\":")
83                 .append(std::to_string(localLocation.GetY()))
84                 .append(",");
85             eventParam.append("\"size\":").append(std::to_string(location.GetSize())).append(",");
86         }
87         if (eventParam.back() == ',') {
88             eventParam.pop_back();
89         }
90         eventParam.append("}],\"changedTouches\":[{");
91         auto changeTouch = touchInfo->GetChangedTouches();
92         for (const auto& change : changeTouch) {
93             auto globalLocation = change.GetGlobalLocation();
94             eventParam.append("\"globalX\":")
95                 .append(std::to_string(globalLocation.GetX()))
96                 .append(",\"globalY\":")
97                 .append(std::to_string(globalLocation.GetY()))
98                 .append(",");
99             auto localLocation = change.GetLocalLocation();
100             eventParam.append("\"localX\":")
101                 .append(std::to_string(localLocation.GetX()))
102                 .append(",\"localY\":")
103                 .append(std::to_string(localLocation.GetY()))
104                 .append(",");
105             eventParam.append("\"size\":").append(std::to_string(change.GetSize())).append(",");
106         }
107         if (eventParam.back() == ',') {
108             eventParam.pop_back();
109         }
110     }
111     eventParam.append("}]}");
112 }
113 
MouseInfoToString(const BaseEventInfo & info,std::string & eventParam)114 void MouseInfoToString(const BaseEventInfo& info, std::string& eventParam)
115 {
116     const auto mouseInfo = TypeInfoHelper::DynamicCast<MouseEventInfo>(&info);
117     eventParam.append("{\"mouse\":{");
118     if (mouseInfo) {
119         auto globalMouse = mouseInfo->GetGlobalMouse();
120         eventParam.append("\"globalX\":")
121             .append(std::to_string(globalMouse.x))
122             .append(",\"globalY\":")
123             .append(std::to_string(globalMouse.y))
124             .append(",\"globalZ\":")
125             .append(std::to_string(globalMouse.z))
126             .append(",\"localX\":")
127             .append(std::to_string(globalMouse.x))
128             .append(",\"localY\":")
129             .append(std::to_string(globalMouse.y))
130             .append(",\"localZ\":")
131             .append(std::to_string(globalMouse.z))
132             .append(",\"deltaX\":")
133             .append(std::to_string(globalMouse.deltaX))
134             .append(",\"deltaY\":")
135             .append(std::to_string(globalMouse.deltaY))
136             .append(",\"deltaZ\":")
137             .append(std::to_string(globalMouse.deltaZ))
138             .append(",\"scrollX\":")
139             .append(std::to_string(globalMouse.scrollX))
140             .append(",\"scrollY\":")
141             .append(std::to_string(globalMouse.scrollY))
142             .append(",\"scrollZ\":")
143             .append(std::to_string(globalMouse.scrollZ))
144             .append(",\"action\":")
145             .append(std::to_string(static_cast<int32_t>(globalMouse.action)))
146             .append(",\"button\":")
147             .append(std::to_string(static_cast<int32_t>(globalMouse.button)))
148             .append(",\"pressedButtons\":")
149             .append(std::to_string(globalMouse.pressedButtons));
150     }
151     eventParam.append("}}");
152 }
153 
SwipeInfoToString(const BaseEventInfo & info,std::string & eventParam)154 void SwipeInfoToString(const BaseEventInfo& info, std::string& eventParam)
155 {
156     const auto& swipeInfo = TypeInfoHelper::DynamicCast<SwipeEventInfo>(&info);
157     eventParam = swipeInfo->ToJsonParamInfo();
158 }
159 
160 } // namespace
161 
~DeclarativeFrontend()162 DeclarativeFrontend::~DeclarativeFrontend() noexcept
163 {
164     LOG_DESTROY();
165 }
166 
Destroy()167 void DeclarativeFrontend::Destroy()
168 {
169     CHECK_RUN_ON(JS);
170     LOGI("DeclarativeFrontend Destroy begin.");
171     // To guarantee the jsEngine_ and delegate_ released in js thread
172     delegate_.Reset();
173     handler_.Reset();
174     if (jsEngine_) {
175         jsEngine_->Destroy();
176     }
177     jsEngine_.Reset();
178     LOGI("DeclarativeFrontend Destroy end.");
179 }
180 
Initialize(FrontendType type,const RefPtr<TaskExecutor> & taskExecutor)181 bool DeclarativeFrontend::Initialize(FrontendType type, const RefPtr<TaskExecutor>& taskExecutor)
182 {
183     LOGD("DeclarativeFrontend initialize begin.");
184     type_ = type;
185     taskExecutor_ = taskExecutor;
186     ACE_DCHECK(type_ == FrontendType::DECLARATIVE_JS);
187     InitializeFrontendDelegate(taskExecutor);
188 
189     bool needPostJsTask = true;
190     auto container = Container::Current();
191     if (container) {
192         const auto& setting = container->GetSettings();
193         needPostJsTask = !(setting.usePlatformAsUIThread && setting.useUIAsJSThread);
194     }
195     auto initJSEngineTask = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_), delegate = delegate_] {
196         auto jsEngine = weakEngine.Upgrade();
197         if (!jsEngine) {
198             return;
199         }
200         jsEngine->Initialize(delegate);
201     };
202     if (needPostJsTask) {
203         taskExecutor->PostTask(initJSEngineTask, TaskExecutor::TaskType::JS);
204     } else {
205         initJSEngineTask();
206     }
207 
208     LOGD("DeclarativeFrontend initialize end.");
209     return true;
210 }
211 
AttachPipelineContext(const RefPtr<PipelineBase> & context)212 void DeclarativeFrontend::AttachPipelineContext(const RefPtr<PipelineBase>& context)
213 {
214     LOGD("DeclarativeFrontend AttachPipelineContext.");
215     if (!delegate_) {
216         return;
217     }
218     handler_ = AceType::MakeRefPtr<DeclarativeEventHandler>(delegate_);
219     auto pipelineContext = AceType::DynamicCast<PipelineContext>(context);
220     if (pipelineContext) {
221         pipelineContext->RegisterEventHandler(handler_);
222     }
223     delegate_->AttachPipelineContext(context);
224 }
225 
AttachSubPipelineContext(const RefPtr<PipelineBase> & context)226 void DeclarativeFrontend::AttachSubPipelineContext(const RefPtr<PipelineBase>& context)
227 {
228     LOGI("DeclarativeFrontend AttachSubPipelineContext.");
229     if (!context) {
230         return;
231     }
232     auto pipelineContext = AceType::DynamicCast<PipelineContext>(context);
233     if (pipelineContext) {
234         pipelineContext->RegisterEventHandler(handler_);
235     }
236     if (!delegate_) {
237         return;
238     }
239     delegate_->AttachSubPipelineContext(context);
240 }
241 
SetAssetManager(const RefPtr<AssetManager> & assetManager)242 void DeclarativeFrontend::SetAssetManager(const RefPtr<AssetManager>& assetManager)
243 {
244     LOGI("DeclarativeFrontend SetAssetManager.");
245     if (delegate_) {
246         delegate_->SetAssetManager(assetManager);
247     }
248 }
249 
InitializeFrontendDelegate(const RefPtr<TaskExecutor> & taskExecutor)250 void DeclarativeFrontend::InitializeFrontendDelegate(const RefPtr<TaskExecutor>& taskExecutor)
251 {
252     const auto& loadCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](const std::string& url,
253                                    const RefPtr<Framework::JsAcePage>& jsPage, bool isMainPage) {
254         auto jsEngine = weakEngine.Upgrade();
255         if (!jsEngine) {
256             return;
257         }
258         jsEngine->LoadJs(url, jsPage, isMainPage);
259     };
260 
261     const auto& setPluginMessageTransferCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
262                                                        const RefPtr<JsMessageDispatcher>& dispatcher) {
263         auto jsEngine = weakEngine.Upgrade();
264         if (!jsEngine) {
265             return;
266         }
267         jsEngine->SetJsMessageDispatcher(dispatcher);
268     };
269 
270     const auto& asyncEventCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
271                                          const std::string& eventId, const std::string& param) {
272         auto jsEngine = weakEngine.Upgrade();
273         if (!jsEngine) {
274             return;
275         }
276         jsEngine->FireAsyncEvent(eventId, param);
277     };
278 
279     const auto& syncEventCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
280                                         const std::string& eventId, const std::string& param) {
281         auto jsEngine = weakEngine.Upgrade();
282         if (!jsEngine) {
283             return;
284         }
285         jsEngine->FireSyncEvent(eventId, param);
286     };
287 
288     const auto& updatePageCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
289                                          const RefPtr<Framework::JsAcePage>& jsPage) {
290         auto jsEngine = weakEngine.Upgrade();
291         if (!jsEngine) {
292             return;
293         }
294         jsEngine->UpdateRunningPage(jsPage);
295         jsEngine->UpdateStagingPage(jsPage);
296     };
297 
298     const auto& resetStagingPageCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)]() {
299         auto jsEngine = weakEngine.Upgrade();
300         if (!jsEngine) {
301             return;
302         }
303         jsEngine->ResetStagingPage();
304     };
305 
306     const auto& destroyPageCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](int32_t pageId) {
307         auto jsEngine = weakEngine.Upgrade();
308         if (!jsEngine) {
309             return;
310         }
311         jsEngine->DestroyPageInstance(pageId);
312     };
313 
314     const auto& destroyApplicationCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
315                                                  const std::string& packageName) {
316         auto jsEngine = weakEngine.Upgrade();
317         if (!jsEngine) {
318             return;
319         }
320         jsEngine->DestroyApplication(packageName);
321     };
322 
323     const auto& updateApplicationStateCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
324                                                      const std::string& packageName, Frontend::State state) {
325         auto jsEngine = weakEngine.Upgrade();
326         if (!jsEngine) {
327             return;
328         }
329         jsEngine->UpdateApplicationState(packageName, state);
330     };
331 
332     const auto& onWindowDisplayModeChangedCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
333                                                          bool isShownInMultiWindow, const std::string& data) {
334         auto jsEngine = weakEngine.Upgrade();
335         if (!jsEngine) {
336             return;
337         }
338         jsEngine->OnWindowDisplayModeChanged(isShownInMultiWindow, data);
339     };
340 
341     const auto& onSaveAbilityStateCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](std::string& data) {
342         auto jsEngine = weakEngine.Upgrade();
343         if (!jsEngine) {
344             LOGE("the js engine is nullptr");
345             return;
346         }
347         jsEngine->OnSaveAbilityState(data);
348     };
349     const auto& onRestoreAbilityStateCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
350                                                     const std::string& data) {
351         auto jsEngine = weakEngine.Upgrade();
352         if (!jsEngine) {
353             LOGE("the js engine is nullptr");
354             return;
355         }
356         jsEngine->OnRestoreAbilityState(data);
357     };
358 
359     const auto& onNewWantCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](const std::string& data) {
360         auto jsEngine = weakEngine.Upgrade();
361         if (!jsEngine) {
362             LOGE("the js engine is nullptr");
363             return;
364         }
365         jsEngine->OnNewWant(data);
366     };
367 
368     const auto& onConfigurationUpdatedCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
369                                                      const std::string& data) {
370         auto jsEngine = weakEngine.Upgrade();
371         if (!jsEngine) {
372             return;
373         }
374         jsEngine->OnConfigurationUpdated(data);
375     };
376 
377     const auto& timerCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
378                                     const std::string& callbackId, const std::string& delay, bool isInterval) {
379         auto jsEngine = weakEngine.Upgrade();
380         if (!jsEngine) {
381             return;
382         }
383         jsEngine->TimerCallback(callbackId, delay, isInterval);
384     };
385 
386     const auto& mediaQueryCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
387                                          const std::string& callbackId, const std::string& args) {
388         auto jsEngine = weakEngine.Upgrade();
389         if (!jsEngine) {
390             return;
391         }
392         jsEngine->MediaQueryCallback(callbackId, args);
393     };
394 
395     const auto& layoutInspectorCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
396                                               const std::string& componentId) {
397         auto jsEngine = weakEngine.Upgrade();
398         if (!jsEngine) {
399             return;
400         }
401         jsEngine->LayoutInspectorCallback(componentId);
402     };
403 
404     const auto& drawInspectorCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
405                                             const std::string& componentId) {
406         auto jsEngine = weakEngine.Upgrade();
407         if (!jsEngine) {
408             return;
409         }
410         jsEngine->DrawInspectorCallback(componentId);
411     };
412 
413     const auto& requestAnimationCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
414                                                const std::string& callbackId, uint64_t timeStamp) {
415         auto jsEngine = weakEngine.Upgrade();
416         if (!jsEngine) {
417             return;
418         }
419         jsEngine->RequestAnimationCallback(callbackId, timeStamp);
420     };
421 
422     const auto& jsCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
423                                  const std::string& callbackId, const std::string& args) {
424         auto jsEngine = weakEngine.Upgrade();
425         if (!jsEngine) {
426             return;
427         }
428         jsEngine->JsCallback(callbackId, args);
429     };
430 
431     const auto& onMemoryLevelCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](const int32_t level) {
432         auto jsEngine = weakEngine.Upgrade();
433         if (!jsEngine) {
434             return;
435         }
436         jsEngine->OnMemoryLevel(level);
437     };
438 
439     const auto& onStartContinuationCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)]() -> bool {
440         auto jsEngine = weakEngine.Upgrade();
441         if (!jsEngine) {
442             return false;
443         }
444         return jsEngine->OnStartContinuation();
445     };
446     const auto& onCompleteContinuationCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](int32_t code) {
447         auto jsEngine = weakEngine.Upgrade();
448         if (!jsEngine) {
449             return;
450         }
451         jsEngine->OnCompleteContinuation(code);
452     };
453     const auto& onRemoteTerminatedCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)]() {
454         auto jsEngine = weakEngine.Upgrade();
455         if (!jsEngine) {
456             return;
457         }
458         jsEngine->OnRemoteTerminated();
459     };
460     const auto& onSaveDataCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](std::string& savedData) {
461         auto jsEngine = weakEngine.Upgrade();
462         if (!jsEngine) {
463             return;
464         }
465         jsEngine->OnSaveData(savedData);
466     };
467     const auto& onRestoreDataCallBack = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
468                                             const std::string& data) -> bool {
469         auto jsEngine = weakEngine.Upgrade();
470         if (!jsEngine) {
471             return false;
472         }
473         return jsEngine->OnRestoreData(data);
474     };
475 
476     const auto& externalEventCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
477                                             const std::string& componentId, const uint32_t nodeId,
478                                             const bool isDestroy) {
479         auto jsEngine = weakEngine.Upgrade();
480         if (!jsEngine) {
481             return;
482         }
483         jsEngine->FireExternalEvent(componentId, nodeId, isDestroy);
484     };
485 
486     if (isFormRender_) {
487         LOGI("Init Form Delegate");
488         delegate_ = AceType::MakeRefPtr<Framework::FormFrontendDelegateDeclarative>(taskExecutor, loadCallback,
489             setPluginMessageTransferCallback, asyncEventCallback, syncEventCallback, updatePageCallback,
490             resetStagingPageCallback, destroyPageCallback, destroyApplicationCallback, updateApplicationStateCallback,
491             timerCallback, mediaQueryCallback, layoutInspectorCallback, drawInspectorCallback, requestAnimationCallback,
492             jsCallback, onWindowDisplayModeChangedCallBack, onConfigurationUpdatedCallBack, onSaveAbilityStateCallBack,
493             onRestoreAbilityStateCallBack, onNewWantCallBack, onMemoryLevelCallBack, onStartContinuationCallBack,
494             onCompleteContinuationCallBack, onRemoteTerminatedCallBack, onSaveDataCallBack, onRestoreDataCallBack,
495             externalEventCallback);
496     } else {
497         delegate_ = AceType::MakeRefPtr<Framework::FrontendDelegateDeclarative>(taskExecutor, loadCallback,
498             setPluginMessageTransferCallback, asyncEventCallback, syncEventCallback, updatePageCallback,
499             resetStagingPageCallback, destroyPageCallback, destroyApplicationCallback, updateApplicationStateCallback,
500             timerCallback, mediaQueryCallback, layoutInspectorCallback, drawInspectorCallback, requestAnimationCallback,
501             jsCallback, onWindowDisplayModeChangedCallBack, onConfigurationUpdatedCallBack, onSaveAbilityStateCallBack,
502             onRestoreAbilityStateCallBack, onNewWantCallBack, onMemoryLevelCallBack, onStartContinuationCallBack,
503             onCompleteContinuationCallBack, onRemoteTerminatedCallBack, onSaveDataCallBack, onRestoreDataCallBack,
504             externalEventCallback);
505     }
506 
507     if (disallowPopLastPage_) {
508         delegate_->DisallowPopLastPage();
509     }
510     if (!jsEngine_) {
511         LOGE("the js engine is nullptr");
512         EventReport::SendAppStartException(AppStartExcepType::JS_ENGINE_CREATE_ERR);
513         return;
514     }
515     delegate_->SetGroupJsBridge(jsEngine_->GetGroupJsBridge());
516     if (Container::IsCurrentUseNewPipeline()) {
517         auto loadPageCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](const std::string& url,
518                                     const std::function<void(const std::string&, int32_t)>& errorCallback) {
519             auto jsEngine = weakEngine.Upgrade();
520             if (!jsEngine) {
521                 return false;
522             }
523             return jsEngine->LoadPageSource(url, errorCallback);
524         };
525         auto loadNamedRouterCallback = [weakEngine = WeakPtr<Framework::JsEngine>(jsEngine_)](
526                                            const std::string& namedRouter, bool isTriggeredByJs) {
527             auto jsEngine = weakEngine.Upgrade();
528             if (!jsEngine) {
529                 return false;
530             }
531             return jsEngine->LoadNamedRouterSource(namedRouter, isTriggeredByJs);
532         };
533         delegate_->InitializeRouterManager(std::move(loadPageCallback), std::move(loadNamedRouterCallback));
534     }
535 }
536 
RunPage(int32_t pageId,const std::string & url,const std::string & params)537 void DeclarativeFrontend::RunPage(int32_t pageId, const std::string& url, const std::string& params)
538 {
539     auto container = Container::Current();
540     auto isStageModel = container ? container->IsUseStageModel() : false;
541     if (!isStageModel && Container::IsCurrentUseNewPipeline()) {
542         // In NG structure and fa mode, first load app.js
543         auto taskExecutor = container ? container->GetTaskExecutor() : nullptr;
544         CHECK_NULL_VOID(taskExecutor);
545         taskExecutor->PostTask(
546             [weak = AceType::WeakClaim(this)]() {
547                 auto frontend = weak.Upgrade();
548                 CHECK_NULL_VOID(frontend);
549                 CHECK_NULL_VOID(frontend->jsEngine_);
550                 frontend->jsEngine_->LoadFaAppSource();
551             },
552             TaskExecutor::TaskType::JS);
553     }
554     // Not use this pageId from backend, manage it in FrontendDelegateDeclarative.
555     if (delegate_) {
556         if (isFormRender_) {
557             auto delegate = AceType::DynamicCast<Framework::FormFrontendDelegateDeclarative>(delegate_);
558             delegate->RunCard(url, params, pageProfile_, 0);
559         } else {
560             delegate_->RunPage(url, params, pageProfile_);
561         }
562     }
563 }
564 
ReplacePage(const std::string & url,const std::string & params)565 void DeclarativeFrontend::ReplacePage(const std::string& url, const std::string& params)
566 {
567     if (delegate_) {
568         delegate_->Replace(url, params);
569     }
570 }
571 
PushPage(const std::string & url,const std::string & params)572 void DeclarativeFrontend::PushPage(const std::string& url, const std::string& params)
573 {
574     if (delegate_) {
575         delegate_->Push(url, params);
576     }
577 }
578 
NavigatePage(uint8_t type,const PageTarget & target,const std::string & params)579 void DeclarativeFrontend::NavigatePage(uint8_t type, const PageTarget& target, const std::string& params)
580 {
581     if (!delegate_) {
582         return;
583     }
584     switch (static_cast<NavigatorType>(type)) {
585         case NavigatorType::PUSH:
586             delegate_->Push(target, params);
587             break;
588         case NavigatorType::REPLACE:
589             delegate_->Replace(target, params);
590             break;
591         case NavigatorType::BACK:
592             delegate_->BackWithTarget(target, params);
593             break;
594         default:
595             LOGE("Navigator type is invalid!");
596             delegate_->BackWithTarget(target, params);
597     }
598 }
599 
GetCurrentPageUrl() const600 std::string DeclarativeFrontend::GetCurrentPageUrl() const
601 {
602     CHECK_NULL_RETURN(delegate_, "");
603     return delegate_->GetCurrentPageUrl();
604 }
605 
606 // Get the currently running JS page information in NG structure.
GetCurrentPageSourceMap() const607 RefPtr<Framework::RevSourceMap> DeclarativeFrontend::GetCurrentPageSourceMap() const
608 {
609     CHECK_NULL_RETURN(delegate_, nullptr);
610     return delegate_->GetCurrentPageSourceMap();
611 }
612 
613 // Get the currently running JS page information in NG structure.
GetFaAppSourceMap() const614 RefPtr<Framework::RevSourceMap> DeclarativeFrontend::GetFaAppSourceMap() const
615 {
616     CHECK_NULL_RETURN(delegate_, nullptr);
617     return delegate_->GetFaAppSourceMap();
618 }
619 
GetStageSourceMap(std::unordered_map<std::string,RefPtr<Framework::RevSourceMap>> & sourceMap) const620 void DeclarativeFrontend::GetStageSourceMap(
621     std::unordered_map<std::string, RefPtr<Framework::RevSourceMap>>& sourceMap) const
622 {
623     if (delegate_) {
624         delegate_->GetStageSourceMap(sourceMap);
625     }
626 }
627 
GetPageRouterManager() const628 RefPtr<NG::PageRouterManager> DeclarativeFrontend::GetPageRouterManager() const
629 {
630     CHECK_NULL_RETURN(delegate_, nullptr);
631     return delegate_->GetPageRouterManager();
632 }
633 
RestoreRouterStack(const std::string & contentInfo)634 std::string DeclarativeFrontend::RestoreRouterStack(const std::string& contentInfo)
635 {
636     if (delegate_) {
637         return delegate_->RestoreRouterStack(contentInfo);
638     }
639     return "";
640 }
641 
GetContentInfo() const642 std::string DeclarativeFrontend::GetContentInfo() const
643 {
644     if (delegate_) {
645         return delegate_->GetContentInfo();
646     }
647     return "";
648 }
649 
GetRouterSize() const650 int32_t DeclarativeFrontend::GetRouterSize() const
651 {
652     if (delegate_) {
653         return delegate_->GetStackSize();
654     }
655     return -1;
656 }
657 
SendCallbackMessage(const std::string & callbackId,const std::string & data) const658 void DeclarativeFrontend::SendCallbackMessage(const std::string& callbackId, const std::string& data) const
659 {
660     if (delegate_) {
661         delegate_->OnJSCallback(callbackId, data);
662     }
663 }
664 
SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher> & dispatcher) const665 void DeclarativeFrontend::SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher>& dispatcher) const
666 {
667     if (delegate_) {
668         delegate_->SetJsMessageDispatcher(dispatcher);
669     }
670 }
671 
TransferComponentResponseData(int callbackId,int32_t code,std::vector<uint8_t> && data) const672 void DeclarativeFrontend::TransferComponentResponseData(int callbackId, int32_t code, std::vector<uint8_t>&& data) const
673 {
674     if (delegate_) {
675         delegate_->TransferComponentResponseData(callbackId, code, std::move(data));
676     }
677 }
678 
TransferJsResponseData(int callbackId,int32_t code,std::vector<uint8_t> && data) const679 void DeclarativeFrontend::TransferJsResponseData(int callbackId, int32_t code, std::vector<uint8_t>&& data) const
680 {
681     if (delegate_) {
682         delegate_->TransferJsResponseData(callbackId, code, std::move(data));
683     }
684 }
685 
GetContextValue()686 NativeValue* DeclarativeFrontend::GetContextValue()
687 {
688     return jsEngine_->GetContextValue();
689 }
690 
691 #if defined(PREVIEW)
TransferJsResponseDataPreview(int callbackId,int32_t code,ResponseData responseData) const692 void DeclarativeFrontend::TransferJsResponseDataPreview(int callbackId, int32_t code, ResponseData responseData) const
693 {
694     delegate_->TransferJsResponseDataPreview(callbackId, code, responseData);
695 }
696 
GetNewComponentWithJsCode(const std::string & jsCode,const std::string & viewID)697 RefPtr<Component> DeclarativeFrontend::GetNewComponentWithJsCode(const std::string& jsCode, const std::string& viewID)
698 {
699     if (jsEngine_) {
700         return jsEngine_->GetNewComponentWithJsCode(jsCode, viewID);
701     }
702     return nullptr;
703 }
704 #endif
705 
TransferJsPluginGetError(int callbackId,int32_t errorCode,std::string && errorMessage) const706 void DeclarativeFrontend::TransferJsPluginGetError(int callbackId, int32_t errorCode, std::string&& errorMessage) const
707 {
708     if (delegate_) {
709         delegate_->TransferJsPluginGetError(callbackId, errorCode, std::move(errorMessage));
710     }
711 }
712 
TransferJsEventData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data) const713 void DeclarativeFrontend::TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const
714 {
715     if (delegate_) {
716         delegate_->TransferJsEventData(callbackId, code, std::move(data));
717     }
718 }
719 
LoadPluginJsCode(std::string && jsCode) const720 void DeclarativeFrontend::LoadPluginJsCode(std::string&& jsCode) const
721 {
722     if (delegate_) {
723         delegate_->LoadPluginJsCode(std::move(jsCode));
724     }
725 }
726 
LoadPluginJsByteCode(std::vector<uint8_t> && jsCode,std::vector<int32_t> && jsCodeLen) const727 void DeclarativeFrontend::LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) const
728 {
729     if (delegate_) {
730         delegate_->LoadPluginJsByteCode(std::move(jsCode), std::move(jsCodeLen));
731     }
732 }
733 
UpdateState(Frontend::State state)734 void DeclarativeFrontend::UpdateState(Frontend::State state)
735 {
736     if (!delegate_ || state == Frontend::State::ON_CREATE) {
737         return;
738     }
739     bool needPostJsTask = true;
740     auto container = Container::Current();
741     CHECK_NULL_VOID(container);
742     const auto& setting = container->GetSettings();
743     needPostJsTask = !(setting.usePlatformAsUIThread && setting.useUIAsJSThread);
744     if (needPostJsTask) {
745         delegate_->UpdateApplicationState(delegate_->GetAppID(), state);
746         return;
747     }
748     if (jsEngine_) {
749         jsEngine_->UpdateApplicationState(delegate_->GetAppID(), state);
750     }
751 }
752 
OnWindowDisplayModeChanged(bool isShownInMultiWindow,const std::string & data)753 void DeclarativeFrontend::OnWindowDisplayModeChanged(bool isShownInMultiWindow, const std::string& data)
754 {
755     delegate_->OnWindowDisplayModeChanged(isShownInMultiWindow, data);
756 }
757 
OnSaveAbilityState(std::string & data)758 void DeclarativeFrontend::OnSaveAbilityState(std::string& data)
759 {
760     if (delegate_) {
761         delegate_->OnSaveAbilityState(data);
762     }
763 }
764 
OnRestoreAbilityState(const std::string & data)765 void DeclarativeFrontend::OnRestoreAbilityState(const std::string& data)
766 {
767     if (delegate_) {
768         delegate_->OnRestoreAbilityState(data);
769     }
770 }
771 
OnNewWant(const std::string & data)772 void DeclarativeFrontend::OnNewWant(const std::string& data)
773 {
774     if (delegate_) {
775         delegate_->OnNewWant(data);
776     }
777 }
778 
GetAccessibilityManager() const779 RefPtr<AccessibilityManager> DeclarativeFrontend::GetAccessibilityManager() const
780 {
781     if (!delegate_) {
782         LOGE("GetAccessibilityManager delegate is null");
783         return nullptr;
784     }
785     return delegate_->GetJSAccessibilityManager();
786 }
787 
GetWindowConfig()788 WindowConfig& DeclarativeFrontend::GetWindowConfig()
789 {
790     if (!delegate_) {
791         static WindowConfig windowConfig;
792         LOGW("delegate is null, return default config");
793         return windowConfig;
794     }
795     return delegate_->GetWindowConfig();
796 }
797 
OnBackPressed()798 bool DeclarativeFrontend::OnBackPressed()
799 {
800     if (!delegate_) {
801         LOGW("delegate is null, return false");
802         return false;
803     }
804     return delegate_->OnPageBackPress();
805 }
806 
OnShow()807 void DeclarativeFrontend::OnShow()
808 {
809     if (delegate_) {
810         foregroundFrontend_ = true;
811         delegate_->OnForeground();
812     }
813 }
814 
OnHide()815 void DeclarativeFrontend::OnHide()
816 {
817     if (delegate_) {
818         delegate_->OnBackGround();
819         foregroundFrontend_ = false;
820     }
821 }
822 
OnConfigurationUpdated(const std::string & data)823 void DeclarativeFrontend::OnConfigurationUpdated(const std::string& data)
824 {
825     if (delegate_) {
826         delegate_->OnConfigurationUpdated(data);
827     }
828 }
829 
OnActive()830 void DeclarativeFrontend::OnActive()
831 {
832     if (delegate_) {
833         foregroundFrontend_ = true;
834         delegate_->InitializeAccessibilityCallback();
835     }
836 }
837 
OnInactive()838 void DeclarativeFrontend::OnInactive() {}
839 
OnStartContinuation()840 bool DeclarativeFrontend::OnStartContinuation()
841 {
842     if (!delegate_) {
843         LOGW("delegate is null, return false");
844         return false;
845     }
846     return delegate_->OnStartContinuation();
847 }
848 
OnCompleteContinuation(int32_t code)849 void DeclarativeFrontend::OnCompleteContinuation(int32_t code)
850 {
851     if (delegate_) {
852         delegate_->OnCompleteContinuation(code);
853     }
854 }
855 
OnMemoryLevel(const int32_t level)856 void DeclarativeFrontend::OnMemoryLevel(const int32_t level)
857 {
858     if (delegate_) {
859         delegate_->OnMemoryLevel(level);
860     }
861 }
862 
OnSaveData(std::string & data)863 void DeclarativeFrontend::OnSaveData(std::string& data)
864 {
865     if (delegate_) {
866         delegate_->OnSaveData(data);
867     }
868 }
869 
GetPluginsUsed(std::string & data)870 void DeclarativeFrontend::GetPluginsUsed(std::string& data)
871 {
872     if (delegate_) {
873         delegate_->GetPluginsUsed(data);
874     }
875 }
876 
OnRestoreData(const std::string & data)877 bool DeclarativeFrontend::OnRestoreData(const std::string& data)
878 {
879     if (!delegate_) {
880         LOGW("delegate is null, return false");
881         return false;
882     }
883     return delegate_->OnRestoreData(data);
884 }
885 
OnRemoteTerminated()886 void DeclarativeFrontend::OnRemoteTerminated()
887 {
888     if (delegate_) {
889         delegate_->OnRemoteTerminated();
890     }
891 }
892 
OnNewRequest(const std::string & data)893 void DeclarativeFrontend::OnNewRequest(const std::string& data)
894 {
895     if (delegate_) {
896         delegate_->OnNewRequest(data);
897     }
898 }
899 
CallRouterBack()900 void DeclarativeFrontend::CallRouterBack()
901 {
902     if (delegate_) {
903         if (delegate_->GetStackSize() == 1 && isSubWindow_) {
904             LOGW("Can't back because this is the last page of sub window!");
905             return;
906         }
907         delegate_->CallPopPage();
908     }
909 }
910 
OnSurfaceChanged(int32_t width,int32_t height)911 void DeclarativeFrontend::OnSurfaceChanged(int32_t width, int32_t height)
912 {
913     if (delegate_) {
914         delegate_->OnSurfaceChanged();
915     }
916 }
917 
OnLayoutCompleted(const std::string & componentId)918 void DeclarativeFrontend::OnLayoutCompleted(const std::string& componentId)
919 {
920     if (delegate_) {
921         delegate_->OnLayoutCompleted(componentId);
922     }
923 }
924 
OnDrawCompleted(const std::string & componentId)925 void DeclarativeFrontend::OnDrawCompleted(const std::string& componentId)
926 {
927     if (delegate_) {
928         delegate_->OnDrawCompleted(componentId);
929     }
930 }
931 
HotReload()932 void DeclarativeFrontend::HotReload()
933 {
934     auto manager = GetPageRouterManager();
935     CHECK_NULL_VOID(manager);
936     manager->FlushFrontend();
937 }
938 
FlushReload()939 void DeclarativeFrontend::FlushReload()
940 {
941     if (jsEngine_) {
942         jsEngine_->FlushReload();
943     }
944 }
945 
DumpFrontend() const946 void DeclarativeFrontend::DumpFrontend() const
947 {
948     if (!delegate_) {
949         return;
950     }
951     int32_t routerIndex = 0;
952     std::string routerName;
953     std::string routerPath;
954     delegate_->GetState(routerIndex, routerName, routerPath);
955 
956     if (DumpLog::GetInstance().GetDumpFile()) {
957         DumpLog::GetInstance().AddDesc("Components: " + std::to_string(delegate_->GetComponentsCount()));
958         DumpLog::GetInstance().AddDesc("Path: " + routerPath);
959         DumpLog::GetInstance().AddDesc("Length: " + std::to_string(routerIndex));
960         DumpLog::GetInstance().Print(0, routerName, 0);
961     }
962 }
963 
GetPagePath() const964 std::string DeclarativeFrontend::GetPagePath() const
965 {
966     if (!delegate_) {
967         return "";
968     }
969     int32_t routerIndex = 0;
970     std::string routerName;
971     std::string routerPath;
972     delegate_->GetState(routerIndex, routerName, routerPath);
973     return routerPath + routerName;
974 }
975 
TriggerGarbageCollection()976 void DeclarativeFrontend::TriggerGarbageCollection()
977 {
978     if (jsEngine_) {
979         jsEngine_->RunGarbageCollection();
980     }
981 }
982 
DumpHeapSnapshot(bool isPrivate)983 void DeclarativeFrontend::DumpHeapSnapshot(bool isPrivate)
984 {
985     if (jsEngine_) {
986         jsEngine_->DumpHeapSnapshot(isPrivate);
987     }
988 }
989 
SetColorMode(ColorMode colorMode)990 void DeclarativeFrontend::SetColorMode(ColorMode colorMode)
991 {
992     if (delegate_) {
993         delegate_->SetColorMode(colorMode);
994     }
995 }
996 
RebuildAllPages()997 void DeclarativeFrontend::RebuildAllPages()
998 {
999     if (delegate_) {
1000         delegate_->RebuildAllPages();
1001     }
1002 }
1003 
NotifyAppStorage(const std::string & key,const std::string & value)1004 void DeclarativeFrontend::NotifyAppStorage(const std::string& key, const std::string& value)
1005 {
1006     if (!delegate_) {
1007         LOGW("delegate is null, return false");
1008         return;
1009     }
1010     delegate_->NotifyAppStorage(jsEngine_, key, value);
1011 }
1012 
HandleAsyncEvent(const EventMarker & eventMarker)1013 void DeclarativeEventHandler::HandleAsyncEvent(const EventMarker& eventMarker)
1014 {
1015     LOGI("HandleAsyncEvent pageId: %{private}d, eventId: %{private}s, eventType: %{private}s",
1016         eventMarker.GetData().pageId, eventMarker.GetData().eventId.c_str(), eventMarker.GetData().eventType.c_str());
1017     std::string param = eventMarker.GetData().GetEventParam();
1018     if (eventMarker.GetData().isDeclarativeUi) {
1019         if (delegate_) {
1020             delegate_->GetUiTask().PostTask([eventMarker] { eventMarker.CallUiFunction(); });
1021         }
1022     } else {
1023         delegate_->FireAsyncEvent(eventMarker.GetData().eventId, param.append("null"), std::string(""));
1024     }
1025 
1026     AccessibilityEvent accessibilityEvent;
1027     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1028     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1029     delegate_->FireAccessibilityEvent(accessibilityEvent);
1030 }
1031 
HandleAsyncEvent(const EventMarker & eventMarker,const BaseEventInfo & info)1032 void DeclarativeEventHandler::HandleAsyncEvent(const EventMarker& eventMarker, const BaseEventInfo& info)
1033 {
1034     std::string eventParam;
1035     if (eventMarker.GetData().eventType.find("touch") != std::string::npos) {
1036         TouchInfoToString(info, eventParam);
1037     } else if (eventMarker.GetData().eventType.find("mouse") != std::string::npos) {
1038         MouseInfoToString(info, eventParam);
1039     } else if (eventMarker.GetData().eventType == "swipe") {
1040         SwipeInfoToString(info, eventParam);
1041     }
1042 
1043     LOGD("HandleAsyncEvent pageId: %{public}d, eventId: %{public}s, eventType: %{public}s",
1044         eventMarker.GetData().pageId, eventMarker.GetData().eventId.c_str(), eventMarker.GetData().eventType.c_str());
1045     std::string param = eventMarker.GetData().GetEventParam();
1046     if (eventParam.empty()) {
1047         param.append("null");
1048     } else {
1049         param.append(eventParam);
1050     }
1051 
1052     if (eventMarker.GetData().isDeclarativeUi) {
1053         if (delegate_) {
1054             auto cinfo = CopyEventInfo(info);
1055             delegate_->GetUiTask().PostTask([eventMarker, cinfo] { eventMarker.CallUiArgFunction(cinfo.get()); });
1056         }
1057     } else {
1058         delegate_->FireAsyncEvent(eventMarker.GetData().eventId, param, "");
1059     }
1060 
1061     AccessibilityEvent accessibilityEvent;
1062     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1063     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1064     delegate_->FireAccessibilityEvent(accessibilityEvent);
1065 }
1066 
HandleAsyncEvent(const EventMarker & eventMarker,const std::shared_ptr<BaseEventInfo> & info)1067 void DeclarativeEventHandler::HandleAsyncEvent(
1068     const EventMarker& eventMarker, const std::shared_ptr<BaseEventInfo>& info)
1069 {
1070     if (eventMarker.GetData().isDeclarativeUi) {
1071         if (delegate_) {
1072             delegate_->GetUiTask().PostTask([eventMarker, info] { eventMarker.CallUiArgFunction(info.get()); });
1073         }
1074     }
1075 }
1076 
HandleSyncEvent(const EventMarker & eventMarker,const KeyEvent & info,bool & result)1077 void DeclarativeEventHandler::HandleSyncEvent(const EventMarker& eventMarker, const KeyEvent& info, bool& result)
1078 {
1079     LOGD("HandleSyncEvent pageId: %{public}d, eventId: %{public}s, eventType: %{public}s", eventMarker.GetData().pageId,
1080         eventMarker.GetData().eventId.c_str(), eventMarker.GetData().eventType.c_str());
1081     std::string param = std::string("\"")
1082                             .append(eventMarker.GetData().eventType)
1083                             .append("\",{\"code\":")
1084                             .append(std::to_string(static_cast<int32_t>(info.code)))
1085                             .append(",\"action\":")
1086                             .append(std::to_string(static_cast<int32_t>(info.action)))
1087                             .append(",\"repeatCount\":")
1088                             .append(std::to_string(static_cast<int32_t>(info.repeatTime)))
1089                             .append(",\"timestamp\":")
1090                             .append(std::to_string(info.timeStamp.time_since_epoch().count()))
1091                             .append(",\"key\":\"")
1092                             .append(info.key)
1093                             .append("\"},");
1094 
1095     result = delegate_->FireSyncEvent(eventMarker.GetData().eventId, param, "");
1096 
1097     AccessibilityEvent accessibilityEvent;
1098     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1099     accessibilityEvent.eventType = std::to_string(static_cast<int32_t>(info.code));
1100     delegate_->FireAccessibilityEvent(accessibilityEvent);
1101 }
1102 
HandleAsyncEvent(const EventMarker & eventMarker,int32_t param)1103 void DeclarativeEventHandler::HandleAsyncEvent(const EventMarker& eventMarker, int32_t param)
1104 {
1105     LOGW("js event handler does not support this event type!");
1106     AccessibilityEvent accessibilityEvent;
1107     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1108     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1109     delegate_->FireAccessibilityEvent(accessibilityEvent);
1110 }
1111 
HandleAsyncEvent(const EventMarker & eventMarker,const KeyEvent & info)1112 void DeclarativeEventHandler::HandleAsyncEvent(const EventMarker& eventMarker, const KeyEvent& info)
1113 {
1114     LOGW("js event handler does not support this event type!");
1115     AccessibilityEvent accessibilityEvent;
1116     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1117     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1118     delegate_->FireAccessibilityEvent(accessibilityEvent);
1119 }
1120 
HandleAsyncEvent(const EventMarker & eventMarker,const std::string & param)1121 void DeclarativeEventHandler::HandleAsyncEvent(const EventMarker& eventMarker, const std::string& param)
1122 {
1123     LOGD("HandleAsyncEvent pageId: %{public}d, eventId: %{public}s", eventMarker.GetData().pageId,
1124         eventMarker.GetData().eventId.c_str());
1125 
1126     if (eventMarker.GetData().isDeclarativeUi) {
1127         std::string fixParam(param);
1128         std::string::size_type startPos = param.find_first_of("{");
1129         std::string::size_type endPos = param.find_last_of("}");
1130         if (startPos != std::string::npos && endPos != std::string::npos && startPos < endPos) {
1131             fixParam = fixParam.substr(startPos, endPos - startPos + 1);
1132         }
1133         if (delegate_) {
1134             delegate_->GetUiTask().PostTask([eventMarker, fixParam] { eventMarker.CallUiStrFunction(fixParam); });
1135         }
1136     } else {
1137         delegate_->FireAsyncEvent(eventMarker.GetData().eventId, param, "");
1138     }
1139 
1140     AccessibilityEvent accessibilityEvent;
1141     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1142     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1143     delegate_->FireAccessibilityEvent(accessibilityEvent);
1144 }
1145 
HandleSyncEvent(const EventMarker & eventMarker,bool & result)1146 void DeclarativeEventHandler::HandleSyncEvent(const EventMarker& eventMarker, bool& result)
1147 {
1148     LOGW("js event handler does not support this event type!");
1149     AccessibilityEvent accessibilityEvent;
1150     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1151     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1152     delegate_->FireAccessibilityEvent(accessibilityEvent);
1153 }
1154 
HandleSyncEvent(const EventMarker & eventMarker,const std::shared_ptr<BaseEventInfo> & info)1155 void DeclarativeEventHandler::HandleSyncEvent(
1156     const EventMarker& eventMarker, const std::shared_ptr<BaseEventInfo>& info)
1157 {
1158     if (delegate_) {
1159         delegate_->GetUiTask().PostSyncTask([eventMarker, info] { eventMarker.CallUiArgFunction(info.get()); });
1160     }
1161 }
1162 
HandleSyncEvent(const EventMarker & eventMarker,const BaseEventInfo & info,bool & result)1163 void DeclarativeEventHandler::HandleSyncEvent(const EventMarker& eventMarker, const BaseEventInfo& info, bool& result)
1164 {
1165     LOGW("js event handler does not support this event type!");
1166     AccessibilityEvent accessibilityEvent;
1167     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1168     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1169     delegate_->FireAccessibilityEvent(accessibilityEvent);
1170 }
1171 
HandleSyncEvent(const EventMarker & eventMarker,const std::string & param,std::string & result)1172 void DeclarativeEventHandler::HandleSyncEvent(
1173     const EventMarker& eventMarker, const std::string& param, std::string& result)
1174 {
1175     LOGW("js event handler does not support this event type!");
1176     AccessibilityEvent accessibilityEvent;
1177     accessibilityEvent.nodeId = StringUtils::StringToInt(eventMarker.GetData().eventId);
1178     accessibilityEvent.eventType = eventMarker.GetData().eventType;
1179     delegate_->FireAccessibilityEvent(accessibilityEvent);
1180     delegate_->FireSyncEvent(eventMarker.GetData().eventId, param, std::string(""), result);
1181 }
1182 
HandleSyncEvent(const EventMarker & eventMarker,const std::string & componentId,const int32_t nodeId,const bool isDestroy)1183 void DeclarativeEventHandler::HandleSyncEvent(
1184     const EventMarker& eventMarker, const std::string& componentId, const int32_t nodeId, const bool isDestroy)
1185 {
1186     if (delegate_) {
1187         delegate_->FireExternalEvent(eventMarker.GetData().eventId, componentId, nodeId, isDestroy);
1188     }
1189 }
1190 
1191 } // namespace OHOS::Ace
1192