Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3694)

Unified Diff: chrome/common/extensions/user_script.cc

Issue 12792005: Allow extensions on chrome:// URLs, when flag is set and permission is explicitly requested (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reinstate original pickle order; add scripts clause to content_script_chrome_url_invalid.json to av… Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/user_script.cc
diff --git a/chrome/common/extensions/user_script.cc b/chrome/common/extensions/user_script.cc
index dc62066c679348861e39773e63f3f14490108cbf..ce497f6c99fa9d4106aaa90f96ffb931c79da6a7 100644
--- a/chrome/common/extensions/user_script.cc
+++ b/chrome/common/extensions/user_script.cc
@@ -4,8 +4,10 @@
#include "chrome/common/extensions/user_script.h"
+#include "base/command_line.h"
#include "base/pickle.h"
#include "base/string_util.h"
+#include "chrome/common/chrome_switches.h"
namespace {
@@ -24,6 +26,15 @@ bool UrlMatchesGlobs(const std::vector<std::string>* globs,
namespace extensions {
+// The bitmask for valid user script injectable schemes used by URLPattern.
+enum {
+ kValidUserScriptSchemes = URLPattern::SCHEME_CHROMEUI |
+ URLPattern::SCHEME_HTTP |
+ URLPattern::SCHEME_HTTPS |
+ URLPattern::SCHEME_FILE |
+ URLPattern::SCHEME_FTP
+};
+
// static
const char UserScript::kFileExtension[] = ".user.js";
@@ -33,6 +44,18 @@ bool UserScript::IsURLUserScript(const GURL& url,
mime_type != "text/html";
}
+// static
+int UserScript::ValidUserScriptSchemes(bool canExecuteScriptEverywhere) {
+ if (canExecuteScriptEverywhere)
+ return URLPattern::SCHEME_ALL;
+ int valid_schemes = kValidUserScriptSchemes;
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kExtensionsOnChromeURLs)) {
+ valid_schemes &= ~URLPattern::SCHEME_CHROMEUI;
+ }
+ return valid_schemes;
+}
+
UserScript::File::File(const base::FilePath& extension_root,
const base::FilePath& relative_path,
const GURL& url)
@@ -184,20 +207,16 @@ void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle,
for (uint64 i = 0; i < num_patterns; ++i) {
int valid_schemes;
CHECK(pickle.ReadInt(iter, &valid_schemes));
+
std::string pattern_str;
- URLPattern pattern(valid_schemes);
CHECK(pickle.ReadString(iter, &pattern_str));
- // We remove the file scheme if it's not actually allowed (see Extension::
- // LoadUserScriptHelper), but we need it temporarily while loading the
- // pattern so that it's valid.
- bool had_file_scheme = (valid_schemes & URLPattern::SCHEME_FILE) != 0;
- if (!had_file_scheme)
- pattern.SetValidSchemes(valid_schemes | URLPattern::SCHEME_FILE);
- CHECK(URLPattern::PARSE_SUCCESS == pattern.Parse(pattern_str));
- if (!had_file_scheme)
- pattern.SetValidSchemes(valid_schemes);
+ URLPattern pattern(kValidUserScriptSchemes);
+ URLPattern::ParseResult result = pattern.Parse(pattern_str);
+ CHECK(URLPattern::PARSE_SUCCESS == result) <<
+ URLPattern::GetParseResultString(result) << " " << pattern_str.c_str();
+ pattern.SetValidSchemes(valid_schemes);
pattern_list->AddPattern(pattern);
}
}

Powered by Google App Engine
This is Rietveld 408576698