1 /*
2 * Copyright (c) 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/card_frontend/form_frontend_delegate_declarative.h"
17
18 #include "base/log/event_report.h"
19 #include "base/utils/utils.h"
20 #include "base/utils/measure_util.h"
21 #include "core/common/thread_checker.h"
22
23 namespace OHOS::Ace::Framework {
~FormFrontendDelegateDeclarative()24 FormFrontendDelegateDeclarative::~FormFrontendDelegateDeclarative()
25 {
26 CHECK_RUN_ON(JS);
27 LOG_DESTROY();
28 }
29
RunCard(const std::string & url,const std::string & params,const std::string & profile,int64_t cardId)30 void FormFrontendDelegateDeclarative::RunCard(const std::string& url,
31 const std::string& params, const std::string& profile, int64_t cardId)
32 {
33 ACE_SCOPED_TRACE("FormFrontendDelegateDeclarative::RunCard");
34 auto pageRouterManager = GetPageRouterManager();
35 CHECK_NULL_VOID(pageRouterManager);
36 pageRouterManager->SetManifestParser(GetManifestParser());
37 pageRouterManager->SetIsCard();
38 auto cardPipeline = GetPipelineContext();
39 auto taskExecutor = GetTaskExecutor();
40 CHECK_NULL_VOID(taskExecutor);
41 cardData_ = params;
42 auto container = Container::Current();
43 CHECK_NULL_VOID(container);
44 auto weakCardPipeline = WeakPtr<PipelineBase>(cardPipeline);
45 container->SetCardPipeline(weakCardPipeline, cardId);
46 #ifndef PREVIEW
47 pageRouterManager->RunCard(url, params, cardId);
48 #else
49 taskExecutor->PostTask(
50 [weak = WeakClaim<NG::PageRouterManager>(RawPtr(pageRouterManager)), url, params, cardId]() {
51 auto pageRouterManager = weak.Upgrade();
52 CHECK_NULL_VOID(pageRouterManager);
53 pageRouterManager->RunCard(url, params, cardId);
54 },
55 TaskExecutor::TaskType::JS);
56 #endif
57 }
58
FireCardEvent(const EventMarker & eventMarker,const std::string & params)59 void FormFrontendDelegateDeclarative::FireCardEvent(const EventMarker& eventMarker, const std::string& params) {}
60
FireCardAction(const std::string & action)61 void FormFrontendDelegateDeclarative::FireCardAction(const std::string& action)
62 {
63 auto context = GetPipelineContext();
64 CHECK_NULL_VOID(context);
65 auto taskExecutor = GetTaskExecutor();
66 CHECK_NULL_VOID(taskExecutor);
67 taskExecutor->PostTask(
68 [weakCardPipeline = WeakPtr<PipelineBase>(context), action]() {
69 auto context = weakCardPipeline.Upgrade();
70 if (context) {
71 context->OnActionEvent(action);
72 }
73 },
74 TaskExecutor::TaskType::UI); // eTSCard UI == Main JS/UI/PLATFORM
75 }
76 } // namespace OHOS::Ace::Framework
77