1 /* 2 * Copyright (c) 2022 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_PLUGIN_PLUGIN_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLUGIN_PLUGIN_PATTERN_H 18 19 #include "core/components/plugin/resource/plugin_request_data.h" 20 #include "core/components_ng/event/event_hub.h" 21 #include "core/components_ng/pattern/pattern.h" 22 #include "core/components_ng/pattern/plugin/plugin_event_hub.h" 23 #include "core/components_ng/pattern/plugin/plugin_layout_property.h" 24 25 namespace OHOS::Ace { 26 class PluginSubContainer; 27 class PluginManagerDelegate; 28 } // namespace OHOS::Ace 29 30 namespace OHOS::Ace::NG { 31 32 class PluginPattern : public Pattern { 33 DECLARE_ACE_TYPE(PluginPattern, Pattern); 34 35 public: 36 PluginPattern() = default; 37 ~PluginPattern() override; 38 39 void OnActionEvent(const std::string& action) const; 40 CreateLayoutProperty()41 RefPtr<LayoutProperty> CreateLayoutProperty() override 42 { 43 return MakeRefPtr<PluginLayoutProperty>(); 44 } 45 CreateEventHub()46 RefPtr<EventHub> CreateEventHub() override 47 { 48 return MakeRefPtr<PluginEventHub>(); 49 } 50 51 std::unique_ptr<DrawDelegate> GetDrawDelegate(); 52 53 const RefPtr<PluginSubContainer>& GetPluginSubContainer() const; 54 GetData()55 const std::string& GetData() const 56 { 57 return data_; 58 } 59 GetPluginRequestInfo()60 const RequestPluginInfo& GetPluginRequestInfo() const 61 { 62 return pluginInfo_; 63 } 64 65 private: 66 void OnAttachToFrameNode() override; 67 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 68 69 void InitPluginManagerDelegate(); 70 void CreatePluginSubContainer(); 71 72 void FireOnCompleteEvent() const; 73 void FireOnErrorEvent(const std::string& code, const std::string& msg) const; 74 75 bool ISAllowUpdate() const; 76 77 void SplitString(const std::string& str, char tag, std::vector<std::string>& strList) const; 78 std::string GetPackagePath(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const; 79 std::string GetPackagePathByWant(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const; 80 std::string GetPackagePathByAbsolutePath(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const; 81 void GetModuleNameByWant(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const; 82 std::string GerPackagePathByBms(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info, 83 const std::vector<std::string>& strList, const std::vector<int32_t>& userIds) const; 84 85 RefPtr<PluginSubContainer> pluginSubContainer_; 86 RefPtr<PluginManagerDelegate> pluginManagerBridge_; 87 88 std::string data_; 89 RequestPluginInfo pluginInfo_; 90 }; 91 92 } // namespace OHOS::Ace::NG 93 94 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLUGIN_PLUGIN_PATTERN_H 95