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 28 namespace OHOS::AAFwk { 29 class Want; 30 class WantParams; 31 } // namespace OHOS::AAFwk 32 33 namespace OHOS::Ace { 34 namespace NG { 35 class SecurityUIExtensionProxy; 36 class UIExtensionProxy; 37 38 struct InnerModalUIExtensionConfig { 39 bool isAsyncModalBinding = false; 40 bool isModal = true; 41 bool isDensityFollowHost = false; 42 }; 43 44 struct UIExtensionConfig { 45 RefPtr<OHOS::Ace::WantWrap> wantWrap = nullptr; 46 RefPtr<NG::FrameNode> placeholderNode = nullptr; 47 bool transferringCaller = false; 48 bool densityDpi = false; 49 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY; 50 }; 51 } 52 53 class ACE_EXPORT UIExtensionModel { 54 public: 55 static UIExtensionModel* GetInstance(); 56 virtual ~UIExtensionModel() = default; 57 58 virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, 59 const RefPtr<NG::FrameNode>& placeholderNode = nullptr, 60 bool transferringCaller = false, bool densityDpi = false); 61 // for Embedded Component 62 virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, NG::SessionType sessionType); 63 // for DynamicComponent 64 virtual void Create(); Create(const NG::UIExtensionConfig & config)65 virtual void Create(const NG::UIExtensionConfig& config) {} 66 virtual void InitializeDynamicComponent(const RefPtr<NG::FrameNode>& frameNode, const std::string& hapPath, 67 const std::string& abcPath, const std::string& entryPoint, void* runtime); 68 virtual void InitializeIsolatedComponent(const RefPtr<NG::FrameNode>& frameNode, 69 const RefPtr<OHOS::Ace::WantWrap>& wantWrap, void* runtime); 70 virtual void SetAdaptiveWidth(bool state); 71 virtual void SetAdaptiveHeight(bool state); 72 73 virtual void SetOnRemoteReady(std::function<void(const RefPtr<NG::UIExtensionProxy>&)>&& onRemoteReady); 74 virtual void SetOnRelease(std::function<void(int32_t)>&& onRelease); 75 virtual void SetOnResult(std::function<void(int32_t, const AAFwk::Want&)>&& onResult); 76 virtual void SetOnTerminated(std::function<void(int32_t, const RefPtr<WantWrap>&)>&& onTerminated, 77 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {} 78 virtual void SetOnReceive(std::function<void(const AAFwk::WantParams&)>&& onReceive, 79 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {} SetSecurityOnRemoteReady(std::function<void (const RefPtr<NG::SecurityUIExtensionProxy> &)> && onRemoteReady)80 virtual void SetSecurityOnRemoteReady( 81 std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>&& onRemoteReady) {} 82 virtual void SetOnError( 83 std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError, 84 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY); 85 virtual void SetPlatformOnError( 86 std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError); 87 }; 88 } // namespace OHOS::Ace 89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MODEL_H 90