• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "ohos_adapter/bridge/ark_datashare_adapter_wrapper.h"
17 
18 namespace OHOS::ArkWeb {
19 
ArkDatashareAdapterWrapper(ArkWebRefPtr<ArkDatashareAdapter> ref)20 ArkDatashareAdapterWrapper::ArkDatashareAdapterWrapper(ArkWebRefPtr<ArkDatashareAdapter> ref) : ctocpp_(ref) {}
21 
OpenDataShareUriForRead(const std::string & uriStr)22 int ArkDatashareAdapterWrapper::OpenDataShareUriForRead(const std::string& uriStr)
23 {
24     if (!ctocpp_) {
25         return -1;
26     }
27 
28     ArkWebString str = ArkWebStringClassToStruct(uriStr);
29     int result = ctocpp_->OpenDataShareUriForRead(str);
30 
31     ArkWebStringStructRelease(str);
32     return result;
33 }
34 
GetFileDisplayName(const std::string & uriStr)35 std::string ArkDatashareAdapterWrapper::GetFileDisplayName(const std::string& uriStr)
36 {
37     if (!ctocpp_) {
38         return "";
39     }
40 
41     ArkWebString ark_str = ArkWebStringClassToStruct(uriStr);
42     ArkWebString ark_result = ctocpp_->GetFileDisplayName(ark_str);
43 
44     std::string result = ArkWebStringStructToClass(ark_result);
45 
46     ArkWebStringStructRelease(ark_str);
47     ArkWebStringStructRelease(ark_result);
48     return result;
49 }
50 
GetRealPath(const std::string & uriStr)51 std::string ArkDatashareAdapterWrapper::GetRealPath(const std::string& uriStr)
52 {
53     if (!ctocpp_) {
54         return "";
55     }
56 
57     ArkWebString ark_str = ArkWebStringClassToStruct(uriStr);
58     ArkWebString ark_result = ctocpp_->GetRealPath(ark_str);
59 
60     std::string result = ArkWebStringStructToClass(ark_result);
61 
62     ArkWebStringStructRelease(ark_str);
63     ArkWebStringStructRelease(ark_result);
64     return result;
65 }
66 
67 } // namespace OHOS::ArkWeb
68