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