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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa.mm

Issue 64273008: [Windows] Finish global and non-global media keys support on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gclient sync. Created 7 years, 1 month 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
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/cocoa/extensions/extension_keybinding_registry_cocoa .h" 5 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/api/commands/command_service.h" 8 #include "chrome/browser/extensions/api/commands/command_service.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 27 matching lines...) Expand all
38 } 38 }
39 39
40 bool ExtensionKeybindingRegistryCocoa::ProcessKeyEvent( 40 bool ExtensionKeybindingRegistryCocoa::ProcessKeyEvent(
41 const content::NativeWebKeyboardEvent& event) { 41 const content::NativeWebKeyboardEvent& event) {
42 if (shortcut_handling_suspended_) 42 if (shortcut_handling_suspended_)
43 return false; 43 return false;
44 44
45 ui::Accelerator accelerator( 45 ui::Accelerator accelerator(
46 static_cast<ui::KeyboardCode>(event.windowsKeyCode), 46 static_cast<ui::KeyboardCode>(event.windowsKeyCode),
47 content::GetModifiersFromNativeWebKeyboardEvent(event)); 47 content::GetModifiersFromNativeWebKeyboardEvent(event));
48 EventTargets::iterator it = event_targets_.find(accelerator); 48 EventTargets::iterator targets = event_targets_.find(accelerator);
49 if (it == event_targets_.end()) 49 if (targets == event_targets_.end())
50 return false; 50 return false;
51 51
52 std::string extension_id = it->second.first; 52 TargetList::const_iterator first_target = targets->second.begin();
53 std::string command_name = it->second.second; 53 DCHECK(!targets->second.empty());
54
55 std::string extension_id = first_target->first;
56 std::string command_name = first_target->second;
54 int type = 0; 57 int type = 0;
55 if (command_name == values::kPageActionCommandEvent) { 58 if (command_name == values::kPageActionCommandEvent) {
56 type = chrome::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC; 59 type = chrome::NOTIFICATION_EXTENSION_COMMAND_PAGE_ACTION_MAC;
57 } else if (command_name == values::kBrowserActionCommandEvent) { 60 } else if (command_name == values::kBrowserActionCommandEvent) {
58 type = chrome::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC; 61 type = chrome::NOTIFICATION_EXTENSION_COMMAND_BROWSER_ACTION_MAC;
59 } else if (command_name == values::kScriptBadgeCommandEvent) { 62 } else if (command_name == values::kScriptBadgeCommandEvent) {
60 type = chrome::NOTIFICATION_EXTENSION_COMMAND_SCRIPT_BADGE_MAC; 63 type = chrome::NOTIFICATION_EXTENSION_COMMAND_SCRIPT_BADGE_MAC;
61 } else { 64 } else {
62 // Not handled by using notifications. Route it through the Browser Event 65 // Not handled by using notifications. Route it through the Browser Event
63 // Router. 66 // Router using the base class (it will iterate through all targets).
64 CommandExecuted(extension_id, command_name); 67 return ExtensionKeybindingRegistry::NotifyEventTargets(accelerator);
65 return true;
66 } 68 }
67 69
70 // Type != named command, so we need to dispatch this event directly.
68 std::pair<const std::string, gfx::NativeWindow> details = 71 std::pair<const std::string, gfx::NativeWindow> details =
69 std::make_pair(extension_id, window_); 72 std::make_pair(extension_id, window_);
70 content::NotificationService::current()->Notify( 73 content::NotificationService::current()->Notify(
71 type, 74 type,
72 content::Source<Profile>(profile_), 75 content::Source<Profile>(profile_),
73 content::Details< 76 content::Details<
74 std::pair<const std::string, gfx::NativeWindow> >(&details)); 77 std::pair<const std::string, gfx::NativeWindow> >(&details));
78 // We expect only one target for these types of events.
79 DCHECK_EQ(1u, targets->second.size());
75 return true; 80 return true;
76 } 81 }
77 82
78 void ExtensionKeybindingRegistryCocoa::AddExtensionKeybinding( 83 void ExtensionKeybindingRegistryCocoa::AddExtensionKeybinding(
79 const extensions::Extension* extension, 84 const extensions::Extension* extension,
80 const std::string& command_name) { 85 const std::string& command_name) {
81 extensions::CommandService* command_service = 86 extensions::CommandService* command_service =
82 extensions::CommandService::Get(profile_); 87 extensions::CommandService::Get(profile_);
83 extensions::CommandMap commands; 88 extensions::CommandMap commands;
84 command_service->GetNamedCommands( 89 command_service->GetNamedCommands(
85 extension->id(), 90 extension->id(),
86 extensions::CommandService::ACTIVE_ONLY, 91 extensions::CommandService::ACTIVE_ONLY,
87 extensions::CommandService::REGULAR, 92 extensions::CommandService::REGULAR,
88 &commands); 93 &commands);
89 94
90 for (extensions::CommandMap::const_iterator iter = commands.begin(); 95 for (extensions::CommandMap::const_iterator iter = commands.begin();
91 iter != commands.end(); ++iter) { 96 iter != commands.end(); ++iter) {
92 if (!command_name.empty() && (iter->second.command_name() != command_name)) 97 if (!command_name.empty() && (iter->second.command_name() != command_name))
93 continue; 98 continue;
94 99
95 ui::Accelerator accelerator(iter->second.accelerator()); 100 ui::Accelerator accelerator(iter->second.accelerator());
96 event_targets_[accelerator] = 101 event_targets_[accelerator].push_back(
97 std::make_pair(extension->id(), iter->second.command_name()); 102 std::make_pair(extension->id(), iter->second.command_name()));
103 // Shortcuts except media keys have only one target in the list. See
104 // comment about |event_targets_|.
105 if (!extensions::CommandService::IsMediaKey(iter->second.accelerator()))
106 DCHECK_EQ(1u, event_targets_[iter->second.accelerator()].size());
98 } 107 }
99 108
100 // Mac implemenetation behaves like GTK with regards to what is kept in the 109 // Mac implemenetation behaves like GTK with regards to what is kept in the
101 // event_targets_ map, because both GTK and Mac need to keep track of Browser 110 // event_targets_ map, because both GTK and Mac need to keep track of Browser
102 // and Page actions, as well as Script Badges. 111 // and Page actions, as well as Script Badges.
103 extensions::Command browser_action; 112 extensions::Command browser_action;
104 if (command_service->GetBrowserActionCommand( 113 if (command_service->GetBrowserActionCommand(
105 extension->id(), 114 extension->id(),
106 extensions::CommandService::ACTIVE_ONLY, 115 extensions::CommandService::ACTIVE_ONLY,
107 &browser_action, 116 &browser_action,
108 NULL)) { 117 NULL)) {
109 ui::Accelerator accelerator(browser_action.accelerator()); 118 ui::Accelerator accelerator(browser_action.accelerator());
110 event_targets_[accelerator] = 119 event_targets_[accelerator].push_back(
111 std::make_pair(extension->id(), browser_action.command_name()); 120 std::make_pair(extension->id(), browser_action.command_name()));
121 // We should have only one target. See comment about |event_targets_|.
122 DCHECK_EQ(1u, event_targets_[accelerator].size());
112 } 123 }
113 124
114 // Add the Page Action (if any). 125 // Add the Page Action (if any).
115 extensions::Command page_action; 126 extensions::Command page_action;
116 if (command_service->GetPageActionCommand( 127 if (command_service->GetPageActionCommand(
117 extension->id(), 128 extension->id(),
118 extensions::CommandService::ACTIVE_ONLY, 129 extensions::CommandService::ACTIVE_ONLY,
119 &page_action, 130 &page_action,
120 NULL)) { 131 NULL)) {
121 ui::Accelerator accelerator(page_action.accelerator()); 132 ui::Accelerator accelerator(page_action.accelerator());
122 event_targets_[accelerator] = 133 event_targets_[accelerator].push_back(
123 std::make_pair(extension->id(), page_action.command_name()); 134 std::make_pair(extension->id(), page_action.command_name()));
135 // We should have only one target. See comment about |event_targets_|.
136 DCHECK_EQ(1u, event_targets_[accelerator].size());
124 } 137 }
125 138
126 // Add the Script Badge (if any). 139 // Add the Script Badge (if any).
127 extensions::Command script_badge; 140 extensions::Command script_badge;
128 if (command_service->GetScriptBadgeCommand( 141 if (command_service->GetScriptBadgeCommand(
129 extension->id(), 142 extension->id(),
130 extensions::CommandService::ACTIVE_ONLY, 143 extensions::CommandService::ACTIVE_ONLY,
131 &script_badge, 144 &script_badge,
132 NULL)) { 145 NULL)) {
133 ui::Accelerator accelerator(script_badge.accelerator()); 146 ui::Accelerator accelerator(script_badge.accelerator());
134 event_targets_[accelerator] = 147 event_targets_[accelerator].push_back(
135 std::make_pair(extension->id(), script_badge.command_name()); 148 std::make_pair(extension->id(), script_badge.command_name()));
149 // We should have only one target. See comment about |event_targets_|.
150 DCHECK_EQ(1u, event_targets_[accelerator].size());
136 } 151 }
137 } 152 }
138 153
139 void ExtensionKeybindingRegistryCocoa::RemoveExtensionKeybindingImpl( 154 void ExtensionKeybindingRegistryCocoa::RemoveExtensionKeybindingImpl(
140 const ui::Accelerator& accelerator, 155 const ui::Accelerator& accelerator,
141 const std::string& command_name) { 156 const std::string& command_name) {
142 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698