OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } | 252 } |
253 | 253 |
254 // Determine the cookie domain key to use for setting the specified cookie. | 254 // Determine the cookie domain key to use for setting the specified cookie. |
255 // On success returns true, and sets cookie_domain_key to either a | 255 // On success returns true, and sets cookie_domain_key to either a |
256 // -host cookie key (ex: "google.com") | 256 // -host cookie key (ex: "google.com") |
257 // -domain cookie key (ex: ".google.com") | 257 // -domain cookie key (ex: ".google.com") |
258 static bool GetCookieDomainKey(const GURL& url, | 258 static bool GetCookieDomainKey(const GURL& url, |
259 const CookieMonster::ParsedCookie& pc, | 259 const CookieMonster::ParsedCookie& pc, |
260 std::string* cookie_domain_key) { | 260 std::string* cookie_domain_key) { |
261 const std::string url_host(url.host()); | 261 const std::string url_host(url.host()); |
262 if (!pc.HasDomain() || pc.Domain().empty()) { | 262 |
263 // No domain was specified in cookie -- default to host cookie. | 263 // If no domain was specified in the cookie, default to a host cookie. |
| 264 // We match IE/Firefox in allowing a domain=IPADDR if it matches the url |
| 265 // ip address hostname exactly. It should be treated as a host cookie. |
| 266 if (!pc.HasDomain() || pc.Domain().empty() || |
| 267 (url.HostIsIPAddress() && url_host == pc.Domain())) { |
264 *cookie_domain_key = url_host; | 268 *cookie_domain_key = url_host; |
265 DCHECK((*cookie_domain_key)[0] != '.'); | 269 DCHECK((*cookie_domain_key)[0] != '.'); |
266 return true; | 270 return true; |
267 } | 271 } |
268 | 272 |
269 // Get the normalized domain specified in cookie line. | 273 // Get the normalized domain specified in cookie line. |
270 // Note: The RFC says we can reject a cookie if the domain | 274 // Note: The RFC says we can reject a cookie if the domain |
271 // attribute does not start with a dot. IE/FF/Safari however, allow a cookie | 275 // attribute does not start with a dot. IE/FF/Safari however, allow a cookie |
272 // of the form domain=my.domain.com, treating it the same as | 276 // of the form domain=my.domain.com, treating it the same as |
273 // domain=.my.domain.com -- for compatibility we do the same here. Firefox | 277 // domain=.my.domain.com -- for compatibility we do the same here. Firefox |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 } | 1113 } |
1110 | 1114 |
1111 std::string CookieMonster::CanonicalCookie::DebugString() const { | 1115 std::string CookieMonster::CanonicalCookie::DebugString() const { |
1112 return StringPrintf("name: %s value: %s path: %s creation: %llu", | 1116 return StringPrintf("name: %s value: %s path: %s creation: %llu", |
1113 name_.c_str(), value_.c_str(), path_.c_str(), | 1117 name_.c_str(), value_.c_str(), path_.c_str(), |
1114 creation_date_.ToTimeT()); | 1118 creation_date_.ToTimeT()); |
1115 } | 1119 } |
1116 | 1120 |
1117 } // namespace | 1121 } // namespace |
1118 | 1122 |
OLD | NEW |