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