[sessions]: Componentize TabRestore code
[chromium-blink-merge.git] / chrome / browser / extensions / extension_context_menu_model.h
blobac18864c6dfd93ccbbe081cd1974808ef28ac21b
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
12 #include "ui/base/models/simple_menu_model.h"
14 class Browser;
15 class ExtensionAction;
16 class Profile;
18 namespace content {
19 class WebContents;
22 namespace extensions {
23 class Extension;
24 class ContextMenuMatcher;
25 class ExtensionContextMenuModelTest;
27 // The context menu model for extension icons.
28 class ExtensionContextMenuModel : public ui::SimpleMenuModel,
29 public ui::SimpleMenuModel::Delegate {
30 public:
31 enum MenuEntries {
32 NAME = 0,
33 CONFIGURE,
34 TOGGLE_VISIBILITY,
35 UNINSTALL,
36 MANAGE,
37 INSPECT_POPUP,
38 ALWAYS_RUN
41 // Type of action the extension icon represents.
42 enum ActionType { NO_ACTION = 0, BROWSER_ACTION, PAGE_ACTION };
44 // The current visibility of the button; this can affect the "hide"/"show"
45 // strings in the menu.
46 enum ButtonVisibility {
47 // The button is visible on the toolbar.
48 VISIBLE,
49 // The button is temporarily visible on the toolbar, as for showign a popup.
50 TRANSITIVELY_VISIBLE,
51 // The button is showed in the overflow menu.
52 OVERFLOWED
55 // Delegate to handle showing an ExtensionAction popup.
56 class PopupDelegate {
57 public:
58 // Called when the user selects the menu item which requests that the
59 // popup be shown and inspected.
60 // The delegate should know which popup to display.
61 virtual void InspectPopup() = 0;
63 protected:
64 virtual ~PopupDelegate() {}
67 // Creates a menu model for the given extension. If
68 // prefs::kExtensionsUIDeveloperMode is enabled then a menu item
69 // will be shown for "Inspect Popup" which, when selected, will cause
70 // ShowPopupForDevToolsWindow() to be called on |delegate|.
71 ExtensionContextMenuModel(const Extension* extension,
72 Browser* browser,
73 ButtonVisibility visibility,
74 PopupDelegate* delegate);
75 ~ExtensionContextMenuModel() override;
77 // Create a menu model for the given extension, without support
78 // for the "Inspect Popup" command.
79 ExtensionContextMenuModel(const Extension* extension, Browser* browser);
81 // SimpleMenuModel::Delegate overrides.
82 bool IsCommandIdChecked(int command_id) const override;
83 bool IsCommandIdEnabled(int command_id) const override;
84 bool GetAcceleratorForCommandId(int command_id,
85 ui::Accelerator* accelerator) override;
86 void ExecuteCommand(int command_id, int event_flags) override;
88 private:
89 friend class ExtensionContextMenuModelTest;
91 void InitMenu(const Extension* extension, ButtonVisibility button_visibility);
93 // Gets the extension we are displaying the menu for. Returns NULL if the
94 // extension has been uninstalled and no longer exists.
95 const Extension* GetExtension() const;
97 // Returns the active web contents.
98 content::WebContents* GetActiveWebContents() const;
100 // Appends the extension's context menu items.
101 void AppendExtensionItems();
103 // A copy of the extension's id.
104 std::string extension_id_;
106 // Whether the menu is for a component extension.
107 bool is_component_;
109 // The extension action of the extension we are displaying the menu for (if
110 // it has one, otherwise NULL).
111 ExtensionAction* extension_action_;
113 Browser* browser_;
115 Profile* profile_;
117 // The delegate which handles the 'inspect popup' menu command (or NULL).
118 PopupDelegate* delegate_;
120 // The type of extension action to which this context menu is attached.
121 ActionType action_type_;
123 // Keeps track of the extension uninstall dialog.
124 scoped_ptr<ExtensionUninstallDialog> extension_uninstall_dialog_;
126 // Menu matcher for context menu items specified by the extension.
127 scoped_ptr<ContextMenuMatcher> extension_items_;
129 // Number of extension items in this menu. Used for testing.
130 int extension_items_count_;
132 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel);
135 } // namespace extensions
137 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_