• 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 #ifndef PREVIEW
19 #include "form_mgr.h"
20 #endif
21 
22 namespace OHOS::Ace::Framework {
~FormFrontendDelegateDeclarative()23 FormFrontendDelegateDeclarative::~FormFrontendDelegateDeclarative()
24 {
25     CHECK_RUN_ON(JS);
26     TAG_LOGI(AceLogTag::ACE_FORM, "FormDelegateDeclarative Destroyed");
27 }
28 
RunCard(const std::string & url,const std::string & params,const std::string & profile,int64_t cardId,const std::string & entryPoint)29 UIContentErrorCode FormFrontendDelegateDeclarative::RunCard(const std::string& url, const std::string& params,
30     const std::string& profile, int64_t cardId, const std::string& entryPoint)
31 {
32     ACE_SCOPED_TRACE("FormFrontendDelegateDeclarative::RunCard");
33     auto pageRouterManager = GetPageRouterManager();
34     CHECK_NULL_RETURN(pageRouterManager, UIContentErrorCode::NULL_PAGE_ROUTER);
35     pageRouterManager->SetManifestParser(GetManifestParser());
36     pageRouterManager->SetIsCard();
37     auto cardPipeline = GetPipelineContext();
38     auto taskExecutor = GetTaskExecutor();
39     CHECK_NULL_RETURN(taskExecutor, UIContentErrorCode::NULL_POINTER);
40     cardData_ = params;
41     auto container = Container::Current();
42     CHECK_NULL_RETURN(container, UIContentErrorCode::NULL_POINTER);
43     auto weakCardPipeline = WeakPtr<PipelineBase>(cardPipeline);
44     container->SetCardPipeline(weakCardPipeline, cardId);
45 #ifndef PREVIEW
46     return pageRouterManager->RunCard(url, params, cardId, entryPoint);
47 #else
48     taskExecutor->PostTask(
49         [weak = WeakClaim<NG::PageRouterManager>(RawPtr(pageRouterManager)), url, params, cardId, entryPoint]() {
50             auto pageRouterManager = weak.Upgrade();
51             CHECK_NULL_VOID(pageRouterManager);
52             pageRouterManager->RunCard(url, params, cardId, entryPoint);
53         },
54         TaskExecutor::TaskType::JS, "ArkUIFormFrontendRunCard");
55     return UIContentErrorCode::NO_ERRORS;
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, "ArkUIFormFrontendFireAction"); // eTSCard UI == Main JS/UI/PLATFORM
75 }
76 
RegisterFont(const std::string & familyName,const std::string & familySrc,const std::string & bundleName,const std::string & moduleName)77 void FormFrontendDelegateDeclarative::RegisterFont(const std::string& familyName, const std::string& familySrc,
78     const std::string& bundleName, const std::string& moduleName)
79 {
80 #ifndef PREVIEW
81     auto container = Container::Current();
82     CHECK_NULL_VOID(container);
83     std::string formBundleName = container->GetBundleName();
84     if (!OHOS::AppExecFwk::FormMgr::GetInstance().IsSystemAppForm(formBundleName)) {
85         TAG_LOGE(AceLogTag::ACE_FORM, "%{public}s is not system form", formBundleName.c_str());
86         return;
87     }
88 
89     FrontendDelegateDeclarative::RegisterFont(familyName, familySrc, bundleName, moduleName);
90 #endif
91 }
92 } // namespace OHOS::Ace::Framework
93