OLD | NEW |
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_menus/context_menus_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/menu_manager.h" | 13 #include "chrome/browser/extensions/menu_manager.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/api/context_menus.h" | 15 #include "chrome/common/extensions/api/context_menus.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 143 } |
144 | 144 |
145 } // namespace | 145 } // namespace |
146 | 146 |
147 namespace extensions { | 147 namespace extensions { |
148 | 148 |
149 namespace Create = api::context_menus::Create; | 149 namespace Create = api::context_menus::Create; |
150 namespace Remove = api::context_menus::Remove; | 150 namespace Remove = api::context_menus::Remove; |
151 namespace Update = api::context_menus::Update; | 151 namespace Update = api::context_menus::Update; |
152 | 152 |
153 bool CreateContextMenuFunction::RunImpl() { | 153 bool ContextMenusCreateFunction::RunImpl() { |
154 MenuItem::Id id(profile()->IsOffTheRecord(), extension_id()); | 154 MenuItem::Id id(profile()->IsOffTheRecord(), extension_id()); |
155 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 155 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
156 EXTENSION_FUNCTION_VALIDATE(params.get()); | 156 EXTENSION_FUNCTION_VALIDATE(params.get()); |
157 | 157 |
158 if (params->create_properties.id.get()) { | 158 if (params->create_properties.id.get()) { |
159 id.string_uid = *params->create_properties.id; | 159 id.string_uid = *params->create_properties.id; |
160 } else { | 160 } else { |
161 if (GetExtension()->has_lazy_background_page()) { | 161 if (GetExtension()->has_lazy_background_page()) { |
162 error_ = kIdRequiredError; | 162 error_ = kIdRequiredError; |
163 return false; | 163 return false; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 success = menu_manager->AddContextItem(GetExtension(), item.release()); | 238 success = menu_manager->AddContextItem(GetExtension(), item.release()); |
239 } | 239 } |
240 | 240 |
241 if (!success) | 241 if (!success) |
242 return false; | 242 return false; |
243 | 243 |
244 menu_manager->WriteToStorage(GetExtension()); | 244 menu_manager->WriteToStorage(GetExtension()); |
245 return true; | 245 return true; |
246 } | 246 } |
247 | 247 |
248 bool UpdateContextMenuFunction::RunImpl() { | 248 bool ContextMenusUpdateFunction::RunImpl() { |
249 bool radio_item_updated = false; | 249 bool radio_item_updated = false; |
250 MenuItem::Id item_id(profile()->IsOffTheRecord(), extension_id()); | 250 MenuItem::Id item_id(profile()->IsOffTheRecord(), extension_id()); |
251 scoped_ptr<Update::Params> params(Update::Params::Create(*args_)); | 251 scoped_ptr<Update::Params> params(Update::Params::Create(*args_)); |
252 | 252 |
253 EXTENSION_FUNCTION_VALIDATE(params.get()); | 253 EXTENSION_FUNCTION_VALIDATE(params.get()); |
254 switch (params->id_type) { | 254 switch (params->id_type) { |
255 case Update::Params::ID_STRING: | 255 case Update::Params::ID_STRING: |
256 item_id.string_uid = *params->id_string; | 256 item_id.string_uid = *params->id_string; |
257 break; | 257 break; |
258 case Update::Params::ID_INTEGER: | 258 case Update::Params::ID_INTEGER: |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 // There is no need to call ItemUpdated if ChangeParent is called because | 348 // There is no need to call ItemUpdated if ChangeParent is called because |
349 // all sanitation is taken care of in ChangeParent. | 349 // all sanitation is taken care of in ChangeParent. |
350 if (!parent && radio_item_updated && !manager->ItemUpdated(item->id())) | 350 if (!parent && radio_item_updated && !manager->ItemUpdated(item->id())) |
351 return false; | 351 return false; |
352 | 352 |
353 manager->WriteToStorage(GetExtension()); | 353 manager->WriteToStorage(GetExtension()); |
354 return true; | 354 return true; |
355 } | 355 } |
356 | 356 |
357 bool RemoveContextMenuFunction::RunImpl() { | 357 bool ContextMenusRemoveFunction::RunImpl() { |
358 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); | 358 scoped_ptr<Remove::Params> params(Remove::Params::Create(*args_)); |
359 EXTENSION_FUNCTION_VALIDATE(params.get()); | 359 EXTENSION_FUNCTION_VALIDATE(params.get()); |
360 | 360 |
361 ExtensionService* service = profile()->GetExtensionService(); | 361 ExtensionService* service = profile()->GetExtensionService(); |
362 MenuManager* manager = service->menu_manager(); | 362 MenuManager* manager = service->menu_manager(); |
363 | 363 |
364 MenuItem::Id id(profile()->IsOffTheRecord(), extension_id()); | 364 MenuItem::Id id(profile()->IsOffTheRecord(), extension_id()); |
365 switch (params->menu_item_id_type) { | 365 switch (params->menu_item_id_type) { |
366 case Remove::Params::MENU_ITEM_ID_STRING: | 366 case Remove::Params::MENU_ITEM_ID_STRING: |
367 id.string_uid = *params->menu_item_id_string; | 367 id.string_uid = *params->menu_item_id_string; |
(...skipping 12 matching lines...) Expand all Loading... |
380 kCannotFindItemError, GetIDString(id)); | 380 kCannotFindItemError, GetIDString(id)); |
381 return false; | 381 return false; |
382 } | 382 } |
383 | 383 |
384 if (!manager->RemoveContextMenuItem(id)) | 384 if (!manager->RemoveContextMenuItem(id)) |
385 return false; | 385 return false; |
386 manager->WriteToStorage(GetExtension()); | 386 manager->WriteToStorage(GetExtension()); |
387 return true; | 387 return true; |
388 } | 388 } |
389 | 389 |
390 bool RemoveAllContextMenusFunction::RunImpl() { | 390 bool ContextMenusRemoveAllFunction::RunImpl() { |
391 ExtensionService* service = profile()->GetExtensionService(); | 391 ExtensionService* service = profile()->GetExtensionService(); |
392 MenuManager* manager = service->menu_manager(); | 392 MenuManager* manager = service->menu_manager(); |
393 manager->RemoveAllContextItems(GetExtension()->id()); | 393 manager->RemoveAllContextItems(GetExtension()->id()); |
394 manager->WriteToStorage(GetExtension()); | 394 manager->WriteToStorage(GetExtension()); |
395 return true; | 395 return true; |
396 } | 396 } |
397 | 397 |
398 } // namespace extensions | 398 } // namespace extensions |
OLD | NEW |