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

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

Issue 10201016: Conflict detection for Extension Keybinding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressed comments Created 8 years, 7 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/extension_browser_event_router.h" 7 #include "chrome/browser/extensions/extension_browser_event_router.h"
8 #include "chrome/browser/extensions/extension_command_service.h"
9 #include "chrome/browser/extensions/extension_command_service_factory.h"
8 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
11 #include "ui/views/focus/focus_manager.h" 13 #include "ui/views/focus/focus_manager.h"
12 14
13 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews( 15 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews(
14 Profile* profile, views::FocusManager* focus_manager) 16 Profile* profile, views::FocusManager* focus_manager)
15 : ExtensionKeybindingRegistry(profile), 17 : ExtensionKeybindingRegistry(profile),
16 profile_(profile), 18 profile_(profile),
17 focus_manager_(focus_manager) { 19 focus_manager_(focus_manager) {
18 Init(); 20 Init();
19 } 21 }
20 22
21 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() { 23 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() {
22 EventTargets::const_iterator iter; 24 EventTargets::const_iterator iter;
23 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) 25 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter)
24 focus_manager_->UnregisterAccelerator(iter->first, this); 26 focus_manager_->UnregisterAccelerator(iter->first, this);
25 } 27 }
26 28
27 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding( 29 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding(
28 const Extension* extension) { 30 const Extension* extension) {
29 // Add all the keybindings (except pageAction and browserAction, which are 31 ExtensionCommandService* command_service =
30 // handled elsewhere). 32 ExtensionCommandServiceFactory::GetForProfile(profile_);
31 const Extension::CommandMap& commands = extension->named_commands(); 33 // Add all the active keybindings (except page actions and browser actions,
34 // which are handled elsewhere).
35 const Extension::CommandMap& commands =
36 command_service->GetActiveNamedCommands(extension->id());
32 Extension::CommandMap::const_iterator iter = commands.begin(); 37 Extension::CommandMap::const_iterator iter = commands.begin();
33 for (; iter != commands.end(); ++iter) { 38 for (; iter != commands.end(); ++iter) {
34 event_targets_[iter->second.accelerator()] = 39 event_targets_[iter->second.accelerator()] =
35 std::make_pair(extension->id(), iter->second.command_name()); 40 std::make_pair(extension->id(), iter->second.command_name());
36 focus_manager_->RegisterAccelerator( 41 focus_manager_->RegisterAccelerator(
37 iter->second.accelerator(), 42 iter->second.accelerator(),
38 ui::AcceleratorManager::kHighPriority, this); 43 ui::AcceleratorManager::kHighPriority, this);
39 } 44 }
40 } 45 }
41 46
42 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybinding( 47 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybinding(
43 const Extension* extension) { 48 const Extension* extension) {
44 EventTargets::const_iterator iter; 49 EventTargets::iterator iter = event_targets_.begin();
45 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) { 50 while (iter != event_targets_.end()) {
46 if (iter->second.first != extension->id()) 51 if (iter->second.first != extension->id()) {
52 ++iter;
47 continue; // Not the extension we asked for. 53 continue; // Not the extension we asked for.
54 }
48 55
49 focus_manager_->UnregisterAccelerator(iter->first, this); 56 focus_manager_->UnregisterAccelerator(iter->first, this);
57
58 EventTargets::iterator old = iter++;
59 event_targets_.erase(old);
50 } 60 }
51 } 61 }
52 62
53 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( 63 bool ExtensionKeybindingRegistryViews::AcceleratorPressed(
54 const ui::Accelerator& accelerator) { 64 const ui::Accelerator& accelerator) {
55 ExtensionService* service = profile_->GetExtensionService(); 65 ExtensionService* service = profile_->GetExtensionService();
56 66
57 EventTargets::iterator it = event_targets_.find(accelerator); 67 EventTargets::iterator it = event_targets_.find(accelerator);
58 if (it == event_targets_.end()) { 68 if (it == event_targets_.end()) {
59 NOTREACHED(); // Shouldn't get this event for something not registered. 69 NOTREACHED(); // Shouldn't get this event for something not registered.
60 return false; 70 return false;
61 } 71 }
62 72
63 service->browser_event_router()->CommandExecuted( 73 service->browser_event_router()->CommandExecuted(
64 profile_, it->second.first, it->second.second); 74 profile_, it->second.first, it->second.second);
65 75
66 return true; 76 return true;
67 } 77 }
68 78
69 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { 79 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const {
70 return true; 80 return true;
71 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698