• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace OHOS::Ace::Framework {
19 
~CardFrontendDelegateDeclarative()20 CardFrontendDelegateDeclarative::~CardFrontendDelegateDeclarative()
21 {
22     CHECK_RUN_ON(JS);
23     TAG_LOGI(AceLogTag::ACE_FORM, "CardDelegateDeclarative Destroyed");
24 }
25 
RunCard(const std::string & url,const std::string & params,const std::string & profile,int64_t cardId)26 UIContentErrorCode CardFrontendDelegateDeclarative::RunCard(
27     const std::string& url, const std::string& params, const std::string& profile, int64_t cardId)
28 {
29     ACE_SCOPED_TRACE("CardFrontendDelegateDeclarative::RunCard");
30     auto pageRouterManager = GetPageRouterManager();
31     CHECK_NULL_RETURN(pageRouterManager, UIContentErrorCode::NULL_PAGE_ROUTER);
32     pageRouterManager->SetManifestParser(GetManifestParser());
33     pageRouterManager->SetIsCard();
34     auto cardPipeline = GetPipelineContext();
35     auto taskExecutor = GetTaskExecutor();
36     CHECK_NULL_RETURN(taskExecutor, UIContentErrorCode::NULL_POINTER);
37     cardData_ = params;
38     taskExecutor->PostTask(
39         [weakPageRouterManager = WeakPtr<NG::PageRouterManager>(pageRouterManager),
40             weakCardPipeline = WeakPtr<PipelineBase>(cardPipeline), url, params, cardId]() {
41             auto pageRouterManager = weakPageRouterManager.Upgrade();
42             CHECK_NULL_VOID(pageRouterManager);
43             auto container = Container::Current();
44             CHECK_NULL_VOID(container);
45             container->SetCardPipeline(weakCardPipeline, cardId);
46             pageRouterManager->RunCard(url, params, cardId);
47         },
48         TaskExecutor::TaskType::UI, "ArkUICardFrontendRunCard"); // eTSCard UI == Main JS/UI/PLATFORM
49 
50     return UIContentErrorCode::NO_ERRORS;
51 }
52 
FireCardEvent(const EventMarker & eventMarker,const std::string & params)53 void CardFrontendDelegateDeclarative::FireCardEvent(const EventMarker& eventMarker, const std::string& params) {}
54 
FireCardAction(const std::string & action)55 void CardFrontendDelegateDeclarative::FireCardAction(const std::string& action)
56 {
57     auto context = GetPipelineContext();
58     CHECK_NULL_VOID(context);
59     auto taskExecutor = GetTaskExecutor();
60     CHECK_NULL_VOID(taskExecutor);
61     taskExecutor->PostTask(
62         [weakCardPipeline = WeakPtr<PipelineBase>(context), action]() {
63             auto context = weakCardPipeline.Upgrade();
64             if (context) {
65                 context->OnActionEvent(action);
66             }
67         },
68         TaskExecutor::TaskType::UI, "ArkUICardFrontendFireAction"); // eTSCard UI == Main JS/UI/PLATFORM
69 }
70 
MeasureText(MeasureContext context)71 double CardFrontendDelegateDeclarative::MeasureText(MeasureContext context)
72     {
73         return 0.0;
74     }
75 
76 } // namespace OHOS::Ace::Framework
77