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 #include "net/base/url_util.h" |
12 namespace { | |
13 | |
14 bool DomainMatch(const GURL& gurl, const std::string& restriction) { | |
15 // TODO(jar): This is not precisely a domain match definition. | |
16 return gurl.DomainIs(restriction); | |
17 } | |
18 | |
19 } // namespace | |
20 | 13 |
21 namespace net { | 14 namespace net { |
22 | 15 |
23 SdchDictionary::SdchDictionary(const std::string& dictionary_text, | 16 SdchDictionary::SdchDictionary(const std::string& dictionary_text, |
24 size_t offset, | 17 size_t offset, |
25 const std::string& client_hash, | 18 const std::string& client_hash, |
26 const std::string& server_hash, | 19 const std::string& server_hash, |
27 const GURL& gurl, | 20 const GURL& gurl, |
28 const std::string& domain, | 21 const std::string& domain, |
29 const std::string& path, | 22 const std::string& path, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 73 |
81 if (domain.empty()) | 74 if (domain.empty()) |
82 return SDCH_DICTIONARY_MISSING_DOMAIN_SPECIFIER; // Domain is required. | 75 return SDCH_DICTIONARY_MISSING_DOMAIN_SPECIFIER; // Domain is required. |
83 | 76 |
84 if (registry_controlled_domains::GetDomainAndRegistry( | 77 if (registry_controlled_domains::GetDomainAndRegistry( |
85 domain, registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES) | 78 domain, registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES) |
86 .empty()) { | 79 .empty()) { |
87 return SDCH_DICTIONARY_SPECIFIES_TOP_LEVEL_DOMAIN; // domain was a TLD. | 80 return SDCH_DICTIONARY_SPECIFIES_TOP_LEVEL_DOMAIN; // domain was a TLD. |
88 } | 81 } |
89 | 82 |
90 if (!DomainMatch(dictionary_url, domain)) | 83 if (!IsDomainMatch(domain, dictionary_url.host())) |
91 return SDCH_DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL; | 84 return SDCH_DICTIONARY_DOMAIN_NOT_MATCHING_SOURCE_URL; |
92 | 85 |
93 std::string referrer_url_host = dictionary_url.host(); | 86 std::string referrer_url_host = dictionary_url.host(); |
94 size_t postfix_domain_index = referrer_url_host.rfind(domain); | 87 size_t postfix_domain_index = referrer_url_host.rfind(domain); |
95 // See if it is indeed a postfix, or just an internal string. | 88 // See if it is indeed a postfix, or just an internal string. |
96 if (referrer_url_host.size() == postfix_domain_index + domain.size()) { | 89 if (referrer_url_host.size() == postfix_domain_index + domain.size()) { |
97 // It is a postfix... so check to see if there's a dot in the prefix. | 90 // It is a postfix... so check to see if there's a dot in the prefix. |
98 size_t end_of_host_index = referrer_url_host.find_first_of('.'); | 91 size_t end_of_host_index = referrer_url_host.find_first_of('.'); |
99 if (referrer_url_host.npos != end_of_host_index && | 92 if (referrer_url_host.npos != end_of_host_index && |
100 end_of_host_index < postfix_domain_index) { | 93 end_of_host_index < postfix_domain_index) { |
(...skipping 11 matching lines...) Expand all Loading... |
112 /* | 105 /* |
113 * 1. The request URL's host name domain-matches the Domain attribute of the | 106 * 1. The request URL's host name domain-matches the Domain attribute of the |
114 * dictionary. | 107 * dictionary. |
115 * 2. If the dictionary has a Port attribute, the request port is one of the | 108 * 2. If the dictionary has a Port attribute, the request port is one of the |
116 * ports listed in the Port attribute. | 109 * ports listed in the Port attribute. |
117 * 3. The request URL path-matches the path attribute of the dictionary. | 110 * 3. The request URL path-matches the path attribute of the dictionary. |
118 * We can override (ignore) item (4) only when we have explicitly enabled | 111 * We can override (ignore) item (4) only when we have explicitly enabled |
119 * HTTPS support AND the dictionary acquisition scheme matches the target | 112 * HTTPS support AND the dictionary acquisition scheme matches the target |
120 * url scheme. | 113 * url scheme. |
121 */ | 114 */ |
122 if (!DomainMatch(target_url, domain_)) | 115 if (!IsDomainMatch(domain_, target_url.host())) |
123 return SDCH_DICTIONARY_FOUND_HAS_WRONG_DOMAIN; | 116 return SDCH_DICTIONARY_FOUND_HAS_WRONG_DOMAIN; |
124 | 117 |
125 if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort())) | 118 if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort())) |
126 return SDCH_DICTIONARY_FOUND_HAS_WRONG_PORT_LIST; | 119 return SDCH_DICTIONARY_FOUND_HAS_WRONG_PORT_LIST; |
127 | 120 |
128 if (path_.size() && !PathMatch(target_url.path(), path_)) | 121 if (path_.size() && !PathMatch(target_url.path(), path_)) |
129 return SDCH_DICTIONARY_FOUND_HAS_WRONG_PATH; | 122 return SDCH_DICTIONARY_FOUND_HAS_WRONG_PATH; |
130 | 123 |
131 if (target_url.SchemeIsCryptographic() != url_.SchemeIsCryptographic()) | 124 if (target_url.SchemeIsCryptographic() != url_.SchemeIsCryptographic()) |
132 return SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME; | 125 return SDCH_DICTIONARY_FOUND_HAS_WRONG_SCHEME; |
(...skipping 22 matching lines...) Expand all Loading... |
155 if (0 != path.compare(0, prefix_length, restriction)) | 148 if (0 != path.compare(0, prefix_length, restriction)) |
156 return false; | 149 return false; |
157 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; | 150 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; |
158 } | 151 } |
159 | 152 |
160 bool SdchDictionary::Expired() const { | 153 bool SdchDictionary::Expired() const { |
161 return base::Time::Now() > expiration_; | 154 return base::Time::Now() > expiration_; |
162 } | 155 } |
163 | 156 |
164 } // namespace net | 157 } // namespace net |
OLD | NEW |