Home | History | Annotate | Download | only in extensions
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_VIEWS_H_
      6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_VIEWS_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "chrome/browser/extensions/extension_keybinding_registry.h"
     12 #include "ui/base/accelerators/accelerator.h"
     13 
     14 class Profile;
     15 
     16 namespace extensions {
     17 class Extension;
     18 }
     19 
     20 namespace views {
     21 class FocusManager;
     22 }
     23 
     24 // ExtensionKeybindingRegistryViews is a class that handles Views-specific
     25 // implementation of the Extension Keybinding shortcuts (keyboard accelerators).
     26 // Note: It handles regular extension commands (not browserAction and pageAction
     27 // popups, which are handled elsewhere). This class registers the accelerators
     28 // on behalf of the extensions and routes the commands to them via the
     29 // BrowserEventRouter.
     30 class ExtensionKeybindingRegistryViews
     31     : public extensions::ExtensionKeybindingRegistry,
     32       public ui::AcceleratorTarget {
     33  public:
     34   ExtensionKeybindingRegistryViews(Profile* profile,
     35                                    views::FocusManager* focus_manager,
     36                                    ExtensionFilter extension_filter,
     37                                    Delegate* delegate);
     38   virtual ~ExtensionKeybindingRegistryViews();
     39 
     40   // Overridden from ui::AcceleratorTarget.
     41   virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
     42   virtual bool CanHandleAccelerators() const OVERRIDE;
     43 
     44  private:
     45   // Overridden from ExtensionKeybindingRegistry:
     46   virtual void AddExtensionKeybinding(
     47       const extensions::Extension* extension,
     48       const std::string& command_name) OVERRIDE;
     49   virtual void RemoveExtensionKeybindingImpl(
     50       const ui::Accelerator& accelerator,
     51       const std::string& command_name) OVERRIDE;
     52 
     53   // Weak pointer to the our profile. Not owned by us.
     54   Profile* profile_;
     55 
     56   // Weak pointer back to the focus manager to use to register and unregister
     57   // accelerators with. Not owned by us.
     58   views::FocusManager* focus_manager_;
     59 
     60   // The content notification registrar for listening to extension events.
     61   content::NotificationRegistrar registrar_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistryViews);
     64 };
     65 
     66 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_VIEWS_H_
     67