diff options
-rw-r--r-- | chrome/browser/extensions/crx_installer.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_webrequest_api.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/webstore_inline_installer.cc | 2 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 9 | ||||
-rw-r--r-- | chrome/common/extensions/url_pattern.cc | 4 | ||||
-rw-r--r-- | chrome/common/extensions/url_pattern.h | 36 | ||||
-rw-r--r-- | chrome/common/extensions/url_pattern_unittest.cc | 34 | ||||
-rw-r--r-- | chrome/common/extensions/user_script_unittest.cc | 16 |
8 files changed, 35 insertions, 70 deletions
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index 9083b65..48f1155 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -292,7 +292,7 @@ bool CrxInstaller::AllowInstall(const Extension* extension, // For self-hosted apps, verify that the entire extent is on the same // host (or a subdomain of the host) the download happened from. There's // no way for us to verify that the app controls any other hosts. - URLPattern pattern(URLPattern::ERROR_ON_PORTS, + URLPattern pattern(URLPattern::USE_PORTS, UserScript::kValidUserScriptSchemes); pattern.SetHost(download_url_.host()); pattern.SetMatchSubdomains(true); diff --git a/chrome/browser/extensions/extension_webrequest_api.cc b/chrome/browser/extensions/extension_webrequest_api.cc index 154b8b0..19e5460 100644 --- a/chrome/browser/extensions/extension_webrequest_api.cc +++ b/chrome/browser/extensions/extension_webrequest_api.cc @@ -424,7 +424,7 @@ bool ExtensionWebRequestEventRouter::RequestFilter::InitFromValue( for (size_t i = 0; i < urls_value->GetSize(); ++i) { std::string url; URLPattern pattern( - URLPattern::ERROR_ON_PORTS, + URLPattern::USE_PORTS, URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS | URLPattern::SCHEME_FTP | URLPattern::SCHEME_FILE | URLPattern::SCHEME_EXTENSION); diff --git a/chrome/browser/extensions/webstore_inline_installer.cc b/chrome/browser/extensions/webstore_inline_installer.cc index 087f435..c41caf5 100644 --- a/chrome/browser/extensions/webstore_inline_installer.cc +++ b/chrome/browser/extensions/webstore_inline_installer.cc @@ -298,7 +298,7 @@ void WebstoreInlineInstaller::OnWebstoreResponseParseSuccess( return; } - URLPattern verified_site_pattern(URLPattern::ERROR_ON_PORTS, + URLPattern verified_site_pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_ALL); verified_site_pattern.SetScheme("*"); verified_site_pattern.SetHost(verified_site_domain); diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 0b465c2..38b7ec5 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -283,7 +283,7 @@ void Extension::OverrideLaunchUrl(const GURL& override_url) { launch_web_url_ = new_url.spec(); - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kValidWebExtentSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); pattern.Parse(new_url.spec()); pattern.SetPath(pattern.path() + '*'); extent_.AddPattern(pattern); @@ -797,8 +797,7 @@ FileBrowserHandler* Extension::LoadFileBrowserHandler( return NULL; } StringToLowerASCII(&filter); - URLPattern pattern(URLPattern::ERROR_ON_PORTS, - URLPattern::SCHEME_FILESYSTEM); + URLPattern pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_FILESYSTEM); if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { *error = ExtensionErrorUtils::FormatErrorMessage( errors::kInvalidURLPatternError, filter); @@ -993,7 +992,7 @@ bool Extension::LoadLaunchURL(const extensions::Manifest* manifest, // Ensure the launch URL is a valid absolute URL and web extent scheme. GURL url(launch_url); - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kValidWebExtentSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { *error = errors::kInvalidLaunchWebURL; return false; @@ -1008,7 +1007,7 @@ bool Extension::LoadLaunchURL(const extensions::Manifest* manifest, // If there is no extent, we default the extent based on the launch URL. if (web_extent().is_empty() && !launch_web_url().empty()) { GURL launch_url(launch_web_url()); - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kValidWebExtentSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); if (!pattern.SetScheme("*")) { *error = errors::kInvalidLaunchWebURL; return false; diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc index 907678c..ba8843a 100644 --- a/chrome/common/extensions/url_pattern.cc +++ b/chrome/common/extensions/url_pattern.cc @@ -99,7 +99,7 @@ bool IsValidPortForScheme(const std::string scheme, const std::string& port) { } // namespace URLPattern::URLPattern() - : parse_option_(ERROR_ON_PORTS), + : parse_option_(USE_PORTS), valid_schemes_(SCHEME_NONE), match_all_urls_(false), match_subdomains_(false), @@ -115,7 +115,7 @@ URLPattern::URLPattern(URLPattern::ParseOption parse_option, int valid_schemes) URLPattern::URLPattern(int valid_schemes, const std::string& pattern) // Strict error checking is used, because this constructor is only // appropriate when we know |pattern| is valid. - : parse_option_(ERROR_ON_PORTS), + : parse_option_(USE_PORTS), valid_schemes_(valid_schemes), match_all_urls_(false), match_subdomains_(false), diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h index 094c472c..aeb6823 100644 --- a/chrome/common/extensions/url_pattern.h +++ b/chrome/common/extensions/url_pattern.h @@ -47,40 +47,6 @@ class GURL; // - http:/bar -- scheme separator not found // - foo://* -- invalid scheme // - chrome:// -- we don't support chrome internal URLs -// -// Design rationale: -// * We need to be able to tell users what 'sites' a given URLPattern will -// affect. For example "This extension will interact with the site -// 'www.google.com'. -// * We'd like to be able to convert as many existing Greasemonkey @include -// patterns to URLPatterns as possible. Greasemonkey @include patterns are -// simple globs, so this won't be perfect. -// * Although we would like to support any scheme, it isn't clear what to tell -// users about URLPatterns that affect data or javascript URLs, so those are -// left out for now. -// -// From a 2008-ish crawl of userscripts.org, the following patterns were found -// in @include lines: -// - total lines : 24471 -// - @include * : 919 -// - @include http://[^\*]+?/ : 11128 (no star in host) -// - @include http://\*\.[^\*]+?/ : 2325 (host prefixed by *.) -// - @include http://\*[^\.][^\*]+?/: 1524 (host prefixed by *, no dot -- many -// appear to only need subdomain -// matching, not real prefix matching) -// - @include http://[^\*/]+\*/ : 320 (host suffixed by *) -// - @include contains .tld : 297 (host suffixed by .tld -- a special -// Greasemonkey domain component that -// tries to match all valid registry- -// controlled suffixes) -// - @include http://\*/ : 228 (host is * exactly, but there is -// more to the pattern) -// -// So, we can support at least half of current @include lines without supporting -// subdomain matching. We can pick up at least another 10% by supporting -// subdomain matching. It is probably possible to coerce more of the existing -// patterns to URLPattern, but the resulting pattern will be more restrictive -// than the original glob, which is probably better than nothing. class URLPattern { public: // A collection of scheme bitmasks for use with valid_schemes. @@ -127,7 +93,7 @@ class URLPattern { // The <all_urls> string pattern. static const char kAllUrlsPattern[]; - explicit URLPattern(ParseOption parse_option, int valid_schemes); + URLPattern(ParseOption parse_option, int valid_schemes); // Convenience to construct a URLPattern from a string. The string is expected // to be a valid pattern when parsed with USE_PORTS. If the string is not diff --git a/chrome/common/extensions/url_pattern_unittest.cc b/chrome/common/extensions/url_pattern_unittest.cc index 1695582..1302755 100644 --- a/chrome/common/extensions/url_pattern_unittest.cc +++ b/chrome/common/extensions/url_pattern_unittest.cc @@ -135,7 +135,7 @@ TEST(ExtensionURLPatternTest, Ports) { // all pages for a given scheme TEST(ExtensionURLPatternTest, Match1) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*/*")); EXPECT_EQ("http", pattern.scheme()); EXPECT_EQ("", pattern.host()); @@ -151,7 +151,7 @@ TEST(ExtensionURLPatternTest, Match1) { // all domains TEST(ExtensionURLPatternTest, Match2) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("https://*/foo*")); EXPECT_EQ("https", pattern.scheme()); EXPECT_EQ("", pattern.host()); @@ -166,7 +166,7 @@ TEST(ExtensionURLPatternTest, Match2) { // subdomains TEST(URLPatternTest, Match3) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.google.com/foo*bar")); EXPECT_EQ("http", pattern.scheme()); @@ -183,7 +183,7 @@ TEST(URLPatternTest, Match3) { // glob escaping TEST(ExtensionURLPatternTest, Match5) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("file:///foo?bar\\*baz")); EXPECT_EQ("file", pattern.scheme()); EXPECT_EQ("", pattern.host()); @@ -196,7 +196,7 @@ TEST(ExtensionURLPatternTest, Match5) { // ip addresses TEST(ExtensionURLPatternTest, Match6) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://127.0.0.1/*")); EXPECT_EQ("http", pattern.scheme()); EXPECT_EQ("127.0.0.1", pattern.host()); @@ -208,7 +208,7 @@ TEST(ExtensionURLPatternTest, Match6) { // subdomain matching with ip addresses TEST(ExtensionURLPatternTest, Match7) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); // allowed, but useless EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.0.0.1/*")); EXPECT_EQ("http", pattern.scheme()); @@ -222,7 +222,7 @@ TEST(ExtensionURLPatternTest, Match7) { // unicode TEST(ExtensionURLPatternTest, Match8) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); // The below is the ASCII encoding of the following URL: // http://*.\xe1\x80\xbf/a\xc2\x81\xe1* EXPECT_EQ(URLPattern::PARSE_SUCCESS, @@ -240,7 +240,7 @@ TEST(ExtensionURLPatternTest, Match8) { // chrome:// TEST(ExtensionURLPatternTest, Match9) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("chrome://favicon/*")); EXPECT_EQ("chrome", pattern.scheme()); EXPECT_EQ("favicon", pattern.host()); @@ -254,7 +254,7 @@ TEST(ExtensionURLPatternTest, Match9) { // *:// TEST(ExtensionURLPatternTest, Match10) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("*://*/*")); EXPECT_TRUE(pattern.MatchesScheme("http")); EXPECT_TRUE(pattern.MatchesScheme("https")); @@ -272,7 +272,7 @@ TEST(ExtensionURLPatternTest, Match10) { // <all_urls> TEST(ExtensionURLPatternTest, Match11) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); EXPECT_TRUE(pattern.MatchesScheme("chrome")); EXPECT_TRUE(pattern.MatchesScheme("http")); @@ -289,7 +289,7 @@ TEST(ExtensionURLPatternTest, Match11) { // Make sure the properties are the same when creating an <all_urls> pattern // via SetMatchAllURLs and by parsing <all_urls>. - URLPattern pattern2(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern2(URLPattern::USE_PORTS, kAllSchemes); pattern2.SetMatchAllURLs(true); EXPECT_EQ(pattern.valid_schemes(), pattern2.valid_schemes()); @@ -303,7 +303,7 @@ TEST(ExtensionURLPatternTest, Match11) { // SCHEME_ALL matches all schemes. TEST(ExtensionURLPatternTest, Match12) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, URLPattern::SCHEME_ALL); + URLPattern pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_ALL); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("<all_urls>")); EXPECT_TRUE(pattern.MatchesScheme("chrome")); EXPECT_TRUE(pattern.MatchesScheme("http")); @@ -342,7 +342,7 @@ static const struct MatchPatterns { // SCHEME_ALL and specific schemes. TEST(ExtensionURLPatternTest, Match13) { for (size_t i = 0; i < arraysize(kMatch13UrlPatternTestCases); ++i) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, URLPattern::SCHEME_ALL); + URLPattern pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_ALL); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse(kMatch13UrlPatternTestCases[i].pattern)) << " while parsing " << kMatch13UrlPatternTestCases[i].pattern; @@ -352,14 +352,14 @@ TEST(ExtensionURLPatternTest, Match13) { } // Negative test. - URLPattern pattern(URLPattern::ERROR_ON_PORTS, URLPattern::SCHEME_ALL); + URLPattern pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_ALL); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("data:*")); EXPECT_FALSE(pattern.MatchesURL(GURL("about:blank"))); }; // file scheme with empty hostname TEST(ExtensionURLPatternTest, Match14) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("file:///foo*")); EXPECT_EQ("file", pattern.scheme()); EXPECT_EQ("", pattern.host()); @@ -375,7 +375,7 @@ TEST(ExtensionURLPatternTest, Match14) { // file scheme without hostname part TEST(ExtensionURLPatternTest, Match15) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("file://foo*")); EXPECT_EQ("file", pattern.scheme()); EXPECT_EQ("", pattern.host()); @@ -391,7 +391,7 @@ TEST(ExtensionURLPatternTest, Match15) { // file scheme with hostname TEST(ExtensionURLPatternTest, Match16) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); EXPECT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("file://localhost/foo*")); EXPECT_EQ("file", pattern.scheme()); // Since hostname is ignored for file://. diff --git a/chrome/common/extensions/user_script_unittest.cc b/chrome/common/extensions/user_script_unittest.cc index 0c06fbb..6f794ab 100644 --- a/chrome/common/extensions/user_script_unittest.cc +++ b/chrome/common/extensions/user_script_unittest.cc @@ -71,7 +71,7 @@ TEST(ExtensionUserScriptTest, Glob_StringAnywhere) { } TEST(ExtensionUserScriptTest, UrlPattern) { - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*/foo*")); UserScript script; @@ -85,11 +85,11 @@ TEST(ExtensionUserScriptTest, UrlPattern) { TEST(ExtensionUserScriptTest, ExcludeUrlPattern) { UserScript script; - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.nytimes.com/*")); script.add_url_pattern(pattern); - URLPattern exclude(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern exclude(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS, exclude.Parse("*://*/*business*")); script.add_exclude_url_pattern(exclude); @@ -101,7 +101,7 @@ TEST(ExtensionUserScriptTest, ExcludeUrlPattern) { TEST(ExtensionUserScriptTest, UrlPatternAndIncludeGlobs) { UserScript script; - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.nytimes.com/*")); script.add_url_pattern(pattern); @@ -115,7 +115,7 @@ TEST(ExtensionUserScriptTest, UrlPatternAndIncludeGlobs) { TEST(ExtensionUserScriptTest, UrlPatternAndExcludeGlobs) { UserScript script; - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern.Parse("http://*.nytimes.com/*")); script.add_url_pattern(pattern); @@ -130,7 +130,7 @@ TEST(ExtensionUserScriptTest, UrlPatternGlobInteraction) { // If there are both, match intersection(union(globs), union(urlpatterns)). UserScript script; - URLPattern pattern(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS,pattern.Parse("http://www.google.com/*")); script.add_url_pattern(pattern); @@ -157,8 +157,8 @@ TEST(ExtensionUserScriptTest, UrlPatternGlobInteraction) { } TEST(ExtensionUserScriptTest, Pickle) { - URLPattern pattern1(URLPattern::ERROR_ON_PORTS, kAllSchemes); - URLPattern pattern2(URLPattern::ERROR_ON_PORTS, kAllSchemes); + URLPattern pattern1(URLPattern::USE_PORTS, kAllSchemes); + URLPattern pattern2(URLPattern::USE_PORTS, kAllSchemes); ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern1.Parse("http://*/foo*")); ASSERT_EQ(URLPattern::PARSE_SUCCESS, pattern2.Parse("http://bar/baz*")); |