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_impl.h"
17
18 #include "ohos_adapter/bridge/ark_ohos_file_mapper_impl.h"
19
20 #include "base/bridge/ark_web_bridge_macros.h"
21
22 namespace OHOS::ArkWeb {
23
ArkOhosResourceAdapterImpl(std::shared_ptr<OHOS::NWeb::OhosResourceAdapter> ref)24 ArkOhosResourceAdapterImpl::ArkOhosResourceAdapterImpl(std::shared_ptr<OHOS::NWeb::OhosResourceAdapter> ref)
25 : real_(ref)
26 {}
27
GetRawFileData(const ArkWebString & rawFile,size_t & len,uint8_t ** dest,bool isSys)28 bool ArkOhosResourceAdapterImpl::GetRawFileData(const ArkWebString& rawFile, size_t& len, uint8_t** dest, bool isSys)
29 {
30 return real_->GetRawFileData(ArkWebStringStructToClass(rawFile), len, dest, isSys);
31 }
32
GetRawFileMapper(const ArkWebString & rawFile,bool isSys)33 ArkWebRefPtr<ArkOhosFileMapper> ArkOhosResourceAdapterImpl::GetRawFileMapper(const ArkWebString& rawFile, bool isSys)
34 {
35 std::shared_ptr<NWeb::OhosFileMapper> fileMapper =
36 real_->GetRawFileMapper(ArkWebStringStructToClass(rawFile), isSys);
37 if (CHECK_SHARED_PTR_IS_NULL(fileMapper)) {
38 return nullptr;
39 }
40
41 return new ArkOhosFileMapperImpl(fileMapper);
42 }
43
IsRawFileExist(const ArkWebString & rawFile,bool isSys)44 bool ArkOhosResourceAdapterImpl::IsRawFileExist(const ArkWebString& rawFile, bool isSys)
45 {
46 return real_->IsRawFileExist(ArkWebStringStructToClass(rawFile), isSys);
47 }
48
GetRawFileLastModTime(const ArkWebString & rawFile,uint16_t & date,uint16_t & time,bool isSys)49 bool ArkOhosResourceAdapterImpl::GetRawFileLastModTime(
50 const ArkWebString& rawFile, uint16_t& date, uint16_t& time, bool isSys)
51 {
52 return real_->GetRawFileLastModTime(ArkWebStringStructToClass(rawFile), date, time, isSys);
53 }
54
GetRawFileLastModTime(const ArkWebString & rawFile,time_t & time,bool isSys)55 bool ArkOhosResourceAdapterImpl::GetRawFileLastModTime(const ArkWebString& rawFile, time_t& time, bool isSys)
56 {
57 return real_->GetRawFileLastModTime(ArkWebStringStructToClass(rawFile), time, isSys);
58 }
59
GetSystemLanguage()60 ArkWebString ArkOhosResourceAdapterImpl::GetSystemLanguage()
61 {
62 std::string result = real_->GetSystemLanguage();
63 return ArkWebStringClassToStruct(result);
64 }
65
66 } // namespace OHOS::ArkWeb
67