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 bool isModalRequestFocus = true; 45 }; 46 47 struct UIExtensionConfig { 48 RefPtr<OHOS::Ace::WantWrap> wantWrap = nullptr; 49 RefPtr<NG::FrameNode> placeholderNode = nullptr; 50 bool transferringCaller = false; 51 bool densityDpi = false; 52 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY; 53 bool backgroundTransparent = true; 54 }; 55 } 56 57 class ACE_EXPORT UIExtensionModel { 58 public: 59 static UIExtensionModel* GetInstance(); 60 virtual ~UIExtensionModel() = default; 61 62 virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, 63 const std::map<NG::PlaceholderType, RefPtr<NG::FrameNode>>& placeholderMap, 64 bool transferringCaller = false, bool densityDpi = false, bool isWindowModeFollowHost = false); 65 // for Embedded Component 66 virtual void Create(const RefPtr<OHOS::Ace::WantWrap>& wantWrap, NG::SessionType sessionType); Create(const NG::UIExtensionConfig & config)67 virtual void Create(const NG::UIExtensionConfig& config) {} 68 virtual void InitializeDynamicComponent(const RefPtr<NG::FrameNode>& frameNode, const std::string& hapPath, 69 const std::string& abcPath, const std::string& entryPoint, void* runtime); 70 virtual void InitializeIsolatedComponent(const RefPtr<NG::FrameNode>& frameNode, 71 const RefPtr<OHOS::Ace::WantWrap>& wantWrap, void* runtime); 72 virtual void SetAdaptiveWidth(bool state); 73 virtual void SetAdaptiveHeight(bool state); GetUiExtensionType(NG::SessionType sessionType)74 virtual std::string GetUiExtensionType(NG::SessionType sessionType) 75 { 76 return ""; 77 } 78 79 virtual void SetOnRemoteReady(std::function<void(const RefPtr<NG::UIExtensionProxy>&)>&& onRemoteReady); 80 virtual void SetOnRelease(std::function<void(int32_t)>&& onRelease); 81 virtual void SetOnResult(std::function<void(int32_t, const AAFwk::Want&)>&& onResult); 82 virtual void SetOnTerminated(std::function<void(int32_t, const RefPtr<WantWrap>&)>&& onTerminated, 83 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {} 84 virtual void SetOnReceive(std::function<void(const AAFwk::WantParams&)>&& onReceive, 85 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) {} SetSecurityOnRemoteReady(std::function<void (const RefPtr<NG::SecurityUIExtensionProxy> &)> && onRemoteReady)86 virtual void SetSecurityOnRemoteReady( 87 std::function<void(const RefPtr<NG::SecurityUIExtensionProxy>&)>&& onRemoteReady) {} 88 virtual void SetOnError( 89 std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError, 90 NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY); 91 virtual void SetPlatformOnError( 92 std::function<void(int32_t code, const std::string& name, const std::string& message)>&& onError); 93 virtual void SetOnDrawReady(std::function<void()>&& onDrawReady); 94 }; 95 } // namespace OHOS::Ace 96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_MODEL_H 97