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/ui_extension_config.h" 27 #include "core/components_ng/pattern/ui_extension/session_wrapper.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 }; 44 45 struct UIExtensionConfig { 46 RefPtr<OHOS::Ace::WantWrap> wantWrap = nullptr; 47 RefPtr<NG::FrameNode> placeholderNode = nullptr; 48 bool transferringCaller = false; 49 bool densityDpi = false; 50 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY; 51 }; 52 } 53 54 class ACE_EXPORT UIExtensionModel { 55 public: 56 static UIExtensionModel* GetInstance(); 57 virtual ~UIExtensionModel() = default; 58 59 virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, 60 const std::map<NG::PlaceholderType, RefPtr<NG::FrameNode>>& placeholderMap, 61 bool transferringCaller = false, bool densityDpi = false); 62 // for Embedded Component 63 virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, NG::SessionType sessionType); 64 // for DynamicComponent 65 virtual void Create(); 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); 73 74 virtual void SetOnRemoteReady(std::function<void(const RefPtr<NG::UIExtensionProxy>&)>&& onRemoteReady); 75 virtual void SetOnRelease(std::function<void(int32_t)>&& onRelease); 76 virtual void SetOnResult(std::function<void(int32_t, const AAFwk::Want&)>&& onResult); 77 virtual void SetOnTerminated(std::function<void(int32_t, const RefPtr<WantWrap>&)>&& onTerminated, 78 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {} 79 virtual void SetOnReceive(std::function<void(const AAFwk::WantParams&)>&& onReceive, 80 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {} SetSecurityOnRemoteReady(std::function<void (const RefPtr<NG::SecurityUIExtensionProxy> &)> && onRemoteReady)81 virtual void SetSecurityOnRemoteReady( 82 std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>&& onRemoteReady) {} 83 virtual void SetOnError( 84 std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError, 85 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY); 86 virtual void SetPlatformOnError( 87 std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError); 88 }; 89 } // namespace OHOS::Ace 90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MODEL_H 91