• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "js_live_form_extension.h"
17 #include "hitrace_meter.h"
18 #include "js_ui_extension_base.h"
19 #include "fms_log_wrapper.h"
20 #include "js_live_form_extension_context.h"
21 #include "js_live_form_extension_impl.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
Create(const std::unique_ptr<Runtime> & runtime)25 JsLiveFormExtension *JsLiveFormExtension::Create(const std::unique_ptr<Runtime> &runtime)
26 {
27     return new JsLiveFormExtension(runtime);
28 }
29 
JsLiveFormExtension(const std::unique_ptr<Runtime> & runtime)30 JsLiveFormExtension::JsLiveFormExtension(const std::unique_ptr<Runtime> &runtime)
31 {
32     impl_ = std::make_shared<JsLiveFormExtensionImpl>(runtime);
33     SetUIExtensionBaseImpl(impl_);
34 }
35 
Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> & record,const std::shared_ptr<AppExecFwk::OHOSApplication> & application,std::shared_ptr<AppExecFwk::AbilityHandler> & handler,const sptr<IRemoteObject> & token)36 void JsLiveFormExtension::Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
37     const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
38     std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
39     const sptr<IRemoteObject> &token)
40 {
41     HILOG_DEBUG("Begin init live form extension");
42     if (record == nullptr) {
43         HILOG_ERROR("null record");
44         return;
45     }
46 
47     auto appContext = Context::GetApplicationContext();
48     if (appContext == nullptr) {
49         HILOG_ERROR("null appContext");
50         return;
51     }
52 
53     if (impl_ == nullptr) {
54         HILOG_ERROR("null impl_");
55         return;
56     }
57 
58     std::shared_ptr<LiveFormExtensionContext> context = std::make_shared<LiveFormExtensionContext>();
59     context->SetToken(token);
60     context->SetApplicationInfo(appContext->GetApplicationInfo());
61     context->SetResourceManager(appContext->GetResourceManager());
62     context->SetParentContext(appContext);
63 
64     auto abilityInfo = record->GetAbilityInfo();
65     context->SetAbilityInfo(abilityInfo);
66     context->InitHapModuleInfo(abilityInfo);
67     context->SetConfiguration(appContext->GetConfiguration());
68     if (abilityInfo->applicationInfo.multiProjects) {
69         std::shared_ptr<Context> moduleContext = context->CreateModuleContext(abilityInfo->moduleName);
70         if (moduleContext != nullptr) {
71             auto rm = moduleContext->GetResourceManager();
72             context->SetResourceManager(rm);
73         }
74     }
75 
76     Extension::Init(record, application, handler, token);
77     impl_->SetContext(context);
78     impl_->SetAbilityInfo(Extension::abilityInfo_);
79     auto extensionCommon = impl_->Init(record, application, handler, token);
80     ExtensionBase<LiveFormExtensionContext>::SetExtensionCommon(extensionCommon);
81 }
82 } // namespace AbilityRuntime
83 } // namespace OHOS