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

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

Issue 523132: Allow an empty list of page actions. (Closed)
Patch Set: '' Created 10 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 | « no previous file | chrome/common/extensions/extension_constants.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
===================================================================
--- chrome/common/extensions/extension.cc (revision 35891)
+++ chrome/common/extensions/extension.cc (working copy)
@@ -1079,6 +1079,8 @@
}
// Initialize page action (optional).
+ DictionaryValue* page_action_value = NULL;
+
if (source.HasKey(keys::kPageActions)) {
ListValue* list_value;
if (!source.GetList(keys::kPageActions, &list_value)) {
@@ -1086,28 +1088,29 @@
return false;
}
- if (list_value->GetSize() != 1u) {
+ size_t list_value_length = list_value->GetSize();
+
+ if (list_value_length == 0u) {
+ // A list with zero items is allowed, and is equivalent to not having
+ // a page_actions key in the manifest. Don't set |page_action_value|.
+ } else if (list_value_length == 1u) {
+ if (!list_value->GetDictionary(0, &page_action_value)) {
+ *error = errors::kInvalidPageAction;
+ return false;
+ }
+ } else { // list_value_length > 1u.
*error = errors::kInvalidPageActionsListSize;
return false;
}
-
- DictionaryValue* page_action_value;
- if (!list_value->GetDictionary(0, &page_action_value)) {
- *error = errors::kInvalidPageAction;
- return false;
- }
-
- page_action_.reset(
- LoadExtensionActionHelper(page_action_value, error));
- if (!page_action_.get())
- return false; // Failed to parse page action definition.
} else if (source.HasKey(keys::kPageAction)) {
- DictionaryValue* page_action_value;
if (!source.GetDictionary(keys::kPageAction, &page_action_value)) {
*error = errors::kInvalidPageAction;
return false;
}
+ }
+ // If page_action_value is not NULL, then there was a valid page action.
+ if (page_action_value) {
page_action_.reset(
LoadExtensionActionHelper(page_action_value, error));
if (!page_action_.get())
@@ -1117,7 +1120,7 @@
// Initialize browser action (optional).
if (source.HasKey(keys::kBrowserAction)) {
// Restrict extensions to one UI surface.
- if (source.HasKey(keys::kPageAction) || source.HasKey(keys::kPageActions)) {
+ if (page_action_.get()) {
*error = errors::kOneUISurfaceOnly;
return false;
}
« no previous file with comments | « no previous file | chrome/common/extensions/extension_constants.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698