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

Side by Side Diff: chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc

Issue 10834393: Make sure events for browser actions, page actions and script badges are not delivered twice. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | 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) 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/gtk/extensions/extension_keybinding_registry_gtk.h" 5 #include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.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/api/commands/command_service_factory.h" 8 #include "chrome/browser/extensions/api/commands/command_service_factory.h"
9 #include "chrome/browser/extensions/browser_event_router.h" 9 #include "chrome/browser/extensions/browser_event_router.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 event->state & GDK_MOD1_MASK); 52 event->state & GDK_MOD1_MASK);
53 return event_targets_.find(accelerator) != event_targets_.end(); 53 return event_targets_.find(accelerator) != event_targets_.end();
54 } 54 }
55 55
56 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding( 56 void ExtensionKeybindingRegistryGtk::AddExtensionKeybinding(
57 const extensions::Extension* extension, 57 const extensions::Extension* extension,
58 const std::string& command_name) { 58 const std::string& command_name) {
59 extensions::CommandService* command_service = 59 extensions::CommandService* command_service =
60 extensions::CommandServiceFactory::GetForProfile(profile_); 60 extensions::CommandServiceFactory::GetForProfile(profile_);
61 extensions::CommandMap commands; 61 extensions::CommandMap commands;
62 if (!command_service->GetNamedCommands( 62 command_service->GetNamedCommands(
63 extension->id(), 63 extension->id(),
64 extensions::CommandService::ACTIVE_ONLY, 64 extensions::CommandService::ACTIVE_ONLY,
65 &commands)) { 65 &commands);
66 return;
67 }
Finnur 2012/08/17 14:45:29 The bug I'm fixing is that if the extension has no
68 66
69 for (extensions::CommandMap::const_iterator iter = commands.begin(); 67 for (extensions::CommandMap::const_iterator iter = commands.begin();
70 iter != commands.end(); ++iter) { 68 iter != commands.end(); ++iter) {
71 if (!command_name.empty() && (iter->second.command_name() != command_name)) 69 if (!command_name.empty() && (iter->second.command_name() != command_name))
72 continue; 70 continue;
73 71
74 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(), 72 ui::AcceleratorGtk accelerator(iter->second.accelerator().key_code(),
75 iter->second.accelerator().IsShiftDown(), 73 iter->second.accelerator().IsShiftDown(),
76 iter->second.accelerator().IsCtrlDown(), 74 iter->second.accelerator().IsCtrlDown(),
77 iter->second.accelerator().IsAltDown()); 75 iter->second.accelerator().IsAltDown());
(...skipping 23 matching lines...) Expand all
101 &browser_action, 99 &browser_action,
102 NULL)) { 100 NULL)) {
103 ui::AcceleratorGtk accelerator(browser_action.accelerator().key_code(), 101 ui::AcceleratorGtk accelerator(browser_action.accelerator().key_code(),
104 browser_action.accelerator().IsShiftDown(), 102 browser_action.accelerator().IsShiftDown(),
105 browser_action.accelerator().IsCtrlDown(), 103 browser_action.accelerator().IsCtrlDown(),
106 browser_action.accelerator().IsAltDown()); 104 browser_action.accelerator().IsAltDown());
107 event_targets_[accelerator] = 105 event_targets_[accelerator] =
108 std::make_pair(extension->id(), browser_action.command_name()); 106 std::make_pair(extension->id(), browser_action.command_name());
109 } 107 }
110 108
109 // Add the Page Action (if any).
111 extensions::Command page_action; 110 extensions::Command page_action;
112 if (command_service->GetPageActionCommand( 111 if (command_service->GetPageActionCommand(
113 extension->id(), 112 extension->id(),
114 extensions::CommandService::ACTIVE_ONLY, 113 extensions::CommandService::ACTIVE_ONLY,
115 &page_action, 114 &page_action,
116 NULL)) { 115 NULL)) {
117 ui::AcceleratorGtk accelerator(page_action.accelerator().key_code(), 116 ui::AcceleratorGtk accelerator(page_action.accelerator().key_code(),
118 page_action.accelerator().IsShiftDown(), 117 page_action.accelerator().IsShiftDown(),
119 page_action.accelerator().IsCtrlDown(), 118 page_action.accelerator().IsCtrlDown(),
120 page_action.accelerator().IsAltDown()); 119 page_action.accelerator().IsAltDown());
121 event_targets_[accelerator] = 120 event_targets_[accelerator] =
122 std::make_pair(extension->id(), page_action.command_name()); 121 std::make_pair(extension->id(), page_action.command_name());
123 } 122 }
123
124 // Add the Script Badge (if any).
Finnur 2012/08/17 14:45:29 Script Badge support was recently added. Therefore
125 extensions::Command script_badge;
126 if (command_service->GetScriptBadgeCommand(
127 extension->id(),
128 extensions::CommandService::ACTIVE_ONLY,
129 &script_badge,
130 NULL)) {
131 ui::AcceleratorGtk accelerator(script_badge.accelerator().key_code(),
132 script_badge.accelerator().IsShiftDown(),
133 script_badge.accelerator().IsCtrlDown(),
134 script_badge.accelerator().IsAltDown());
135 event_targets_[accelerator] =
136 std::make_pair(extension->id(), script_badge.command_name());
137 }
124 } 138 }
125 139
126 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding( 140 void ExtensionKeybindingRegistryGtk::RemoveExtensionKeybinding(
127 const extensions::Extension* extension, 141 const extensions::Extension* extension,
128 const std::string& command_name) { 142 const std::string& command_name) {
129 EventTargets::iterator iter = event_targets_.begin(); 143 EventTargets::iterator iter = event_targets_.begin();
130 while (iter != event_targets_.end()) { 144 while (iter != event_targets_.end()) {
131 if (iter->second.first != extension->id() || 145 if (iter->second.first != extension->id() ||
132 (!command_name.empty() && iter->second.second != command_name)) { 146 (!command_name.empty() && iter->second.second != command_name)) {
133 ++iter; 147 ++iter;
134 continue; // Not the extension or command we asked for. 148 continue; // Not the extension or command we asked for.
135 } 149 }
136 150
137 // On GTK, unlike Windows, the Event Targets contain all events but we must 151 // On GTK, unlike Windows, the Event Targets contain all events but we must
138 // only unregister the ones we own. 152 // only unregister the ones we registered targets for.
139 if (ShouldIgnoreCommand(iter->second.second)) { 153 if (!ShouldIgnoreCommand(iter->second.second)) {
140 ++iter; 154 gtk_accel_group_disconnect_key(accel_group_,
141 continue; 155 iter->first.GetGdkKeyCode(),
156 iter->first.gdk_modifier_type());
142 } 157 }
143 158
144 gtk_accel_group_disconnect_key(accel_group_,
145 iter->first.GetGdkKeyCode(),
146 iter->first.gdk_modifier_type());
147 EventTargets::iterator old = iter++; 159 EventTargets::iterator old = iter++;
148 event_targets_.erase(old); 160 event_targets_.erase(old);
Finnur 2012/08/17 14:45:29 When reviewing this code more closely (following t
149 } 161 }
150 } 162 }
151 163
152 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator( 164 gboolean ExtensionKeybindingRegistryGtk::OnGtkAccelerator(
153 GtkAccelGroup* group, 165 GtkAccelGroup* group,
154 GObject* acceleratable, 166 GObject* acceleratable,
155 guint keyval, 167 guint keyval,
156 GdkModifierType modifier) { 168 GdkModifierType modifier) {
157 ui::AcceleratorGtk accelerator(keyval, modifier); 169 ui::AcceleratorGtk accelerator(keyval, modifier);
158 170
159 ExtensionService* service = profile_->GetExtensionService(); 171 ExtensionService* service = profile_->GetExtensionService();
160 172
161 EventTargets::iterator it = event_targets_.find(accelerator); 173 EventTargets::iterator it = event_targets_.find(accelerator);
162 if (it == event_targets_.end()) { 174 if (it == event_targets_.end()) {
163 NOTREACHED(); // Shouldn't get this event for something not registered. 175 NOTREACHED(); // Shouldn't get this event for something not registered.
164 return FALSE; 176 return FALSE;
165 } 177 }
166 178
167 service->browser_event_router()->CommandExecuted( 179 service->browser_event_router()->CommandExecuted(
168 profile_, it->second.first, it->second.second); 180 profile_, it->second.first, it->second.second);
169 181
170 return TRUE; 182 return TRUE;
171 } 183 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698