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 content::kHttpScheme, |
24 content::kHttpsScheme, | 24 content::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 content::kAboutScheme, | |
30 }; | 31 }; |
31 | 32 |
32 const int kValidSchemeMasks[] = { | 33 const int kValidSchemeMasks[] = { |
33 URLPattern::SCHEME_HTTP, | 34 URLPattern::SCHEME_HTTP, |
34 URLPattern::SCHEME_HTTPS, | 35 URLPattern::SCHEME_HTTPS, |
35 URLPattern::SCHEME_FILE, | 36 URLPattern::SCHEME_FILE, |
36 URLPattern::SCHEME_FTP, | 37 URLPattern::SCHEME_FTP, |
37 URLPattern::SCHEME_CHROMEUI, | 38 URLPattern::SCHEME_CHROMEUI, |
38 URLPattern::SCHEME_EXTENSION, | 39 URLPattern::SCHEME_EXTENSION, |
39 URLPattern::SCHEME_FILESYSTEM, | 40 URLPattern::SCHEME_FILESYSTEM, |
41 URLPattern::SCHEME_ABOUT, | |
40 }; | 42 }; |
41 | 43 |
42 COMPILE_ASSERT(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks), | 44 COMPILE_ASSERT(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks), |
43 must_keep_these_arrays_in_sync); | 45 must_keep_these_arrays_in_sync); |
44 | 46 |
45 const char kParseSuccess[] = "Success."; | 47 const char kParseSuccess[] = "Success."; |
46 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; | 48 const char kParseErrorMissingSchemeSeparator[] = "Missing scheme separator."; |
47 const char kParseErrorInvalidScheme[] = "Invalid scheme."; | 49 const char kParseErrorInvalidScheme[] = "Invalid scheme."; |
48 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; | 50 const char kParseErrorWrongSchemeType[] = "Wrong scheme type."; |
49 const char kParseErrorEmptyHost[] = "Host can not be empty."; | 51 const char kParseErrorEmptyHost[] = "Host can not be empty."; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 | 404 |
403 return test.host()[test.host().length() - host_.length() - 1] == '.'; | 405 return test.host()[test.host().length() - host_.length() - 1] == '.'; |
404 } | 406 } |
405 | 407 |
406 bool URLPattern::MatchesPath(const std::string& test) const { | 408 bool URLPattern::MatchesPath(const std::string& test) const { |
407 // Make the behaviour of OverlapsWith consistent with MatchesURL, which is | 409 // Make the behaviour of OverlapsWith consistent with MatchesURL, which is |
408 // need to match hosted apps on e.g. 'google.com' also run on 'google.com/'. | 410 // need to match hosted apps on e.g. 'google.com' also run on 'google.com/'. |
409 if (test + "/*" == path_escaped_) | 411 if (test + "/*" == path_escaped_) |
410 return true; | 412 return true; |
411 | 413 |
414 // If the path is a wildcard, allow any path. | |
415 if (path_escaped_ == "*" || path_escaped_ == "/*") | |
not at google - send to devlin
2014/04/18 16:04:55
this will change host permissions beyond just abou
| |
416 return true; | |
417 | |
412 return MatchPattern(test, path_escaped_); | 418 return MatchPattern(test, path_escaped_); |
413 } | 419 } |
414 | 420 |
415 const std::string& URLPattern::GetAsString() const { | 421 const std::string& URLPattern::GetAsString() const { |
416 if (!spec_.empty()) | 422 if (!spec_.empty()) |
417 return spec_; | 423 return spec_; |
418 | 424 |
419 if (match_all_urls_) { | 425 if (match_all_urls_) { |
420 spec_ = kAllUrlsPattern; | 426 spec_ = kAllUrlsPattern; |
421 return spec_; | 427 return spec_; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 } | 542 } |
537 | 543 |
538 return result; | 544 return result; |
539 } | 545 } |
540 | 546 |
541 // static | 547 // static |
542 const char* URLPattern::GetParseResultString( | 548 const char* URLPattern::GetParseResultString( |
543 URLPattern::ParseResult parse_result) { | 549 URLPattern::ParseResult parse_result) { |
544 return kParseResultMessages[parse_result]; | 550 return kParseResultMessages[parse_result]; |
545 } | 551 } |
OLD | NEW |