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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/extension_constants.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 script.set_extension_id(id()); 1072 script.set_extension_id(id());
1073 if (converted_from_user_script_) { 1073 if (converted_from_user_script_) {
1074 script.set_emulate_greasemonkey(true); 1074 script.set_emulate_greasemonkey(true);
1075 script.set_match_all_frames(true); // greasemonkey matches all frames 1075 script.set_match_all_frames(true); // greasemonkey matches all frames
1076 } 1076 }
1077 content_scripts_.push_back(script); 1077 content_scripts_.push_back(script);
1078 } 1078 }
1079 } 1079 }
1080 1080
1081 // Initialize page action (optional). 1081 // Initialize page action (optional).
1082 DictionaryValue* page_action_value = NULL;
1083
1082 if (source.HasKey(keys::kPageActions)) { 1084 if (source.HasKey(keys::kPageActions)) {
1083 ListValue* list_value; 1085 ListValue* list_value;
1084 if (!source.GetList(keys::kPageActions, &list_value)) { 1086 if (!source.GetList(keys::kPageActions, &list_value)) {
1085 *error = errors::kInvalidPageActionsList; 1087 *error = errors::kInvalidPageActionsList;
1086 return false; 1088 return false;
1087 } 1089 }
1088 1090
1089 if (list_value->GetSize() != 1u) { 1091 size_t list_value_length = list_value->GetSize();
1092
1093 if (list_value_length == 0u) {
1094 // A list with zero items is allowed, and is equivalent to not having
1095 // a page_actions key in the manifest. Don't set |page_action_value|.
1096 } else if (list_value_length == 1u) {
1097 if (!list_value->GetDictionary(0, &page_action_value)) {
1098 *error = errors::kInvalidPageAction;
1099 return false;
1100 }
1101 } else { // list_value_length > 1u.
1090 *error = errors::kInvalidPageActionsListSize; 1102 *error = errors::kInvalidPageActionsListSize;
1091 return false; 1103 return false;
1092 } 1104 }
1093
1094 DictionaryValue* page_action_value;
1095 if (!list_value->GetDictionary(0, &page_action_value)) {
1096 *error = errors::kInvalidPageAction;
1097 return false;
1098 }
1099
1100 page_action_.reset(
1101 LoadExtensionActionHelper(page_action_value, error));
1102 if (!page_action_.get())
1103 return false; // Failed to parse page action definition.
1104 } else if (source.HasKey(keys::kPageAction)) { 1105 } else if (source.HasKey(keys::kPageAction)) {
1105 DictionaryValue* page_action_value;
1106 if (!source.GetDictionary(keys::kPageAction, &page_action_value)) { 1106 if (!source.GetDictionary(keys::kPageAction, &page_action_value)) {
1107 *error = errors::kInvalidPageAction; 1107 *error = errors::kInvalidPageAction;
1108 return false; 1108 return false;
1109 } 1109 }
1110 }
1110 1111
1112 // If page_action_value is not NULL, then there was a valid page action.
1113 if (page_action_value) {
1111 page_action_.reset( 1114 page_action_.reset(
1112 LoadExtensionActionHelper(page_action_value, error)); 1115 LoadExtensionActionHelper(page_action_value, error));
1113 if (!page_action_.get()) 1116 if (!page_action_.get())
1114 return false; // Failed to parse page action definition. 1117 return false; // Failed to parse page action definition.
1115 } 1118 }
1116 1119
1117 // Initialize browser action (optional). 1120 // Initialize browser action (optional).
1118 if (source.HasKey(keys::kBrowserAction)) { 1121 if (source.HasKey(keys::kBrowserAction)) {
1119 // Restrict extensions to one UI surface. 1122 // Restrict extensions to one UI surface.
1120 if (source.HasKey(keys::kPageAction) || source.HasKey(keys::kPageActions)) { 1123 if (page_action_.get()) {
1121 *error = errors::kOneUISurfaceOnly; 1124 *error = errors::kOneUISurfaceOnly;
1122 return false; 1125 return false;
1123 } 1126 }
1124 1127
1125 DictionaryValue* browser_action_value; 1128 DictionaryValue* browser_action_value;
1126 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) { 1129 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) {
1127 *error = errors::kInvalidBrowserAction; 1130 *error = errors::kInvalidBrowserAction;
1128 return false; 1131 return false;
1129 } 1132 }
1130 1133
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 UserScript::PatternList::const_iterator pattern = 1329 UserScript::PatternList::const_iterator pattern =
1327 content_script->url_patterns().begin(); 1330 content_script->url_patterns().begin();
1328 for (; pattern != content_script->url_patterns().end(); ++pattern) { 1331 for (; pattern != content_script->url_patterns().end(); ++pattern) {
1329 if (pattern->match_subdomains() && pattern->host().empty()) 1332 if (pattern->match_subdomains() && pattern->host().empty())
1330 return true; 1333 return true;
1331 } 1334 }
1332 } 1335 }
1333 1336
1334 return false; 1337 return false;
1335 } 1338 }
OLDNEW
« 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