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 #ifndef ARK_WEB_DATA_BASE_WRAPPER_H_
17 #define ARK_WEB_DATA_BASE_WRAPPER_H_
18 #pragma once
19 
20 #include "include/nweb_data_base.h"
21 #include "ohos_nweb/include/ark_web_data_base.h"
22 
23 namespace OHOS::ArkWeb {
24 
25 class ArkWebDataBaseWrapper : public OHOS::NWeb::NWebDataBase {
26 public:
27     ArkWebDataBaseWrapper(ArkWebRefPtr<ArkWebDataBase> ark_web_data_base);
28     ~ArkWebDataBaseWrapper() = default;
29 
30     /**
31      * @brief delete all specifies permission type.
32      *
33      * @param type specifies permission type.
34      * @param incognito true if web is in the incognito mode, flase otherwise.
35      */
36     void ClearAllPermission(int type, bool incognito) override;
37 
38     /**
39      * @brief get username and password.
40      *
41      * @param host the host to which the credentials apply.
42      * @param realm the realm to which the credentials apply.
43      * @param user_name the username.
44      * @param password the password.
45      * @param password_size the password array size.
46      */
47     void GetHttpAuthCredentials(const std::string& host, const std::string& realm, std::string& user_name,
48         char* password, uint32_t password_size) override;
49 
50     /**
51      * @brief save http authentication credentials.
52      *
53      * @param host the host to which the credentials apply.
54      * @param realm the realm to which the credentials apply.
55      * @param username the user_name.
56      * @param password the password.
57      */
58     void SaveHttpAuthCredentials(
59         const std::string& host, const std::string& realm, const std::string& user_name, const char* password) override;
60 
61     /**
62      * @brief Get whether instances holds any http authentication credentials.
63      *
64      * @return true if instances saved any http authentication credentials.
65      */
66     bool ExistHttpAuthCredentials() override;
67 
68     /**
69      * @brief clear all saved authentication credentials.
70      *
71      */
72     void DeleteHttpAuthCredentials() override;
73 
74     /**
75      * @brief obtains all origins of a specified permission type.
76      *
77      * @param type specifies permission type.
78      * @param incognito true if web is in the incognito mode, flase otherwise.
79      *
80      * @return return all origin.
81      */
82     std::vector<std::string> GetOriginsByPermission(int type, bool incognito) override;
83 
84     /**
85      * @brief get specifies permission type result by origin.
86      *
87      * @param origin url source.
88      * @param type specifies permission type.
89      * @param result saved result.
90      * @param incognito true if web is in the incognito mode, flase otherwise.
91      *
92      * @return return Whether there is a saved result.
93      */
94     bool GetPermissionResultByOrigin(const std::string& origin, int type, bool& result, bool incognito) override;
95 
96     /**
97      * @brief set specifies permission type result by origin.
98      *
99      * @param origin url source.
100      * @param type specifies permission type.
101      * @param result set result.
102      * @param incognito true if web is in the incognito mode, flase otherwise.
103      *
104      * @return 0 if successfully set specifies permission type result by origin
105      *         other return error id.
106      */
107     int SetPermissionByOrigin(const std::string& origin, int type, bool result, bool incognito) override;
108 
109     /**
110      * @brief gets whether the instance holds the specified permissions for the
111      *        specified source.
112      *
113      * @param origin url source.
114      * @param type specifies permission type.
115      * @param incognito true if web is in the incognito mode, flase otherwise.
116      *
117      * @return true if instances saved origin specified permissions.
118      */
119     bool ExistPermissionByOrigin(const std::string& origin, int type, bool incognito) override;
120 
121     /**
122      * @brief delete specifies permission type by origin.
123      *
124      * @param origin url source.
125      * @param type specifies permission type.
126      * @param incognito true if web is in the incognito mode, flase otherwise.
127      *
128      * @return 0 if successfully delete specifies permission type result by origin
129      *         other return error id.
130      */
131     int ClearPermissionByOrigin(const std::string& origin, int type, bool incognito) override;
132 
133 private:
134     ArkWebRefPtr<ArkWebDataBase> ark_web_data_base_;
135 };
136 
137 } // namespace OHOS::ArkWeb
138 
139 #endif // ARK_WEB_DATA_BASE_WRAPPER_H_
140