1 /*
2  * Copyright (c) 2022-2023 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 class PluginPattern : public Pattern {
32     DECLARE_ACE_TYPE(PluginPattern, Pattern);
33 
34 public:
35     PluginPattern() = default;
36     ~PluginPattern() override;
37 
38     void OnActionEvent(const std::string& action) const;
39 
CreateLayoutProperty()40     RefPtr<LayoutProperty> CreateLayoutProperty() override
41     {
42         return MakeRefPtr<PluginLayoutProperty>();
43     }
44 
CreateEventHub()45     RefPtr<EventHub> CreateEventHub() override
46     {
47         return MakeRefPtr<PluginEventHub>();
48     }
49 
50     void ReplaceAll(std::string& str, const std::string& pattern, const std::string& newPattern);
51 
52     std::unique_ptr<DrawDelegate> GetDrawDelegate();
53 
54     const RefPtr<PluginSubContainer>& GetPluginSubContainer() const;
55 
GetData()56     const std::string& GetData() const
57     {
58         return data_;
59     }
60 
GetPluginRequestInfo()61     const RequestPluginInfo& GetPluginRequestInfo() const
62     {
63         return pluginInfo_;
64     }
65 
66     void FlushReload() const;
67 
68 private:
69     void OnAttachToFrameNode() override;
70     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
71 
72     void InitPluginManagerDelegate();
73     void CreatePluginSubContainer();
74 
75     void FireOnCompleteEvent() const;
76     void FireOnErrorEvent(const std::string& code, const std::string& msg);
77 
78     bool ISAllowUpdate() const;
79 
80     void SplitString(const std::string& str, char tag, std::vector<std::string>& strList) const;
81     std::string GetPackagePath(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
82     std::string GetPackagePathByWant(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
83     std::string GetPackagePathByAbsolutePath(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
84     void GetAbilityNameByWant(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
85     std::string GerPackagePathByBms(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info,
86         const std::vector<std::string>& strList, const std::vector<int32_t>& userIds) const;
87 
88     RefPtr<PluginSubContainer> pluginSubContainer_;
89     RefPtr<PluginManagerDelegate> pluginManagerBridge_;
90 
91     std::string data_;
92     RequestPluginInfo pluginInfo_;
93     bool loadFialState_ = false;
94 
95     ACE_DISALLOW_COPY_AND_MOVE(PluginPattern);
96 };
97 } // namespace OHOS::Ace::NG
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLUGIN_PLUGIN_PATTERN_H
99