| 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 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 bool CookieMonster::CanonicalCookie::IsOnPath( | 2660 bool CookieMonster::CanonicalCookie::IsOnPath( |
| 2661 const std::string& url_path) const { | 2661 const std::string& url_path) const { |
| 2662 | 2662 |
| 2663 // A zero length would be unsafe for our trailing '/' checks, and | 2663 // A zero length would be unsafe for our trailing '/' checks, and |
| 2664 // would also make no sense for our prefix match. The code that | 2664 // would also make no sense for our prefix match. The code that |
| 2665 // creates a CanonicalCookie should make sure the path is never zero length, | 2665 // creates a CanonicalCookie should make sure the path is never zero length, |
| 2666 // but we double check anyway. | 2666 // but we double check anyway. |
| 2667 if (path_.empty()) | 2667 if (path_.empty()) |
| 2668 return false; | 2668 return false; |
| 2669 | 2669 |
| 2670 // The Mozilla code broke it into 3 cases, if it's strings lengths | 2670 // The Mozilla code broke this into three cases, based on if the cookie path |
| 2671 // are less than, equal, or greater. I think this is simpler: | 2671 // was longer, the same length, or shorter than the length of the url path. |
| 2672 // I think the approach below is simpler. |
| 2672 | 2673 |
| 2673 // Make sure the cookie path is a prefix of the url path. If the | 2674 // Make sure the cookie path is a prefix of the url path. If the |
| 2674 // url path is shorter than the cookie path, then the cookie path | 2675 // url path is shorter than the cookie path, then the cookie path |
| 2675 // can't be a prefix. | 2676 // can't be a prefix. |
| 2676 if (url_path.find(path_) != 0) | 2677 if (url_path.find(path_) != 0) |
| 2677 return false; | 2678 return false; |
| 2678 | 2679 |
| 2679 // Now we know that url_path is >= cookie_path, and that cookie_path | 2680 // Now we know that url_path is >= cookie_path, and that cookie_path |
| 2680 // is a prefix of url_path. If they are the are the same length then | 2681 // is a prefix of url_path. If they are the are the same length then |
| 2681 // they are identical, otherwise we need an additional check: | 2682 // they are identical, otherwise we need an additional check: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2731 std::string CookieMonster::CanonicalCookie::DebugString() const { | 2732 std::string CookieMonster::CanonicalCookie::DebugString() const { |
| 2732 return base::StringPrintf( | 2733 return base::StringPrintf( |
| 2733 "name: %s value: %s domain: %s path: %s creation: %" | 2734 "name: %s value: %s domain: %s path: %s creation: %" |
| 2734 PRId64, | 2735 PRId64, |
| 2735 name_.c_str(), value_.c_str(), | 2736 name_.c_str(), value_.c_str(), |
| 2736 domain_.c_str(), path_.c_str(), | 2737 domain_.c_str(), path_.c_str(), |
| 2737 static_cast<int64>(creation_date_.ToTimeT())); | 2738 static_cast<int64>(creation_date_.ToTimeT())); |
| 2738 } | 2739 } |
| 2739 | 2740 |
| 2740 } // namespace | 2741 } // namespace |
| OLD | NEW |