• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RESOURCE_ADAPTER_IMPL_H
17 #define OHOS_RESOURCE_ADAPTER_IMPL_H
18 
19 #include "extractor.h"
20 #include "file_mapper.h"
21 #include "ohos_resource_adapter.h"
22 
23 namespace OHOS::NWeb {
24 class OhosFileMapperImpl : public OhosFileMapper {
25 public:
26     OhosFileMapperImpl(std::unique_ptr<OHOS::AbilityBase::FileMapper> fileMap,
27         const std::shared_ptr<OHOS::AbilityBase::Extractor>& extractor);
28 
29     ~OhosFileMapperImpl() override = default;
30 
31     int32_t GetFd() override;
32 
33     int32_t GetOffset() override;
34 
35     std::string GetFileName() override;
36 
37     bool IsCompressed() override;
38 
39     void* GetDataPtr() override;
40 
41     size_t GetDataLen() override;
42 
43     bool UnzipData(uint8_t** dest, size_t& len) override;
44 
45 private:
46     std::shared_ptr<OHOS::AbilityBase::Extractor> extractor_ = nullptr;
47 
48     std::unique_ptr<OHOS::AbilityBase::FileMapper> fileMap_ = nullptr;
49 };
50 
51 class OhosResourceAdapterImpl : public OhosResourceAdapter {
52 public:
53     explicit OhosResourceAdapterImpl(const std::string& hapPath);
54 
55     ~OhosResourceAdapterImpl() override = default;
56 
57     bool GetRawFileData(const std::string& rawFile, size_t& len,
58         uint8_t** dest, bool isSys = false) override;
59 
60     std::shared_ptr<OhosFileMapper> GetRawFileMapper(const std::string& rawFile,
61         bool isSys = false) override;
62 
63     bool IsRawFileExist(const std::string& rawFile, bool isSys = false) override;
64 
65     bool GetRawFileLastModTime(const std::string& rawFile,
66         uint16_t& date, uint16_t& time, bool isSys = false) override;
67 
68     bool GetRawFileLastModTime(const std::string& rawFile, time_t& time, bool isSys = false) override;
69 
70     static bool GetResourceString(const std::string& bundleName, const std::string& moduleName,
71         const int32_t resId, std::string& result);
72 
73     static std::string GetArkWebVersion();
74 
75     static std::string ConvertToSandboxPath(const std::string& installPath, const std::string& prefixPath);
76 
77     static void SetArkWebCoreHapPathOverride(const std::string& hapPath);
78 
79     std::string GetSystemLanguage() override;
80 
81 private:
82     void Init(const std::string& hapPath);
83 
84     static std::string GetModuleName(const char *configStr, size_t len);
85 
86     static std::string ParseModuleName(const std::shared_ptr<OHOS::AbilityBase::Extractor> &manager);
87 
88     static bool GetRawFileData(const std::shared_ptr<OHOS::AbilityBase::Extractor>& manager,
89         const std::string& rawFile, size_t& len, std::unique_ptr<uint8_t[]>& dest);
90 
91     static bool HasEntry(const std::shared_ptr<OHOS::AbilityBase::Extractor>& manager,
92         const std::string& rawFile);
93 
94     static bool GetFileInfo(const std::shared_ptr<OHOS::AbilityBase::Extractor>& manager,
95         const std::string& rawFile, OHOS::AbilityBase::FileInfo& info);
96 
97     static std::shared_ptr<OhosFileMapper> GetRawFileMapper(
98         const std::shared_ptr<OHOS::AbilityBase::Extractor>& manager,
99         const std::string& rawFile);
100 
101     std::shared_ptr<OHOS::AbilityBase::Extractor> sysExtractor_;
102     std::shared_ptr<OHOS::AbilityBase::Extractor> extractor_;
103     static std::string arkWebCoreHapPathOverride_;
104 };
105 }  // namespace OHOS::NWeb
106 
107 #endif  // OHOS_RESOURCE_ADAPTER_IMPL_H
108