OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "net/base/url_util.h" | 5 #include "net/base/url_util.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include <netinet/in.h> | 10 #include <netinet/in.h> |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return true; | 431 return true; |
432 } | 432 } |
433 | 433 |
434 if (is_local6) | 434 if (is_local6) |
435 *is_local6 = false; | 435 *is_local6 = false; |
436 return normalized_host == "localhost" || | 436 return normalized_host == "localhost" || |
437 normalized_host == "localhost.localdomain" || | 437 normalized_host == "localhost.localdomain" || |
438 IsNormalizedLocalhostTLD(normalized_host); | 438 IsNormalizedLocalhostTLD(normalized_host); |
439 } | 439 } |
440 | 440 |
| 441 bool IsDomainMatch(const std::string& domain, const std::string& host) { |
| 442 // Can domain match in two ways; as a domain cookie (where the cookie |
| 443 // domain begins with ".") or as a host cookie (where it doesn't). |
| 444 |
| 445 // Some consumers of the CookieMonster expect to set cookies on |
| 446 // URLs like http://.strange.url. To retrieve cookies in this instance, |
| 447 // we allow matching as a host cookie even when the domain_ starts with |
| 448 // a period. |
| 449 if (host == domain) |
| 450 return true; |
| 451 |
| 452 // Domain cookie must have an initial ".". To match, it must be |
| 453 // equal to url's host with initial period removed, or a suffix of |
| 454 // it. |
| 455 |
| 456 // Arguably this should only apply to "http" or "https" cookies, but |
| 457 // extension cookie tests currently use the funtionality, and if we |
| 458 // ever decide to implement that it should be done by preventing |
| 459 // such cookies from being set. |
| 460 if (domain.empty() || domain[0] != '.') |
| 461 return false; |
| 462 |
| 463 // The host with a "." prefixed. |
| 464 if (domain.compare(1, std::string::npos, host) == 0) |
| 465 return true; |
| 466 |
| 467 // A pure suffix of the host (ok since we know the domain already |
| 468 // starts with a ".") |
| 469 return (host.length() > domain.length() && |
| 470 host.compare(host.length() - domain.length(), domain.length(), |
| 471 domain) == 0); |
| 472 } |
| 473 |
441 } // namespace net | 474 } // namespace net |
OLD | NEW |