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

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

Issue 504183004: Continue key propagation for extensions without any listeners to chrome.commands.onCommand. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Change manifest to use MacCtrl. Created 6 years, 3 months 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" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/command.h" 11 #include "chrome/common/extensions/command.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "extensions/browser/event_router.h" 13 #include "extensions/browser/event_router.h"
14 #include "extensions/browser/extension_registry.h" 14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/extension_system.h" 15 #include "extensions/browser/extension_system.h"
16 #include "extensions/browser/notification_types.h" 16 #include "extensions/browser/notification_types.h"
17 #include "extensions/common/extension_set.h" 17 #include "extensions/common/extension_set.h"
18 #include "extensions/common/manifest_constants.h" 18 #include "extensions/common/manifest_constants.h"
19 19
20 namespace {
21 const char kOnCommandEventName[] = "commands.onCommand";
22 } // namespace
23
20 namespace extensions { 24 namespace extensions {
21 25
22 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( 26 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry(
23 content::BrowserContext* context, 27 content::BrowserContext* context,
24 ExtensionFilter extension_filter, 28 ExtensionFilter extension_filter,
25 Delegate* delegate) 29 Delegate* delegate)
26 : browser_context_(context), 30 : browser_context_(context),
27 extension_filter_(extension_filter), 31 extension_filter_(extension_filter),
28 delegate_(delegate), 32 delegate_(delegate),
29 extension_registry_observer_(this) { 33 extension_registry_observer_(this) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // not set the delegate as it deals only with named commands (not page/browser 112 // not set the delegate as it deals only with named commands (not page/browser
109 // actions that are associated with the current page directly). 113 // actions that are associated with the current page directly).
110 ActiveTabPermissionGranter* granter = 114 ActiveTabPermissionGranter* granter =
111 delegate_ ? delegate_->GetActiveTabPermissionGranter() : NULL; 115 delegate_ ? delegate_->GetActiveTabPermissionGranter() : NULL;
112 if (granter) 116 if (granter)
113 granter->GrantIfRequested(extension); 117 granter->GrantIfRequested(extension);
114 118
115 scoped_ptr<base::ListValue> args(new base::ListValue()); 119 scoped_ptr<base::ListValue> args(new base::ListValue());
116 args->Append(new base::StringValue(command)); 120 args->Append(new base::StringValue(command));
117 121
118 scoped_ptr<Event> event(new Event("commands.onCommand", args.Pass())); 122 scoped_ptr<Event> event(new Event(kOnCommandEventName, args.Pass()));
119 event->restrict_to_browser_context = browser_context_; 123 event->restrict_to_browser_context = browser_context_;
120 event->user_gesture = EventRouter::USER_GESTURE_ENABLED; 124 event->user_gesture = EventRouter::USER_GESTURE_ENABLED;
121 EventRouter::Get(browser_context_) 125 EventRouter::Get(browser_context_)
122 ->DispatchEventToExtension(extension_id, event.Pass()); 126 ->DispatchEventToExtension(extension_id, event.Pass());
123 } 127 }
124 128
125 bool ExtensionKeybindingRegistry::IsAcceleratorRegistered( 129 bool ExtensionKeybindingRegistry::IsAcceleratorRegistered(
126 const ui::Accelerator& accelerator) const { 130 const ui::Accelerator& accelerator) const {
127 return event_targets_.find(accelerator) != event_targets_.end(); 131 return event_targets_.find(accelerator) != event_targets_.end();
128 } 132 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return false; 231 return false;
228 } 232 }
229 233
230 bool ExtensionKeybindingRegistry::ExecuteCommands( 234 bool ExtensionKeybindingRegistry::ExecuteCommands(
231 const ui::Accelerator& accelerator, 235 const ui::Accelerator& accelerator,
232 const std::string& extension_id) { 236 const std::string& extension_id) {
233 EventTargets::iterator targets = event_targets_.find(accelerator); 237 EventTargets::iterator targets = event_targets_.find(accelerator);
234 if (targets == event_targets_.end() || targets->second.empty()) 238 if (targets == event_targets_.end() || targets->second.empty())
235 return false; 239 return false;
236 240
241 if (!extension_id.empty() &&
242 !extensions::EventRouter::Get(browser_context_)
243 ->ExtensionHasEventListener(extension_id, kOnCommandEventName))
244 return false;
245
237 bool executed = false; 246 bool executed = false;
238 for (TargetList::const_iterator it = targets->second.begin(); 247 for (TargetList::const_iterator it = targets->second.begin();
239 it != targets->second.end(); it++) { 248 it != targets->second.end(); it++) {
240 if (extension_id.empty() || it->first == extension_id) { 249 if (extension_id.empty() || it->first == extension_id) {
241 CommandExecuted(it->first, it->second); 250 CommandExecuted(it->first, it->second);
242 executed = true; 251 executed = true;
243 } 252 }
244 } 253 }
245 254
246 return executed; 255 return executed;
247 } 256 }
248 257
249 } // namespace extensions 258 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698