| 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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
| 6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
| 7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
| 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 9 * | 9 * |
| 10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return url_path.substr(0, idx); | 102 return url_path.substr(0, idx); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 CanonicalCookie::CanonicalCookie() | 107 CanonicalCookie::CanonicalCookie() |
| 108 : secure_(false), | 108 : secure_(false), |
| 109 httponly_(false) { | 109 httponly_(false) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 CanonicalCookie::CanonicalCookie( | 112 CanonicalCookie::CanonicalCookie(const GURL& url, |
| 113 const GURL& url, const std::string& name, const std::string& value, | 113 const std::string& name, |
| 114 const std::string& domain, const std::string& path, | 114 const std::string& value, |
| 115 const base::Time& creation, const base::Time& expiration, | 115 const std::string& domain, |
| 116 const base::Time& last_access, bool secure, bool httponly, | 116 const std::string& path, |
| 117 CookiePriority priority) | 117 const base::Time& creation, |
| 118 const base::Time& expiration, |
| 119 const base::Time& last_access, |
| 120 bool secure, |
| 121 bool httponly, |
| 122 bool firstpartyonly, |
| 123 CookiePriority priority) |
| 118 : source_(GetCookieSourceFromURL(url)), | 124 : source_(GetCookieSourceFromURL(url)), |
| 119 name_(name), | 125 name_(name), |
| 120 value_(value), | 126 value_(value), |
| 121 domain_(domain), | 127 domain_(domain), |
| 122 path_(path), | 128 path_(path), |
| 123 creation_date_(creation), | 129 creation_date_(creation), |
| 124 expiry_date_(expiration), | 130 expiry_date_(expiration), |
| 125 last_access_date_(last_access), | 131 last_access_date_(last_access), |
| 126 secure_(secure), | 132 secure_(secure), |
| 127 httponly_(httponly), | 133 httponly_(httponly), |
| 134 first_party_only_(firstpartyonly), |
| 128 priority_(priority) { | 135 priority_(priority) { |
| 129 } | 136 } |
| 130 | 137 |
| 131 CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) | 138 CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) |
| 132 : source_(GetCookieSourceFromURL(url)), | 139 : source_(GetCookieSourceFromURL(url)), |
| 133 name_(pc.Name()), | 140 name_(pc.Name()), |
| 134 value_(pc.Value()), | 141 value_(pc.Value()), |
| 135 path_(CanonPath(url, pc)), | 142 path_(CanonPath(url, pc)), |
| 136 creation_date_(Time::Now()), | 143 creation_date_(Time::Now()), |
| 137 last_access_date_(Time()), | 144 last_access_date_(Time()), |
| 138 secure_(pc.IsSecure()), | 145 secure_(pc.IsSecure()), |
| 139 httponly_(pc.IsHttpOnly()), | 146 httponly_(pc.IsHttpOnly()), |
| 147 first_party_only_(pc.IsFirstPartyOnly()), |
| 140 priority_(pc.Priority()) { | 148 priority_(pc.Priority()) { |
| 141 if (pc.HasExpires()) | 149 if (pc.HasExpires()) |
| 142 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_); | 150 expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_); |
| 143 | 151 |
| 144 // Do the best we can with the domain. | 152 // Do the best we can with the domain. |
| 145 std::string cookie_domain; | 153 std::string cookie_domain; |
| 146 std::string domain_string; | 154 std::string domain_string; |
| 147 if (pc.HasDomain()) { | 155 if (pc.HasDomain()) { |
| 148 domain_string = pc.Domain(); | 156 domain_string = pc.Domain(); |
| 149 } | 157 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 239 |
| 232 std::string cookie_path = CanonicalCookie::CanonPath(url, parsed_cookie); | 240 std::string cookie_path = CanonicalCookie::CanonPath(url, parsed_cookie); |
| 233 Time server_time(creation_time); | 241 Time server_time(creation_time); |
| 234 if (options.has_server_time()) | 242 if (options.has_server_time()) |
| 235 server_time = options.server_time(); | 243 server_time = options.server_time(); |
| 236 | 244 |
| 237 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, | 245 Time cookie_expires = CanonicalCookie::CanonExpiration(parsed_cookie, |
| 238 creation_time, | 246 creation_time, |
| 239 server_time); | 247 server_time); |
| 240 | 248 |
| 241 return new CanonicalCookie(url, parsed_cookie.Name(), parsed_cookie.Value(), | 249 return new CanonicalCookie( |
| 242 cookie_domain, cookie_path, creation_time, | 250 url, parsed_cookie.Name(), parsed_cookie.Value(), cookie_domain, |
| 243 cookie_expires, creation_time, | 251 cookie_path, creation_time, cookie_expires, creation_time, |
| 244 parsed_cookie.IsSecure(), | 252 parsed_cookie.IsSecure(), parsed_cookie.IsHttpOnly(), |
| 245 parsed_cookie.IsHttpOnly(), | 253 parsed_cookie.IsFirstPartyOnly(), parsed_cookie.Priority()); |
| 246 parsed_cookie.Priority()); | |
| 247 } | 254 } |
| 248 | 255 |
| 249 CanonicalCookie* CanonicalCookie::Create(const GURL& url, | 256 CanonicalCookie* CanonicalCookie::Create(const GURL& url, |
| 250 const std::string& name, | 257 const std::string& name, |
| 251 const std::string& value, | 258 const std::string& value, |
| 252 const std::string& domain, | 259 const std::string& domain, |
| 253 const std::string& path, | 260 const std::string& path, |
| 254 const base::Time& creation, | 261 const base::Time& creation, |
| 255 const base::Time& expiration, | 262 const base::Time& expiration, |
| 256 bool secure, | 263 bool secure, |
| 257 bool http_only, | 264 bool http_only, |
| 265 bool first_party_only, |
| 258 CookiePriority priority) { | 266 CookiePriority priority) { |
| 259 // Expect valid attribute tokens and values, as defined by the ParsedCookie | 267 // Expect valid attribute tokens and values, as defined by the ParsedCookie |
| 260 // logic, otherwise don't create the cookie. | 268 // logic, otherwise don't create the cookie. |
| 261 std::string parsed_name = ParsedCookie::ParseTokenString(name); | 269 std::string parsed_name = ParsedCookie::ParseTokenString(name); |
| 262 if (parsed_name != name) | 270 if (parsed_name != name) |
| 263 return NULL; | 271 return NULL; |
| 264 std::string parsed_value = ParsedCookie::ParseValueString(value); | 272 std::string parsed_value = ParsedCookie::ParseValueString(value); |
| 265 if (parsed_value != value) | 273 if (parsed_value != value) |
| 266 return NULL; | 274 return NULL; |
| 267 | 275 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 286 url::Component path_component(0, cookie_path.length()); | 294 url::Component path_component(0, cookie_path.length()); |
| 287 url::RawCanonOutputT<char> canon_path; | 295 url::RawCanonOutputT<char> canon_path; |
| 288 url::Component canon_path_component; | 296 url::Component canon_path_component; |
| 289 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, | 297 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, |
| 290 &canon_path_component); | 298 &canon_path_component); |
| 291 cookie_path = std::string(canon_path.data() + canon_path_component.begin, | 299 cookie_path = std::string(canon_path.data() + canon_path_component.begin, |
| 292 canon_path_component.len); | 300 canon_path_component.len); |
| 293 | 301 |
| 294 return new CanonicalCookie(url, parsed_name, parsed_value, cookie_domain, | 302 return new CanonicalCookie(url, parsed_name, parsed_value, cookie_domain, |
| 295 cookie_path, creation, expiration, creation, | 303 cookie_path, creation, expiration, creation, |
| 296 secure, http_only, priority); | 304 secure, http_only, first_party_only, priority); |
| 297 } | 305 } |
| 298 | 306 |
| 299 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { | 307 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { |
| 300 | 308 |
| 301 // A zero length would be unsafe for our trailing '/' checks, and | 309 // A zero length would be unsafe for our trailing '/' checks, and |
| 302 // would also make no sense for our prefix match. The code that | 310 // would also make no sense for our prefix match. The code that |
| 303 // creates a CanonicalCookie should make sure the path is never zero length, | 311 // creates a CanonicalCookie should make sure the path is never zero length, |
| 304 // but we double check anyway. | 312 // but we double check anyway. |
| 305 if (path_.empty()) | 313 if (path_.empty()) |
| 306 return false; | 314 return false; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 if (IsSecure() && !url.SchemeIsSecure()) | 383 if (IsSecure() && !url.SchemeIsSecure()) |
| 376 return false; | 384 return false; |
| 377 // Don't include cookies for requests that don't apply to the cookie domain. | 385 // Don't include cookies for requests that don't apply to the cookie domain. |
| 378 if (!IsDomainMatch(url.host())) | 386 if (!IsDomainMatch(url.host())) |
| 379 return false; | 387 return false; |
| 380 // Don't include cookies for requests with a url path that does not path | 388 // Don't include cookies for requests with a url path that does not path |
| 381 // match the cookie-path. | 389 // match the cookie-path. |
| 382 if (!IsOnPath(url.path())) | 390 if (!IsOnPath(url.path())) |
| 383 return false; | 391 return false; |
| 384 | 392 |
| 393 // Include first-party-only cookies iff |options| tells us to include all of |
| 394 // them, or if a first-party URL is set and its origin matches the origin of |
| 395 // |url|. |
| 396 if (IsFirstPartyOnly() && !options.include_first_party_only() && |
| 397 options.first_party_url().GetOrigin() != url.GetOrigin()) { |
| 398 return false; |
| 399 } |
| 400 |
| 385 return true; | 401 return true; |
| 386 } | 402 } |
| 387 | 403 |
| 388 std::string CanonicalCookie::DebugString() const { | 404 std::string CanonicalCookie::DebugString() const { |
| 389 return base::StringPrintf( | 405 return base::StringPrintf( |
| 390 "name: %s value: %s domain: %s path: %s creation: %" | 406 "name: %s value: %s domain: %s path: %s creation: %" |
| 391 PRId64, | 407 PRId64, |
| 392 name_.c_str(), value_.c_str(), | 408 name_.c_str(), value_.c_str(), |
| 393 domain_.c_str(), path_.c_str(), | 409 domain_.c_str(), path_.c_str(), |
| 394 static_cast<int64>(creation_date_.ToTimeT())); | 410 static_cast<int64>(creation_date_.ToTimeT())); |
| 395 } | 411 } |
| 396 | 412 |
| 397 CanonicalCookie* CanonicalCookie::Duplicate() const { | 413 CanonicalCookie* CanonicalCookie::Duplicate() const { |
| 398 CanonicalCookie* cc = new CanonicalCookie(); | 414 CanonicalCookie* cc = new CanonicalCookie(); |
| 399 cc->source_ = source_; | 415 cc->source_ = source_; |
| 400 cc->name_ = name_; | 416 cc->name_ = name_; |
| 401 cc->value_ = value_; | 417 cc->value_ = value_; |
| 402 cc->domain_ = domain_; | 418 cc->domain_ = domain_; |
| 403 cc->path_ = path_; | 419 cc->path_ = path_; |
| 404 cc->creation_date_ = creation_date_; | 420 cc->creation_date_ = creation_date_; |
| 405 cc->expiry_date_ = expiry_date_; | 421 cc->expiry_date_ = expiry_date_; |
| 406 cc->last_access_date_ = last_access_date_; | 422 cc->last_access_date_ = last_access_date_; |
| 407 cc->secure_ = secure_; | 423 cc->secure_ = secure_; |
| 408 cc->httponly_ = httponly_; | 424 cc->httponly_ = httponly_; |
| 425 cc->first_party_only_ = first_party_only_; |
| 409 cc->priority_ = priority_; | 426 cc->priority_ = priority_; |
| 410 return cc; | 427 return cc; |
| 411 } | 428 } |
| 412 | 429 |
| 413 } // namespace net | 430 } // namespace net |
| OLD | NEW |