[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_keybinding_registry_views.cc
blob477a08eeb4064ccb8a8040dd4fa304900f409b36
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"
14 // static
15 void extensions::ExtensionKeybindingRegistry::SetShortcutHandlingSuspended(
16 bool suspended) {
17 views::FocusManager::set_shortcut_handling_suspended(suspended);
20 ExtensionKeybindingRegistryViews::ExtensionKeybindingRegistryViews(
21 Profile* profile,
22 views::FocusManager* focus_manager,
23 ExtensionFilter extension_filter,
24 Delegate* delegate)
25 : ExtensionKeybindingRegistry(profile, extension_filter, delegate),
26 profile_(profile),
27 focus_manager_(focus_manager) {
28 Init();
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))
40 return;
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(
48 extension->id(),
49 extensions::CommandService::ACTIVE_ONLY,
50 extensions::CommandService::REGULAR,
51 &commands))
52 return;
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))
56 continue;
57 if (!IsAcceleratorRegistered(iter->second.accelerator())) {
58 focus_manager_->RegisterAccelerator(iter->second.accelerator(),
59 ui::AcceleratorManager::kHighPriority,
60 this);
63 AddEventTarget(iter->second.accelerator(),
64 extension->id(),
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 {
81 return true;