summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/url_pattern.cc
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-03 10:01:26 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-03 10:01:26 +0000
commitab57a59d94280b432f728787fc2563227797d101 (patch)
tree0bebabb8be797300add05b6673cafc824fc4a9b0 /chrome/common/extensions/url_pattern.cc
parentf979ce4f17143dc97f7bfbdc81759993fd283bc5 (diff)
downloadchromium_src-ab57a59d94280b432f728787fc2563227797d101.zip
chromium_src-ab57a59d94280b432f728787fc2563227797d101.tar.gz
chromium_src-ab57a59d94280b432f728787fc2563227797d101.tar.bz2
Revert 61323 - Component extensions (and whitelisted extensions) specifying <all_urls> in their Extension match pattern should be allowed to run content scripts everywhere (including chrome://, chrome-extension://, about: and gallery pages.
The intent was to also allow these extensions to specify more granular permissions, such as about:version instead of <all_urls>, but that didn't make the cut this time. This CL also enables <all_urls> for host permissions for regular extensions, which was disabled before. Note: That still doesn't give them permission to script the gallery and chrome:// pages, etc. BUG=36275 TEST=New: ExtensionBrowserTest.AllUrlsWhitelistedExtension, ExtensionBrowserTest.AllUrlsRegularExtensions Review URL: http://codereview.chromium.org/3440027 TBR=finnur@chromium.org Review URL: http://codereview.chromium.org/3557006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/url_pattern.cc')
-rw-r--r--chrome/common/extensions/url_pattern.cc49
1 files changed, 10 insertions, 39 deletions
diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc
index 62459a3..80fc5fb 100644
--- a/chrome/common/extensions/url_pattern.cc
+++ b/chrome/common/extensions/url_pattern.cc
@@ -9,7 +9,6 @@
#include "base/string_util.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
-#include "googleurl/src/url_util.h"
// TODO(aa): Consider adding chrome-extension? What about more obscure ones
// like data: and javascript: ?
@@ -35,21 +34,10 @@ COMPILE_ASSERT(arraysize(kValidSchemes) == arraysize(kValidSchemeMasks),
static const char kPathSeparator[] = "/";
-const char URLPattern::kAllUrlsPattern[] = "<all_urls>";
-
-static bool IsStandardScheme(const std::string& scheme) {
- // "*" gets the same treatment as a standard scheme.
- if (scheme == "*")
- return true;
-
- return url_util::IsStandard(scheme.c_str(),
- url_parse::Component(0, static_cast<int>(scheme.length())));
-}
+static const char kAllUrlsPattern[] = "<all_urls>";
URLPattern::URLPattern()
- : valid_schemes_(SCHEME_NONE),
- match_all_urls_(false),
- match_subdomains_(false) {}
+ : valid_schemes_(0), match_all_urls_(false), match_subdomains_(false) {}
URLPattern::URLPattern(int valid_schemes)
: valid_schemes_(valid_schemes), match_all_urls_(false),
@@ -76,32 +64,24 @@ bool URLPattern::Parse(const std::string& pattern) {
return true;
}
- size_t scheme_end_pos = pattern.find(":");
+ size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator);
if (scheme_end_pos == std::string::npos)
return false;
if (!SetScheme(pattern.substr(0, scheme_end_pos)))
return false;
- std::string separator =
- pattern.substr(scheme_end_pos, strlen(chrome::kStandardSchemeSeparator));
- if (separator == chrome::kStandardSchemeSeparator)
- scheme_end_pos += strlen(chrome::kStandardSchemeSeparator);
- else
- scheme_end_pos += 1;
-
- // Advance past the scheme separator.
- size_t host_start_pos = scheme_end_pos;
+ size_t host_start_pos = scheme_end_pos +
+ strlen(chrome::kStandardSchemeSeparator);
if (host_start_pos >= pattern.length())
return false;
// Parse out the host and path.
size_t path_start_pos = 0;
- bool standard_scheme = IsStandardScheme(scheme_);
-
- // File URLs are special because they have no host.
- if (scheme_ == chrome::kFileScheme || !standard_scheme) {
+ // File URLs are special because they have no host. There are other schemes
+ // with the same structure, but we don't support them (yet).
+ if (scheme_ == chrome::kFileScheme) {
path_start_pos = host_start_pos;
} else {
size_t host_end_pos = pattern.find(kPathSeparator, host_start_pos);
@@ -145,9 +125,6 @@ bool URLPattern::SetScheme(const std::string& scheme) {
}
bool URLPattern::IsValidScheme(const std::string& scheme) const {
- if (valid_schemes_ == SCHEME_ALL)
- return true;
-
for (size_t i = 0; i < arraysize(kValidSchemes); ++i) {
if (scheme == kValidSchemes[i] && (valid_schemes_ & kValidSchemeMasks[i]))
return true;
@@ -160,9 +137,6 @@ bool URLPattern::MatchesUrl(const GURL &test) const {
if (!MatchesScheme(test.scheme()))
return false;
- if (match_all_urls_)
- return true;
-
if (!MatchesHost(test))
return false;
@@ -235,12 +209,9 @@ std::string URLPattern::GetAsString() const {
if (match_all_urls_)
return kAllUrlsPattern;
- bool standard_scheme = IsStandardScheme(scheme_);
-
- std::string spec = scheme_ +
- (standard_scheme ? chrome::kStandardSchemeSeparator : ":");
+ std::string spec = scheme_ + chrome::kStandardSchemeSeparator;
- if (scheme_ != chrome::kFileScheme && standard_scheme) {
+ if (scheme_ != chrome::kFileScheme) {
if (match_subdomains_) {
spec += "*";
if (!host_.empty())