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_ADAPTER_OHOS_ENTRANCE_PA_ENGINE_ENGINE_COMMON_JS_BACKEND_ENGINE_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_PA_ENGINE_ENGINE_COMMON_JS_BACKEND_ENGINE_H 18 19 #include <string> 20 #include <unordered_map> 21 22 #include "abs_shared_result_set.h" 23 #include "data_ability_predicates.h" 24 #include "form_provider_info.h" 25 #include "iremote_object.h" 26 #include "napi_remote_object.h" 27 #include "pac_map.h" 28 #include "adapter/ohos/entrance/pa_container.h" 29 #include "values_bucket.h" 30 #include "want.h" 31 32 #include "core/common/backend.h" 33 34 namespace OHOS::Ace { 35 class JsBackendEngine : public AceType { 36 DECLARE_ACE_TYPE(JsBackendEngine, AceType); 37 38 public: 39 JsBackendEngine() = default; 40 virtual ~JsBackendEngine() = default; 41 42 virtual bool Initialize(BackendType type, SrcLanguage language) = 0; 43 44 virtual bool InitializeInner(BackendType type, SrcLanguage language) = 0; 45 46 virtual void SetAssetManager(const RefPtr<AssetManager>& assetManager) = 0; 47 48 virtual void LoadJs(const std::string& url, const OHOS::AAFwk::Want& want) = 0; 49 50 virtual void DestroyApplication(const std::string& packageName) = 0; 51 52 virtual int32_t Insert( 53 const Uri& uri, const OHOS::NativeRdb::ValuesBucket& value, const CallingInfo& callingInfo) = 0; 54 virtual std::shared_ptr<AppExecFwk::PacMap> Call(const std::string& method, const std::string& arg, 55 const AppExecFwk::PacMap& pacMap, const CallingInfo& callingInfo) = 0; 56 virtual std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(const Uri& uri, 57 const std::vector<std::string>& columns, const OHOS::NativeRdb::DataAbilityPredicates& predicates, 58 const CallingInfo& callingInfo) = 0; 59 virtual int32_t Update(const Uri& uri, const OHOS::NativeRdb::ValuesBucket& value, 60 const OHOS::NativeRdb::DataAbilityPredicates& predicates, const CallingInfo& callingInfo) = 0; 61 virtual int32_t Delete( 62 const Uri& uri, const OHOS::NativeRdb::DataAbilityPredicates& predicates, const CallingInfo& callingInfo) = 0; 63 64 virtual int32_t BatchInsert( 65 const Uri& uri, const std::vector<OHOS::NativeRdb::ValuesBucket>& values, const CallingInfo& callingInfo) = 0; 66 virtual std::string GetType(const Uri& uri, const CallingInfo& callingInfo) = 0; 67 virtual std::vector<std::string> GetFileTypes( 68 const Uri& uri, const std::string& mimeTypeFilter, const CallingInfo& callingInfo) = 0; 69 virtual int32_t OpenFile(const Uri& uri, const std::string& mode, const CallingInfo& callingInfo) = 0; 70 virtual int32_t OpenRawFile(const Uri& uri, const std::string& mode, const CallingInfo& callingInfo) = 0; 71 virtual Uri NormalizeUri(const Uri& uri, const CallingInfo& callingInfo) = 0; 72 virtual Uri DenormalizeUri(const Uri& uri, const CallingInfo& callingInfo) = 0; 73 virtual sptr<IRemoteObject> OnConnectService(const OHOS::AAFwk::Want& want) = 0; 74 virtual void OnDisconnectService(const OHOS::AAFwk::Want& want) = 0; 75 virtual void OnCreate(const OHOS::AAFwk::Want& want) = 0; 76 virtual void OnDelete(const int64_t formId) = 0; 77 virtual void OnTriggerEvent(const int64_t formId, const std::string& message) = 0; 78 virtual void OnUpdate(const int64_t formId) = 0; 79 virtual void OnCastTemptoNormal(const int64_t formId) = 0; 80 virtual void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap) = 0; 81 virtual int32_t OnAcquireFormState(const OHOS::AAFwk::Want& want) = 0; 82 virtual void OnCommand(const OHOS::AAFwk::Want& want, int startId) = 0; 83 virtual bool OnShare(int64_t formId, OHOS::AAFwk::WantParams& wantParams) = 0; 84 virtual void PostTask(const std::function<void()>& task, const std::string& name, int64_t delayTime = 0) = 0; 85 virtual void PostSyncTask(const std::function<void()>& task, const std::string& name) = 0; 86 virtual void RemoveTask(const std::string& name) = 0; 87 SetFormData(const AppExecFwk::FormProviderData & formProviderData)88 void SetFormData(const AppExecFwk::FormProviderData& formProviderData) 89 { 90 formProviderData_ = formProviderData; 91 } 92 GetFormData()93 AppExecFwk::FormProviderData GetFormData() const 94 { 95 return formProviderData_; 96 } 97 AddExtraNativeObject(const std::string & key,void * value)98 void AddExtraNativeObject(const std::string& key, void* value) 99 { 100 extraNativeObject_[key] = value; 101 } 102 GetExtraNativeObject()103 const std::unordered_map<std::string, void*>& GetExtraNativeObject() const 104 { 105 return extraNativeObject_; 106 } 107 IsDebugVersion()108 bool IsDebugVersion() const 109 { 110 return isDebugVersion_; 111 } 112 SetDebugVersion(bool value)113 void SetDebugVersion(bool value) 114 { 115 isDebugVersion_ = value; 116 } 117 NeedDebugBreakPoint()118 bool NeedDebugBreakPoint() const 119 { 120 return needDebugBreakPoint_; 121 } 122 SetNeedDebugBreakPoint(bool value)123 void SetNeedDebugBreakPoint(bool value) 124 { 125 needDebugBreakPoint_ = value; 126 } 127 SetHapPath(std::string hapPath)128 void SetHapPath(std::string hapPath) 129 { 130 hapPath_ = hapPath; 131 } 132 GetHapPath()133 std::string GetHapPath() 134 { 135 return hapPath_; 136 } 137 SetWorkerPath(std::shared_ptr<Platform::WorkerPath> workerPath)138 void SetWorkerPath(std::shared_ptr<Platform::WorkerPath> workerPath) 139 { 140 workerPath_ = workerPath; 141 } 142 GetWorkerPath()143 std::shared_ptr<Platform::WorkerPath> GetWorkerPath() 144 { 145 return workerPath_; 146 } 147 148 private: 149 std::string instanceName_; 150 AppExecFwk::FormProviderData formProviderData_; 151 std::unordered_map<std::string, void*> extraNativeObject_; 152 // weather the app has debugger.so. 153 bool isDebugVersion_ = false; 154 // if debug, '-D' means need debug breakpoint, by default, do not enter breakpoint. 155 bool needDebugBreakPoint_ = false; 156 std::string hapPath_; 157 std::shared_ptr<Platform::WorkerPath> workerPath_; 158 }; 159 160 } // namespace OHOS::Ace 161 162 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_PA_ENGINE_ENGINE_COMMON_JS_BACKEND_ENGINE_H 163