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, 78 int type, 79 bool incognito) = 0; 80 81 /** 82 * @brief get specifies permission type result by origin. 83 * 84 * @param origin url source. 85 * @param type specifies permission type. 86 * @param result saved result. 87 * @return return whether there is a saved result. 88 */ 89 virtual bool GetPermissionResultByOrigin(const std::string& origin, 90 int type, 91 bool& result, 92 bool incognito) = 0; 93 94 /** 95 * @brief set specifies permission type result by origin. 96 * 97 * @param origin url source. 98 * @param type specifies permission type. 99 * @param result set result. 100 * @return 0 if successfully set specifies permission type result by origin other return error id. 101 */ 102 virtual int SetPermissionByOrigin(const std::string& origin, 103 int type, 104 bool result, 105 bool incognito) = 0; 106 107 /** 108 * @brief delete specifies permission type by origin. 109 * 110 * @param origin url source. 111 * @param type specifies permission type. 112 * @return 0 if successfully delete specifies permission type result by origin other return error id. 113 */ 114 virtual int ClearPermissionByOrigin(const std::string& origin, 115 int type, 116 bool incognito) = 0; 117 118 /** 119 * @brief delete all specifies permission type. 120 * 121 * @param type specifies permission type. 122 */ 123 virtual void ClearAllPermission(int type, bool incognito) = 0; 124 125 /** 126 * @brief obtains all origins of a specified permission type. 127 * 128 * @param type specifies permission type. 129 * @return return all origin. 130 */ 131 virtual std::vector<std::string> GetOriginsByPermission(int type, 132 bool incognito) = 0; 133 }; 134 } // namespace OHOS::NWeb 135 136 #endif // NWEB_DATA_BASE_H 137