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

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: 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
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 89bc2785fc161ee3e80b5a7882b834a2d2f5169e..fe14f2f2e229eea5ac20d2bec01acb68ca2487bd 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -376,6 +376,14 @@ GURL Extension::GetResourceURL(const GURL& extension_url,
return ret_val;
}
+GURL Extension::GetBackgroundURL() const {
+ if (!background_scripts_.empty())
+ return GetResourceURL(
+ extension_filenames::kGeneratedBackgroundPageFilename);
Matt Perry 2012/01/09 21:12:17 nit: braces around multi-line if/else
+ else
+ return background_url_;
+}
+
bool Extension::IsResourceWebAccessible(const std::string& relative_path)
const {
// For old manifest versions which do not specify web_accessible_resources
@@ -1242,10 +1250,40 @@ 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,
string16* error) {
+ if (!background_scripts_.empty())
Matt Perry 2012/01/09 21:12:17 Maybe it should be an error to have both a backgro
+ return true;
+
base::Value* background_page_value = NULL;
if (!manifest->Get(keys::kBackgroundPage, &background_page_value)) {
if (manifest_version_ == 1)
@@ -2023,6 +2061,9 @@ bool Extension::InitFromValue(extensions::Manifest* manifest, int flags,
}
}
+ if (!LoadBackgroundScripts(manifest, error))
+ return false;
+
if (!LoadBackgroundPage(manifest, api_permissions, error))
return false;

Powered by Google App Engine
This is Rietveld 408576698