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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc

Issue 23812010: Implement first part of supporting global extension commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gclient sync Created 7 years, 2 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 | Annotate | Revision Log
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/ui/views/extensions/extension_keybinding_registry_views .h" 5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
6 6
7 #include "chrome/browser/extensions/api/commands/command_service.h" 7 #include "chrome/browser/extensions/api/commands/command_service.h"
8 #include "chrome/browser/extensions/extension_keybinding_registry.h" 8 #include "chrome/browser/extensions/extension_keybinding_registry.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"
(...skipping 29 matching lines...) Expand all
40 // This object only handles named commands, not browser/page actions. 40 // This object only handles named commands, not browser/page actions.
41 if (ShouldIgnoreCommand(command_name)) 41 if (ShouldIgnoreCommand(command_name))
42 return; 42 return;
43 43
44 extensions::CommandService* command_service = 44 extensions::CommandService* command_service =
45 extensions::CommandService::Get(profile_); 45 extensions::CommandService::Get(profile_);
46 // Add all the active keybindings (except page actions and browser actions, 46 // Add all the active keybindings (except page actions and browser actions,
47 // which are handled elsewhere). 47 // which are handled elsewhere).
48 extensions::CommandMap commands; 48 extensions::CommandMap commands;
49 if (!command_service->GetNamedCommands( 49 if (!command_service->GetNamedCommands(
50 extension->id(), extensions::CommandService::ACTIVE_ONLY, &commands)) 50 extension->id(),
51 extensions::CommandService::ACTIVE_ONLY,
52 extensions::CommandService::REGULAR,
53 &commands))
51 return; 54 return;
52 extensions::CommandMap::const_iterator iter = commands.begin(); 55 extensions::CommandMap::const_iterator iter = commands.begin();
53 for (; iter != commands.end(); ++iter) { 56 for (; iter != commands.end(); ++iter) {
54 if (!command_name.empty() && (iter->second.command_name() != command_name)) 57 if (!command_name.empty() && (iter->second.command_name() != command_name))
55 continue; 58 continue;
56 59
57 event_targets_[iter->second.accelerator()] = 60 event_targets_[iter->second.accelerator()] =
58 std::make_pair(extension->id(), iter->second.command_name()); 61 std::make_pair(extension->id(), iter->second.command_name());
59 focus_manager_->RegisterAccelerator( 62 focus_manager_->RegisterAccelerator(
60 iter->second.accelerator(), 63 iter->second.accelerator(),
61 ui::AcceleratorManager::kHighPriority, this); 64 ui::AcceleratorManager::kHighPriority, this);
62 } 65 }
63 } 66 }
64 67
65 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybinding( 68 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl(
66 const extensions::Extension* extension, 69 const ui::Accelerator& accelerator,
67 const std::string& command_name) { 70 const std::string& command_name) {
68 // This object only handles named commands, not browser/page actions. 71 focus_manager_->UnregisterAccelerator(accelerator, this);
69 if (ShouldIgnoreCommand(command_name))
70 return;
71
72 EventTargets::iterator iter = event_targets_.begin();
73 while (iter != event_targets_.end()) {
74 if (iter->second.first != extension->id() ||
75 (!command_name.empty() && (iter->second.second != command_name))) {
76 ++iter;
77 continue; // Not the extension or command we asked for.
78 }
79
80 focus_manager_->UnregisterAccelerator(iter->first, this);
81
82 EventTargets::iterator old = iter++;
83 event_targets_.erase(old);
84 }
85 } 72 }
86 73
87 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( 74 bool ExtensionKeybindingRegistryViews::AcceleratorPressed(
88 const ui::Accelerator& accelerator) { 75 const ui::Accelerator& accelerator) {
89 EventTargets::iterator it = event_targets_.find(accelerator); 76 EventTargets::iterator it = event_targets_.find(accelerator);
90 if (it == event_targets_.end()) { 77 if (it == event_targets_.end()) {
91 NOTREACHED(); // Shouldn't get this event for something not registered. 78 NOTREACHED(); // Shouldn't get this event for something not registered.
92 return false; 79 return false;
93 } 80 }
94 81
95 CommandExecuted(it->second.first, it->second.second); 82 CommandExecuted(it->second.first, it->second.second);
96 83
97 return true; 84 return true;
98 } 85 }
99 86
100 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { 87 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const {
101 return true; 88 return true;
102 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698