OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_context_menu_api.h" | 5 #include "chrome/browser/extensions/extension_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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 return false; | 258 return false; |
259 } | 259 } |
260 success = menu_manager->AddChildItem(parent_id, item.release()); | 260 success = menu_manager->AddChildItem(parent_id, item.release()); |
261 } else { | 261 } else { |
262 success = menu_manager->AddContextItem(GetExtension(), item.release()); | 262 success = menu_manager->AddContextItem(GetExtension(), item.release()); |
263 } | 263 } |
264 | 264 |
265 if (!success) | 265 if (!success) |
266 return false; | 266 return false; |
267 | 267 |
268 menu_manager->SanitizeRadioButtons(); | |
269 | |
268 return true; | 270 return true; |
269 } | 271 } |
270 | 272 |
271 bool UpdateContextMenuFunction::RunImpl() { | 273 bool UpdateContextMenuFunction::RunImpl() { |
272 ExtensionMenuItem::Id item_id(profile(), extension_id(), 0); | 274 ExtensionMenuItem::Id item_id(profile(), extension_id(), 0); |
273 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &item_id.uid)); | 275 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &item_id.uid)); |
274 | 276 |
275 ExtensionService* service = profile()->GetExtensionService(); | 277 ExtensionService* service = profile()->GetExtensionService(); |
276 ExtensionMenuManager* manager = service->menu_manager(); | 278 ExtensionMenuManager* manager = service->menu_manager(); |
277 ExtensionMenuItem* item = manager->GetItemById(item_id); | 279 ExtensionMenuItem* item = manager->GetItemById(item_id); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 // Parent id. | 327 // Parent id. |
326 ExtensionMenuItem* parent = NULL; | 328 ExtensionMenuItem* parent = NULL; |
327 if (!GetParent(*properties, *menu_manager, &parent)) | 329 if (!GetParent(*properties, *menu_manager, &parent)) |
328 return false; | 330 return false; |
329 if (parent && !menu_manager->ChangeParent(item->id(), &parent->id())) | 331 if (parent && !menu_manager->ChangeParent(item->id(), &parent->id())) |
330 return false; | 332 return false; |
331 | 333 |
332 if (!SetURLPatterns(*properties, item)) | 334 if (!SetURLPatterns(*properties, item)) |
333 return false; | 335 return false; |
334 | 336 |
337 menu_manager->SanitizeRadioButtons(); | |
338 | |
335 return true; | 339 return true; |
336 } | 340 } |
337 | 341 |
338 bool RemoveContextMenuFunction::RunImpl() { | 342 bool RemoveContextMenuFunction::RunImpl() { |
339 ExtensionMenuItem::Id id(profile(), extension_id(), 0); | 343 ExtensionMenuItem::Id id(profile(), extension_id(), 0); |
340 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &id.uid)); | 344 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &id.uid)); |
341 ExtensionService* service = profile()->GetExtensionService(); | 345 ExtensionService* service = profile()->GetExtensionService(); |
342 ExtensionMenuManager* manager = service->menu_manager(); | 346 ExtensionMenuManager* manager = service->menu_manager(); |
343 | 347 |
344 ExtensionMenuItem* item = manager->GetItemById(id); | 348 ExtensionMenuItem* item = manager->GetItemById(id); |
345 // Ensure one extension can't remove another's menu items. | 349 // Ensure one extension can't remove another's menu items. |
346 if (!item || item->extension_id() != extension_id()) { | 350 if (!item || item->extension_id() != extension_id()) { |
347 error_ = ExtensionErrorUtils::FormatErrorMessage( | 351 error_ = ExtensionErrorUtils::FormatErrorMessage( |
348 kCannotFindItemError, base::IntToString(id.uid)); | 352 kCannotFindItemError, base::IntToString(id.uid)); |
349 return false; | 353 return false; |
350 } | 354 } |
351 | 355 |
352 return manager->RemoveContextMenuItem(id); | 356 if (manager->RemoveContextMenuItem(id)) { |
Aaron Boodman
2011/12/15 00:43:21
We usually prefer the opposite pattern:
if (!some
| |
357 manager->SanitizeRadioButtons(); | |
358 return true; | |
359 } | |
360 | |
361 return false; | |
353 } | 362 } |
354 | 363 |
355 bool RemoveAllContextMenusFunction::RunImpl() { | 364 bool RemoveAllContextMenusFunction::RunImpl() { |
356 ExtensionService* service = profile()->GetExtensionService(); | 365 ExtensionService* service = profile()->GetExtensionService(); |
357 ExtensionMenuManager* manager = service->menu_manager(); | 366 ExtensionMenuManager* manager = service->menu_manager(); |
358 manager->RemoveAllContextItems(extension_id()); | 367 manager->RemoveAllContextItems(extension_id()); |
359 return true; | 368 return true; |
360 } | 369 } |
OLD | NEW |