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

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

Issue 9150008: Introduce background.scripts feature for extension manifests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready to land Created 8 years, 11 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 10c849e20d20e37006f721116996baf3484b12dc..98727ba9769eb209ea31a22ab77fe7da72839303 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -373,6 +373,15 @@ GURL Extension::GetResourceURL(const GURL& extension_url,
return ret_val;
}
+GURL Extension::GetBackgroundURL() const {
+ if (!background_scripts_.empty()) {
+ return GetResourceURL(
+ extension_filenames::kGeneratedBackgroundPageFilename);
+ } else {
+ return background_url_;
+ }
+}
+
bool Extension::IsResourceWebAccessible(const std::string& relative_path)
const {
// For old manifest versions which do not specify web_accessible_resources
@@ -1189,6 +1198,33 @@ bool Extension::LoadWebIntentServices(const extensions::Manifest* manifest,
return true;
}
+bool Extension::LoadBackgroundScripts(const extensions::Manifest* manifest,
+ string16* error) {
+ Value* background_scripts_value = NULL;
+ if (!manifest->Get(keys::kBackgroundScripts, &background_scripts_value))
+ return true;
+
+ CHECK(background_scripts_value);
+ if (background_scripts_value->GetType() != Value::TYPE_LIST) {
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
+ return false;
+ }
+
+ ListValue* background_scripts =
+ static_cast<ListValue*>(background_scripts_value);
+ for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
+ std::string script;
+ if (!background_scripts->GetString(i, &script)) {
+ *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidBackgroundScript, base::IntToString(i));
+ return false;
+ }
+ background_scripts_.push_back(script);
+ }
+
+ return true;
+}
+
bool Extension::LoadBackgroundPage(
const extensions::Manifest* manifest,
const ExtensionAPIPermissionSet& api_permissions,
@@ -1208,6 +1244,11 @@ bool Extension::LoadBackgroundPage(
return false;
}
+ if (!background_scripts_.empty()) {
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
+ return false;
+ }
+
if (is_hosted_app()) {
// Make sure "background" permission is set.
if (!api_permissions.count(ExtensionAPIPermission::kBackground)) {
@@ -1970,6 +2011,9 @@ bool Extension::InitFromValue(extensions::Manifest* manifest, int flags,
}
}
+ if (!LoadBackgroundScripts(manifest, error))
+ return false;
+
if (!LoadBackgroundPage(manifest, api_permissions, error))
return false;
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698