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

Side by Side Diff: chrome/browser/extensions/api/context_menu/context_menu_api.cc

Issue 10664037: Moved ExtensionMenuManager and ExtensionMenuItem into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merged with latest master Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/extensions/api/context_menu/context_menu_api.h" 5 #include "chrome/browser/extensions/api/context_menu/context_menu_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 26 matching lines...) Expand all
37 "Cannot create item with duplicate id *"; 37 "Cannot create item with duplicate id *";
38 const char kIdRequiredError[] = "Extensions using event pages must pass an " 38 const char kIdRequiredError[] = "Extensions using event pages must pass an "
39 "id parameter to chrome.contextMenus.create"; 39 "id parameter to chrome.contextMenus.create";
40 const char kInvalidValueError[] = "Invalid value for *"; 40 const char kInvalidValueError[] = "Invalid value for *";
41 const char kInvalidTypeStringError[] = "Invalid type string '*'"; 41 const char kInvalidTypeStringError[] = "Invalid type string '*'";
42 const char kParentsMustBeNormalError[] = 42 const char kParentsMustBeNormalError[] =
43 "Parent items must have type \"normal\""; 43 "Parent items must have type \"normal\"";
44 const char kTitleNeededError[] = 44 const char kTitleNeededError[] =
45 "All menu items except for separators must have a title"; 45 "All menu items except for separators must have a title";
46 46
47 std::string GetIDString(const ExtensionMenuItem::Id& id) { 47 std::string GetIDString(const extensions::MenuItem::Id& id) {
48 if (id.uid == 0) 48 if (id.uid == 0)
49 return id.string_uid; 49 return id.string_uid;
50 else 50 else
51 return base::IntToString(id.uid); 51 return base::IntToString(id.uid);
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 namespace extensions { 56 namespace extensions {
57 57
58 bool ExtensionContextMenuFunction::ParseContexts( 58 bool ExtensionContextMenuFunction::ParseContexts(
59 const DictionaryValue& properties, 59 const DictionaryValue& properties,
60 const char* key, 60 const char* key,
61 ExtensionMenuItem::ContextList* result) { 61 MenuItem::ContextList* result) {
62 ListValue* list = NULL; 62 ListValue* list = NULL;
63 if (!properties.GetList(key, &list)) { 63 if (!properties.GetList(key, &list)) {
64 return true; 64 return true;
65 } 65 }
66 ExtensionMenuItem::ContextList tmp_result; 66 MenuItem::ContextList tmp_result;
67 67
68 std::string value; 68 std::string value;
69 for (size_t i = 0; i < list->GetSize(); i++) { 69 for (size_t i = 0; i < list->GetSize(); i++) {
70 if (!list->GetString(i, &value)) 70 if (!list->GetString(i, &value))
71 return false; 71 return false;
72 72
73 if (value == "all") { 73 if (value == "all") {
74 tmp_result.Add(ExtensionMenuItem::ALL); 74 tmp_result.Add(MenuItem::ALL);
75 } else if (value == "page") { 75 } else if (value == "page") {
76 tmp_result.Add(ExtensionMenuItem::PAGE); 76 tmp_result.Add(MenuItem::PAGE);
77 } else if (value == "selection") { 77 } else if (value == "selection") {
78 tmp_result.Add(ExtensionMenuItem::SELECTION); 78 tmp_result.Add(MenuItem::SELECTION);
79 } else if (value == "link") { 79 } else if (value == "link") {
80 tmp_result.Add(ExtensionMenuItem::LINK); 80 tmp_result.Add(MenuItem::LINK);
81 } else if (value == "editable") { 81 } else if (value == "editable") {
82 tmp_result.Add(ExtensionMenuItem::EDITABLE); 82 tmp_result.Add(MenuItem::EDITABLE);
83 } else if (value == "image") { 83 } else if (value == "image") {
84 tmp_result.Add(ExtensionMenuItem::IMAGE); 84 tmp_result.Add(MenuItem::IMAGE);
85 } else if (value == "video") { 85 } else if (value == "video") {
86 tmp_result.Add(ExtensionMenuItem::VIDEO); 86 tmp_result.Add(MenuItem::VIDEO);
87 } else if (value == "audio") { 87 } else if (value == "audio") {
88 tmp_result.Add(ExtensionMenuItem::AUDIO); 88 tmp_result.Add(MenuItem::AUDIO);
89 } else if (value == "frame") { 89 } else if (value == "frame") {
90 tmp_result.Add(ExtensionMenuItem::FRAME); 90 tmp_result.Add(MenuItem::FRAME);
91 } else { 91 } else {
92 error_ = ExtensionErrorUtils::FormatErrorMessage(kInvalidValueError, key); 92 error_ = ExtensionErrorUtils::FormatErrorMessage(kInvalidValueError, key);
93 return false; 93 return false;
94 } 94 }
95 } 95 }
96 *result = tmp_result; 96 *result = tmp_result;
97 return true; 97 return true;
98 } 98 }
99 99
100 bool ExtensionContextMenuFunction::ParseType( 100 bool ExtensionContextMenuFunction::ParseType(
101 const DictionaryValue& properties, 101 const DictionaryValue& properties,
102 const ExtensionMenuItem::Type& default_value, 102 const MenuItem::Type& default_value,
103 ExtensionMenuItem::Type* result) { 103 MenuItem::Type* result) {
104 DCHECK(result); 104 DCHECK(result);
105 if (!properties.HasKey(kTypeKey)) { 105 if (!properties.HasKey(kTypeKey)) {
106 *result = default_value; 106 *result = default_value;
107 return true; 107 return true;
108 } 108 }
109 109
110 std::string type_string; 110 std::string type_string;
111 if (!properties.GetString(kTypeKey, &type_string)) 111 if (!properties.GetString(kTypeKey, &type_string))
112 return false; 112 return false;
113 113
114 if (type_string == "normal") { 114 if (type_string == "normal") {
115 *result = ExtensionMenuItem::NORMAL; 115 *result = MenuItem::NORMAL;
116 } else if (type_string == "checkbox") { 116 } else if (type_string == "checkbox") {
117 *result = ExtensionMenuItem::CHECKBOX; 117 *result = MenuItem::CHECKBOX;
118 } else if (type_string == "radio") { 118 } else if (type_string == "radio") {
119 *result = ExtensionMenuItem::RADIO; 119 *result = MenuItem::RADIO;
120 } else if (type_string == "separator") { 120 } else if (type_string == "separator") {
121 *result = ExtensionMenuItem::SEPARATOR; 121 *result = MenuItem::SEPARATOR;
122 } else { 122 } else {
123 error_ = ExtensionErrorUtils::FormatErrorMessage(kInvalidTypeStringError, 123 error_ = ExtensionErrorUtils::FormatErrorMessage(kInvalidTypeStringError,
124 type_string); 124 type_string);
125 return false; 125 return false;
126 } 126 }
127 return true; 127 return true;
128 } 128 }
129 129
130 bool ExtensionContextMenuFunction::ParseChecked( 130 bool ExtensionContextMenuFunction::ParseChecked(
131 ExtensionMenuItem::Type type, 131 MenuItem::Type type,
132 const DictionaryValue& properties, 132 const DictionaryValue& properties,
133 bool default_value, 133 bool default_value,
134 bool* checked) { 134 bool* checked) {
135 if (!properties.HasKey(kCheckedKey)) { 135 if (!properties.HasKey(kCheckedKey)) {
136 *checked = default_value; 136 *checked = default_value;
137 return true; 137 return true;
138 } 138 }
139 if (!properties.GetBoolean(kCheckedKey, checked)) 139 if (!properties.GetBoolean(kCheckedKey, checked))
140 return false; 140 return false;
141 if (checked && type != ExtensionMenuItem::CHECKBOX && 141 if (checked && type != MenuItem::CHECKBOX && type != MenuItem::RADIO) {
142 type != ExtensionMenuItem::RADIO) {
143 error_ = kCheckedError; 142 error_ = kCheckedError;
144 return false; 143 return false;
145 } 144 }
146 return true; 145 return true;
147 } 146 }
148 147
149 bool ExtensionContextMenuFunction::ParseID( 148 bool ExtensionContextMenuFunction::ParseID(const Value* value,
150 const Value* value, 149 MenuItem::Id* result) {
151 ExtensionMenuItem::Id* result) {
152 return (value->GetAsInteger(&result->uid) || 150 return (value->GetAsInteger(&result->uid) ||
153 value->GetAsString(&result->string_uid)); 151 value->GetAsString(&result->string_uid));
154 } 152 }
155 153
156 bool ExtensionContextMenuFunction::GetParent( 154 bool ExtensionContextMenuFunction::GetParent(const DictionaryValue& properties,
157 const DictionaryValue& properties, 155 const MenuManager& manager,
158 const ExtensionMenuManager& manager, 156 MenuItem** result) {
159 ExtensionMenuItem** result) {
160 if (!properties.HasKey(kParentIdKey)) 157 if (!properties.HasKey(kParentIdKey))
161 return true; 158 return true;
162 ExtensionMenuItem::Id parent_id(profile()->IsOffTheRecord(), extension_id()); 159 MenuItem::Id parent_id(profile()->IsOffTheRecord(), extension_id());
163 Value* parent_id_value = NULL; 160 Value* parent_id_value = NULL;
164 if (properties.Get(kParentIdKey, &parent_id_value) && 161 if (properties.Get(kParentIdKey, &parent_id_value) &&
165 !ParseID(parent_id_value, &parent_id)) 162 !ParseID(parent_id_value, &parent_id))
166 return false; 163 return false;
167 164
168 ExtensionMenuItem* parent = manager.GetItemById(parent_id); 165 MenuItem* parent = manager.GetItemById(parent_id);
169 if (!parent) { 166 if (!parent) {
170 error_ = ExtensionErrorUtils::FormatErrorMessage( 167 error_ = ExtensionErrorUtils::FormatErrorMessage(
171 kCannotFindItemError, GetIDString(parent_id)); 168 kCannotFindItemError, GetIDString(parent_id));
172 return false; 169 return false;
173 } 170 }
174 if (parent->type() != ExtensionMenuItem::NORMAL) { 171 if (parent->type() != MenuItem::NORMAL) {
175 error_ = kParentsMustBeNormalError; 172 error_ = kParentsMustBeNormalError;
176 return false; 173 return false;
177 } 174 }
178 *result = parent; 175 *result = parent;
179 return true; 176 return true;
180 } 177 }
181 178
182 bool CreateContextMenuFunction::RunImpl() { 179 bool CreateContextMenuFunction::RunImpl() {
183 DictionaryValue* properties; 180 DictionaryValue* properties;
184 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties)); 181 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties));
185 EXTENSION_FUNCTION_VALIDATE(properties != NULL); 182 EXTENSION_FUNCTION_VALIDATE(properties != NULL);
186 183
187 ExtensionMenuItem::Id id(profile()->IsOffTheRecord(), extension_id()); 184 MenuItem::Id id(profile()->IsOffTheRecord(), extension_id());
188 if (properties->HasKey(kIdKey)) { 185 if (properties->HasKey(kIdKey)) {
189 EXTENSION_FUNCTION_VALIDATE(properties->GetString(kIdKey, 186 EXTENSION_FUNCTION_VALIDATE(properties->GetString(kIdKey,
190 &id.string_uid)); 187 &id.string_uid));
191 } else { 188 } else {
192 if (GetExtension()->has_lazy_background_page()) { 189 if (GetExtension()->has_lazy_background_page()) {
193 error_ = kIdRequiredError; 190 error_ = kIdRequiredError;
194 return false; 191 return false;
195 } 192 }
196 EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(kGeneratedIdKey, 193 EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(kGeneratedIdKey,
197 &id.uid)); 194 &id.uid));
198 } 195 }
199 196
200 std::string title; 197 std::string title;
201 if (properties->HasKey(kTitleKey) && 198 if (properties->HasKey(kTitleKey) &&
202 !properties->GetString(kTitleKey, &title)) 199 !properties->GetString(kTitleKey, &title))
203 return false; 200 return false;
204 201
205 ExtensionMenuManager* menu_manager = 202 MenuManager* menu_manager = profile()->GetExtensionService()->menu_manager();
206 profile()->GetExtensionService()->menu_manager();
207 203
208 if (menu_manager->GetItemById(id)) { 204 if (menu_manager->GetItemById(id)) {
209 error_ = ExtensionErrorUtils::FormatErrorMessage(kDuplicateIDError, 205 error_ = ExtensionErrorUtils::FormatErrorMessage(kDuplicateIDError,
210 GetIDString(id)); 206 GetIDString(id));
211 return false; 207 return false;
212 } 208 }
213 209
214 if (GetExtension()->has_lazy_background_page() && 210 if (GetExtension()->has_lazy_background_page() &&
215 properties->HasKey(kOnclickKey)) { 211 properties->HasKey(kOnclickKey)) {
216 error_ = kOnclickDisallowedError; 212 error_ = kOnclickDisallowedError;
217 return false; 213 return false;
218 } 214 }
219 215
220 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::PAGE); 216 MenuItem::ContextList contexts(MenuItem::PAGE);
221 if (!ParseContexts(*properties, kContextsKey, &contexts)) 217 if (!ParseContexts(*properties, kContextsKey, &contexts))
222 return false; 218 return false;
223 219
224 ExtensionMenuItem::Type type; 220 MenuItem::Type type;
225 if (!ParseType(*properties, ExtensionMenuItem::NORMAL, &type)) 221 if (!ParseType(*properties, MenuItem::NORMAL, &type))
226 return false; 222 return false;
227 223
228 if (title.empty() && type != ExtensionMenuItem::SEPARATOR) { 224 if (title.empty() && type != MenuItem::SEPARATOR) {
229 error_ = kTitleNeededError; 225 error_ = kTitleNeededError;
230 return false; 226 return false;
231 } 227 }
232 228
233 bool checked; 229 bool checked;
234 if (!ParseChecked(type, *properties, false, &checked)) 230 if (!ParseChecked(type, *properties, false, &checked))
235 return false; 231 return false;
236 232
237 bool enabled = true; 233 bool enabled = true;
238 if (properties->HasKey(kEnabledKey)) 234 if (properties->HasKey(kEnabledKey))
239 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(kEnabledKey, &enabled)); 235 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(kEnabledKey, &enabled));
240 236
241 scoped_ptr<ExtensionMenuItem> item( 237 scoped_ptr<MenuItem> item(
242 new ExtensionMenuItem(id, title, checked, enabled, type, contexts)); 238 new MenuItem(id, title, checked, enabled, type, contexts));
243 239
244 if (!item->PopulateURLPatterns( 240 if (!item->PopulateURLPatterns(
245 *properties, kDocumentUrlPatternsKey, kTargetUrlPatternsKey, &error_)) 241 *properties, kDocumentUrlPatternsKey, kTargetUrlPatternsKey, &error_))
246 return false; 242 return false;
247 243
248 bool success = true; 244 bool success = true;
249 if (properties->HasKey(kParentIdKey)) { 245 if (properties->HasKey(kParentIdKey)) {
250 ExtensionMenuItem* parent = NULL; 246 MenuItem* parent = NULL;
251 if (!GetParent(*properties, *menu_manager, &parent)) 247 if (!GetParent(*properties, *menu_manager, &parent))
252 return false; 248 return false;
253 success = menu_manager->AddChildItem(parent->id(), item.release()); 249 success = menu_manager->AddChildItem(parent->id(), item.release());
254 } else { 250 } else {
255 success = menu_manager->AddContextItem(GetExtension(), item.release()); 251 success = menu_manager->AddContextItem(GetExtension(), item.release());
256 } 252 }
257 253
258 if (!success) 254 if (!success)
259 return false; 255 return false;
260 256
261 menu_manager->WriteToStorage(GetExtension()); 257 menu_manager->WriteToStorage(GetExtension());
262 return true; 258 return true;
263 } 259 }
264 260
265 bool UpdateContextMenuFunction::RunImpl() { 261 bool UpdateContextMenuFunction::RunImpl() {
266 bool radioItemUpdated = false; 262 bool radioItemUpdated = false;
267 ExtensionMenuItem::Id item_id(profile()->IsOffTheRecord(), extension_id()); 263 MenuItem::Id item_id(profile()->IsOffTheRecord(), extension_id());
268 Value* id_value = NULL; 264 Value* id_value = NULL;
269 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &id_value)); 265 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &id_value));
270 EXTENSION_FUNCTION_VALIDATE(ParseID(id_value, &item_id)); 266 EXTENSION_FUNCTION_VALIDATE(ParseID(id_value, &item_id));
271 267
272 ExtensionService* service = profile()->GetExtensionService(); 268 ExtensionService* service = profile()->GetExtensionService();
273 ExtensionMenuManager* manager = service->menu_manager(); 269 MenuManager* manager = service->menu_manager();
274 ExtensionMenuItem* item = manager->GetItemById(item_id); 270 MenuItem* item = manager->GetItemById(item_id);
275 if (!item || item->extension_id() != extension_id()) { 271 if (!item || item->extension_id() != extension_id()) {
276 error_ = ExtensionErrorUtils::FormatErrorMessage( 272 error_ = ExtensionErrorUtils::FormatErrorMessage(
277 kCannotFindItemError, GetIDString(item_id)); 273 kCannotFindItemError, GetIDString(item_id));
278 return false; 274 return false;
279 } 275 }
280 276
281 DictionaryValue* properties = NULL; 277 DictionaryValue* properties = NULL;
282 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties)); 278 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
283 EXTENSION_FUNCTION_VALIDATE(properties != NULL); 279 EXTENSION_FUNCTION_VALIDATE(properties != NULL);
284 280
285 // Type. 281 // Type.
286 ExtensionMenuItem::Type type; 282 MenuItem::Type type;
287 if (!ParseType(*properties, item->type(), &type)) 283 if (!ParseType(*properties, item->type(), &type))
288 return false; 284 return false;
289 if (type != item->type()) { 285 if (type != item->type()) {
290 if (type == ExtensionMenuItem::RADIO || 286 if (type == MenuItem::RADIO || item->type() == MenuItem::RADIO) {
291 item->type() == ExtensionMenuItem::RADIO) {
292 radioItemUpdated = true; 287 radioItemUpdated = true;
293 } 288 }
294 item->set_type(type); 289 item->set_type(type);
295 } 290 }
296 291
297 // Title. 292 // Title.
298 if (properties->HasKey(kTitleKey)) { 293 if (properties->HasKey(kTitleKey)) {
299 std::string title; 294 std::string title;
300 EXTENSION_FUNCTION_VALIDATE(properties->GetString(kTitleKey, &title)); 295 EXTENSION_FUNCTION_VALIDATE(properties->GetString(kTitleKey, &title));
301 if (title.empty() && type != ExtensionMenuItem::SEPARATOR) { 296 if (title.empty() && type != MenuItem::SEPARATOR) {
302 error_ = kTitleNeededError; 297 error_ = kTitleNeededError;
303 return false; 298 return false;
304 } 299 }
305 item->set_title(title); 300 item->set_title(title);
306 } 301 }
307 302
308 // Checked state. 303 // Checked state.
309 bool checked; 304 bool checked;
310 if (!ParseChecked(item->type(), *properties, item->checked(), &checked)) 305 if (!ParseChecked(item->type(), *properties, item->checked(), &checked))
311 return false; 306 return false;
312 if (checked != item->checked()) { 307 if (checked != item->checked()) {
313 if (!item->SetChecked(checked)) 308 if (!item->SetChecked(checked))
314 return false; 309 return false;
315 radioItemUpdated = true; 310 radioItemUpdated = true;
316 } 311 }
317 312
318 // Enabled. 313 // Enabled.
319 bool enabled; 314 bool enabled;
320 if (properties->HasKey(kEnabledKey)) { 315 if (properties->HasKey(kEnabledKey)) {
321 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(kEnabledKey, &enabled)); 316 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(kEnabledKey, &enabled));
322 item->set_enabled(enabled); 317 item->set_enabled(enabled);
323 } 318 }
324 319
325 // Contexts. 320 // Contexts.
326 ExtensionMenuItem::ContextList contexts(item->contexts()); 321 MenuItem::ContextList contexts(item->contexts());
327 if (!ParseContexts(*properties, kContextsKey, &contexts)) 322 if (!ParseContexts(*properties, kContextsKey, &contexts))
328 return false; 323 return false;
329 if (contexts != item->contexts()) 324 if (contexts != item->contexts())
330 item->set_contexts(contexts); 325 item->set_contexts(contexts);
331 326
332 // Parent id. 327 // Parent id.
333 ExtensionMenuItem* parent = NULL; 328 MenuItem* parent = NULL;
334 if (!GetParent(*properties, *manager, &parent)) 329 if (!GetParent(*properties, *manager, &parent))
335 return false; 330 return false;
336 if (parent && !manager->ChangeParent(item->id(), &parent->id())) 331 if (parent && !manager->ChangeParent(item->id(), &parent->id()))
337 return false; 332 return false;
338 333
339 if (!item->PopulateURLPatterns( 334 if (!item->PopulateURLPatterns(
340 *properties, kDocumentUrlPatternsKey, kTargetUrlPatternsKey, &error_)) 335 *properties, kDocumentUrlPatternsKey, kTargetUrlPatternsKey, &error_))
341 return false; 336 return false;
342 337
343 // There is no need to call ItemUpdated if ChangeParent is called because 338 // There is no need to call ItemUpdated if ChangeParent is called because
344 // all sanitation is taken care of in ChangeParent. 339 // all sanitation is taken care of in ChangeParent.
345 if (!parent && radioItemUpdated && !manager->ItemUpdated(item->id())) 340 if (!parent && radioItemUpdated && !manager->ItemUpdated(item->id()))
346 return false; 341 return false;
347 342
348 manager->WriteToStorage(GetExtension()); 343 manager->WriteToStorage(GetExtension());
349 return true; 344 return true;
350 } 345 }
351 346
352 bool RemoveContextMenuFunction::RunImpl() { 347 bool RemoveContextMenuFunction::RunImpl() {
353 ExtensionMenuItem::Id id(profile()->IsOffTheRecord(), extension_id()); 348 MenuItem::Id id(profile()->IsOffTheRecord(), extension_id());
354 Value* id_value = NULL; 349 Value* id_value = NULL;
355 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &id_value)); 350 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &id_value));
356 EXTENSION_FUNCTION_VALIDATE(ParseID(id_value, &id)); 351 EXTENSION_FUNCTION_VALIDATE(ParseID(id_value, &id));
357 ExtensionService* service = profile()->GetExtensionService(); 352 ExtensionService* service = profile()->GetExtensionService();
358 ExtensionMenuManager* manager = service->menu_manager(); 353 MenuManager* manager = service->menu_manager();
359 354
360 ExtensionMenuItem* item = manager->GetItemById(id); 355 MenuItem* item = manager->GetItemById(id);
361 // Ensure one extension can't remove another's menu items. 356 // Ensure one extension can't remove another's menu items.
362 if (!item || item->extension_id() != extension_id()) { 357 if (!item || item->extension_id() != extension_id()) {
363 error_ = ExtensionErrorUtils::FormatErrorMessage( 358 error_ = ExtensionErrorUtils::FormatErrorMessage(
364 kCannotFindItemError, GetIDString(id)); 359 kCannotFindItemError, GetIDString(id));
365 return false; 360 return false;
366 } 361 }
367 362
368 if (!manager->RemoveContextMenuItem(id)) 363 if (!manager->RemoveContextMenuItem(id))
369 return false; 364 return false;
370 manager->WriteToStorage(GetExtension()); 365 manager->WriteToStorage(GetExtension());
371 return true; 366 return true;
372 } 367 }
373 368
374 bool RemoveAllContextMenusFunction::RunImpl() { 369 bool RemoveAllContextMenusFunction::RunImpl() {
375 ExtensionService* service = profile()->GetExtensionService(); 370 ExtensionService* service = profile()->GetExtensionService();
376 ExtensionMenuManager* manager = service->menu_manager(); 371 MenuManager* manager = service->menu_manager();
377 manager->RemoveAllContextItems(GetExtension()->id()); 372 manager->RemoveAllContextItems(GetExtension()->id());
378 manager->WriteToStorage(GetExtension()); 373 manager->WriteToStorage(GetExtension());
379 return true; 374 return true;
380 } 375 }
381 376
382 } // namespace extensions 377 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698