• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_TEST_JSON_JSON_FRONTEND_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_JSON_JSON_FRONTEND_H
18 
19 #include <unordered_map>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/utils/macros.h"
23 #include "core/common/ace_page.h"
24 #include "core/common/container.h"
25 #include "core/common/frontend.h"
26 #include "core/common/js_message_dispatcher.h"
27 
28 namespace OHOS::Ace {
29 
30 class ACE_EXPORT JsonFrontend : public Frontend {
31     DECLARE_ACE_TYPE(JsonFrontend, Frontend);
32 
33 public:
34     JsonFrontend() = default;
35     ~JsonFrontend() override = default;
36 
37     bool Initialize(FrontendType type, const RefPtr<TaskExecutor>& taskExecutor) override;
38 
Destroy()39     void Destroy() override {}
40 
41     void AttachPipelineContext(const RefPtr<PipelineBase>& context) override;
42 
43     void SetAssetManager(const RefPtr<AssetManager>& assetManager) override;
44 
45     void AddPage(const RefPtr<AcePage>& page) override;
46 
47     RefPtr<AcePage> GetPage(int32_t pageId) const override;
48 
49     void RunPage(int32_t pageId, const std::string& content, const std::string& params) override;
50 
51     void PushPage(const std::string& content, const std::string& params) override;
52 
53     void UpdatePage(int32_t pageId, const std::string& content);
54 
55     RefPtr<AceEventHandler> GetEventHandler() override;
56 
57     void UpdateState(Frontend::State state) override;
58 
59     bool IsForeground() override;
60 
61     RefPtr<AccessibilityManager> GetAccessibilityManager() const override;
62 
63     bool OnBackPressed() override;
64 
65     void OnShow() override;
66 
67     void OnHide() override;
68 
69     void OnActive() override;
70 
71     void OnInactive() override;
72 
73     bool OnStartContinuation() override;
74 
75     void OnCompleteContinuation(int32_t code) override;
76 
OnMemoryLevel(const int32_t level)77     void OnMemoryLevel(const int32_t level) override {}
78 
79     void OnSaveData(std::string& data) override;
80 
OnSaveAbilityState(std::string & data)81     void OnSaveAbilityState (std::string& data) override {}
82 
OnRestoreAbilityState(const std::string & data)83     void OnRestoreAbilityState (const std::string& data) override {}
84 
85     bool OnRestoreData(const std::string& data) override;
86 
OnRemoteTerminated()87     void OnRemoteTerminated() override {}
88 
89     void OnNewRequest(const std::string& data) override;
90 
OnNewWant(const std::string & data)91     void OnNewWant(const std::string& data) override {}
92 
93     void CallRouterBack() override;
94 
OnSurfaceChanged(int32_t width,int32_t height)95     void OnSurfaceChanged(int32_t width, int32_t height) override {}
96 
ReplacePage(const std::string & url,const std::string & params)97     void ReplacePage(const std::string& url, const std::string& params) override {}
98 
DumpFrontend()99     void DumpFrontend() const override
100     {
101         // maybe will implement later,
102         LOGI("json not support dump now.");
103     }
104 
GetPagePath()105     std::string GetPagePath() const override
106     {
107         return "";
108     }
109 
SetEventHandler(const RefPtr<AceEventHandler> & handler)110     void SetEventHandler(const RefPtr<AceEventHandler>& handler)
111     {
112         handler_ = handler;
113     }
114 
GetWindowConfig()115     WindowConfig& GetWindowConfig() override
116     {
117         return windowConfig_;
118     }
119 
GetType()120     FrontendType GetType() override
121     {
122         return type_;
123     }
124 
SendCallbackMessage(const std::string & callbackId,const std::string & data)125     void SendCallbackMessage(const std::string& callbackId, const std::string& data) const override
126     {
127         // maybe will implement later
128         LOGI("json frontend not support.");
129     }
130 
SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher> & dispatcher)131     void SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher>& dispatcher) const override
132     {
133         // maybe will implement later
134         LOGI("json frontend not support.");
135     }
136 
TransferComponentResponseData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)137     void TransferComponentResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override
138     {
139         // maybe will implement later
140         LOGI("json frontend not support.");
141     }
142 
TransferJsResponseData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)143     void TransferJsResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override
144     {
145         // maybe will implement later
146         LOGI("json frontend not support.");
147     }
148 
TransferJsPluginGetError(int32_t callbackId,int32_t errorCode,std::string && errorMessage)149     void TransferJsPluginGetError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override
150     {
151         // maybe will implement later
152         LOGI("json frontend not support.");
153     }
154 
TransferJsEventData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)155     void TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override
156     {
157         // maybe will implement later
158         LOGI("json frontend not support.");
159     }
160 
LoadPluginJsCode(std::string && jsCode)161     void LoadPluginJsCode(std::string&& jsCode) const override
162     {
163         LOGI("json frontend not support.");
164     }
165 
LoadPluginJsByteCode(std::vector<uint8_t> && jsCode,std::vector<int32_t> && jsCodeLen)166     void LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) const override
167     {
168         LOGI("json frontend not support.");
169     }
170 
171 private:
172     FrontendType type_ { FrontendType::JSON };
173     static constexpr int32_t JSON_DESIGN_WIDTH = 1080;
174     std::unordered_map<int, RefPtr<AcePage>> pageMap_;
175     RefPtr<PipelineBase> pipelineContext_;
176     RefPtr<AceEventHandler> handler_;
177     WindowConfig windowConfig_ { .designWidth = JSON_DESIGN_WIDTH, .autoDesignWidth = false };
178 };
179 
180 } // namespace OHOS::Ace
181 
182 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_JSON_JSON_FRONTEND_H
183