| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Brought to you by number 42. | 5 // Brought to you by number 42. |
| 6 | 6 |
| 7 #ifndef NET_COOKIES_COOKIE_STORE_H_ | 7 #ifndef NET_COOKIES_COOKIE_STORE_H_ |
| 8 #define NET_COOKIES_COOKIE_STORE_H_ | 8 #define NET_COOKIES_COOKIE_STORE_H_ |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // The cookie was overwritten with an already-expired expiration date. | 57 // The cookie was overwritten with an already-expired expiration date. |
| 58 EXPIRED_OVERWRITE | 58 EXPIRED_OVERWRITE |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Returns whether |cause| is one that could be a reason for deleting a | 61 // Returns whether |cause| is one that could be a reason for deleting a |
| 62 // cookie. This function assumes that ChangeCause::EXPLICIT is a reason for | 62 // cookie. This function assumes that ChangeCause::EXPLICIT is a reason for |
| 63 // deletion. | 63 // deletion. |
| 64 static bool ChangeCauseIsDeletion(ChangeCause cause); | 64 static bool ChangeCauseIsDeletion(ChangeCause cause); |
| 65 | 65 |
| 66 // Callback definitions. | 66 // Callback definitions. |
| 67 typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; | 67 typedef base::OnceCallback<void(const CookieList& cookies)> |
| 68 typedef base::Callback<void(const std::string& cookie)> GetCookiesCallback; | 68 GetCookieListCallback; |
| 69 typedef base::Callback<void(bool success)> SetCookiesCallback; | 69 typedef base::OnceCallback<void(const std::string& cookie)> |
| 70 typedef base::Callback<void(int num_deleted)> DeleteCallback; | 70 GetCookiesCallback; |
| 71 typedef base::OnceCallback<void(bool success)> SetCookiesCallback; |
| 72 typedef base::OnceCallback<void(int num_deleted)> DeleteCallback; |
| 73 |
| 71 typedef base::Callback<void(const CanonicalCookie& cookie, ChangeCause cause)> | 74 typedef base::Callback<void(const CanonicalCookie& cookie, ChangeCause cause)> |
| 72 CookieChangedCallback; | 75 CookieChangedCallback; |
| 73 typedef base::CallbackList<void(const CanonicalCookie& cookie, | 76 typedef base::CallbackList<void(const CanonicalCookie& cookie, |
| 74 ChangeCause cause)> | 77 ChangeCause cause)> |
| 75 CookieChangedCallbackList; | 78 CookieChangedCallbackList; |
| 76 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; | 79 typedef CookieChangedCallbackList::Subscription CookieChangedSubscription; |
| 77 typedef base::Callback<bool(const CanonicalCookie& cookie)> CookiePredicate; | 80 typedef base::Callback<bool(const CanonicalCookie& cookie)> CookiePredicate; |
| 78 | 81 |
| 79 virtual ~CookieStore(); | 82 virtual ~CookieStore(); |
| 80 | 83 |
| 81 // Returns the cookie line (e.g. "cookie1=value1; cookie2=value2") represented | 84 // Returns the cookie line (e.g. "cookie1=value1; cookie2=value2") represented |
| 82 // by |cookies|. The string is built in the same order as the given list. | 85 // by |cookies|. The string is built in the same order as the given list. |
| 83 // | 86 // |
| 84 // TODO(mkwst): We really should standardize on either | 87 // TODO(mkwst): We really should standardize on either |
| 85 // 'std::vector<CanonicalCookie>' or 'std::vector<CanonicalCookie*>'. | 88 // 'std::vector<CanonicalCookie>' or 'std::vector<CanonicalCookie*>'. |
| 86 static std::string BuildCookieLine( | 89 static std::string BuildCookieLine( |
| 87 const std::vector<CanonicalCookie>& cookies); | 90 const std::vector<CanonicalCookie>& cookies); |
| 88 static std::string BuildCookieLine( | 91 static std::string BuildCookieLine( |
| 89 const std::vector<CanonicalCookie*>& cookies); | 92 const std::vector<CanonicalCookie*>& cookies); |
| 90 | 93 |
| 91 // Sets the cookies specified by |cookie_list| returned from |url| | 94 // Sets the cookies specified by |cookie_list| returned from |url| |
| 92 // with options |options| in effect. Expects a cookie line, like | 95 // with options |options| in effect. Expects a cookie line, like |
| 93 // "a=1; domain=b.com". | 96 // "a=1; domain=b.com". |
| 94 // | 97 // |
| 95 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie | 98 // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie |
| 96 // and it would overwrite an existing HTTPONLY cookie. | 99 // and it would overwrite an existing HTTPONLY cookie. |
| 97 // Returns true if the cookie is successfully set. | 100 // Returns true if the cookie is successfully set. |
| 98 virtual void SetCookieWithOptionsAsync( | 101 virtual void SetCookieWithOptionsAsync(const GURL& url, |
| 99 const GURL& url, | 102 const std::string& cookie_line, |
| 100 const std::string& cookie_line, | 103 const CookieOptions& options, |
| 101 const CookieOptions& options, | 104 SetCookiesCallback callback) = 0; |
| 102 const SetCookiesCallback& callback) = 0; | |
| 103 | 105 |
| 104 // Sets a cookie given explicit user-provided cookie attributes. The cookie | 106 // Sets a cookie given explicit user-provided cookie attributes. The cookie |
| 105 // name, value, domain, etc. are each provided as separate strings. This | 107 // name, value, domain, etc. are each provided as separate strings. This |
| 106 // function expects each attribute to be well-formed. It will check for | 108 // function expects each attribute to be well-formed. It will check for |
| 107 // disallowed characters (e.g. the ';' character is disallowed within the | 109 // disallowed characters (e.g. the ';' character is disallowed within the |
| 108 // cookie value attribute) and will return false without setting the cookie | 110 // cookie value attribute) and will return false without setting the cookie |
| 109 // if such characters are found. | 111 // if such characters are found. |
| 110 // | 112 // |
| 111 // If |creation_time| is null, it will be set to the time the cookie is set. | 113 // If |creation_time| is null, it will be set to the time the cookie is set. |
| 112 // If |last_access_time| is null, it be set to |creation_time|. | 114 // If |last_access_time| is null, it be set to |creation_time|. |
| 113 // | 115 // |
| 114 // If unable to set a cookie, will invoke |callback| with false. | 116 // If unable to set a cookie, will invoke |callback| with false. |
| 115 virtual void SetCookieWithDetailsAsync( | 117 virtual void SetCookieWithDetailsAsync(const GURL& url, |
| 116 const GURL& url, | 118 const std::string& name, |
| 117 const std::string& name, | 119 const std::string& value, |
| 118 const std::string& value, | 120 const std::string& domain, |
| 119 const std::string& domain, | 121 const std::string& path, |
| 120 const std::string& path, | 122 base::Time creation_time, |
| 121 base::Time creation_time, | 123 base::Time expiration_time, |
| 122 base::Time expiration_time, | 124 base::Time last_access_time, |
| 123 base::Time last_access_time, | 125 bool secure, |
| 124 bool secure, | 126 bool http_only, |
| 125 bool http_only, | 127 CookieSameSite same_site, |
| 126 CookieSameSite same_site, | 128 CookiePriority priority, |
| 127 CookiePriority priority, | 129 SetCookiesCallback callback) = 0; |
| 128 const SetCookiesCallback& callback) = 0; | |
| 129 | 130 |
| 130 // TODO(rdsmith): Remove SetCookieWithDetailsAsync in favor of this. | 131 // TODO(rdsmith): Remove SetCookieWithDetailsAsync in favor of this. |
| 131 // Set the cookie on the cookie store. |cookie.IsCanonical()| must | 132 // Set the cookie on the cookie store. |cookie.IsCanonical()| must |
| 132 // be true. |secure_source| indicates if the source of the setting | 133 // be true. |secure_source| indicates if the source of the setting |
| 133 // may be considered secure (if from a URL, the scheme is | 134 // may be considered secure (if from a URL, the scheme is |
| 134 // cryptographic), and |modify_http_only| indicates if the source of | 135 // cryptographic), and |modify_http_only| indicates if the source of |
| 135 // the setting may modify http_only cookies. The current time will | 136 // the setting may modify http_only cookies. The current time will |
| 136 // be used in place of a null creation time. | 137 // be used in place of a null creation time. |
| 137 virtual void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie, | 138 virtual void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie, |
| 138 bool secure_source, | 139 bool secure_source, |
| 139 bool modify_http_only, | 140 bool modify_http_only, |
| 140 const SetCookiesCallback& callback) = 0; | 141 SetCookiesCallback callback) = 0; |
| 141 | 142 |
| 142 // TODO(???): what if the total size of all the cookies >4k, can we have a | 143 // TODO(???): what if the total size of all the cookies >4k, can we have a |
| 143 // header that big or do we need multiple Cookie: headers? | 144 // header that big or do we need multiple Cookie: headers? |
| 144 // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k. | 145 // Note: Some sites, such as Facebook, occasionally use Cookie headers >4k. |
| 145 // | 146 // |
| 146 // Simple interface, gets a cookie string "a=b; c=d" for the given URL. | 147 // Simple interface, gets a cookie string "a=b; c=d" for the given URL. |
| 147 // Gets all cookies that apply to |url| given |options|. Use options to | 148 // Gets all cookies that apply to |url| given |options|. Use options to |
| 148 // access httponly cookies. | 149 // access httponly cookies. |
| 149 // | 150 // |
| 150 // The returned cookies are ordered by longest path, then earliest | 151 // The returned cookies are ordered by longest path, then earliest |
| 151 // creation date. | 152 // creation date. |
| 152 // | 153 // |
| 153 // TODO(mkwst): This method is deprecated; callsites should be updated to | 154 // TODO(mkwst): This method is deprecated; callsites should be updated to |
| 154 // use 'GetCookieListWithOptionsAsync'. | 155 // use 'GetCookieListWithOptionsAsync'. |
| 155 virtual void GetCookiesWithOptionsAsync( | 156 virtual void GetCookiesWithOptionsAsync(const GURL& url, |
| 156 const GURL& url, | 157 const CookieOptions& options, |
| 157 const CookieOptions& options, | 158 GetCookiesCallback callback) = 0; |
| 158 const GetCookiesCallback& callback) = 0; | |
| 159 | 159 |
| 160 // Obtains a CookieList for the given |url| and |options|. The returned | 160 // Obtains a CookieList for the given |url| and |options|. The returned |
| 161 // cookies are passed into |callback|, ordered by longest path, then earliest | 161 // cookies are passed into |callback|, ordered by longest path, then earliest |
| 162 // creation date. | 162 // creation date. |
| 163 virtual void GetCookieListWithOptionsAsync( | 163 virtual void GetCookieListWithOptionsAsync( |
| 164 const GURL& url, | 164 const GURL& url, |
| 165 const CookieOptions& options, | 165 const CookieOptions& options, |
| 166 const GetCookieListCallback& callback) = 0; | 166 GetCookieListCallback callback) = 0; |
| 167 | 167 |
| 168 // Returns all cookies associated with |url|, including http-only, and | 168 // Returns all cookies associated with |url|, including http-only, and |
| 169 // same-site cookies. The returned cookies are ordered by longest path, then | 169 // same-site cookies. The returned cookies are ordered by longest path, then |
| 170 // by earliest creation date, and are not marked as having been accessed. | 170 // by earliest creation date, and are not marked as having been accessed. |
| 171 // | 171 // |
| 172 // TODO(mkwst): This method is deprecated, and should be removed, either by | 172 // TODO(mkwst): This method is deprecated, and should be removed, either by |
| 173 // updating callsites to use 'GetCookieListWithOptionsAsync' with an explicit | 173 // updating callsites to use 'GetCookieListWithOptionsAsync' with an explicit |
| 174 // CookieOptions, or by changing CookieOptions' defaults. | 174 // CookieOptions, or by changing CookieOptions' defaults. |
| 175 void GetAllCookiesForURLAsync(const GURL& url, | 175 void GetAllCookiesForURLAsync(const GURL& url, |
| 176 const GetCookieListCallback& callback); | 176 GetCookieListCallback callback); |
| 177 | 177 |
| 178 // Returns all the cookies, for use in management UI, etc. This does not mark | 178 // Returns all the cookies, for use in management UI, etc. This does not mark |
| 179 // the cookies as having been accessed. The returned cookies are ordered by | 179 // the cookies as having been accessed. The returned cookies are ordered by |
| 180 // longest path, then by earliest creation date. | 180 // longest path, then by earliest creation date. |
| 181 virtual void GetAllCookiesAsync(const GetCookieListCallback& callback) = 0; | 181 virtual void GetAllCookiesAsync(GetCookieListCallback callback) = 0; |
| 182 | 182 |
| 183 // Deletes all cookies that might apply to |url| that have |cookie_name|. | 183 // Deletes all cookies that might apply to |url| that have |cookie_name|. |
| 184 virtual void DeleteCookieAsync(const GURL& url, | 184 virtual void DeleteCookieAsync(const GURL& url, |
| 185 const std::string& cookie_name, | 185 const std::string& cookie_name, |
| 186 const base::Closure& callback) = 0; | 186 base::OnceClosure callback) = 0; |
| 187 | 187 |
| 188 // Deletes one specific cookie. |cookie| must have been returned by a previous | 188 // Deletes one specific cookie. |cookie| must have been returned by a previous |
| 189 // query on this CookieStore. Invokes |callback| with 1 if a cookie was | 189 // query on this CookieStore. Invokes |callback| with 1 if a cookie was |
| 190 // deleted, 0 otherwise. | 190 // deleted, 0 otherwise. |
| 191 virtual void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, | 191 virtual void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, |
| 192 const DeleteCallback& callback) = 0; | 192 DeleteCallback callback) = 0; |
| 193 | 193 |
| 194 // Deletes all of the cookies that have a creation_date greater than or equal | 194 // Deletes all of the cookies that have a creation_date greater than or equal |
| 195 // to |delete_begin| and less than |delete_end| | 195 // to |delete_begin| and less than |delete_end| |
| 196 // Calls |callback| with the number of cookies deleted. | 196 // Calls |callback| with the number of cookies deleted. |
| 197 virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, | 197 virtual void DeleteAllCreatedBetweenAsync(const base::Time& delete_begin, |
| 198 const base::Time& delete_end, | 198 const base::Time& delete_end, |
| 199 const DeleteCallback& callback) = 0; | 199 DeleteCallback callback) = 0; |
| 200 | 200 |
| 201 // Deletes all of the cookies that match the given predicate and that have a | 201 // Deletes all of the cookies that match the given predicate and that have a |
| 202 // creation_date greater than or equal to |delete_begin| and smaller than | 202 // creation_date greater than or equal to |delete_begin| and smaller than |
| 203 // |delete_end|. This includes all http_only and secure cookies. Avoid | 203 // |delete_end|. This includes all http_only and secure cookies. Avoid |
| 204 // deleting cookies that could leave websites with a partial set of visible | 204 // deleting cookies that could leave websites with a partial set of visible |
| 205 // cookies. | 205 // cookies. |
| 206 // Calls |callback| with the number of cookies deleted. | 206 // Calls |callback| with the number of cookies deleted. |
| 207 virtual void DeleteAllCreatedBetweenWithPredicateAsync( | 207 virtual void DeleteAllCreatedBetweenWithPredicateAsync( |
| 208 const base::Time& delete_begin, | 208 const base::Time& delete_begin, |
| 209 const base::Time& delete_end, | 209 const base::Time& delete_end, |
| 210 const CookiePredicate& predicate, | 210 const CookiePredicate& predicate, |
| 211 const DeleteCallback& callback) = 0; | 211 DeleteCallback callback) = 0; |
| 212 | 212 |
| 213 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) = 0; | 213 virtual void DeleteSessionCookiesAsync(DeleteCallback) = 0; |
| 214 | 214 |
| 215 // Deletes all cookies in the store. | 215 // Deletes all cookies in the store. |
| 216 void DeleteAllAsync(const DeleteCallback& callback); | 216 void DeleteAllAsync(DeleteCallback callback); |
| 217 | 217 |
| 218 // Flush the backing store (if any) to disk and post the given callback when | 218 // Flush the backing store (if any) to disk and post the given callback when |
| 219 // done. | 219 // done. |
| 220 virtual void FlushStore(const base::Closure& callback) = 0; | 220 virtual void FlushStore(base::OnceClosure callback) = 0; |
| 221 | 221 |
| 222 // Protects session cookies from deletion on shutdown, if the underlying | 222 // Protects session cookies from deletion on shutdown, if the underlying |
| 223 // CookieStore implemention is currently configured to store them to disk. | 223 // CookieStore implemention is currently configured to store them to disk. |
| 224 // Otherwise, does nothing. | 224 // Otherwise, does nothing. |
| 225 virtual void SetForceKeepSessionState(); | 225 virtual void SetForceKeepSessionState(); |
| 226 | 226 |
| 227 // Add a callback to be notified when the set of cookies named |name| that | 227 // Add a callback to be notified when the set of cookies named |name| that |
| 228 // would be sent for a request to |url| changes. The returned handle is | 228 // would be sent for a request to |url| changes. The returned handle is |
| 229 // guaranteed not to hold a hard reference to the CookieStore object. | 229 // guaranteed not to hold a hard reference to the CookieStore object. |
| 230 // | 230 // |
| (...skipping 24 matching lines...) Expand all Loading... |
| 255 int GetChannelIDServiceID(); | 255 int GetChannelIDServiceID(); |
| 256 | 256 |
| 257 protected: | 257 protected: |
| 258 CookieStore(); | 258 CookieStore(); |
| 259 int channel_id_service_id_; | 259 int channel_id_service_id_; |
| 260 }; | 260 }; |
| 261 | 261 |
| 262 } // namespace net | 262 } // namespace net |
| 263 | 263 |
| 264 #endif // NET_COOKIES_COOKIE_STORE_H_ | 264 #endif // NET_COOKIES_COOKIE_STORE_H_ |
| OLD | NEW |