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

Side by Side Diff: chrome/browser/extensions/api/commands/command_service.cc

Issue 180783012: Media Keys should not count towards the max of four shortcuts per extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move IsMediaKey from c/b/e/a/c/command_service.h &&.cc to c/c/e/command.h && .cc Created 6 years, 9 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
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/extensions/api/commands/command_service.h" 5 #include "chrome/browser/extensions/api/commands/command_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 std::string GetPlatformKeybindingKeyForAccelerator( 48 std::string GetPlatformKeybindingKeyForAccelerator(
49 const ui::Accelerator& accelerator, const std::string extension_id) { 49 const ui::Accelerator& accelerator, const std::string extension_id) {
50 std::string key = extensions::Command::CommandPlatform() + ":" + 50 std::string key = extensions::Command::CommandPlatform() + ":" +
51 extensions::Command::AcceleratorToString(accelerator); 51 extensions::Command::AcceleratorToString(accelerator);
52 52
53 // Media keys have a 1-to-many relationship with targets, unlike regular 53 // Media keys have a 1-to-many relationship with targets, unlike regular
54 // shortcut (1-to-1 relationship). That means two or more extensions can 54 // shortcut (1-to-1 relationship). That means two or more extensions can
55 // register for the same media key so the extension ID needs to be added to 55 // register for the same media key so the extension ID needs to be added to
56 // the key to make sure the key is unique. 56 // the key to make sure the key is unique.
57 if (extensions::CommandService::IsMediaKey(accelerator)) 57 if (extensions::Command::IsMediaKey(accelerator))
58 key += ":" + extension_id; 58 key += ":" + extension_id;
59 59
60 return key; 60 return key;
61 } 61 }
62 62
63 bool IsForCurrentPlatform(const std::string& key) { 63 bool IsForCurrentPlatform(const std::string& key) {
64 return StartsWithASCII( 64 return StartsWithASCII(
65 key, extensions::Command::CommandPlatform() + ":", true); 65 key, extensions::Command::CommandPlatform() + ":", true);
66 } 66 }
67 67
(...skipping 15 matching lines...) Expand all
83 } 83 }
84 84
85 // Checks if |extension| is permitted to automatically assign the |accelerator| 85 // Checks if |extension| is permitted to automatically assign the |accelerator|
86 // key. 86 // key.
87 bool CanAutoAssign(const ui::Accelerator& accelerator, 87 bool CanAutoAssign(const ui::Accelerator& accelerator,
88 const Extension* extension, 88 const Extension* extension,
89 Profile* profile, 89 Profile* profile,
90 bool is_named_command, 90 bool is_named_command,
91 bool is_global) { 91 bool is_global) {
92 // Media Keys are non-exclusive, so allow auto-assigning them. 92 // Media Keys are non-exclusive, so allow auto-assigning them.
93 if (extensions::CommandService::IsMediaKey(accelerator)) 93 if (extensions::Command::IsMediaKey(accelerator))
94 return true; 94 return true;
95 95
96 if (is_global) { 96 if (is_global) {
97 if (!is_named_command) 97 if (!is_named_command)
98 return false; // Browser and page actions are not global in nature. 98 return false; // Browser and page actions are not global in nature.
99 99
100 // Global shortcuts are restricted to (Ctrl|Command)+Shift+[0-9]. 100 // Global shortcuts are restricted to (Ctrl|Command)+Shift+[0-9].
101 #if defined OS_MACOSX 101 #if defined OS_MACOSX
102 if (!accelerator.IsCmdDown()) 102 if (!accelerator.IsCmdDown())
103 return false; 103 return false;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 ProfileKeyedAPIFactory<CommandService>* CommandService::GetFactoryInstance() { 162 ProfileKeyedAPIFactory<CommandService>* CommandService::GetFactoryInstance() {
163 return g_factory.Pointer(); 163 return g_factory.Pointer();
164 } 164 }
165 165
166 // static 166 // static
167 CommandService* CommandService::Get(content::BrowserContext* context) { 167 CommandService* CommandService::Get(content::BrowserContext* context) {
168 return ProfileKeyedAPIFactory<CommandService>::GetForProfile(context); 168 return ProfileKeyedAPIFactory<CommandService>::GetForProfile(context);
169 } 169 }
170 170
171 // static 171 // static
172 bool CommandService::IsMediaKey(const ui::Accelerator& accelerator) {
173 if (accelerator.modifiers() != 0)
174 return false;
175
176 return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK ||
177 accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK ||
178 accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE ||
179 accelerator.key_code() == ui::VKEY_MEDIA_STOP);
180 }
181
182 // static
183 bool CommandService::RemovesBookmarkShortcut( 172 bool CommandService::RemovesBookmarkShortcut(
184 const extensions::Extension* extension) { 173 const extensions::Extension* extension) {
185 using extensions::SettingsOverrides; 174 using extensions::SettingsOverrides;
186 const SettingsOverrides* settings_overrides = 175 const SettingsOverrides* settings_overrides =
187 SettingsOverrides::Get(extension); 176 SettingsOverrides::Get(extension);
188 177
189 return settings_overrides && 178 return settings_overrides &&
190 SettingsOverrides::RemovesBookmarkShortcut(*settings_overrides) && 179 SettingsOverrides::RemovesBookmarkShortcut(*settings_overrides) &&
191 (extensions::PermissionsData::HasAPIPermission( 180 (extensions::PermissionsData::HasAPIPermission(
192 extension, 181 extension,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 bool CommandService::AddKeybindingPref( 243 bool CommandService::AddKeybindingPref(
255 const ui::Accelerator& accelerator, 244 const ui::Accelerator& accelerator,
256 std::string extension_id, 245 std::string extension_id,
257 std::string command_name, 246 std::string command_name,
258 bool allow_overrides, 247 bool allow_overrides,
259 bool global) { 248 bool global) {
260 if (accelerator.key_code() == ui::VKEY_UNKNOWN) 249 if (accelerator.key_code() == ui::VKEY_UNKNOWN)
261 return false; 250 return false;
262 251
263 // Media Keys are allowed to be used by named command only. 252 // Media Keys are allowed to be used by named command only.
264 DCHECK(!IsMediaKey(accelerator) || 253 DCHECK(!Command::IsMediaKey(accelerator) ||
265 (command_name != manifest_values::kPageActionCommandEvent && 254 (command_name != manifest_values::kPageActionCommandEvent &&
266 command_name != manifest_values::kBrowserActionCommandEvent)); 255 command_name != manifest_values::kBrowserActionCommandEvent));
267 256
268 DictionaryPrefUpdate updater(profile_->GetPrefs(), 257 DictionaryPrefUpdate updater(profile_->GetPrefs(),
269 prefs::kExtensionCommands); 258 prefs::kExtensionCommands);
270 base::DictionaryValue* bindings = updater.Get(); 259 base::DictionaryValue* bindings = updater.Get();
271 260
272 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator, 261 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator,
273 extension_id); 262 extension_id);
274 263
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 596
608 return true; 597 return true;
609 } 598 }
610 599
611 template <> 600 template <>
612 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 601 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
613 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 602 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
614 } 603 }
615 604
616 } // namespace extensions 605 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/commands/command_service.h ('k') | chrome/browser/extensions/extension_keybinding_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698