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_impl.h"
17 
18 #include "base/bridge/ark_web_bridge_macros.h"
19 
20 namespace OHOS::ArkWeb {
21 
ArkOhosWebDataBaseAdapterImpl(NWeb::OhosWebDataBaseAdapter & ref)22 ArkOhosWebDataBaseAdapterImpl::ArkOhosWebDataBaseAdapterImpl(NWeb::OhosWebDataBaseAdapter& ref) : real_(ref) {}
23 
ExistHttpAuthCredentials()24 bool ArkOhosWebDataBaseAdapterImpl::ExistHttpAuthCredentials()
25 {
26     return real_.ExistHttpAuthCredentials();
27 }
28 
DeleteHttpAuthCredentials()29 void ArkOhosWebDataBaseAdapterImpl::DeleteHttpAuthCredentials()
30 {
31     return real_.DeleteHttpAuthCredentials();
32 }
33 
SaveHttpAuthCredentials(const ArkWebString & host,const ArkWebString & realm,const ArkWebString & username,const char * password)34 void ArkOhosWebDataBaseAdapterImpl::SaveHttpAuthCredentials(
35     const ArkWebString& host, const ArkWebString& realm, const ArkWebString& username, const char* password)
36 {
37     real_.SaveHttpAuthCredentials(ArkWebStringStructToClass(host), ArkWebStringStructToClass(realm),
38         ArkWebStringStructToClass(username), password);
39 }
40 
GetHttpAuthCredentials(const ArkWebString & host,const ArkWebString & realm,ArkWebString & username,char * password,uint32_t passwordSize)41 void ArkOhosWebDataBaseAdapterImpl::GetHttpAuthCredentials(
42     const ArkWebString& host, const ArkWebString& realm, ArkWebString& username, char* password, uint32_t passwordSize)
43 {
44     std::string s_username;
45     real_.GetHttpAuthCredentials(
46         ArkWebStringStructToClass(host), ArkWebStringStructToClass(realm), s_username, password, passwordSize);
47     username = ArkWebStringClassToStruct(s_username);
48 }
49 
ArkOhosWebPermissionDataBaseAdapterImpl(NWeb::OhosWebPermissionDataBaseAdapter & ref)50 ArkOhosWebPermissionDataBaseAdapterImpl::ArkOhosWebPermissionDataBaseAdapterImpl(
51     NWeb::OhosWebPermissionDataBaseAdapter& ref)
52     : real_(ref)
53 {}
54 
ExistPermissionByOrigin(const ArkWebString & origin,const int32_t & key)55 bool ArkOhosWebPermissionDataBaseAdapterImpl::ExistPermissionByOrigin(const ArkWebString& origin, const int32_t& key)
56 {
57     return real_.ExistPermissionByOrigin(ArkWebStringStructToClass(origin), (NWeb::WebPermissionType)key);
58 }
59 
GetPermissionResultByOrigin(const ArkWebString & origin,const int32_t & key,bool & result)60 bool ArkOhosWebPermissionDataBaseAdapterImpl::GetPermissionResultByOrigin(
61     const ArkWebString& origin, const int32_t& key, bool& result)
62 {
63     return real_.GetPermissionResultByOrigin(ArkWebStringStructToClass(origin), (NWeb::WebPermissionType)key, result);
64 }
65 
SetPermissionByOrigin(const ArkWebString & origin,const int32_t & key,bool result)66 void ArkOhosWebPermissionDataBaseAdapterImpl::SetPermissionByOrigin(
67     const ArkWebString& origin, const int32_t& key, bool result)
68 {
69     real_.SetPermissionByOrigin(ArkWebStringStructToClass(origin), (NWeb::WebPermissionType)key, result);
70 }
71 
ClearPermissionByOrigin(const ArkWebString & origin,const int32_t & key)72 void ArkOhosWebPermissionDataBaseAdapterImpl::ClearPermissionByOrigin(const ArkWebString& origin, const int32_t& key)
73 {
74     real_.ClearPermissionByOrigin(ArkWebStringStructToClass(origin), (NWeb::WebPermissionType)key);
75 }
76 
ClearAllPermission(const int32_t & key)77 void ArkOhosWebPermissionDataBaseAdapterImpl::ClearAllPermission(const int32_t& key)
78 {
79     real_.ClearAllPermission((NWeb::WebPermissionType)key);
80 }
81 
GetOriginsByPermission(const int32_t & key,ArkWebStringVector & origins)82 void ArkOhosWebPermissionDataBaseAdapterImpl::GetOriginsByPermission(const int32_t& key, ArkWebStringVector& origins)
83 {
84     std::vector<std::string> temp;
85     real_.GetOriginsByPermission((NWeb::WebPermissionType)key, temp);
86     origins = ArkWebStringVectorClassToStruct(temp);
87 }
88 
89 } // namespace OHOS::ArkWeb
90