| 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 "extensions/common/url_pattern.h" | 5 #include "extensions/common/url_pattern.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_piece.h" | 8 #include "base/strings/string_piece.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
| 12 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 #include "url/url_util.h" | 14 #include "url/url_util.h" |
| 15 | 15 |
| 16 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; | 16 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // TODO(aa): What about more obscure schemes like data: and javascript: ? | 20 // TODO(aa): What about more obscure schemes like data: and javascript: ? |
| 21 // Note: keep this array in sync with kValidSchemeMasks. | 21 // Note: keep this array in sync with kValidSchemeMasks. |
| 22 const char* kValidSchemes[] = { | 22 const char* kValidSchemes[] = { |
| 23 content::kHttpScheme, | 23 url::kHttpScheme, |
| 24 content::kHttpsScheme, | 24 url::kHttpsScheme, |
| 25 content::kFileScheme, | 25 content::kFileScheme, |
| 26 content::kFtpScheme, | 26 content::kFtpScheme, |
| 27 content::kChromeUIScheme, | 27 content::kChromeUIScheme, |
| 28 extensions::kExtensionScheme, | 28 extensions::kExtensionScheme, |
| 29 content::kFileSystemScheme, | 29 content::kFileSystemScheme, |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 const int kValidSchemeMasks[] = { | 32 const int kValidSchemeMasks[] = { |
| 33 URLPattern::SCHEME_HTTP, | 33 URLPattern::SCHEME_HTTP, |
| 34 URLPattern::SCHEME_HTTPS, | 34 URLPattern::SCHEME_HTTPS, |
| 35 URLPattern::SCHEME_FILE, | 35 URLPattern::SCHEME_FILE, |
| 36 URLPattern::SCHEME_FTP, | 36 URLPattern::SCHEME_FTP, |
| 37 URLPattern::SCHEME_CHROMEUI, | 37 URLPattern::SCHEME_CHROMEUI, |
| 38 URLPattern::SCHEME_EXTENSION, | 38 URLPattern::SCHEME_EXTENSION, |
| 39 URLPattern::SCHEME_FILESYSTEM, | 39 URLPattern::SCHEME_FILESYSTEM, |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 358 } |
| 359 | 359 |
| 360 bool URLPattern::MatchesScheme(const std::string& test) const { | 360 bool URLPattern::MatchesScheme(const std::string& test) const { |
| 361 if (!IsValidScheme(test)) | 361 if (!IsValidScheme(test)) |
| 362 return false; | 362 return false; |
| 363 | 363 |
| 364 return scheme_ == "*" || test == scheme_; | 364 return scheme_ == "*" || test == scheme_; |
| 365 } | 365 } |
| 366 | 366 |
| 367 bool URLPattern::MatchesHost(const std::string& host) const { | 367 bool URLPattern::MatchesHost(const std::string& host) const { |
| 368 std::string test(content::kHttpScheme); | 368 std::string test(url::kHttpScheme); |
| 369 test += content::kStandardSchemeSeparator; | 369 test += content::kStandardSchemeSeparator; |
| 370 test += host; | 370 test += host; |
| 371 test += "/"; | 371 test += "/"; |
| 372 return MatchesHost(GURL(test)); | 372 return MatchesHost(GURL(test)); |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool URLPattern::MatchesHost(const GURL& test) const { | 375 bool URLPattern::MatchesHost(const GURL& test) const { |
| 376 // If the hosts are exactly equal, we have a match. | 376 // If the hosts are exactly equal, we have a match. |
| 377 if (test.host() == host_) | 377 if (test.host() == host_) |
| 378 return true; | 378 return true; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 536 } |
| 537 | 537 |
| 538 return result; | 538 return result; |
| 539 } | 539 } |
| 540 | 540 |
| 541 // static | 541 // static |
| 542 const char* URLPattern::GetParseResultString( | 542 const char* URLPattern::GetParseResultString( |
| 543 URLPattern::ParseResult parse_result) { | 543 URLPattern::ParseResult parse_result) { |
| 544 return kParseResultMessages[parse_result]; | 544 return kParseResultMessages[parse_result]; |
| 545 } | 545 } |
| OLD | NEW |