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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
7 #include "chrome/browser/extensions/api/commands/command_service.h"
8 #include "chrome/browser/extensions/extension_keybinding_registry.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "extensions/common/extension.h"
12 #include "ui/views/focus/focus_manager.h"
15 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended(
17 views::FocusManager::set_shortcut_handling_suspended(suspended
);
20 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews(
22 views::FocusManager
* focus_manager
,
23 ExtensionFilter extension_filter
,
25 : ExtensionKeybindingRegistry(profile
, extension_filter
, delegate
),
27 focus_manager_(focus_manager
) {
31 ExtensionKeybindingRegistryViews::~ExtensionKeybindingRegistryViews() {
32 focus_manager_
->UnregisterAccelerators(this);
35 void ExtensionKeybindingRegistryViews::AddExtensionKeybinding(
36 const extensions::Extension
* extension
,
37 const std::string
& command_name
) {
38 // This object only handles named commands, not browser/page actions.
39 if (ShouldIgnoreCommand(command_name
))
42 extensions::CommandService
* command_service
=
43 extensions::CommandService::Get(profile_
);
44 // Add all the active keybindings (except page actions and browser actions,
45 // which are handled elsewhere).
46 extensions::CommandMap commands
;
47 if (!command_service
->GetNamedCommands(
49 extensions::CommandService::ACTIVE_ONLY
,
50 extensions::CommandService::REGULAR
,
53 extensions::CommandMap::const_iterator iter
= commands
.begin();
54 for (; iter
!= commands
.end(); ++iter
) {
55 if (!command_name
.empty() && (iter
->second
.command_name() != command_name
))
57 if (!IsAcceleratorRegistered(iter
->second
.accelerator())) {
58 focus_manager_
->RegisterAccelerator(iter
->second
.accelerator(),
59 ui::AcceleratorManager::kHighPriority
,
63 AddEventTarget(iter
->second
.accelerator(),
65 iter
->second
.command_name());
69 void ExtensionKeybindingRegistryViews::RemoveExtensionKeybindingImpl(
70 const ui::Accelerator
& accelerator
,
71 const std::string
& command_name
) {
72 focus_manager_
->UnregisterAccelerator(accelerator
, this);
75 bool ExtensionKeybindingRegistryViews::AcceleratorPressed(
76 const ui::Accelerator
& accelerator
) {
77 return ExtensionKeybindingRegistry::NotifyEventTargets(accelerator
);
80 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const {