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