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

Unified Diff: chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc

Issue 360423002: Allow WebContents key handling to supplant extension overrides of the bookmark shortcut (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: update test Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc
diff --git a/chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc b/chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc
index 477a08eeb4064ccb8a8040dd4fa304900f409b36..8495b908cc144daa156819b9663a6e215d59d631 100644
--- a/chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc
+++ b/chrome/browser/ui/views/extensions/extension_keybinding_registry_views.cc
@@ -4,10 +4,13 @@
#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/extension_keybinding_registry.h"
-#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/accelerator_utils.h"
+#include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "ui/views/focus/focus_manager.h"
@@ -55,8 +58,18 @@ void ExtensionKeybindingRegistryViews::AddExtensionKeybinding(
if (!command_name.empty() && (iter->second.command_name() != command_name))
continue;
if (!IsAcceleratorRegistered(iter->second.accelerator())) {
+ ui::AcceleratorManager::HandlerPriority priority =
+ ui::AcceleratorManager::kHighPriority;
+ // Extensions overriding the bookmark shortcut need normal priority to
+ // preserve the built-in processing order of the key and not override
+ // WebContents key handling.
+ if (iter->second.accelerator() ==
+ chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE) &&
+ extensions::UIOverrides::RemovesBookmarkShortcut(extension)) {
+ priority = ui::AcceleratorManager::kNormalPriority;
+ }
Finnur 2014/07/02 11:56:16 I'd rather have a utility function on the Command
Mike Wittman 2014/07/02 21:56:19 We can do the utility function, but putting it in
Finnur 2014/07/03 11:09:59 Ah, I see. That's probably fine then.
focus_manager_->RegisterAccelerator(iter->second.accelerator(),
- ui::AcceleratorManager::kHighPriority,
+ priority,
Finnur 2014/07/02 11:56:16 Then this becomes: Command::GetPriority(iter->se
Mike Wittman 2014/07/02 21:56:19 Done.
this);
}
@@ -74,6 +87,22 @@ void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl(
bool ExtensionKeybindingRegistryViews::AcceleratorPressed(
const ui::Accelerator& accelerator) {
+ // As a special case, if the extension removes and reassigns the bookmark
+ // shortcut we don't respond here but instead allow it to be handled by the
+ // standard browser command processing. This preserves the same shortcut key
+ // handling of Chrome's built-in bookmarking function, which can be overridden
+ // by key handling on web pages.
+ std::string extension_id, command_name;
+ GetFirstTarget(accelerator, &extension_id, &command_name);
+ const extensions::Extension* extension =
+ extensions::ExtensionRegistry::Get(browser_context())->
+ enabled_extensions().GetByID(extension_id);
+ if (accelerator ==
+ chrome::GetPrimaryChromeAcceleratorForCommandId(IDC_BOOKMARK_PAGE) &&
+ extensions::UIOverrides::RemovesBookmarkShortcut(extension)) {
+ return false;
+ }
Finnur 2014/07/02 11:56:16 and this becomes: if (Command::GetPriority(acceler
Mike Wittman 2014/07/02 21:56:19 Done.
+
return ExtensionKeybindingRegistry::NotifyEventTargets(accelerator);
}

Powered by Google App Engine
This is Rietveld 408576698