MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / chrome / browser / extensions / extension_context_menu_model.h
blob264c31d0bb39b1e29b6a89b7d44f7fd62b1190e3
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;
28 // The context menu model for extension icons.
29 class ExtensionContextMenuModel
30 : public base::RefCounted<ExtensionContextMenuModel>,
31 public ui::SimpleMenuModel,
32 public ui::SimpleMenuModel::Delegate,
33 public extensions::ExtensionUninstallDialog::Delegate {
34 public:
35 enum MenuEntries {
36 NAME = 0,
37 CONFIGURE,
38 TOGGLE_VISIBILITY,
39 UNINSTALL,
40 MANAGE,
41 INSPECT_POPUP,
42 ALWAYS_RUN
45 // Type of action the extension icon represents.
46 enum ActionType { NO_ACTION = 0, BROWSER_ACTION, PAGE_ACTION };
48 // Delegate to handle showing an ExtensionAction popup.
49 class PopupDelegate {
50 public:
51 // Called when the user selects the menu item which requests that the
52 // popup be shown and inspected.
53 // The delegate should know which popup to display.
54 virtual void InspectPopup() = 0;
56 protected:
57 virtual ~PopupDelegate() {}
60 // Creates a menu model for the given extension. If
61 // prefs::kExtensionsUIDeveloperMode is enabled then a menu item
62 // will be shown for "Inspect Popup" which, when selected, will cause
63 // ShowPopupForDevToolsWindow() to be called on |delegate|.
64 ExtensionContextMenuModel(const extensions::Extension* extension,
65 Browser* browser,
66 PopupDelegate* delegate);
68 // Create a menu model for the given extension, without support
69 // for the "Inspect Popup" command.
70 ExtensionContextMenuModel(const extensions::Extension* extension,
71 Browser* browser);
73 // SimpleMenuModel::Delegate overrides.
74 bool IsCommandIdChecked(int command_id) const override;
75 bool IsCommandIdEnabled(int command_id) const override;
76 bool GetAcceleratorForCommandId(int command_id,
77 ui::Accelerator* accelerator) override;
78 void ExecuteCommand(int command_id, int event_flags) override;
80 // ExtensionUninstallDialog::Delegate:
81 void ExtensionUninstallAccepted() override;
82 void ExtensionUninstallCanceled() override;
84 private:
85 friend class base::RefCounted<ExtensionContextMenuModel>;
86 friend class extensions::ExtensionContextMenuModelTest;
88 ~ExtensionContextMenuModel() override;
90 void InitMenu(const extensions::Extension* extension);
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 extensions::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 // The extension action of the extension we are displaying the menu for (if
106 // it has one, otherwise NULL).
107 ExtensionAction* extension_action_;
109 Browser* browser_;
111 Profile* profile_;
113 // The delegate which handles the 'inspect popup' menu command (or NULL).
114 PopupDelegate* delegate_;
116 // The type of extension action to which this context menu is attached.
117 ActionType action_type_;
119 // Keeps track of the extension uninstall dialog.
120 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_;
122 // Menu matcher for context menu items specified by the extension.
123 scoped_ptr<extensions::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 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_