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

Unified Diff: chrome/browser/extensions/extension_keybinding_registry.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/extension_keybinding_registry.cc
diff --git a/chrome/browser/extensions/extension_keybinding_registry.cc b/chrome/browser/extensions/extension_keybinding_registry.cc
index a819ab409c17a2a842b5d4a5249afd2bce7f4be2..7c6d1e53251088bd6a5f425fcfe9fe2f1df04150 100644
--- a/chrome/browser/extensions/extension_keybinding_registry.cc
+++ b/chrome/browser/extensions/extension_keybinding_registry.cc
@@ -7,6 +7,7 @@
#include "base/values.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/active_tab_permission_granter.h"
+#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
@@ -37,18 +38,18 @@ ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() {
void ExtensionKeybindingRegistry::RemoveExtensionKeybinding(
const Extension* extension,
const std::string& command_name) {
- EventTargets::iterator iter = event_targets_.begin();
- while (iter != event_targets_.end()) {
- if (iter->second.first != extension->id() ||
- (!command_name.empty() && (iter->second.second != command_name))) {
- ++iter;
+ EventTargets::iterator eit = event_targets_.begin();
+ while (eit != event_targets_.end()) {
+ if (eit->second.first != extension->id() ||
+ (!command_name.empty() && (eit->second.second != command_name))) {
+ ++eit;
continue; // Not the extension or command we asked for.
}
// Let each platform-specific implementation get a chance to clean up.
- RemoveExtensionKeybindingImpl(iter->first, command_name);
+ RemoveExtensionKeybindingImpl(eit->first, command_name);
- EventTargets::iterator old = iter++;
+ EventTargets::iterator old = eit++;
event_targets_.erase(old);
// If a specific command_name was requested, it has now been deleted so
@@ -56,6 +57,26 @@ void ExtensionKeybindingRegistry::RemoveExtensionKeybinding(
if (!command_name.empty())
break;
}
+
+ MediaKeysEventTargets::iterator mit = media_keys_event_targets_.begin();
+ while (mit != media_keys_event_targets_.end()) {
+ TargetList& target_list = mit->second;
+ TargetList::iterator target = target_list.begin();
+ while (target != target_list.end()) {
+ if (target->first == extension->id() &&
+ (command_name.empty() || command_name == target->second)) {
+ target = target_list.erase(target);
+ } else {
+ target++;
+ }
+ }
+
+ MediaKeysEventTargets::iterator old = mit++;
+ if (target_list.empty()) {
+ RemoveExtensionKeybindingImpl(old->first, command_name);
+ media_keys_event_targets_.erase(old);
+ }
+ }
}
void ExtensionKeybindingRegistry::Init() {
@@ -78,6 +99,28 @@ bool ExtensionKeybindingRegistry::ShouldIgnoreCommand(
command == manifest_values::kScriptBadgeCommandEvent;
}
+bool ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator(
+ const ui::Accelerator& accelerator) {
+ if (extensions::CommandService::IsMediaKey(accelerator)) {
+ MediaKeysEventTargets::iterator targets =
+ media_keys_event_targets_.find(accelerator);
+ if (targets == media_keys_event_targets_.end() || targets->second.empty())
+ return false;
+
+ for (TargetList::const_iterator it = targets->second.begin();
+ it != targets->second.end(); it++)
+ CommandExecuted(it->first, it->second);
+ } else {
+ EventTargets::iterator it = event_targets_.find(accelerator);
+ if (it == event_targets_.end())
+ return false;
+
+ CommandExecuted(it->second.first, it->second.second);
+ }
+
+ return true;
+}
+
void ExtensionKeybindingRegistry::CommandExecuted(
const std::string& extension_id, const std::string& command) {
ExtensionService* service =

Powered by Google App Engine
This is Rietveld 408576698