Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / extensions / extension_context_menu_model.h
blobd8fb2b14e3daa365f542f79a8cff6a537133015b
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 "ui/base/models/simple_menu_model.h"
13 class Browser;
14 class ExtensionAction;
15 class Profile;
17 namespace content {
18 class WebContents;
21 namespace extensions {
22 class Extension;
23 class ContextMenuMatcher;
24 class ExtensionContextMenuModelTest;
26 // The context menu model for extension icons.
27 class ExtensionContextMenuModel : public ui::SimpleMenuModel,
28 public ui::SimpleMenuModel::Delegate {
29 public:
30 enum MenuEntries {
31 NAME = 0,
32 CONFIGURE,
33 TOGGLE_VISIBILITY,
34 UNINSTALL,
35 MANAGE,
36 INSPECT_POPUP,
37 ALWAYS_RUN
40 // Type of action the extension icon represents.
41 enum ActionType { NO_ACTION = 0, BROWSER_ACTION, PAGE_ACTION };
43 // The current visibility of the button; this can affect the "hide"/"show"
44 // strings in the menu.
45 enum ButtonVisibility {
46 // The button is visible on the toolbar.
47 VISIBLE,
48 // The button is temporarily visible on the toolbar, as for showign a popup.
49 TRANSITIVELY_VISIBLE,
50 // The button is showed in the overflow menu.
51 OVERFLOWED
54 // Delegate to handle showing an ExtensionAction popup.
55 class PopupDelegate {
56 public:
57 // Called when the user selects the menu item which requests that the
58 // popup be shown and inspected.
59 // The delegate should know which popup to display.
60 virtual void InspectPopup() = 0;
62 protected:
63 virtual ~PopupDelegate() {}
66 // Creates a menu model for the given extension. If
67 // prefs::kExtensionsUIDeveloperMode is enabled then a menu item
68 // will be shown for "Inspect Popup" which, when selected, will cause
69 // ShowPopupForDevToolsWindow() to be called on |delegate|.
70 ExtensionContextMenuModel(const Extension* extension,
71 Browser* browser,
72 ButtonVisibility visibility,
73 PopupDelegate* delegate);
74 ~ExtensionContextMenuModel() override;
76 // Create a menu model for the given extension, without support
77 // for the "Inspect Popup" command.
78 ExtensionContextMenuModel(const Extension* extension, Browser* browser);
80 // SimpleMenuModel::Delegate overrides.
81 bool IsCommandIdChecked(int command_id) const override;
82 bool IsCommandIdEnabled(int command_id) const override;
83 bool GetAcceleratorForCommandId(int command_id,
84 ui::Accelerator* accelerator) override;
85 void ExecuteCommand(int command_id, int event_flags) override;
87 private:
88 friend class ExtensionContextMenuModelTest;
90 void InitMenu(const Extension* extension, ButtonVisibility button_visibility);
92 // Gets the extension we are displaying the menu for. Returns NULL if the
93 // extension has been uninstalled and no longer exists.
94 const Extension* GetExtension() const;
96 // Returns the active web contents.
97 content::WebContents* GetActiveWebContents() const;
99 // Appends the extension's context menu items.
100 void AppendExtensionItems();
102 // A copy of the extension's id.
103 std::string extension_id_;
105 // Whether the menu is for a component extension.
106 bool is_component_;
108 // The extension action of the extension we are displaying the menu for (if
109 // it has one, otherwise NULL).
110 ExtensionAction* extension_action_;
112 Browser* browser_;
114 Profile* profile_;
116 // The delegate which handles the 'inspect popup' menu command (or NULL).
117 PopupDelegate* delegate_;
119 // The type of extension action to which this context menu is attached.
120 ActionType action_type_;
122 // Menu matcher for context menu items specified by the extension.
123 scoped_ptr<ContextMenuMatcher> extension_items_;
125 // Number of extension items in this menu. Used for testing.
126 int extension_items_count_;
128 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel);
131 } // namespace extensions
133 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_