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())) |
Aaron Boodman
2011/10/31 23:57:11
Can't testing the scheme and match_all_urls_ also
dcheng
2011/11/01 18:18:02
It won't have quite the same meaning if I move it
Aaron Boodman
2011/11/01 19:20:57
Sorry, I still don't see it. Coffee has not kicked
| |
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 return MatchesSecurityOriginHelper(test) && |
318 if (scheme_ != chrome::kFileScheme && !MatchesHost(test)) | 318 MatchesPath(test.PathForRequest()); |
319 } | |
320 | |
321 bool URLPattern::MatchesSecurityOrigin(const GURL& test) const { | |
322 if (!MatchesScheme(test.scheme())) | |
319 return false; | 323 return false; |
320 | 324 |
321 if (!MatchesPath(test.PathForRequest())) | 325 if (match_all_urls_) |
322 return false; | 326 return true; |
323 | 327 |
324 if (!MatchesPort(test.EffectiveIntPort())) | 328 return MatchesSecurityOriginHelper(test); |
325 return false; | |
326 | |
327 return true; | |
328 } | 329 } |
329 | 330 |
330 bool URLPattern::MatchesScheme(const std::string& test) const { | 331 bool URLPattern::MatchesScheme(const std::string& test) const { |
331 if (!IsValidScheme(test)) | 332 if (!IsValidScheme(test)) |
332 return false; | 333 return false; |
333 | 334 |
334 return scheme_ == "*" || test == scheme_; | 335 return scheme_ == "*" || test == scheme_; |
335 } | 336 } |
336 | 337 |
337 bool URLPattern::MatchesHost(const std::string& host) const { | 338 bool URLPattern::MatchesHost(const std::string& host) const { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 const std::vector<std::string>& schemes) const { | 457 const std::vector<std::string>& schemes) const { |
457 for (std::vector<std::string>::const_iterator i = schemes.begin(); | 458 for (std::vector<std::string>::const_iterator i = schemes.begin(); |
458 i != schemes.end(); ++i) { | 459 i != schemes.end(); ++i) { |
459 if (MatchesScheme(*i)) | 460 if (MatchesScheme(*i)) |
460 return true; | 461 return true; |
461 } | 462 } |
462 | 463 |
463 return false; | 464 return false; |
464 } | 465 } |
465 | 466 |
467 bool URLPattern::MatchesSecurityOriginHelper(const GURL& test) const { | |
468 // Ignore hostname if scheme is file://. | |
469 if (scheme_ != chrome::kFileScheme && !MatchesHost(test)) | |
470 return false; | |
471 | |
472 if (!MatchesPort(test.EffectiveIntPort())) | |
473 return false; | |
474 | |
475 return true; | |
476 } | |
477 | |
466 std::vector<std::string> URLPattern::GetExplicitSchemes() const { | 478 std::vector<std::string> URLPattern::GetExplicitSchemes() const { |
467 std::vector<std::string> result; | 479 std::vector<std::string> result; |
468 | 480 |
469 if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) { | 481 if (scheme_ != "*" && !match_all_urls_ && IsValidScheme(scheme_)) { |
470 result.push_back(scheme_); | 482 result.push_back(scheme_); |
471 return result; | 483 return result; |
472 } | 484 } |
473 | 485 |
474 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { | 486 for (size_t i = 0; i < arraysize(kValidSchemes); ++i) { |
475 if (MatchesScheme(kValidSchemes[i])) { | 487 if (MatchesScheme(kValidSchemes[i])) { |
(...skipping 17 matching lines...) Expand all Loading... | |
493 } | 505 } |
494 | 506 |
495 return result; | 507 return result; |
496 } | 508 } |
497 | 509 |
498 // static | 510 // static |
499 const char* URLPattern::GetParseResultString( | 511 const char* URLPattern::GetParseResultString( |
500 URLPattern::ParseResult parse_result) { | 512 URLPattern::ParseResult parse_result) { |
501 return kParseResultMessages[parse_result]; | 513 return kParseResultMessages[parse_result]; |
502 } | 514 } |
OLD | NEW |