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

Unified Diff: chrome/browser/extensions/api/commands/command_service.cc

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: Address some comments. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/commands/command_service.cc
diff --git a/chrome/browser/extensions/api/commands/command_service.cc b/chrome/browser/extensions/api/commands/command_service.cc
index 9bff7a572ad6b3dfc860973b97a532ed4069ecb4..1a62a32dc9f174bfff987d24aed55c46d18f6957 100644
--- a/chrome/browser/extensions/api/commands/command_service.cc
+++ b/chrome/browser/extensions/api/commands/command_service.cc
@@ -4,8 +4,12 @@
#include "chrome/browser/extensions/api/commands/command_service.h"
+#include <vector>
+
#include "base/lazy_instance.h"
#include "base/prefs/scoped_user_pref_update.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
Finnur 2013/11/13 10:22:24 Can either of this include be deleted now?
zhchbin 2013/11/13 16:05:11 Done.
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -110,6 +114,17 @@ CommandService* CommandService::Get(Profile* profile) {
return ProfileKeyedAPIFactory<CommandService>::GetForProfile(profile);
}
+// static
+bool CommandService::IsMediaKey(const ui::Accelerator& accelerator) {
+ if (accelerator.modifiers() != 0)
+ return false;
+
+ return (accelerator.key_code() == ui::VKEY_MEDIA_NEXT_TRACK ||
+ accelerator.key_code() == ui::VKEY_MEDIA_PREV_TRACK ||
+ accelerator.key_code() == ui::VKEY_MEDIA_PLAY_PAUSE ||
+ accelerator.key_code() == ui::VKEY_MEDIA_STOP);
+}
+
bool CommandService::GetBrowserActionCommand(
const std::string& extension_id,
QueryType type,
@@ -193,6 +208,8 @@ bool CommandService::AddKeybindingPref(
base::DictionaryValue* bindings = updater.Get();
std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator);
+ if (IsMediaKey(accelerator))
Finnur 2013/11/13 10:22:24 Please document why we do this. Perhaps something
zhchbin 2013/11/13 16:05:11 Done.
+ key += ":" + extension_id;
if (!allow_overrides && bindings->HasKey(key))
return false; // Already taken.
@@ -287,8 +304,12 @@ Command CommandService::FindCommandByName(
item->GetBoolean(kGlobal, &global);
std::string shortcut = it.key();
- if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true))
- shortcut = shortcut.substr(Command::CommandPlatform().length() + 1);
+ if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true)) {
+ std::vector<std::string> tokens;
+ base::SplitString(shortcut, ':', &tokens);
+ CHECK(tokens.size() >= 2);
+ shortcut = tokens[1]; // The second token is the shortcut assigned.
+ }
return Command(command_name, string16(), shortcut, global);
}
@@ -311,9 +332,9 @@ void CommandService::AssignInitialKeybindings(const Extension* extension) {
extensions::CommandMap::const_iterator iter = commands->begin();
for (; iter != commands->end(); ++iter) {
- if (!chrome::IsChromeAccelerator(
- iter->second.accelerator(), profile_) &&
- IsWhitelistedGlobalShortcut(iter->second)) {
+ if ((!chrome::IsChromeAccelerator(iter->second.accelerator(), profile_) &&
+ IsWhitelistedGlobalShortcut(iter->second)) ||
+ extensions::CommandService::IsMediaKey(iter->second.accelerator())) {
AddKeybindingPref(iter->second.accelerator(),
extension->id(),
iter->second.command_name(),

Powered by Google App Engine
This is Rietveld 408576698