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

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

Issue 64273008: [Windows] Finish global and non-global media keys support on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_commands_global_registry.h" 5 #include "chrome/browser/extensions/extension_commands_global_registry.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/api/commands/command_service.h" 9 #include "chrome/browser/extensions/api/commands/command_service.h"
10 #include "chrome/browser/extensions/extension_keybinding_registry.h" 10 #include "chrome/browser/extensions/extension_keybinding_registry.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/global_shortcut_listener.h" 12 #include "chrome/browser/extensions/global_shortcut_listener.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 15
16 namespace extensions { 16 namespace extensions {
17 17
18 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry( 18 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry(
19 Profile* profile) 19 Profile* profile)
20 : ExtensionKeybindingRegistry( 20 : ExtensionKeybindingRegistry(
21 profile, ExtensionKeybindingRegistry::ALL_EXTENSIONS, NULL), 21 profile, ExtensionKeybindingRegistry::ALL_EXTENSIONS, NULL),
22 profile_(profile) { 22 profile_(profile) {
23 Init(); 23 Init();
24 } 24 }
25 25
26 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { 26 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() {
27 EventTargets::const_iterator iter; 27 EventTargets::const_iterator eit;
28 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) { 28 for (eit = event_targets_.begin(); eit != event_targets_.end(); ++eit) {
29 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( 29 GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
30 iter->first, this); 30 eit->first, this);
31 }
Finnur 2013/11/12 16:27:54 I'm not too keen on the iter -> eit/mit change her
zhchbin 2013/11/13 05:01:57 Done.
32
33 MediaKeysEventTargets::const_iterator mit;
34 for (mit = media_keys_event_targets_.begin();
35 mit != media_keys_event_targets_.end();
36 ++mit) {
37 GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
38 mit->first, this);
31 } 39 }
32 } 40 }
33 41
34 static base::LazyInstance< 42 static base::LazyInstance<
35 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry> > 43 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry> >
36 g_factory = LAZY_INSTANCE_INITIALIZER; 44 g_factory = LAZY_INSTANCE_INITIALIZER;
37 45
38 // static 46 // static
39 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>* 47 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>*
40 ExtensionCommandsGlobalRegistry::GetFactoryInstance() { 48 ExtensionCommandsGlobalRegistry::GetFactoryInstance() {
(...skipping 28 matching lines...) Expand all
69 77
70 extensions::CommandMap::const_iterator iter = commands.begin(); 78 extensions::CommandMap::const_iterator iter = commands.begin();
71 for (; iter != commands.end(); ++iter) { 79 for (; iter != commands.end(); ++iter) {
72 if (!command_name.empty() && (iter->second.command_name() != command_name)) 80 if (!command_name.empty() && (iter->second.command_name() != command_name))
73 continue; 81 continue;
74 82
75 VLOG(0) << "Adding global keybinding for " << extension->name().c_str() 83 VLOG(0) << "Adding global keybinding for " << extension->name().c_str()
76 << " " << command_name.c_str() 84 << " " << command_name.c_str()
77 << " key: " << iter->second.accelerator().GetShortcutText(); 85 << " key: " << iter->second.accelerator().GetShortcutText();
78 86
79 event_targets_[iter->second.accelerator()] = 87 if (extensions::CommandService::IsMediaKey(iter->second.accelerator())) {
80 std::make_pair(extension->id(), iter->second.command_name()); 88 std::pair<std::string, std::string> target =
89 std::make_pair(extension->id(), iter->second.command_name());
90 media_keys_event_targets_[iter->second.accelerator()].push_back(target);
91 } else {
92 event_targets_[iter->second.accelerator()] =
93 std::make_pair(extension->id(), iter->second.command_name());
94 }
81 95
82 GlobalShortcutListener::GetInstance()->RegisterAccelerator( 96 GlobalShortcutListener::GetInstance()->RegisterAccelerator(
83 iter->second.accelerator(), this); 97 iter->second.accelerator(), this);
84 } 98 }
85 } 99 }
86 100
87 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl( 101 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl(
88 const ui::Accelerator& accelerator, 102 const ui::Accelerator& accelerator,
89 const std::string& command_name) { 103 const std::string& command_name) {
90 VLOG(0) << "Removing keybinding for " << command_name.c_str(); 104 VLOG(0) << "Removing keybinding for " << command_name.c_str();
91 105
92 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( 106 GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
93 accelerator, this); 107 accelerator, this);
94 } 108 }
95 109
96 void ExtensionCommandsGlobalRegistry::OnKeyPressed( 110 void ExtensionCommandsGlobalRegistry::OnKeyPressed(
97 const ui::Accelerator& accelerator) { 111 const ui::Accelerator& accelerator) {
98 EventTargets::iterator it = event_targets_.find(accelerator); 112 ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator(accelerator);
99 if (it == event_targets_.end()) {
100 NOTREACHED(); // Shouldn't get this event for something not registered.
101 return;
102 }
103
104 CommandExecuted(it->second.first, it->second.second);
105 } 113 }
106 114
107 } // namespace extensions 115 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698