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