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 UIContentErrorCode CardFrontendDelegateDeclarative::RunCard(
34 const std::string& url, 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_RETURN(pageRouterManager, UIContentErrorCode::NULL_PAGE_ROUTER);
39 pageRouterManager->SetManifestParser(GetManifestParser());
40 pageRouterManager->SetIsCard();
41 auto cardPipeline = GetPipelineContext();
42 auto taskExecutor = GetTaskExecutor();
43 CHECK_NULL_RETURN(taskExecutor, UIContentErrorCode::NULL_POINTER);
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, "ArkUICardFrontendRunCard"); // eTSCard UI == Main JS/UI/PLATFORM
56
57 return UIContentErrorCode::NO_ERRORS;
58 }
59
FireCardEvent(const EventMarker & eventMarker,const std::string & params)60 void CardFrontendDelegateDeclarative::FireCardEvent(const EventMarker& eventMarker, const std::string& params) {}
61
FireCardAction(const std::string & action)62 void CardFrontendDelegateDeclarative::FireCardAction(const std::string& action)
63 {
64 auto context = GetPipelineContext();
65 CHECK_NULL_VOID(context);
66 auto taskExecutor = GetTaskExecutor();
67 CHECK_NULL_VOID(taskExecutor);
68 taskExecutor->PostTask(
69 [weakCardPipeline = WeakPtr<PipelineBase>(context), action]() {
70 auto context = weakCardPipeline.Upgrade();
71 if (context) {
72 context->OnActionEvent(action);
73 }
74 },
75 TaskExecutor::TaskType::UI, "ArkUICardFrontendFireAction"); // eTSCard UI == Main JS/UI/PLATFORM
76 }
77
MeasureText(MeasureContext context)78 double CardFrontendDelegateDeclarative::MeasureText(MeasureContext context)
79 {
80 return 0.0;
81 }
82
83 } // namespace OHOS::Ace::Framework
84