OLD | NEW |
---|---|
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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 extension->id(), | 64 extension->id(), |
65 extensions::CommandService::ACTIVE_ONLY, | 65 extensions::CommandService::ACTIVE_ONLY, |
66 extensions::CommandService::GLOBAL, | 66 extensions::CommandService::GLOBAL, |
67 &commands)) | 67 &commands)) |
68 return; | 68 return; |
69 | 69 |
70 extensions::CommandMap::const_iterator iter = commands.begin(); | 70 extensions::CommandMap::const_iterator iter = commands.begin(); |
71 for (; iter != commands.end(); ++iter) { | 71 for (; iter != commands.end(); ++iter) { |
72 if (!command_name.empty() && (iter->second.command_name() != command_name)) | 72 if (!command_name.empty() && (iter->second.command_name() != command_name)) |
73 continue; | 73 continue; |
74 const ui::Accelerator& accelerator = iter->second.accelerator(); | |
74 | 75 |
75 VLOG(0) << "Adding global keybinding for " << extension->name().c_str() | 76 VLOG(0) << "Adding global keybinding for " << extension->name().c_str() |
76 << " " << command_name.c_str() | 77 << " " << command_name.c_str() |
77 << " key: " << iter->second.accelerator().GetShortcutText(); | 78 << " key: " << accelerator.GetShortcutText(); |
78 | 79 |
79 event_targets_[iter->second.accelerator()].push_back( | 80 size_t target_count = |
80 std::make_pair(extension->id(), iter->second.command_name())); | 81 event_targets_.find(accelerator) != event_targets_.end() ? |
81 // Shortcuts except media keys have only one target in the list. See comment | 82 event_targets_[accelerator].size() : 0; |
82 // about |event_targets_|. | 83 if (extensions::CommandService::IsMediaKey(accelerator) && |
83 if (!extensions::CommandService::IsMediaKey(iter->second.accelerator())) | 84 target_count > 0U) { |
84 DCHECK(event_targets_[iter->second.accelerator()].size() == 1); | 85 event_targets_[accelerator].push_back( |
86 std::make_pair(extension->id(), iter->second.command_name())); | |
87 continue; // Shortcut listener already listening for this media key. | |
88 } | |
85 | 89 |
86 GlobalShortcutListener::GetInstance()->RegisterAccelerator( | 90 DCHECK_EQ(0U, target_count); |
87 iter->second.accelerator(), this); | 91 if (GlobalShortcutListener::GetInstance()->RegisterAccelerator( |
92 accelerator, this)) { | |
93 event_targets_[accelerator].push_back( | |
94 std::make_pair(extension->id(), iter->second.command_name())); | |
95 } | |
Finnur
2013/12/17 16:35:45
Good catch. But I think a better alternative is (p
zhchbin
2013/12/18 01:53:07
Done. See the newest patch, actually the problem i
| |
88 } | 96 } |
89 } | 97 } |
90 | 98 |
91 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl( | 99 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl( |
92 const ui::Accelerator& accelerator, | 100 const ui::Accelerator& accelerator, |
93 const std::string& command_name) { | 101 const std::string& command_name) { |
94 VLOG(0) << "Removing keybinding for " << command_name.c_str(); | 102 VLOG(0) << "Removing keybinding for " << command_name.c_str(); |
95 | 103 |
96 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( | 104 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
97 accelerator, this); | 105 accelerator, this); |
98 } | 106 } |
99 | 107 |
100 void ExtensionCommandsGlobalRegistry::OnKeyPressed( | 108 void ExtensionCommandsGlobalRegistry::OnKeyPressed( |
101 const ui::Accelerator& accelerator) { | 109 const ui::Accelerator& accelerator) { |
102 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 110 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
103 } | 111 } |
104 | 112 |
105 } // namespace extensions | 113 } // namespace extensions |
OLD | NEW |