1 /* 2 * Copyright (c) 2021-2022 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_ADAPTER_OHOS_ENTRANCE_PA_ENGINE_BACKEND_DELEGATE_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_PA_ENGINE_BACKEND_DELEGATE_H 18 19 #include <vector> 20 21 #include "base/json/json_util.h" 22 #include "base/memory/ace_type.h" 23 #include "base/utils/noncopyable.h" 24 #include "core/common/backend.h" 25 #include "core/event/ace_event_helper.h" 26 #include "frameworks/bridge/js_frontend/engine/common/group_js_bridge.h" 27 28 namespace OHOS::Ace { 29 30 class BackendDelegate : public AceType { 31 DECLARE_ACE_TYPE(BackendDelegate, AceType); 32 33 public: 34 BackendDelegate() = default; 35 ~BackendDelegate() override = default; 36 37 // posting js task from jsengine 38 virtual void PostJsTask(std::function<void()>&& task) = 0; 39 40 // posting js task from jsengine 41 virtual void PostDelayedJsTask(std::function<void()>&& task, uint32_t delayTime) = 0; 42 43 virtual BackendType GetType() const = 0; 44 45 virtual SingleTaskExecutor GetAnimationJsTask() = 0; 46 47 virtual bool GetAssetContent(const std::string& url, std::string& content) = 0; 48 virtual bool GetAssetContent(const std::string& url, std::vector<uint8_t>& content) = 0; 49 virtual bool GetResourceData(const std::string& fileUri, std::vector<uint8_t>& content, std::string& ami) = 0; 50 virtual std::string GetAssetPath(const std::string& url) = 0; 51 52 virtual void AddTaskObserver(std::function<void()>&& task) = 0; 53 virtual void RemoveTaskObserver() = 0; 54 55 virtual void SetCallBackResult(const std::string& callBackId, const std::string& result) = 0; 56 57 virtual const RefPtr<GroupJsBridge>& GetGroupJsBridge() = 0; 58 SetAssetManager(const RefPtr<AssetManager> & assetManager)59 ACE_EXPORT void SetAssetManager(const RefPtr<AssetManager>& assetManager) 60 { 61 assetManager_ = assetManager; 62 } 63 GetAssetManager()64 ACE_EXPORT RefPtr<AssetManager> GetAssetManager() const 65 { 66 return assetManager_; 67 } 68 69 protected: 70 RefPtr<AssetManager> assetManager_; 71 72 ACE_DISALLOW_COPY_AND_MOVE(BackendDelegate); 73 }; 74 75 } // namespace OHOS::Ace 76 77 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_PA_ENGINE_BACKEND_DELEGATE_H 78