1 /*
2 * Copyright (c) 2024 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_nweb/bridge/ark_web_data_base_impl.h"
17
18 #include "base/bridge/ark_web_bridge_macros.h"
19
20 namespace OHOS::ArkWeb {
21
ArkWebDataBaseImpl(std::shared_ptr<OHOS::NWeb::NWebDataBase> nweb_data_base)22 ArkWebDataBaseImpl::ArkWebDataBaseImpl(std::shared_ptr<OHOS::NWeb::NWebDataBase> nweb_data_base)
23 : nweb_data_base_(nweb_data_base)
24 {}
25
ClearAllPermission(int type,bool incognito)26 void ArkWebDataBaseImpl::ClearAllPermission(int type, bool incognito)
27 {
28 nweb_data_base_->ClearAllPermission(type, incognito);
29 }
30
GetHttpAuthCredentials(const ArkWebString & host,const ArkWebString & realm,ArkWebString & user_name,char * password,uint32_t password_size)31 void ArkWebDataBaseImpl::GetHttpAuthCredentials(const ArkWebString& host, const ArkWebString& realm,
32 ArkWebString& user_name, char* password, uint32_t password_size)
33 {
34 std::string cls_user_name;
35 nweb_data_base_->GetHttpAuthCredentials(
36 ArkWebStringStructToClass(host), ArkWebStringStructToClass(realm), cls_user_name, password, password_size);
37 user_name = ArkWebStringClassToStruct(cls_user_name);
38 }
39
SaveHttpAuthCredentials(const ArkWebString & host,const ArkWebString & realm,const ArkWebString & user_name,const char * password)40 void ArkWebDataBaseImpl::SaveHttpAuthCredentials(
41 const ArkWebString& host, const ArkWebString& realm, const ArkWebString& user_name, const char* password)
42 {
43 nweb_data_base_->SaveHttpAuthCredentials(ArkWebStringStructToClass(host), ArkWebStringStructToClass(realm),
44 ArkWebStringStructToClass(user_name), password);
45 }
46
ExistHttpAuthCredentials()47 bool ArkWebDataBaseImpl::ExistHttpAuthCredentials()
48 {
49 return nweb_data_base_->ExistHttpAuthCredentials();
50 }
51
DeleteHttpAuthCredentials()52 void ArkWebDataBaseImpl::DeleteHttpAuthCredentials()
53 {
54 nweb_data_base_->DeleteHttpAuthCredentials();
55 }
56
GetOriginsByPermission(int type,bool incognito)57 ArkWebStringVector ArkWebDataBaseImpl::GetOriginsByPermission(int type, bool incognito)
58 {
59 return ArkWebStringVectorClassToStruct(nweb_data_base_->GetOriginsByPermission(type, incognito));
60 }
61
GetPermissionByOrigin(const ArkWebString & origin,int type,bool & result,bool incognito)62 bool ArkWebDataBaseImpl::GetPermissionByOrigin(const ArkWebString& origin, int type, bool& result, bool incognito)
63 {
64 return nweb_data_base_->GetPermissionResultByOrigin(ArkWebStringStructToClass(origin), type, result, incognito);
65 }
66
SetPermissionByOrigin(const ArkWebString & origin,int type,bool result,bool incognito)67 int ArkWebDataBaseImpl::SetPermissionByOrigin(const ArkWebString& origin, int type, bool result, bool incognito)
68 {
69 return nweb_data_base_->SetPermissionByOrigin(ArkWebStringStructToClass(origin), type, result, incognito);
70 }
71
ExistPermissionByOrigin(const ArkWebString & origin,int type,bool incognito)72 bool ArkWebDataBaseImpl::ExistPermissionByOrigin(const ArkWebString& origin, int type, bool incognito)
73 {
74 return nweb_data_base_->ExistPermissionByOrigin(ArkWebStringStructToClass(origin), type, incognito);
75 }
76
ClearPermissionByOrigin(const ArkWebString & origin,int type,bool incognito)77 int ArkWebDataBaseImpl::ClearPermissionByOrigin(const ArkWebString& origin, int type, bool incognito)
78 {
79 return nweb_data_base_->ClearPermissionByOrigin(ArkWebStringStructToClass(origin), type, incognito);
80 }
81
82 } // namespace OHOS::ArkWeb
83