• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/common/thread_checker.h"
21 
22 namespace OHOS::Ace::Framework {
~FormFrontendDelegateDeclarative()23 FormFrontendDelegateDeclarative::~FormFrontendDelegateDeclarative()
24 {
25     CHECK_RUN_ON(JS);
26     LOG_DESTROY();
27 }
28 
RunCard(const std::string & url,const std::string & params,const std::string & profile,int64_t cardId)29 void FormFrontendDelegateDeclarative::RunCard(const std::string& url,
30     const std::string& params, const std::string& profile, int64_t cardId)
31 {
32     ACE_SCOPED_TRACE("FormFrontendDelegateDeclarative::RunCard");
33     auto pageRouterManager = GetPageRouterManager();
34     CHECK_NULL_VOID(pageRouterManager);
35     pageRouterManager->SetManifestParser(GetManifestParser());
36     pageRouterManager->SetIsCard();
37     auto cardPipeline = GetPipelineContext();
38     auto taskExecutor = GetTaskExecutor();
39     CHECK_NULL_VOID(taskExecutor);
40     cardData_ = params;
41     auto container = Container::Current();
42     CHECK_NULL_VOID(container);
43     auto weakCardPipeline = WeakPtr<PipelineBase>(cardPipeline);
44     container->SetCardPipeline(weakCardPipeline, cardId);
45 #ifndef PREVIEW
46     pageRouterManager->RunCard(url, params, cardId);
47 #else
48     taskExecutor->PostTask(
49         [weak = WeakClaim<NG::PageRouterManager>(RawPtr(pageRouterManager)), url, params, cardId]() {
50             auto pageRouterManager = weak.Upgrade();
51             CHECK_NULL_VOID(pageRouterManager);
52             pageRouterManager->RunCard(url, params, cardId);
53         },
54         TaskExecutor::TaskType::JS);
55 #endif
56 }
57 
FireCardEvent(const EventMarker & eventMarker,const std::string & params)58 void FormFrontendDelegateDeclarative::FireCardEvent(const EventMarker& eventMarker, const std::string& params) {}
59 
FireCardAction(const std::string & action)60 void FormFrontendDelegateDeclarative::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 } // namespace OHOS::Ace::Framework
76