OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/url_pattern.h" | 5 #include "chrome/common/extensions/url_pattern.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 300 |
301 bool URLPattern::SetPort(const std::string& port) { | 301 bool URLPattern::SetPort(const std::string& port) { |
302 spec_.clear(); | 302 spec_.clear(); |
303 if (IsValidPortForScheme(scheme_, port)) { | 303 if (IsValidPortForScheme(scheme_, port)) { |
304 port_ = port; | 304 port_ = port; |
305 return true; | 305 return true; |
306 } | 306 } |
307 return false; | 307 return false; |
308 } | 308 } |
309 | 309 |
310 bool URLPattern::MatchesURL(const GURL &test) const { | 310 bool URLPattern::MatchesURL(const GURL& test) const { |
311 if (!MatchesScheme(test.scheme())) | 311 if (!MatchesScheme(test.scheme())) |
312 return false; | 312 return false; |
313 | 313 |
314 if (match_all_urls_) | 314 if (match_all_urls_) |
315 return true; | 315 return true; |
316 | 316 |
317 // Ignore hostname if scheme is file://. | 317 // Ignore hostname if scheme is file://. |
318 if (scheme_ != chrome::kFileScheme && !MatchesHost(test)) | 318 if (scheme_ != chrome::kFileScheme && !MatchesHost(test)) |
319 return false; | 319 return false; |
320 | 320 |
321 if (!MatchesPath(test.PathForRequest())) | 321 if (!MatchesPath(test.PathForRequest())) |
322 return false; | 322 return false; |
323 | 323 |
324 if (!MatchesPort(test.EffectiveIntPort())) | 324 if (!MatchesPort(test.EffectiveIntPort())) |
325 return false; | 325 return false; |
326 | 326 |
327 return true; | 327 return true; |
328 } | 328 } |
329 | 329 |
330 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const { | |
331 // TODO(dcheng): Combine in a helper with the above? | |
Aaron Boodman
2011/10/20 06:53:51
Yes please. Looks like MatchesURL is just MatchesS
| |
332 if (!MatchesScheme(test.scheme())) | |
333 return false; | |
334 | |
335 if (match_all_urls_) | |
336 return true; | |
337 | |
338 // Ignore hostname if scheme is file://. | |
339 if (scheme_ != chrome::kFileScheme && !MatchesHost(test)) | |
340 return false; | |
341 | |
342 if (!MatchesPort(test.EffectiveIntPort())) | |
343 return false; | |
344 | |
345 return true; | |
346 } | |
347 | |
330 bool URLPattern::MatchesScheme(const std::string& test) const { | 348 bool URLPattern::MatchesScheme(const std::string& test) const { |
331 if (!IsValidScheme(test)) | 349 if (!IsValidScheme(test)) |
332 return false; | 350 return false; |
333 | 351 |
334 return scheme_ == "*" || test == scheme_; | 352 return scheme_ == "*" || test == scheme_; |
335 } | 353 } |
336 | 354 |
337 bool URLPattern::MatchesHost(const std::string& host) const { | 355 bool URLPattern::MatchesHost(const std::string& host) const { |
338 std::string test(chrome::kHttpScheme); | 356 std::string test(chrome::kHttpScheme); |
339 test += chrome::kStandardSchemeSeparator; | 357 test += chrome::kStandardSchemeSeparator; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 } | 511 } |
494 | 512 |
495 return result; | 513 return result; |
496 } | 514 } |
497 | 515 |
498 // static | 516 // static |
499 const char* URLPattern::GetParseResultString( | 517 const char* URLPattern::GetParseResultString( |
500 URLPattern::ParseResult parse_result) { | 518 URLPattern::ParseResult parse_result) { |
501 return kParseResultMessages[parse_result]; | 519 return kParseResultMessages[parse_result]; |
502 } | 520 } |
OLD | NEW |