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

Side by Side Diff: chrome/browser/extensions/context_menu_matcher.cc

Issue 11365181: Remove GetExtensionService from Profile. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: replace missing extension_system include Created 8 years 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 "base/utf_string_conversions.h" 5 #include "base/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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/common/context_menu_params.h" 11 #include "content/public/common/context_menu_params.h"
11 #include "ui/gfx/favicon_size.h" 12 #include "ui/gfx/favicon_size.h"
12 13
13 namespace extensions { 14 namespace extensions {
14 15
15 // static 16 // static
16 const size_t ContextMenuMatcher::kMaxExtensionItemTitleLength = 75; 17 const size_t ContextMenuMatcher::kMaxExtensionItemTitleLength = 75;
17 18
18 ContextMenuMatcher::ContextMenuMatcher( 19 ContextMenuMatcher::ContextMenuMatcher(
19 Profile* profile, 20 Profile* profile,
20 ui::SimpleMenuModel::Delegate* delegate, 21 ui::SimpleMenuModel::Delegate* delegate,
21 ui::SimpleMenuModel* menu_model, 22 ui::SimpleMenuModel* menu_model,
22 const base::Callback<bool(const MenuItem*)>& filter) 23 const base::Callback<bool(const MenuItem*)>& filter)
23 : profile_(profile), menu_model_(menu_model), delegate_(delegate), 24 : profile_(profile), menu_model_(menu_model), delegate_(delegate),
24 filter_(filter) { 25 filter_(filter) {
25 } 26 }
26 27
27 void ContextMenuMatcher::AppendExtensionItems(const std::string& extension_id, 28 void ContextMenuMatcher::AppendExtensionItems(const std::string& extension_id,
28 const string16& selection_text, 29 const string16& selection_text,
29 int* index) 30 int* index)
30 { 31 {
31 ExtensionService* service = profile_->GetExtensionService(); 32 ExtensionService* service =
33 extensions::ExtensionSystem::Get(profile_)->extension_service();
32 MenuManager* manager = service->menu_manager(); 34 MenuManager* manager = service->menu_manager();
33 const Extension* extension = service->GetExtensionById(extension_id, false); 35 const Extension* extension = service->GetExtensionById(extension_id, false);
34 DCHECK_GE(*index, 0); 36 DCHECK_GE(*index, 0);
35 int max_index = 37 int max_index =
36 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; 38 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
37 if (!extension || *index >= max_index) 39 if (!extension || *index >= max_index)
38 return; 40 return;
39 41
40 // Find matching items. 42 // Find matching items.
41 const MenuItem::List* all_items = manager->MenuItems(extension_id); 43 const MenuItem::List* all_items = manager->MenuItems(extension_id);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { 110 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const {
109 MenuItem* item = GetExtensionMenuItem(command_id); 111 MenuItem* item = GetExtensionMenuItem(command_id);
110 if (!item) 112 if (!item)
111 return true; 113 return true;
112 return item->enabled(); 114 return item->enabled();
113 } 115 }
114 116
115 void ContextMenuMatcher::ExecuteCommand(int command_id, 117 void ContextMenuMatcher::ExecuteCommand(int command_id,
116 content::WebContents* web_contents, 118 content::WebContents* web_contents,
117 const content::ContextMenuParams& params) { 119 const content::ContextMenuParams& params) {
118 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); 120 MenuManager* manager = extensions::ExtensionSystem::Get(profile_)->
121 extension_service()->menu_manager();
119 MenuItem* item = GetExtensionMenuItem(command_id); 122 MenuItem* item = GetExtensionMenuItem(command_id);
120 if (!item) 123 if (!item)
121 return; 124 return;
122 125
123 manager->ExecuteCommand(profile_, web_contents, params, item->id()); 126 manager->ExecuteCommand(profile_, web_contents, params, item->id());
124 } 127 }
125 128
126 MenuItem::List ContextMenuMatcher::GetRelevantExtensionItems( 129 MenuItem::List ContextMenuMatcher::GetRelevantExtensionItems(
127 const MenuItem::List& items, 130 const MenuItem::List& items,
128 bool can_cross_incognito) { 131 bool can_cross_incognito) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } else if (item->type() == MenuItem::SEPARATOR) { 200 } else if (item->type() == MenuItem::SEPARATOR) {
198 if (i != items.begin() && last_type != MenuItem::SEPARATOR) { 201 if (i != items.begin() && last_type != MenuItem::SEPARATOR) {
199 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); 202 menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
200 } 203 }
201 } 204 }
202 last_type = item->type(); 205 last_type = item->type();
203 } 206 }
204 } 207 }
205 208
206 MenuItem* ContextMenuMatcher::GetExtensionMenuItem(int id) const { 209 MenuItem* ContextMenuMatcher::GetExtensionMenuItem(int id) const {
207 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); 210 MenuManager* manager = extensions::ExtensionSystem::Get(profile_)->
211 extension_service()->menu_manager();
208 std::map<int, MenuItem::Id>::const_iterator i = 212 std::map<int, MenuItem::Id>::const_iterator i =
209 extension_item_map_.find(id); 213 extension_item_map_.find(id);
210 if (i != extension_item_map_.end()) { 214 if (i != extension_item_map_.end()) {
211 MenuItem* item = manager->GetItemById(i->second); 215 MenuItem* item = manager->GetItemById(i->second);
212 if (item) 216 if (item)
213 return item; 217 return item;
214 } 218 }
215 return NULL; 219 return NULL;
216 } 220 }
217 221
218 void ContextMenuMatcher::SetExtensionIcon(const std::string& extension_id) { 222 void ContextMenuMatcher::SetExtensionIcon(const std::string& extension_id) {
219 ExtensionService* service = profile_->GetExtensionService(); 223 ExtensionService* service =
224 extensions::ExtensionSystem::Get(profile_)->extension_service();
220 MenuManager* menu_manager = service->menu_manager(); 225 MenuManager* menu_manager = service->menu_manager();
221 226
222 int index = menu_model_->GetItemCount() - 1; 227 int index = menu_model_->GetItemCount() - 1;
223 DCHECK_GE(index, 0); 228 DCHECK_GE(index, 0);
224 229
225 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); 230 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id);
226 DCHECK(icon.width() == gfx::kFaviconSize); 231 DCHECK(icon.width() == gfx::kFaviconSize);
227 DCHECK(icon.height() == gfx::kFaviconSize); 232 DCHECK(icon.height() == gfx::kFaviconSize);
228 233
229 menu_model_->SetIcon(index, gfx::Image(icon)); 234 menu_model_->SetIcon(index, gfx::Image(icon));
230 } 235 }
231 236
232 } // namespace extensions 237 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/browser_action_apitest.cc ('k') | chrome/browser/extensions/crx_installer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698