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 chrome::kHttpScheme, | 23 content::kHttpScheme, |
24 content::kHttpsScheme, | 24 content::kHttpsScheme, |
25 chrome::kFileScheme, | 25 chrome::kFileScheme, |
26 chrome::kFtpScheme, | 26 chrome::kFtpScheme, |
27 chrome::kChromeUIScheme, | 27 chrome::kChromeUIScheme, |
28 extensions::kExtensionScheme, | 28 extensions::kExtensionScheme, |
29 chrome::kFileSystemScheme, | 29 chrome::kFileSystemScheme, |
30 }; | 30 }; |
31 | 31 |
32 const int kValidSchemeMasks[] = { | 32 const int kValidSchemeMasks[] = { |
33 URLPattern::SCHEME_HTTP, | 33 URLPattern::SCHEME_HTTP, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 353 } |
354 | 354 |
355 bool URLPattern::MatchesScheme(const std::string& test) const { | 355 bool URLPattern::MatchesScheme(const std::string& test) const { |
356 if (!IsValidScheme(test)) | 356 if (!IsValidScheme(test)) |
357 return false; | 357 return false; |
358 | 358 |
359 return scheme_ == "*" || test == scheme_; | 359 return scheme_ == "*" || test == scheme_; |
360 } | 360 } |
361 | 361 |
362 bool URLPattern::MatchesHost(const std::string& host) const { | 362 bool URLPattern::MatchesHost(const std::string& host) const { |
363 std::string test(chrome::kHttpScheme); | 363 std::string test(content::kHttpScheme); |
364 test += content::kStandardSchemeSeparator; | 364 test += content::kStandardSchemeSeparator; |
365 test += host; | 365 test += host; |
366 test += "/"; | 366 test += "/"; |
367 return MatchesHost(GURL(test)); | 367 return MatchesHost(GURL(test)); |
368 } | 368 } |
369 | 369 |
370 bool URLPattern::MatchesHost(const GURL& test) const { | 370 bool URLPattern::MatchesHost(const GURL& test) const { |
371 // If the hosts are exactly equal, we have a match. | 371 // If the hosts are exactly equal, we have a match. |
372 if (test.host() == host_) | 372 if (test.host() == host_) |
373 return true; | 373 return true; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 } | 531 } |
532 | 532 |
533 return result; | 533 return result; |
534 } | 534 } |
535 | 535 |
536 // static | 536 // static |
537 const char* URLPattern::GetParseResultString( | 537 const char* URLPattern::GetParseResultString( |
538 URLPattern::ParseResult parse_result) { | 538 URLPattern::ParseResult parse_result) { |
539 return kParseResultMessages[parse_result]; | 539 return kParseResultMessages[parse_result]; |
540 } | 540 } |
OLD | NEW |