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 #include "chrome/common/content_settings_pattern_parser.h" | 5 #include "chrome/common/content_settings_pattern_parser.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
9 #include "extensions/common/constants.h" | 9 #include "extensions/common/constants.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 if (!IsAsciiDigit(port[i])) { | 166 if (!IsAsciiDigit(port[i])) { |
167 builder->Invalid(); | 167 builder->Invalid(); |
168 return; | 168 return; |
169 } | 169 } |
170 } | 170 } |
171 // TODO(markusheintz): Check port range. | 171 // TODO(markusheintz): Check port range. |
172 builder->WithPort(port); | 172 builder->WithPort(port); |
173 } | 173 } |
174 } else { | 174 } else { |
175 if (scheme != std::string(extensions::kExtensionScheme) && | 175 if (scheme != std::string(extensions::kExtensionScheme) && |
176 scheme != std::string(content::kFileScheme)) | 176 scheme != std::string(url::kFileScheme)) |
177 builder->WithPortWildcard(); | 177 builder->WithPortWildcard(); |
178 } | 178 } |
179 | 179 |
180 if (path_component.IsNonEmpty()) { | 180 if (path_component.IsNonEmpty()) { |
181 const std::string path = pattern_spec.substr(path_component.start, | 181 const std::string path = pattern_spec.substr(path_component.start, |
182 path_component.len); | 182 path_component.len); |
183 if (path.substr(1) == kPathWildcard) | 183 if (path.substr(1) == kPathWildcard) |
184 builder->WithPathWildcard(); | 184 builder->WithPathWildcard(); |
185 else | 185 else |
186 builder->WithPath(path); | 186 builder->WithPath(path); |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 // static | 190 // static |
191 std::string PatternParser::ToString( | 191 std::string PatternParser::ToString( |
192 const ContentSettingsPattern::PatternParts& parts) { | 192 const ContentSettingsPattern::PatternParts& parts) { |
193 // Return the most compact form to support legacy code and legacy pattern | 193 // Return the most compact form to support legacy code and legacy pattern |
194 // strings. | 194 // strings. |
195 if (parts.is_scheme_wildcard && | 195 if (parts.is_scheme_wildcard && |
196 parts.has_domain_wildcard && | 196 parts.has_domain_wildcard && |
197 parts.host.empty() && | 197 parts.host.empty() && |
198 parts.is_port_wildcard) | 198 parts.is_port_wildcard) |
199 return "*"; | 199 return "*"; |
200 | 200 |
201 std::string str; | 201 std::string str; |
202 if (!parts.is_scheme_wildcard) | 202 if (!parts.is_scheme_wildcard) |
203 str += parts.scheme + content::kStandardSchemeSeparator; | 203 str += parts.scheme + content::kStandardSchemeSeparator; |
204 | 204 |
205 if (parts.scheme == content::kFileScheme) { | 205 if (parts.scheme == url::kFileScheme) { |
206 if (parts.is_path_wildcard) | 206 if (parts.is_path_wildcard) |
207 return str + kUrlPathSeparator + kPathWildcard; | 207 return str + kUrlPathSeparator + kPathWildcard; |
208 else | 208 else |
209 return str + parts.path; | 209 return str + parts.path; |
210 } | 210 } |
211 | 211 |
212 if (parts.has_domain_wildcard) { | 212 if (parts.has_domain_wildcard) { |
213 if (parts.host.empty()) | 213 if (parts.host.empty()) |
214 str += kHostWildcard; | 214 str += kHostWildcard; |
215 else | 215 else |
216 str += kDomainWildcard; | 216 str += kDomainWildcard; |
217 } | 217 } |
218 str += parts.host; | 218 str += parts.host; |
219 | 219 |
220 if (parts.scheme == std::string(extensions::kExtensionScheme)) { | 220 if (parts.scheme == std::string(extensions::kExtensionScheme)) { |
221 str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path; | 221 str += parts.path.empty() ? std::string(kUrlPathSeparator) : parts.path; |
222 return str; | 222 return str; |
223 } | 223 } |
224 | 224 |
225 if (!parts.is_port_wildcard) { | 225 if (!parts.is_port_wildcard) { |
226 str += std::string(kUrlPortSeparator) + parts.port; | 226 str += std::string(kUrlPortSeparator) + parts.port; |
227 } | 227 } |
228 | 228 |
229 return str; | 229 return str; |
230 } | 230 } |
231 | 231 |
232 } // namespace content_settings | 232 } // namespace content_settings |
OLD | NEW |