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

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

Issue 10544059: Change the platform app manifest structure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 a06497ef55f1c4e4233cee33abdde90e174aa86e..690033820f1e241300fa294ed3ebe35c3b7d6db1 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1593,9 +1593,7 @@ bool Extension::LoadWebAccessibleResources(string16* error) {
}
bool Extension::LoadSandboxedPages(string16* error) {
- // Can't use HasKey, since it doesn't do path expansion.
- Value* ignored = NULL;
- if (!manifest_->Get(keys::kSandboxedPages, &ignored))
+ if (!manifest_->HasPath(keys::kSandboxedPages))
return true;
ListValue* list_value = NULL;
@@ -1615,7 +1613,7 @@ bool Extension::LoadSandboxedPages(string16* error) {
sandboxed_pages_.insert(relative_path);
}
- if (manifest_->Get(keys::kSandboxedPagesCSP, &ignored)) {
+ if (manifest_->HasPath(keys::kSandboxedPagesCSP)) {
if (!manifest_->GetString(
keys::kSandboxedPagesCSP, &sandboxed_pages_content_security_policy_)) {
*error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP);
@@ -1719,8 +1717,21 @@ bool Extension::LoadOptionsPage(string16* error) {
}
bool Extension::LoadBackgroundScripts(string16* error) {
+ if (is_platform_app()) {
+ if (manifest_->HasPath(keys::kBackgroundScripts)) {
+ *error = ASCIIToUTF16(errors::kPlatformAppInvalidBackgroundScripts);
+ return false;
+ }
+
+ return LoadBackgroundScripts(keys::kPlatformAppBackgroundScripts, error);
+ }
+
+ return LoadBackgroundScripts(keys::kBackgroundScripts, error);
+}
+
+bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
Value* background_scripts_value = NULL;
- if (!manifest_->Get(keys::kBackgroundScripts, &background_scripts_value))
+ if (!manifest_->Get(key, &background_scripts_value))
return true;
CHECK(background_scripts_value);
@@ -1747,45 +1758,67 @@ bool Extension::LoadBackgroundScripts(string16* error) {
bool Extension::LoadBackgroundPage(
const ExtensionAPIPermissionSet& api_permissions,
string16* error) {
- base::Value* background_page_value = NULL;
- if (!manifest_->Get(keys::kBackgroundPage, &background_page_value))
- manifest_->Get(keys::kBackgroundPageLegacy, &background_page_value);
+ if (is_platform_app()) {
+ if (manifest_->HasPath(keys::kBackgroundPage) ||
+ manifest_->HasPath(keys::kBackgroundPageLegacy)) {
+ *error = ASCIIToUTF16(errors::kPlatformAppInvalidBackgroundPage);
+ return false;
+ }
- if (!background_page_value)
- return true;
+ return LoadBackgroundPage(
+ keys::kPlatformAppBackgroundPage, api_permissions, error);
+ }
- std::string background_str;
- if (!background_page_value->GetAsString(&background_str)) {
- *error = ASCIIToUTF16(errors::kInvalidBackground);
+
+ if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error))
return false;
- }
+ if (background_url_.is_empty())
+ return LoadBackgroundPage(
+ keys::kBackgroundPageLegacy, api_permissions, error);
+ return true;
+}
+
+bool Extension::LoadBackgroundPage(
+ const std::string& key,
+ const ExtensionAPIPermissionSet& api_permissions,
+ string16* error) {
+ base::Value* background_page_value = NULL;
+ if (!manifest_->Get(key, &background_page_value))
+ return true;
if (!background_scripts_.empty()) {
*error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
return false;
}
+
+ std::string background_str;
+ if (!background_page_value->GetAsString(&background_str)) {
+ *error = ASCIIToUTF16(errors::kInvalidBackground);
+ return false;
+ }
+
if (is_hosted_app()) {
+ background_url_ = GURL(background_str);
+
// Make sure "background" permission is set.
if (!api_permissions.count(ExtensionAPIPermission::kBackground)) {
*error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
return false;
}
// Hosted apps require an absolute URL.
- GURL bg_page(background_str);
- if (!bg_page.is_valid()) {
+ if (!background_url_.is_valid()) {
*error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
return false;
}
- if (!(bg_page.SchemeIs("https") ||
+ if (!(background_url_.SchemeIs("https") ||
(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAllowHTTPBackgroundPage) &&
- bg_page.SchemeIs("http")))) {
+ background_url_.SchemeIs("http")))) {
*error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
return false;
}
- background_url_ = bg_page;
} else {
background_url_ = GetResourceURL(background_str);
}

Powered by Google App Engine
This is Rietveld 408576698