1 // Copyright 2014 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 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_PLATFORM_DELEGATE_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_PLATFORM_DELEGATE_VIEWS_H_
8 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h"
9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_registrar.h"
11 #include "ui/base/accelerators/accelerator.h"
13 class ToolbarActionViewDelegateViews
;
15 // An abstract "View" for an ExtensionAction (either a BrowserAction or a
16 // PageAction). This contains the logic for showing the action's popup and
17 // the context menu. This class doesn't subclass View directly, as the
18 // implementations for page actions/browser actions are different types of
20 // All common logic for executing extension actions should go in this class;
21 // ToolbarActionViewDelegate classes should only have knowledge relating to
22 // the views::View wrapper.
23 class ExtensionActionPlatformDelegateViews
24 : public ExtensionActionPlatformDelegate
,
25 public content::NotificationObserver
,
26 public ui::AcceleratorTarget
{
28 ExtensionActionPlatformDelegateViews(
29 ExtensionActionViewController
* controller
);
30 ~ExtensionActionPlatformDelegateViews() override
;
33 // ExtensionActionPlatformDelegate:
34 void RegisterCommand() override
;
36 scoped_ptr
<extensions::ExtensionViewHost
> host
,
37 bool grant_tab_permissions
,
38 ExtensionActionViewController::PopupShowAction show_action
) override
;
39 void CloseOverflowMenu() override
;
41 // content::NotificationObserver:
42 void Observe(int type
,
43 const content::NotificationSource
& source
,
44 const content::NotificationDetails
& details
) override
;
46 // ui::AcceleratorTarget:
47 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
48 bool CanHandleAccelerators() const override
;
50 // Unregisters the accelerator for the extension action's command, if one
51 // exists. If |only_if_removed| is true, then this will only unregister if the
52 // command has been removed.
53 void UnregisterCommand(bool only_if_removed
);
55 ToolbarActionViewDelegateViews
* GetDelegateViews() const;
57 // The owning ExtensionActionViewController.
58 ExtensionActionViewController
* controller_
;
60 // The extension key binding accelerator this extension action is listening
61 // for (to show the popup).
62 scoped_ptr
<ui::Accelerator
> action_keybinding_
;
64 content::NotificationRegistrar registrar_
;
66 DISALLOW_COPY_AND_ASSIGN(ExtensionActionPlatformDelegateViews
);
69 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_PLATFORM_DELEGATE_VIEWS_H_