| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/sdch_dictionary.h" | 5 #include "net/base/sdch_dictionary.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" |
| 7 #include "base/time/clock.h" | 8 #include "base/time/clock.h" |
| 8 #include "base/time/default_clock.h" | 9 #include "base/time/default_clock.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 bool DomainMatch(const GURL& gurl, const std::string& restriction) { | 15 bool DomainMatch(const GURL& gurl, const std::string& restriction) { |
| 15 // TODO(jar): This is not precisely a domain match definition. | 16 // TODO(jar): This is not precisely a domain match definition. |
| 16 return gurl.DomainIs(restriction); | 17 return gurl.DomainIs(restriction); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 // TODO(jar): Remove overly restrictive failsafe test (added per security | 135 // TODO(jar): Remove overly restrictive failsafe test (added per security |
| 135 // review) when we have a need to be more general. | 136 // review) when we have a need to be more general. |
| 136 if (!target_url.SchemeIsHTTPOrHTTPS()) | 137 if (!target_url.SchemeIsHTTPOrHTTPS()) |
| 137 return SDCH_ATTEMPT_TO_DECODE_NON_HTTP_DATA; | 138 return SDCH_ATTEMPT_TO_DECODE_NON_HTTP_DATA; |
| 138 | 139 |
| 139 return SDCH_OK; | 140 return SDCH_OK; |
| 140 } | 141 } |
| 141 | 142 |
| 142 // static | 143 // static |
| 143 bool SdchDictionary::PathMatch(const std::string& path, | 144 bool SdchDictionary::PathMatch(const base::StringPiece& path, |
| 144 const std::string& restriction) { | 145 const base::StringPiece& restriction) { |
| 145 /* Must be either: | 146 /* Must be either: |
| 146 * 1. P2 is equal to P1 | 147 * 1. P2 is equal to P1 |
| 147 * 2. P2 is a prefix of P1 and either the final character in P2 is "/" | 148 * 2. P2 is a prefix of P1 and either the final character in P2 is "/" |
| 148 * or the character following P2 in P1 is "/". | 149 * or the character following P2 in P1 is "/". |
| 149 */ | 150 */ |
| 150 if (path == restriction) | 151 if (path == restriction) |
| 151 return true; | 152 return true; |
| 152 size_t prefix_length = restriction.size(); | 153 size_t prefix_length = restriction.size(); |
| 153 if (prefix_length > path.size()) | 154 if (prefix_length > path.size()) |
| 154 return false; // Can't be a prefix. | 155 return false; // Can't be a prefix. |
| 155 if (0 != path.compare(0, prefix_length, restriction)) | 156 if (!base::StartsWith(path, restriction, base::CompareCase::SENSITIVE)) |
| 156 return false; | 157 return false; |
| 157 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; | 158 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; |
| 158 } | 159 } |
| 159 | 160 |
| 160 bool SdchDictionary::Expired() const { | 161 bool SdchDictionary::Expired() const { |
| 161 return base::Time::Now() > expiration_; | 162 return base::Time::Now() > expiration_; |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace net | 165 } // namespace net |
| OLD | NEW |