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

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

Issue 709813004: Remove the deprecated function ExtensionService::extensions(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed thestig@'s comments. Created 6 years, 1 month 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 "chrome/browser/extensions/extension_keybinding_registry.h" 5 #include "chrome/browser/extensions/extension_keybinding_registry.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/extensions/active_tab_permission_granter.h" 8 #include "chrome/browser/extensions/active_tab_permission_granter.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/command.h" 10 #include "chrome/common/extensions/command.h"
12 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
13 #include "extensions/browser/event_router.h" 12 #include "extensions/browser/event_router.h"
14 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/extension_system.h"
16 #include "extensions/browser/notification_types.h" 14 #include "extensions/browser/notification_types.h"
17 #include "extensions/common/extension_set.h" 15 #include "extensions/common/extension_set.h"
18 #include "extensions/common/manifest_constants.h" 16 #include "extensions/common/manifest_constants.h"
19 17
20 namespace { 18 namespace {
21 const char kOnCommandEventName[] = "commands.onCommand"; 19 const char kOnCommandEventName[] = "commands.onCommand";
22 } // namespace 20 } // namespace
23 21
24 namespace extensions { 22 namespace extensions {
25 23
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 66
69 // If a specific command_name was requested, it has now been deleted so no 67 // If a specific command_name was requested, it has now been deleted so no
70 // further work is required. 68 // further work is required.
71 if (!command_name.empty()) 69 if (!command_name.empty())
72 break; 70 break;
73 } 71 }
74 } 72 }
75 } 73 }
76 74
77 void ExtensionKeybindingRegistry::Init() { 75 void ExtensionKeybindingRegistry::Init() {
78 ExtensionService* service = 76 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
79 ExtensionSystem::Get(browser_context_)->extension_service(); 77 if (!registry)
80 if (!service) 78 return; // ExtensionRegistry can be null during testing.
81 return; // ExtensionService can be null during testing.
82 79
83 const ExtensionSet* extensions = service->extensions(); 80 for (const scoped_refptr<const extensions::Extension>& extension :
84 ExtensionSet::const_iterator iter = extensions->begin(); 81 registry->enabled_extensions())
85 for (; iter != extensions->end(); ++iter) 82 if (ExtensionMatchesFilter(extension.get()))
86 if (ExtensionMatchesFilter(iter->get())) 83 AddExtensionKeybinding(extension.get(), std::string());
87 AddExtensionKeybinding(iter->get(), std::string());
88 } 84 }
89 85
90 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( 86 bool ExtensionKeybindingRegistry::ShouldIgnoreCommand(
91 const std::string& command) const { 87 const std::string& command) const {
92 return command == manifest_values::kPageActionCommandEvent || 88 return command == manifest_values::kPageActionCommandEvent ||
93 command == manifest_values::kBrowserActionCommandEvent; 89 command == manifest_values::kBrowserActionCommandEvent;
94 } 90 }
95 91
96 bool ExtensionKeybindingRegistry::NotifyEventTargets( 92 bool ExtensionKeybindingRegistry::NotifyEventTargets(
97 const ui::Accelerator& accelerator) { 93 const ui::Accelerator& accelerator) {
98 return ExecuteCommands(accelerator, std::string()); 94 return ExecuteCommands(accelerator, std::string());
99 } 95 }
100 96
101 void ExtensionKeybindingRegistry::CommandExecuted( 97 void ExtensionKeybindingRegistry::CommandExecuted(
102 const std::string& extension_id, const std::string& command) { 98 const std::string& extension_id, const std::string& command) {
103 ExtensionService* service = 99 const Extension* extension = ExtensionRegistry::Get(browser_context_)
104 ExtensionSystem::Get(browser_context_)->extension_service(); 100 ->enabled_extensions()
105 101 .GetByID(extension_id);
106 const Extension* extension = service->extensions()->GetByID(extension_id);
107 if (!extension) 102 if (!extension)
108 return; 103 return;
109 104
110 // Grant before sending the event so that the permission is granted before 105 // Grant before sending the event so that the permission is granted before
111 // the extension acts on the command. NOTE: The Global Commands handler does 106 // the extension acts on the command. NOTE: The Global Commands handler does
112 // not set the delegate as it deals only with named commands (not page/browser 107 // not set the delegate as it deals only with named commands (not page/browser
113 // actions that are associated with the current page directly). 108 // actions that are associated with the current page directly).
114 ActiveTabPermissionGranter* granter = 109 ActiveTabPermissionGranter* granter =
115 delegate_ ? delegate_->GetActiveTabPermissionGranter() : NULL; 110 delegate_ ? delegate_->GetActiveTabPermissionGranter() : NULL;
116 if (granter) 111 if (granter)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int type, 182 int type,
188 const content::NotificationSource& source, 183 const content::NotificationSource& source,
189 const content::NotificationDetails& details) { 184 const content::NotificationDetails& details) {
190 switch (type) { 185 switch (type) {
191 case extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED: 186 case extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED:
192 case extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { 187 case extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED: {
193 std::pair<const std::string, const std::string>* payload = 188 std::pair<const std::string, const std::string>* payload =
194 content::Details<std::pair<const std::string, const std::string> >( 189 content::Details<std::pair<const std::string, const std::string> >(
195 details).ptr(); 190 details).ptr();
196 191
197 const Extension* extension = ExtensionSystem::Get(browser_context_) 192 const Extension* extension = ExtensionRegistry::Get(browser_context_)
198 ->extension_service() 193 ->enabled_extensions()
199 ->extensions() 194 .GetByID(payload->first);
200 ->GetByID(payload->first);
201 // During install and uninstall the extension won't be found. We'll catch 195 // During install and uninstall the extension won't be found. We'll catch
202 // those events above, with the LOADED/UNLOADED, so we ignore this event. 196 // those events above, with the LOADED/UNLOADED, so we ignore this event.
203 if (!extension) 197 if (!extension)
204 return; 198 return;
205 199
206 if (ExtensionMatchesFilter(extension)) { 200 if (ExtensionMatchesFilter(extension)) {
207 if (type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED) 201 if (type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED)
208 AddExtensionKeybinding(extension, payload->second); 202 AddExtensionKeybinding(extension, payload->second);
209 else 203 else
210 RemoveExtensionKeybinding(extension, payload->second); 204 RemoveExtensionKeybinding(extension, payload->second);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 if (extension_id.empty() || it->first == extension_id) { 242 if (extension_id.empty() || it->first == extension_id) {
249 CommandExecuted(it->first, it->second); 243 CommandExecuted(it->first, it->second);
250 executed = true; 244 executed = true;
251 } 245 }
252 } 246 }
253 247
254 return executed; 248 return executed;
255 } 249 }
256 250
257 } // namespace extensions 251 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_functional_browsertest.cc ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698