• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class DrawDelegate;
29 } // namespace OHOS::Ace
30 
31 namespace OHOS::Ace::NG {
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     void DumpInfo() override;
52     void DumpInfo(std::unique_ptr<JsonValue>& json) override;
53 
54     void ReplaceAll(std::string& str, const std::string& pattern, const std::string& newPattern);
55 
56     std::unique_ptr<DrawDelegate> GetDrawDelegate();
57 
58     const RefPtr<PluginSubContainer>& GetPluginSubContainer() const;
59 
GetData()60     const std::string& GetData() const
61     {
62         return data_;
63     }
64 
GetPluginRequestInfo()65     const RequestPluginInfo& GetPluginRequestInfo() const
66     {
67         return pluginInfo_;
68     }
69 
70     void FlushReload() const;
71 
72 private:
73     void OnAttachToFrameNode() override;
74     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
75 
76     void InitPluginManagerDelegate();
77     void CreatePluginSubContainer();
78 
79     void FireOnCompleteEvent() const;
80     void FireOnErrorEvent(const std::string& code, const std::string& msg);
81 
82     bool ISAllowUpdate() const;
83 
84     void SplitString(const std::string& str, char tag, std::vector<std::string>& strList) const;
85     std::string GetPackageCodeLanguage(const RequestPluginInfo& info) const;
86     std::string GetPackagePath(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
87     std::string GetPackagePathByWant(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
88     std::string GetPackagePathByAbsolutePath(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
89     void GetAbilityNameByWant(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info) const;
90     std::string GetPackagePathByBms(const WeakPtr<PluginPattern>& weak, RequestPluginInfo& info,
91         const std::vector<std::string>& strList, const std::vector<int32_t>& userIds) const;
92 
93     RefPtr<PluginSubContainer> pluginSubContainer_;
94     RefPtr<PluginManagerDelegate> pluginManagerBridge_;
95 
96     std::string data_;
97     RequestPluginInfo pluginInfo_;
98     bool loadFialState_ = false;
99 
100     ACE_DISALLOW_COPY_AND_MOVE(PluginPattern);
101 };
102 } // namespace OHOS::Ace::NG
103 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PLUGIN_PLUGIN_PATTERN_H
104