Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_action_platform_delegate_views.h
blob83b31fbf9a630e29698860a332f7e75f21feef89
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 "base/callback.h"
9 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
12 #include "ui/base/accelerators/accelerator.h"
13 #include "ui/views/context_menu_controller.h"
15 class ToolbarActionViewDelegateViews;
17 namespace views {
18 class MenuRunner;
19 class View;
22 // An abstract "View" for an ExtensionAction (either a BrowserAction or a
23 // PageAction). This contains the logic for showing the action's popup and
24 // the context menu. This class doesn't subclass View directly, as the
25 // implementations for page actions/browser actions are different types of
26 // views.
27 // All common logic for executing extension actions should go in this class;
28 // ToolbarActionViewDelegate classes should only have knowledge relating to
29 // the views::View wrapper.
30 class ExtensionActionPlatformDelegateViews
31 : public ExtensionActionPlatformDelegate,
32 public content::NotificationObserver,
33 public ui::AcceleratorTarget,
34 public views::ContextMenuController {
35 public:
36 ExtensionActionPlatformDelegateViews(
37 ExtensionActionViewController* controller);
38 ~ExtensionActionPlatformDelegateViews() override;
40 private:
41 // ExtensionActionPlatformDelegate:
42 bool IsMenuRunning() const override;
43 void RegisterCommand() override;
44 void OnDelegateSet() override;
45 void CloseActivePopup() override;
46 extensions::ExtensionViewHost* ShowPopupWithUrl(
47 ExtensionActionViewController::PopupShowAction show_action,
48 const GURL& popup_url,
49 bool grant_tab_permissions) override;
51 // content::NotificationObserver:
52 void Observe(int type,
53 const content::NotificationSource& source,
54 const content::NotificationDetails& details) override;
56 // ui::AcceleratorTarget:
57 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
58 bool CanHandleAccelerators() const override;
60 // views::ContextMenuController:
61 void ShowContextMenuForView(views::View* source,
62 const gfx::Point& point,
63 ui::MenuSourceType source_type) override;
65 // Shows the context menu for extension action.
66 void DoShowContextMenu(ui::MenuSourceType source_type);
68 // Unregisters the accelerator for the extension action's command, if one
69 // exists. If |only_if_removed| is true, then this will only unregister if the
70 // command has been removed.
71 void UnregisterCommand(bool only_if_removed);
73 // Closes the currently-active menu, if needed. This is the case when there
74 // is an active menu that wouldn't close automatically when a new one is
75 // opened.
76 // Returns true if a menu was closed, false otherwise.
77 bool CloseActiveMenuIfNeeded();
79 ToolbarActionViewDelegateViews* GetDelegateViews() const;
81 // The owning ExtensionActionViewController.
82 ExtensionActionViewController* controller_;
84 // Responsible for running the menu.
85 scoped_ptr<views::MenuRunner> menu_runner_;
87 // The extension key binding accelerator this extension action is listening
88 // for (to show the popup).
89 scoped_ptr<ui::Accelerator> action_keybinding_;
91 // If non-NULL, this is the next ExtensionActionViewController context menu
92 // which wants to run once the current owner (this one) is done.
93 base::Closure followup_context_menu_task_;
95 content::NotificationRegistrar registrar_;
97 base::WeakPtrFactory<ExtensionActionPlatformDelegateViews> weak_factory_;
99 DISALLOW_COPY_AND_ASSIGN(ExtensionActionPlatformDelegateViews);
102 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_ACTION_PLATFORM_DELEGATE_VIEWS_H_