• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_BRIDGE_ARKTS_FRONTEND_ARKTS_PLUGIN_FRONTEND_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ARKTS_FRONTEND_ARKTS_PLUGIN_FRONTEND_H
18 
19 #include <string>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/memory/referenced.h"
23 #include "base/thread/task_executor.h"
24 #include "base/utils/noncopyable.h"
25 #include "core/common/frontend.h"
26 #include "core/pipeline/pipeline_context.h"
27 #include "frameworks/bridge/common/accessibility/accessibility_node_manager.h"
28 #include "bridge/plugin_frontend/plugin_frontend.h"
29 
30 typedef struct __ani_env ani_env;
31 typedef class __ani_ref* ani_ref;
32 
33 namespace OHOS::Ace {
34 /**
35  * @brief Proxy class to interact with Koala frontend and static ArkTS runtime.
36  *
37  */
38 class ACE_FORCE_EXPORT ArktsPluginFrontend : public PluginFrontend {
39     DECLARE_ACE_TYPE(ArktsPluginFrontend, PluginFrontend);
40 
41 public:
ArktsPluginFrontend(void * runtime)42     explicit ArktsPluginFrontend(void* runtime) : env_(reinterpret_cast<ani_env*>(runtime))
43     {
44         type_ = FrontendType::ARK_TS;
45     }
46     ~ArktsPluginFrontend() override = default;
47 
Initialize(FrontendType type,const RefPtr<TaskExecutor> & taskExecutor)48     bool Initialize(FrontendType type, const RefPtr<TaskExecutor>& taskExecutor) override
49     {
50         taskExecutor_ = taskExecutor;
51         return true;
52     }
53 
54     void Destroy() override;
55 
56     void AttachPipelineContext(const RefPtr<PipelineBase>& context) override;
57 
SetAssetManager(const RefPtr<AssetManager> & assetManager)58     void SetAssetManager(const RefPtr<AssetManager>& assetManager) override
59     {
60         assetManager_ = assetManager;
61     }
62 
63     UIContentErrorCode RunPage(const std::string& url, const std::string& params) override;
64     UIContentErrorCode RunPage(
65         const std::shared_ptr<std::vector<uint8_t>>& content, const std::string& params) override;
66 
RunPageByNamedRouter(const std::string & name,const std::string & params)67     UIContentErrorCode RunPageByNamedRouter(const std::string& name, const std::string& params) override
68     {
69         return UIContentErrorCode::NO_ERRORS;
70     }
71 
ReplacePage(const std::string & url,const std::string & params)72     void ReplacePage(const std::string& url, const std::string& params) override {}
73 
PushPage(const std::string & url,const std::string & params)74     void PushPage(const std::string& url, const std::string& params) override {}
75 
AddPage(const RefPtr<AcePage> & page)76     void AddPage(const RefPtr<AcePage>& page) override {}
77 
GetPage(int32_t)78     RefPtr<AcePage> GetPage(int32_t /*pageId*/) const override
79     {
80         return nullptr;
81     }
82 
GetCurrentPageUrl()83     std::string GetCurrentPageUrl() const override
84     {
85         return "";
86     }
87 
GetCurrentPageSourceMap()88     RefPtr<Framework::RevSourceMap> GetCurrentPageSourceMap() const override
89     {
90         return nullptr;
91     }
92 
GetFaAppSourceMap()93     RefPtr<Framework::RevSourceMap> GetFaAppSourceMap() const override
94     {
95         return nullptr;
96     }
97 
GetStageSourceMap(std::unordered_map<std::string,RefPtr<Framework::RevSourceMap>> & sourceMap)98     void GetStageSourceMap(std::unordered_map<std::string, RefPtr<Framework::RevSourceMap>>& sourceMap) const override
99     {}
100 
SendCallbackMessage(const std::string & callbackId,const std::string & data)101     void SendCallbackMessage(const std::string& callbackId, const std::string& data) const override {}
SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher> & dispatcher)102     void SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher>& dispatcher) const override {}
TransferComponentResponseData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)103     void TransferComponentResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override {}
TransferJsResponseData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)104     void TransferJsResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override {}
TransferJsPluginGetError(int32_t callbackId,int32_t errorCode,std::string && errorMessage)105     void TransferJsPluginGetError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override {}
TransferJsEventData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)106     void TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override {}
LoadPluginJsCode(std::string && jsCode)107     void LoadPluginJsCode(std::string&& jsCode) const override {}
LoadPluginJsByteCode(std::vector<uint8_t> && jsCode,std::vector<int32_t> && jsCodeLen)108     void LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) const override {}
109 
UpdateState(Frontend::State state)110     void UpdateState(Frontend::State state) override {}
111 
OnBackPressed()112     bool OnBackPressed() override
113     {
114         return false;
115     }
OnShow()116     void OnShow() override {}
OnHide()117     void OnHide() override {}
OnConfigurationUpdated(const std::string & data)118     void OnConfigurationUpdated(const std::string& data) override {}
OnSaveAbilityState(std::string & data)119     void OnSaveAbilityState(std::string& data) override {}
OnRestoreAbilityState(const std::string & data)120     void OnRestoreAbilityState(const std::string& data) override {}
OnNewWant(const std::string & data)121     void OnNewWant(const std::string& data) override {}
OnActive()122     void OnActive() override {}
OnInactive()123     void OnInactive() override {}
OnStartContinuation()124     bool OnStartContinuation() override
125     {
126         return false;
127     }
OnCompleteContinuation(int32_t code)128     void OnCompleteContinuation(int32_t code) override {}
OnSaveData(std::string & data)129     void OnSaveData(std::string& data) override {}
GetPluginsUsed(std::string & data)130     void GetPluginsUsed(std::string& data) override {}
OnRestoreData(const std::string & data)131     bool OnRestoreData(const std::string& data) override
132     {
133         return false;
134     }
OnRemoteTerminated()135     void OnRemoteTerminated() override {}
OnNewRequest(const std::string & data)136     void OnNewRequest(const std::string& data) override {}
OnMemoryLevel(const int32_t level)137     void OnMemoryLevel(const int32_t level) override {}
CallRouterBack()138     void CallRouterBack() override {}
OnSurfaceChanged(int32_t width,int32_t height)139     void OnSurfaceChanged(int32_t width, int32_t height) override {}
OnLayoutCompleted(const std::string & componentId)140     void OnLayoutCompleted(const std::string& componentId) override
141     {
142         LOGE("%{public}s NOT IMPLEMENTED", __func__);
143     }
144 
OnDrawCompleted(const std::string & componentId)145     void OnDrawCompleted(const std::string& componentId) override
146     {
147         LOGE("%{public}s NOT IMPLEMENTED", __func__);
148     }
149 
DumpFrontend()150     void DumpFrontend() const override {}
GetPagePath()151     std::string GetPagePath() const override
152     {
153         return "";
154     }
TriggerGarbageCollection()155     void TriggerGarbageCollection() override {}
DumpHeapSnapshot(bool isPrivate)156     void DumpHeapSnapshot(bool isPrivate) override {}
NotifyUIIdle()157     void NotifyUIIdle() override {}
SetColorMode(ColorMode colorMode)158     void SetColorMode(ColorMode colorMode) override {}
RebuildAllPages()159     void RebuildAllPages() override {}
NotifyAppStorage(const std::string & key,const std::string & value)160     void NotifyAppStorage(const std::string& key, const std::string& value) override {}
161 
GetEventHandler()162     RefPtr<AceEventHandler> GetEventHandler() override
163     {
164         return nullptr;
165     }
166 
IsForeground()167     bool IsForeground() override
168     {
169         return foregroundFrontend_;
170     }
171 
GetAccessibilityManager()172     RefPtr<AccessibilityManager> GetAccessibilityManager() const override
173     {
174         return accessibilityManager_;
175     }
GetWindowConfig()176     WindowConfig& GetWindowConfig() override
177     {
178         static WindowConfig config;
179         return config;
180     }
181 
NavigatePage(uint8_t type,const PageTarget & target,const std::string & params)182     void NavigatePage(uint8_t type, const PageTarget& target, const std::string& params) override {}
183 
RestoreRouterStack(const std::string & contentInfo,ContentInfoType type)184     std::pair<RouterRecoverRecord, UIContentErrorCode> RestoreRouterStack(
185         const std::string& contentInfo, ContentInfoType type) override
186     {
187         return { RouterRecoverRecord(), UIContentErrorCode::NO_ERRORS };
188     }
GetContentInfo(ContentInfoType type)189     std::string GetContentInfo(ContentInfoType type) const override
190     {
191         return "";
192     }
GetRouterSize()193     int32_t GetRouterSize() const override
194     {
195         return 0;
196     }
197 
FlushReload()198     void FlushReload() override {}
HotReload()199     void HotReload() override {}
200 
SetPluginBundleName(const std::string & pluginBundleName)201     void SetPluginBundleName(const std::string& pluginBundleName) override
202     {
203         pluginBundleName_ = pluginBundleName;
204     }
205 
SetPluginModuleName(const std::string & pluginModuleName)206     void SetPluginModuleName(const std::string& pluginModuleName) override
207     {
208         pluginModuleName_ = pluginModuleName;
209     }
210 
211 private:
212     RefPtr<TaskExecutor> taskExecutor_;
213     RefPtr<PipelineContext> pipeline_;
214     ani_env* env_; // ani_env
215     ani_ref app_ = nullptr;
216     bool foregroundFrontend_ = false;
217     std::string pluginBundleName_;
218     std::string pluginModuleName_;
219     RefPtr<AssetManager> assetManager_;
220 
221     RefPtr<Framework::AccessibilityNodeManager> accessibilityManager_
222         = Framework::AccessibilityNodeManager::Create();
223 
224     ACE_DISALLOW_COPY_AND_MOVE(ArktsPluginFrontend);
225 };
226 
227 } // namespace OHOS::Ace
228 
229 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_ARKTS_FRONTEND_ARKTS_PLUGIN_FRONTEND_H
230