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 #include "ohos_adapter/bridge/ark_ohos_resource_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_ohos_file_mapper_wrapper.h"
19
20 #include "base/bridge/ark_web_bridge_macros.h"
21
22 namespace OHOS::ArkWeb {
23
ArkOhosResourceAdapterWrapper(ArkWebRefPtr<ArkOhosResourceAdapter> ref)24 ArkOhosResourceAdapterWrapper::ArkOhosResourceAdapterWrapper(ArkWebRefPtr<ArkOhosResourceAdapter> ref) : ctocpp_(ref) {}
25
GetRawFileData(const std::string & rawFile,size_t & len,uint8_t ** dest,bool isSys)26 bool ArkOhosResourceAdapterWrapper::GetRawFileData(const std::string& rawFile, size_t& len, uint8_t** dest, bool isSys)
27 {
28 ArkWebString ark_raw_file = ArkWebStringClassToStruct(rawFile);
29 bool result = ctocpp_->GetRawFileData(ark_raw_file, len, dest, isSys);
30 ArkWebStringStructRelease(ark_raw_file);
31 return result;
32 }
33
GetRawFileMapper(const std::string & rawFile,bool isSys)34 std::shared_ptr<NWeb::OhosFileMapper> ArkOhosResourceAdapterWrapper::GetRawFileMapper(
35 const std::string& rawFile, bool isSys)
36 {
37 ArkWebString ark_raw_file = ArkWebStringClassToStruct(rawFile);
38 ArkWebRefPtr<ArkOhosFileMapper> mapper = ctocpp_->GetRawFileMapper(ark_raw_file, isSys);
39 ArkWebStringStructRelease(ark_raw_file);
40 if (CHECK_REF_PTR_IS_NULL(mapper)) {
41 return nullptr;
42 }
43 return std::make_shared<ArkOhosFileMapperWrapper>(mapper);
44 }
45
IsRawFileExist(const std::string & rawFile,bool isSys)46 bool ArkOhosResourceAdapterWrapper::IsRawFileExist(const std::string& rawFile, bool isSys)
47 {
48 ArkWebString ark_raw_file = ArkWebStringClassToStruct(rawFile);
49 bool result = ctocpp_->IsRawFileExist(ark_raw_file, isSys);
50 ArkWebStringStructRelease(ark_raw_file);
51 return result;
52 }
53
GetRawFileLastModTime(const std::string & rawFile,uint16_t & date,uint16_t & time,bool isSys)54 bool ArkOhosResourceAdapterWrapper::GetRawFileLastModTime(
55 const std::string& rawFile, uint16_t& date, uint16_t& time, bool isSys)
56 {
57 ArkWebString ark_raw_file = ArkWebStringClassToStruct(rawFile);
58 bool result = ctocpp_->GetRawFileLastModTime(ark_raw_file, date, time, isSys);
59 ArkWebStringStructRelease(ark_raw_file);
60 return result;
61 }
62
GetRawFileLastModTime(const std::string & rawFile,time_t & time,bool isSys)63 bool ArkOhosResourceAdapterWrapper::GetRawFileLastModTime(const std::string& rawFile, time_t& time, bool isSys)
64 {
65 ArkWebString ark_raw_file = ArkWebStringClassToStruct(rawFile);
66 bool result = ctocpp_->GetRawFileLastModTime(ark_raw_file, time, isSys);
67 ArkWebStringStructRelease(ark_raw_file);
68 return result;
69 }
70
GetSystemLanguage()71 std::string ArkOhosResourceAdapterWrapper::GetSystemLanguage()
72 {
73 if (!ctocpp_) {
74 return "";
75 }
76
77 ArkWebString ark_result = ctocpp_->GetSystemLanguage();
78 std::string result = ArkWebStringStructToClass(ark_result);
79 ArkWebStringStructRelease(ark_result);
80 return result;
81 }
82 } // namespace OHOS::ArkWeb
83