Index: chrome/common/extensions/extension.cc |
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc |
index 429dfb5ea9e8dd38c0e4bbb360d7d435374475ee..f67e26eaa9fe1f8765dead750b21e35cdeb93785 100644 |
--- a/chrome/common/extensions/extension.cc |
+++ b/chrome/common/extensions/extension.cc |
@@ -246,6 +246,17 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
result->add_url_pattern(pattern); |
} |
+ // include/exclude globs (mostly for Greasemonkey compat) |
+ if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, |
+ error, &UserScript::add_glob, result)) { |
+ return false; |
+ } |
+ |
+ if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, |
+ error, &UserScript::add_exclude_glob, result)) { |
+ return false; |
+ } |
+ |
// js and css keys |
ListValue* js = NULL; |
if (content_script->HasKey(keys::kJs) && |
@@ -309,6 +320,38 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
return true; |
} |
+bool Extension::LoadGlobsHelper( |
+ const DictionaryValue* content_script, |
+ int content_script_index, |
+ const wchar_t* globs_property_name, |
+ std::string* error, |
+ void (UserScript::*add_method) (const std::string& glob), |
+ UserScript *instance) { |
+ if (!content_script->HasKey(globs_property_name)) |
+ return true; // they are optional |
+ |
+ ListValue* list = NULL; |
+ if (!content_script->GetList(globs_property_name, &list)) { |
+ *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlobList, |
+ IntToString(content_script_index), WideToASCII(globs_property_name)); |
+ return false; |
+ } |
+ |
+ for (size_t i = 0; i < list->GetSize(); ++i) { |
+ std::string glob; |
+ if (!list->GetString(i, &glob)) { |
+ *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlob, |
+ IntToString(content_script_index), WideToASCII(globs_property_name), |
+ IntToString(i)); |
+ return false; |
+ } |
+ |
+ (instance->*add_method)(glob); |
+ } |
+ |
+ return true; |
+} |
+ |
ExtensionAction* Extension::LoadExtensionActionHelper( |
const DictionaryValue* extension_action, std::string* error) { |
scoped_ptr<ExtensionAction> result(new ExtensionAction()); |
@@ -448,7 +491,8 @@ ExtensionResource Extension::GetResource(const FilePath& extension_path, |
} |
Extension::Extension(const FilePath& path) |
- : is_theme_(false), background_page_ready_(false) { |
+ : is_theme_(false), background_page_ready_(false), |
+ converted_from_user_script_(false) { |
DCHECK(path.IsAbsolute()); |
location_ = INVALID; |
@@ -666,6 +710,10 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, |
} |
} |
+ // Initialize converted_from_user_script (if present) |
+ source.GetBoolean(keys::kConvertedFromUserScript, |
+ &converted_from_user_script_); |
+ |
// Initialize icons (if present). |
if (source.HasKey(keys::kIcons)) { |
DictionaryValue* icons_value = NULL; |
@@ -941,6 +989,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, |
if (!LoadUserScriptHelper(content_script, i, error, &script)) |
return false; // Failed to parse script context definition |
script.set_extension_id(id()); |
+ if (converted_from_user_script_) |
+ script.set_emulate_greasemonkey(true); |
content_scripts_.push_back(script); |
} |
} |