| 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
| 7 #include "chrome/browser/extensions/context_menu_matcher.h" | 7 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { | 128 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { |
| 129 MenuItem* item = GetExtensionMenuItem(command_id); | 129 MenuItem* item = GetExtensionMenuItem(command_id); |
| 130 if (!item) | 130 if (!item) |
| 131 return true; | 131 return true; |
| 132 return item->enabled(); | 132 return item->enabled(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void ContextMenuMatcher::ExecuteCommand(int command_id, | 135 void ContextMenuMatcher::ExecuteCommand(int command_id, |
| 136 content::WebContents* web_contents, | 136 content::WebContents* web_contents, |
| 137 const content::ContextMenuParams& params) { | 137 const content::ContextMenuParams& params) { |
| 138 MenuManager* manager = extensions::ExtensionSystem::Get(profile_)-> | |
| 139 extension_service()->menu_manager(); | |
| 140 MenuItem* item = GetExtensionMenuItem(command_id); | 138 MenuItem* item = GetExtensionMenuItem(command_id); |
| 141 if (!item) | 139 if (!item) |
| 142 return; | 140 return; |
| 143 | 141 |
| 142 MenuManager* manager = MenuManager::Get(profile_); |
| 144 manager->ExecuteCommand(profile_, web_contents, params, item->id()); | 143 manager->ExecuteCommand(profile_, web_contents, params, item->id()); |
| 145 } | 144 } |
| 146 | 145 |
| 147 bool ContextMenuMatcher::GetRelevantExtensionTopLevelItems( | 146 bool ContextMenuMatcher::GetRelevantExtensionTopLevelItems( |
| 148 const std::string& extension_id, | 147 const std::string& extension_id, |
| 149 const Extension** extension, | 148 const Extension** extension, |
| 150 bool* can_cross_incognito, | 149 bool* can_cross_incognito, |
| 151 MenuItem::List& items) { | 150 MenuItem::List& items) { |
| 152 ExtensionService* service = | 151 ExtensionService* service = |
| 153 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 152 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 154 MenuManager* manager = service->menu_manager(); | |
| 155 *extension = service->GetExtensionById(extension_id, false); | 153 *extension = service->GetExtensionById(extension_id, false); |
| 156 | 154 |
| 157 if (!*extension) | 155 if (!*extension) |
| 158 return false; | 156 return false; |
| 159 | 157 |
| 160 // Find matching items. | 158 // Find matching items. |
| 159 MenuManager* manager = MenuManager::Get(profile_); |
| 161 const MenuItem::List* all_items = manager->MenuItems(extension_id); | 160 const MenuItem::List* all_items = manager->MenuItems(extension_id); |
| 162 if (!all_items || all_items->empty()) | 161 if (!all_items || all_items->empty()) |
| 163 return false; | 162 return false; |
| 164 | 163 |
| 165 *can_cross_incognito = extension_util::CanCrossIncognito(*extension, service); | 164 *can_cross_incognito = extension_util::CanCrossIncognito(*extension, service); |
| 166 items = GetRelevantExtensionItems(*all_items, | 165 items = GetRelevantExtensionItems(*all_items, |
| 167 *can_cross_incognito); | 166 *can_cross_incognito); |
| 168 | 167 |
| 169 return true; | 168 return true; |
| 170 } | 169 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 239 |
| 241 menu_model->AddRadioItem(menu_id, title, radio_group_id); | 240 menu_model->AddRadioItem(menu_id, title, radio_group_id); |
| 242 } else if (item->type() == MenuItem::SEPARATOR) { | 241 } else if (item->type() == MenuItem::SEPARATOR) { |
| 243 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); | 242 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); |
| 244 } | 243 } |
| 245 last_type = item->type(); | 244 last_type = item->type(); |
| 246 } | 245 } |
| 247 } | 246 } |
| 248 | 247 |
| 249 MenuItem* ContextMenuMatcher::GetExtensionMenuItem(int id) const { | 248 MenuItem* ContextMenuMatcher::GetExtensionMenuItem(int id) const { |
| 250 MenuManager* manager = extensions::ExtensionSystem::Get(profile_)-> | 249 MenuManager* manager = MenuManager::Get(profile_); |
| 251 extension_service()->menu_manager(); | |
| 252 std::map<int, MenuItem::Id>::const_iterator i = | 250 std::map<int, MenuItem::Id>::const_iterator i = |
| 253 extension_item_map_.find(id); | 251 extension_item_map_.find(id); |
| 254 if (i != extension_item_map_.end()) { | 252 if (i != extension_item_map_.end()) { |
| 255 MenuItem* item = manager->GetItemById(i->second); | 253 MenuItem* item = manager->GetItemById(i->second); |
| 256 if (item) | 254 if (item) |
| 257 return item; | 255 return item; |
| 258 } | 256 } |
| 259 return NULL; | 257 return NULL; |
| 260 } | 258 } |
| 261 | 259 |
| 262 void ContextMenuMatcher::SetExtensionIcon(const std::string& extension_id) { | 260 void ContextMenuMatcher::SetExtensionIcon(const std::string& extension_id) { |
| 263 ExtensionService* service = | 261 MenuManager* menu_manager = MenuManager::Get(profile_); |
| 264 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
| 265 MenuManager* menu_manager = service->menu_manager(); | |
| 266 | 262 |
| 267 int index = menu_model_->GetItemCount() - 1; | 263 int index = menu_model_->GetItemCount() - 1; |
| 268 DCHECK_GE(index, 0); | 264 DCHECK_GE(index, 0); |
| 269 | 265 |
| 270 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | 266 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
| 271 DCHECK(icon.width() == gfx::kFaviconSize); | 267 DCHECK(icon.width() == gfx::kFaviconSize); |
| 272 DCHECK(icon.height() == gfx::kFaviconSize); | 268 DCHECK(icon.height() == gfx::kFaviconSize); |
| 273 | 269 |
| 274 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); | 270 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); |
| 275 } | 271 } |
| 276 | 272 |
| 277 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |