1 /* 2 * Copyright (c) 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 OHOS_ABILITY_RUNTIME_JS_WORKER_H 17 #define OHOS_ABILITY_RUNTIME_JS_WORKER_H 18 19 #include <string> 20 #include "bundle_mgr_proxy.h" 21 #include "js_environment_impl.h" 22 #include "native_engine/native_engine.h" 23 24 namespace OHOS { 25 namespace AbilityRuntime { 26 void StartDebuggerInWorkerModule(); 27 void InitWorkerFunc(NativeEngine* nativeEngine); 28 void OffWorkerFunc(NativeEngine* nativeEngine); 29 int32_t GetContainerId(); 30 void UpdateContainerScope(int32_t id); 31 void RestoreContainerScope(int32_t id); 32 void SetJsFramework(); 33 34 class AssetHelper final { 35 public: AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo)36 explicit AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo) : workerInfo_(workerInfo) 37 { 38 if (!(workerInfo_->codePath).empty() && (workerInfo->codePath).back() != '/') { 39 (workerInfo_->codePath).append("/"); 40 } 41 } 42 43 std::string NormalizedFileName(const std::string& fileName) const; 44 45 void operator()(const std::string& uri, std::vector<uint8_t>& content, std::string &ami); 46 47 sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy(); 48 49 bool ReadAmiData(const std::string& ami, std::vector<uint8_t>& content) const; 50 51 bool ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content); 52 53 void GetAmi(std::string& ami, const std::string& filePath); 54 private: 55 std::shared_ptr<JsEnv::WorkerInfo> workerInfo_; 56 sptr<AppExecFwk::IBundleMgr> bundleMgrProxy_ = nullptr; 57 }; 58 59 } // namespace AbilityRuntime 60 } // namespace OHOS 61 62 #endif // OHOS_ABILITY_RUNTIME_JS_WORKER_H