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 OnLayoutCompleted(const std::string & componentId)97 void OnLayoutCompleted(const std::string& componentId) override {} OnDrawCompleted(const std::string & componentId)98 void OnDrawCompleted(const std::string& componentId) override {} 99 ReplacePage(const std::string & url,const std::string & params)100 void ReplacePage(const std::string& url, const std::string& params) override {} 101 DumpFrontend()102 void DumpFrontend() const override 103 { 104 // maybe will implement later, 105 LOGI("json not support dump now."); 106 } 107 GetPagePath()108 std::string GetPagePath() const override 109 { 110 return ""; 111 } 112 SetEventHandler(const RefPtr<AceEventHandler> & handler)113 void SetEventHandler(const RefPtr<AceEventHandler>& handler) 114 { 115 handler_ = handler; 116 } 117 GetWindowConfig()118 WindowConfig& GetWindowConfig() override 119 { 120 return windowConfig_; 121 } 122 SendCallbackMessage(const std::string & callbackId,const std::string & data)123 void SendCallbackMessage(const std::string& callbackId, const std::string& data) const override 124 { 125 // maybe will implement later 126 LOGI("json frontend not support."); 127 } 128 SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher> & dispatcher)129 void SetJsMessageDispatcher(const RefPtr<JsMessageDispatcher>& dispatcher) const override 130 { 131 // maybe will implement later 132 LOGI("json frontend not support."); 133 } 134 TransferComponentResponseData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)135 void TransferComponentResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override 136 { 137 // maybe will implement later 138 LOGI("json frontend not support."); 139 } 140 TransferJsResponseData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)141 void TransferJsResponseData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override 142 { 143 // maybe will implement later 144 LOGI("json frontend not support."); 145 } 146 TransferJsPluginGetError(int32_t callbackId,int32_t errorCode,std::string && errorMessage)147 void TransferJsPluginGetError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const override 148 { 149 // maybe will implement later 150 LOGI("json frontend not support."); 151 } 152 TransferJsEventData(int32_t callbackId,int32_t code,std::vector<uint8_t> && data)153 void TransferJsEventData(int32_t callbackId, int32_t code, std::vector<uint8_t>&& data) const override 154 { 155 // maybe will implement later 156 LOGI("json frontend not support."); 157 } 158 LoadPluginJsCode(std::string && jsCode)159 void LoadPluginJsCode(std::string&& jsCode) const override 160 { 161 LOGI("json frontend not support."); 162 } 163 LoadPluginJsByteCode(std::vector<uint8_t> && jsCode,std::vector<int32_t> && jsCodeLen)164 void LoadPluginJsByteCode(std::vector<uint8_t>&& jsCode, std::vector<int32_t>&& jsCodeLen) const override 165 { 166 LOGI("json frontend not support."); 167 } 168 169 private: 170 static constexpr int32_t JSON_DESIGN_WIDTH = 1080; 171 std::unordered_map<int, RefPtr<AcePage>> pageMap_; 172 RefPtr<PipelineBase> pipelineContext_; 173 RefPtr<AceEventHandler> handler_; 174 WindowConfig windowConfig_ { .designWidth = JSON_DESIGN_WIDTH, .autoDesignWidth = false }; 175 }; 176 177 } // namespace OHOS::Ace 178 179 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_JSON_JSON_FRONTEND_H 180