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_COOKIE_MANAGER_H_ 17 #define ARK_WEB_COOKIE_MANAGER_H_ 18 #pragma once 19 20 #include "ohos_nweb/include/ark_web_bool_value_callback.h" 21 #include "ohos_nweb/include/ark_web_long_value_callback.h" 22 #include "ohos_nweb/include/ark_web_string_value_callback.h" 23 24 namespace OHOS::ArkWeb { 25 26 /*--ark web(source=webcore)--*/ 27 class ArkWebCookieManager : public virtual ArkWebBaseRefCounted { 28 public: 29 /** 30 * @brief Ensures all cookies currently accessible through the ReturnCookie 31 * API are written to persistent storage. 32 * 33 * @param true if store cookie success else return false. 34 */ 35 /*--ark web()--*/ 36 virtual bool Store() = 0; 37 38 /** 39 * @brief Ensures all cookies currently accessible through the ReturnCookie 40 * API are written to persistent storage. 41 * 42 * @param callback a callback to be executed when cookies has Stored. 43 */ 44 /*--ark web()--*/ 45 virtual void Store(ArkWebRefPtr<ArkWebBoolValueCallback> callback) = 0; 46 47 /** 48 * @brief Sets a single cookie (key-value pair) for the given URL sync. 49 * 50 * @param url the URL for which the cookie is to be set. 51 * @param value the cookie as a string, using the format of the 'Set-Cookie' 52 * HTTP response header. 53 * @param incognito_mode true if web is in the incognito mode, flase 54 * otherwise. 55 * 56 * @return 0 if set cookie success else return error id. 57 */ 58 /*--ark web()--*/ 59 virtual int SetCookie(const ArkWebString& url, const ArkWebString& value, bool incognito_mode) = 0; 60 61 /** 62 * @brief Sets a single cookie (key-value pair) for the given URL. 63 * 64 * @param url the URL for which the cookie is to be set. 65 * @param value the cookie as a string, using the format of the 'Set-Cookie' 66 * HTTP response header. 67 * @param callback a callback to be executed when the cookie has been set. 68 */ 69 /*--ark web()--*/ 70 virtual void SetCookie( 71 const ArkWebString& url, const ArkWebString& value, ArkWebRefPtr<ArkWebBoolValueCallback> callback) = 0; 72 73 /** 74 * @brief Gets whether there are stored cookies. 75 * 76 * @param incognito_mode true if web is in the incognito mode, flase 77 * otherwise. 78 * 79 * @return true if there are stored cookies else false. 80 */ 81 /*--ark web()--*/ 82 virtual bool ExistCookies(bool incognito_mode) = 0; 83 84 /** 85 * @brief Gets whether there are stored cookies. 86 * 87 * @param callback a callback to be executed when the cookie has checked. 88 */ 89 /*--ark web()--*/ 90 virtual void ExistCookies(ArkWebRefPtr<ArkWebBoolValueCallback> callback) = 0; 91 92 /** 93 * @brief Gets all the cookies for the given URL. This is sync method 94 * 95 * @param url the URL for which the cookies are requested. 96 * @param incognito_mode true if web is in the incognito mode, flase 97 * otherwise. 98 * 99 * @return the cookie value for given URL. 100 */ 101 /*--ark web()--*/ 102 virtual ArkWebString ReturnCookie(const ArkWebString& url, bool& is_valid, bool incognito_mode) = 0; 103 104 /** 105 * @brief Gets all the cookies for the given URL. 106 * 107 * @param url the URL for which the cookies are requested. 108 * @param callback a callback which is executed when the cookies have been 109 * gotten. 110 */ 111 /*--ark web()--*/ 112 virtual void ReturnCookie(const ArkWebString& url, ArkWebRefPtr<ArkWebStringValueCallback> callback) = 0; 113 114 /** 115 * @brief Configs a single cookie (key-value pair) for the given URL. 116 * 117 * @param url the URL for which the cookie is to be set. 118 * @param value the cookie as a string, using the format of the 'Set-Cookie' 119 * HTTP response header. 120 * @param callback a callback to be executed when the cookie has been set. 121 */ 122 /*--ark web()--*/ 123 virtual void ConfigCookie( 124 const ArkWebString& url, const ArkWebString& value, ArkWebRefPtr<ArkWebLongValueCallback> callback) = 0; 125 126 /** 127 * @brief Removes all session cookies, which are cookies without an expiration 128 * date. 129 * 130 * @param callback a callback to be executed when all session cookies has 131 * removed. 132 */ 133 /*--ark web()--*/ 134 virtual void DeleteSessionCookies(ArkWebRefPtr<ArkWebBoolValueCallback> callback) = 0; 135 136 /** 137 * @brief Removes all cookies. 138 * 139 * @param callback a callback to be executed when all cookies has removed. 140 * @param incognito_mode true if web is in the incognito mode, flase 141 * otherwise. 142 */ 143 /*--ark web()--*/ 144 virtual void DeleteCookieEntirely(ArkWebRefPtr<ArkWebBoolValueCallback> callback, bool incognito_mode) = 0; 145 146 /** 147 * @brief Get whether the instance can send and accept cookies. 148 * 149 * @return true if the instance send and accept cookies. 150 */ 151 /*--ark web()--*/ 152 virtual bool IsAcceptCookieAllowed() = 0; 153 154 /** 155 * @brief Sets whether the instance should send and accept cookies. By default 156 * this is set to be true and the nweb accepts cookies. 157 * 158 * @param accept whether the instance should send and accept cookies. 159 */ 160 /*--ark web()--*/ 161 virtual void PutAcceptCookieEnabled(bool accept) = 0; 162 163 /** 164 * @brief Get whether the instance allows setting cookies of third parties 165 * 166 * @return true if the instance allows the setting of third-party cookies. 167 */ 168 /*--ark web()--*/ 169 virtual bool IsThirdPartyCookieAllowed() = 0; 170 171 /** 172 * @brief Get whether instances can send and accept cookies for file scheme 173 * URLs. 174 * 175 * @return true if instances send and accept cookies for file scheme URLs. 176 */ 177 /*--ark web()--*/ 178 virtual bool IsFileURLSchemeCookiesAllowed() = 0; 179 180 /** 181 * @brief Set whether the instance allows setting cookies of third parties. By 182 * default, this value is set to be false. Nweb does not allow the 183 * setting of third-party cookies. 184 * 185 * @param accept whether the instance allows the setting of third-party 186 * cookies. 187 */ 188 /*--ark web()--*/ 189 virtual void PutAcceptThirdPartyCookieEnabled(bool accept) = 0; 190 191 /** 192 * @brief Sets whether the instance should send and accept cookies for file 193 * scheme URLs. 194 * 195 * @param allow whether the instance should send and accept cookies for file 196 * scheme URLs. 197 */ 198 /*--ark web()--*/ 199 virtual void PutAcceptFileURLSchemeCookiesEnabled(bool allow) = 0; 200 201 /** 202 * @Description: Gets all the cookies for the given URL async. 203 * 204 * @Input url: the URL for which the cookies are requested. 205 * @Input incognitoMode: true if web is in the incognito mode, false otherwise. 206 * @Input callback: a callback which is executed when the cookies have been gotten. 207 */ 208 /*--ark web()--*/ 209 virtual void GetCookieAsync( 210 const ArkWebString& url, bool incognitoMode, ArkWebRefPtr<ArkWebStringValueCallback> callback) = 0; 211 212 /** 213 * @Description: Sets a single cookie (key-value pair) for the given URL sync. 214 * 215 * @Input url: the URL for which the cookie is to be set. 216 * @Input value: the cookie as a string, using the format of the 'Set-Cookie' HTTP response header. 217 * @Input incognitoMode: true if web is in the incognito mode, false otherwise. 218 * @Input includeHttpOnly: If true, HTTP-only cookies can also be overwritten. 219 * @return: 0 if set cookie success else return error id. 220 */ 221 /*--ark web()--*/ 222 virtual int SetCookieSync( 223 const ArkWebString& url, const ArkWebString& value, bool incognitoMode, bool includeHttpOnly) = 0; 224 225 /** 226 * @Description: Sets a single cookie (key-value pair) for the given URL async. 227 * 228 * @Input url: the URL for which the cookie is to be set. 229 * @Input value: the cookie as a string, using the format of the 'Set-Cookie' HTTP response header. 230 * @Input incognitoMode: true if web is in the incognito mode, false otherwise. 231 * @Input includeHttpOnly: If true, HTTP-only cookies can also be overwritten. 232 * @Input callback: a callback to be executed when the cookie has been set. 233 */ 234 /*--ark web()--*/ 235 virtual void SetCookieAsync(const ArkWebString& url, const ArkWebString& value, bool incognitoMode, 236 bool includeHttpOnly, ArkWebRefPtr<ArkWebLongValueCallback> callback) = 0; 237 }; 238 239 } // namespace OHOS::ArkWeb 240 241 #endif // ARK_WEB_COOKIE_MANAGER_H_ 242