| 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_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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 MenuItem::ContextList* result) { | 61 MenuItem::ContextList* result) { |
| 62 ListValue* list = NULL; | 62 const ListValue* list = NULL; |
| 63 if (!properties.GetList(key, &list)) { | 63 if (!properties.GetList(key, &list)) { |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 MenuItem::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 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return (value->GetAsInteger(&result->uid) || | 150 return (value->GetAsInteger(&result->uid) || |
| 151 value->GetAsString(&result->string_uid)); | 151 value->GetAsString(&result->string_uid)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool ExtensionContextMenuFunction::GetParent(const DictionaryValue& properties, | 154 bool ExtensionContextMenuFunction::GetParent(const DictionaryValue& properties, |
| 155 const MenuManager& manager, | 155 const MenuManager& manager, |
| 156 MenuItem** result) { | 156 MenuItem** result) { |
| 157 if (!properties.HasKey(kParentIdKey)) | 157 if (!properties.HasKey(kParentIdKey)) |
| 158 return true; | 158 return true; |
| 159 MenuItem::Id parent_id(profile()->IsOffTheRecord(), extension_id()); | 159 MenuItem::Id parent_id(profile()->IsOffTheRecord(), extension_id()); |
| 160 Value* parent_id_value = NULL; | 160 const Value* parent_id_value = NULL; |
| 161 if (properties.Get(kParentIdKey, &parent_id_value) && | 161 if (properties.Get(kParentIdKey, &parent_id_value) && |
| 162 !ParseID(parent_id_value, &parent_id)) | 162 !ParseID(parent_id_value, &parent_id)) |
| 163 return false; | 163 return false; |
| 164 | 164 |
| 165 MenuItem* parent = manager.GetItemById(parent_id); | 165 MenuItem* parent = manager.GetItemById(parent_id); |
| 166 if (!parent) { | 166 if (!parent) { |
| 167 error_ = ExtensionErrorUtils::FormatErrorMessage( | 167 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 168 kCannotFindItemError, GetIDString(parent_id)); | 168 kCannotFindItemError, GetIDString(parent_id)); |
| 169 return false; | 169 return false; |
| 170 } | 170 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 368 |
| 369 bool RemoveAllContextMenusFunction::RunImpl() { | 369 bool RemoveAllContextMenusFunction::RunImpl() { |
| 370 ExtensionService* service = profile()->GetExtensionService(); | 370 ExtensionService* service = profile()->GetExtensionService(); |
| 371 MenuManager* manager = service->menu_manager(); | 371 MenuManager* manager = service->menu_manager(); |
| 372 manager->RemoveAllContextItems(GetExtension()->id()); | 372 manager->RemoveAllContextItems(GetExtension()->id()); |
| 373 manager->WriteToStorage(GetExtension()); | 373 manager->WriteToStorage(GetExtension()); |
| 374 return true; | 374 return true; |
| 375 } | 375 } |
| 376 | 376 |
| 377 } // namespace extensions | 377 } // namespace extensions |
| OLD | NEW |