1 /* 2 * Copyright (c) 2022-2023 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 SetDebuggerApp(bool isDebugApp); 28 void InitWorkerFunc(NativeEngine* nativeEngine); 29 void OffWorkerFunc(NativeEngine* nativeEngine); 30 int32_t GetContainerId(); 31 void UpdateContainerScope(int32_t id); 32 void RestoreContainerScope(int32_t id); 33 void SetJsFramework(); 34 35 class AssetHelper final { 36 public: AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo)37 explicit AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo) : workerInfo_(workerInfo) 38 { 39 if (!(workerInfo_->codePath).empty() && (workerInfo->codePath).back() != '/') { 40 (workerInfo_->codePath).append("/"); 41 } 42 } 43 44 std::string NormalizedFileName(const std::string& fileName) const; 45 46 void operator()(const std::string& uri, std::vector<uint8_t>& content, std::string &ami); 47 48 bool ReadAmiData(const std::string& ami, std::vector<uint8_t>& content) const; 49 50 bool ReadFilePathData(const std::string& filePath, std::vector<uint8_t>& content); 51 52 void GetAmi(std::string& ami, const std::string& filePath); 53 private: 54 std::shared_ptr<JsEnv::WorkerInfo> workerInfo_; 55 }; 56 57 } // namespace AbilityRuntime 58 } // namespace OHOS 59 60 #endif // OHOS_ABILITY_RUNTIME_JS_WORKER_H