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_web_data_base_adapter_wrapper.h"
17
18 namespace OHOS::ArkWeb {
19
ArkOhosWebDataBaseAdapterWrapper(ArkWebRefPtr<ArkOhosWebDataBaseAdapter> ref)20 ArkOhosWebDataBaseAdapterWrapper::ArkOhosWebDataBaseAdapterWrapper(ArkWebRefPtr<ArkOhosWebDataBaseAdapter> ref)
21 : ctocpp_(ref)
22 {}
23
ExistHttpAuthCredentials()24 bool ArkOhosWebDataBaseAdapterWrapper::ExistHttpAuthCredentials()
25 {
26 if (!ctocpp_) {
27 return false;
28 }
29 return ctocpp_->ExistHttpAuthCredentials();
30 }
31
DeleteHttpAuthCredentials()32 void ArkOhosWebDataBaseAdapterWrapper::DeleteHttpAuthCredentials()
33 {
34 if (!ctocpp_) {
35 return;
36 }
37 return ctocpp_->DeleteHttpAuthCredentials();
38 }
39
SaveHttpAuthCredentials(const std::string & host,const std::string & realm,const std::string & username,const char * password)40 void ArkOhosWebDataBaseAdapterWrapper::SaveHttpAuthCredentials(
41 const std::string& host, const std::string& realm, const std::string& username, const char* password)
42 {
43 if (!ctocpp_) {
44 return;
45 }
46 ArkWebString ark_host = ArkWebStringClassToStruct(host);
47 ArkWebString ark_realm = ArkWebStringClassToStruct(realm);
48 ArkWebString ark_username = ArkWebStringClassToStruct(username);
49 ctocpp_->SaveHttpAuthCredentials(ark_host, ark_realm, ark_username, password);
50 ArkWebStringStructRelease(ark_host);
51 ArkWebStringStructRelease(ark_realm);
52 ArkWebStringStructRelease(ark_username);
53 }
54
GetHttpAuthCredentials(const std::string & host,const std::string & realm,std::string & username,char * password,uint32_t passwordSize)55 void ArkOhosWebDataBaseAdapterWrapper::GetHttpAuthCredentials(
56 const std::string& host, const std::string& realm, std::string& username, char* password, uint32_t passwordSize)
57 {
58 if (!ctocpp_) {
59 return;
60 }
61 ArkWebString ark_host = ArkWebStringClassToStruct(host);
62 ArkWebString ark_realm = ArkWebStringClassToStruct(realm);
63 ArkWebString ark_username = ArkWebStringClassToStruct(username);
64 ctocpp_->GetHttpAuthCredentials(ark_host, ark_realm, ark_username, password, passwordSize);
65 username = ArkWebStringStructToClass(ark_username);
66 ArkWebStringStructRelease(ark_host);
67 ArkWebStringStructRelease(ark_realm);
68 ArkWebStringStructRelease(ark_username);
69 }
70
ArkOhosWebPermissionDataBaseAdapterWrapper(ArkWebRefPtr<ArkOhosWebPermissionDataBaseAdapter> ref)71 ArkOhosWebPermissionDataBaseAdapterWrapper::ArkOhosWebPermissionDataBaseAdapterWrapper(
72 ArkWebRefPtr<ArkOhosWebPermissionDataBaseAdapter> ref)
73 : ctocpp_(ref)
74 {}
75
ExistPermissionByOrigin(const std::string & origin,const OHOS::NWeb::WebPermissionType & key)76 bool ArkOhosWebPermissionDataBaseAdapterWrapper::ExistPermissionByOrigin(
77 const std::string& origin, const OHOS::NWeb::WebPermissionType& key)
78 {
79 if (!ctocpp_) {
80 return false;
81 }
82
83 ArkWebString ark_origin = ArkWebStringClassToStruct(origin);
84 const int32_t ark_key = (int32_t)key;
85 bool result = ctocpp_->ExistPermissionByOrigin(ark_origin, ark_key);
86 ArkWebStringStructRelease(ark_origin);
87 return result;
88 }
89
GetPermissionResultByOrigin(const std::string & origin,const OHOS::NWeb::WebPermissionType & key,bool & result)90 bool ArkOhosWebPermissionDataBaseAdapterWrapper::GetPermissionResultByOrigin(
91 const std::string& origin, const OHOS::NWeb::WebPermissionType& key, bool& result)
92 {
93 if (!ctocpp_) {
94 return false;
95 }
96
97 ArkWebString ark_origin = ArkWebStringClassToStruct(origin);
98 const int32_t ark_key = (int32_t)key;
99 bool res = ctocpp_->GetPermissionResultByOrigin(ark_origin, ark_key, result);
100 ArkWebStringStructRelease(ark_origin);
101 return res;
102 }
103
SetPermissionByOrigin(const std::string & origin,const OHOS::NWeb::WebPermissionType & key,bool result)104 void ArkOhosWebPermissionDataBaseAdapterWrapper::SetPermissionByOrigin(
105 const std::string& origin, const OHOS::NWeb::WebPermissionType& key, bool result)
106 {
107 if (!ctocpp_) {
108 return;
109 }
110 ArkWebString ark_origin = ArkWebStringClassToStruct(origin);
111 const int32_t ark_key = (int32_t)key;
112 ctocpp_->SetPermissionByOrigin(ark_origin, ark_key, result);
113 ArkWebStringStructRelease(ark_origin);
114 }
115
ClearPermissionByOrigin(const std::string & origin,const OHOS::NWeb::WebPermissionType & key)116 void ArkOhosWebPermissionDataBaseAdapterWrapper::ClearPermissionByOrigin(
117 const std::string& origin, const OHOS::NWeb::WebPermissionType& key)
118 {
119 if (!ctocpp_) {
120 return;
121 }
122 ArkWebString ark_origin = ArkWebStringClassToStruct(origin);
123 const int32_t ark_key = (int32_t)key;
124 ctocpp_->ClearPermissionByOrigin(ark_origin, ark_key);
125 ArkWebStringStructRelease(ark_origin);
126 }
127
ClearAllPermission(const OHOS::NWeb::WebPermissionType & key)128 void ArkOhosWebPermissionDataBaseAdapterWrapper::ClearAllPermission(const OHOS::NWeb::WebPermissionType& key)
129 {
130 if (!ctocpp_) {
131 return;
132 }
133 const int32_t ark_key = (int32_t)key;
134 return ctocpp_->ClearAllPermission(ark_key);
135 }
136
GetOriginsByPermission(const OHOS::NWeb::WebPermissionType & key,std::vector<std::string> & origins)137 void ArkOhosWebPermissionDataBaseAdapterWrapper::GetOriginsByPermission(
138 const OHOS::NWeb::WebPermissionType& key, std::vector<std::string>& origins)
139 {
140 if (!ctocpp_) {
141 return;
142 }
143 const int32_t ark_key = (int32_t)key;
144 ArkWebStringVector vec;
145 ctocpp_->GetOriginsByPermission(ark_key, vec);
146 origins = ArkWebStringVectorStructToClass(vec);
147 ArkWebStringVectorStructRelease(vec);
148 }
149
150 } // namespace OHOS::ArkWeb
151