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

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

Issue 109413003: Refactor GlobalShortcutListener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update as comments. Created 7 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
« no previous file with comments | « no previous file | chrome/browser/extensions/global_shortcut_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 74
75 VLOG(0) << "Adding global keybinding for " << extension->name().c_str() 75 VLOG(0) << "Adding global keybinding for " << extension->name().c_str()
76 << " " << command_name.c_str() 76 << " " << command_name.c_str()
77 << " key: " << iter->second.accelerator().GetShortcutText(); 77 << " key: " << iter->second.accelerator().GetShortcutText();
78 78
79 event_targets_[iter->second.accelerator()].push_back( 79 event_targets_[iter->second.accelerator()].push_back(
80 std::make_pair(extension->id(), iter->second.command_name())); 80 std::make_pair(extension->id(), iter->second.command_name()));
81 // Shortcuts except media keys have only one target in the list. See comment 81 if (!extensions::CommandService::IsMediaKey(iter->second.accelerator())) {
82 // about |event_targets_|. 82 // Shortcuts except media keys have only one target in the list. See
83 if (!extensions::CommandService::IsMediaKey(iter->second.accelerator())) 83 // comment about |event_targets_|.
84 DCHECK(event_targets_[iter->second.accelerator()].size() == 1); 84 DCHECK(event_targets_[iter->second.accelerator()].size() == 1);
85 } else if (event_targets_[iter->second.accelerator()].size() > 1) {
86 // Now the |iter->second.accelerator()| is one of the media keys, we have
87 // registerd it successfully, so pass it by.
88 continue;
89 }
85 90
86 GlobalShortcutListener::GetInstance()->RegisterAccelerator( 91 if (!GlobalShortcutListener::GetInstance()->RegisterAccelerator(
87 iter->second.accelerator(), this); 92 iter->second.accelerator(), this))
zhchbin 2013/12/17 13:34:32 You may ask why I didn't call RegisterAccelerator
Finnur 2013/12/17 14:31:40 Wondering if this would be simpler (you'll need to
zhchbin 2013/12/17 15:15:46 Thanks very much! In this case we should also pus
93 event_targets_.erase(iter->second.accelerator());
88 } 94 }
89 } 95 }
90 96
91 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl( 97 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl(
92 const ui::Accelerator& accelerator, 98 const ui::Accelerator& accelerator,
93 const std::string& command_name) { 99 const std::string& command_name) {
94 VLOG(0) << "Removing keybinding for " << command_name.c_str(); 100 VLOG(0) << "Removing keybinding for " << command_name.c_str();
95 101
96 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( 102 GlobalShortcutListener::GetInstance()->UnregisterAccelerator(
97 accelerator, this); 103 accelerator, this);
98 } 104 }
99 105
100 void ExtensionCommandsGlobalRegistry::OnKeyPressed( 106 void ExtensionCommandsGlobalRegistry::OnKeyPressed(
101 const ui::Accelerator& accelerator) { 107 const ui::Accelerator& accelerator) {
102 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); 108 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator);
103 } 109 }
104 110
105 } // namespace extensions 111 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/global_shortcut_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698