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..7470629a210ace72662d3e5c007907fd802e6384 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 { |
@@ -33,6 +35,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) |
@@ -128,8 +142,8 @@ void UserScript::PickleURLPatternSet(::Pickle* pickle, |
pickle->WriteUInt64(pattern_list.patterns().size()); |
for (URLPatternSet::const_iterator pattern = pattern_list.begin(); |
pattern != pattern_list.end(); ++pattern) { |
- pickle->WriteInt(pattern->valid_schemes()); |
pickle->WriteString(pattern->GetAsString()); |
Matt Perry
2013/03/19 17:49:32
Why change this?
aboxhall
2013/03/20 22:04:59
Because I don't want to set valid_schemes until af
Matt Perry
2013/03/20 22:32:48
Yeah I'd prefer to keep the old pickle order, just
aboxhall
2013/03/20 22:51:48
Good call, done.
|
+ pickle->WriteInt(pattern->valid_schemes()); |
} |
} |
@@ -182,22 +196,17 @@ void UserScript::UnpickleURLPatternSet(const ::Pickle& pickle, |
pattern_list->ClearPatterns(); |
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); |
+ URLPattern pattern(kValidUserScriptSchemes); |
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::ParseResult result = pattern.Parse(pattern_str); |
+ CHECK(URLPattern::PARSE_SUCCESS == result) << |
+ URLPattern::GetParseResultString(result) << " " << pattern_str.c_str(); |
+ int valid_schemes; |
+ CHECK(pickle.ReadInt(iter, &valid_schemes)); |
+ pattern.SetValidSchemes(valid_schemes); |
pattern_list->AddPattern(pattern); |
} |
} |