• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MODEL_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 
23 #include "base/utils/macros.h"
24 #include "base/want/want_wrap.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/pattern/ui_extension/session_wrapper.h"
27 #include "core/components_ng/pattern/ui_extension/ui_extension_config.h"
28 
29 namespace OHOS::AAFwk {
30 class Want;
31 class WantParams;
32 } // namespace OHOS::AAFwk
33 
34 namespace OHOS::Ace {
35 namespace NG {
36 class SecurityUIExtensionProxy;
37 class UIExtensionProxy;
38 
39 struct InnerModalUIExtensionConfig {
40     bool isAsyncModalBinding = false;
41     bool isModal = true;
42     bool isDensityFollowHost = false;
43     bool isWindowModeFollowHost = false;
44 };
45 
46 struct UIExtensionConfig {
47     RefPtr<OHOS::Ace::WantWrap> wantWrap = nullptr;
48     RefPtr<NG::FrameNode> placeholderNode = nullptr;
49     bool transferringCaller = false;
50     bool densityDpi = false;
51     NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY;
52     bool backgroundTransparent = true;
53 };
54 }
55 
56 class ACE_EXPORT UIExtensionModel {
57 public:
58     static UIExtensionModel* GetInstance();
59     virtual ~UIExtensionModel() = default;
60 
61     virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap,
62         const std::map<NG::PlaceholderType, RefPtr<NG::FrameNode>>& placeholderMap,
63         bool transferringCaller = false, bool densityDpi = false, bool isWindowModeFollowHost = false);
64     // for Embedded Component
65     virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, NG::SessionType sessionType);
Create(const NG::UIExtensionConfig & config)66     virtual void Create(const NG::UIExtensionConfig& config) {}
67     virtual void InitializeDynamicComponent(const RefPtr<NG::FrameNode>& frameNode, const std::string& hapPath,
68         const std::string& abcPath, const std::string& entryPoint, void* runtime);
69     virtual void InitializeIsolatedComponent(const RefPtr<NG::FrameNode>& frameNode,
70         const RefPtr<OHOS::Ace::WantWrap>& wantWrap, void* runtime);
71     virtual void SetAdaptiveWidth(bool state);
72     virtual void SetAdaptiveHeight(bool state);
GetUiExtensionType(NG::SessionType sessionType)73     virtual std::string GetUiExtensionType(NG::SessionType sessionType)
74     {
75         return "";
76     }
77 
78     virtual void SetOnRemoteReady(std::function<void(const RefPtr<NG::UIExtensionProxy>&)>&& onRemoteReady);
79     virtual void SetOnRelease(std::function<void(int32_t)>&& onRelease);
80     virtual void SetOnResult(std::function<void(int32_t, const AAFwk::Want&)>&& onResult);
81     virtual void SetOnTerminated(std::function<void(int32_t, const RefPtr<WantWrap>&)>&& onTerminated,
82         NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {}
83     virtual void SetOnReceive(std::function<void(const AAFwk::WantParams&)>&& onReceive,
84         NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {}
SetSecurityOnRemoteReady(std::function<void (const RefPtr<NG::SecurityUIExtensionProxy> &)> && onRemoteReady)85     virtual void SetSecurityOnRemoteReady(
86         std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>&& onRemoteReady) {}
87     virtual void SetOnError(
88         std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError,
89         NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY);
90     virtual void SetPlatformOnError(
91         std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError);
92     virtual void SetOnDrawReady(std::function<void()>&& onDrawReady);
93 };
94 } // namespace OHOS::Ace
95 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MODEL_H
96