Add a webstorePrivate API to show a permission prompt for delegated bundle installs
[chromium-blink-merge.git] / chrome / browser / extensions / extension_context_menu_model.h
blob31599498b8ca90c19228b3696097aa45bc7c129b
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 // The current visibility of the button; this can affect the "hide"/"show"
49 // strings in the menu.
50 enum ButtonVisibility {
51 // The button is visible on the toolbar.
52 VISIBLE,
53 // The button is temporarily visible on the toolbar, as for showign a popup.
54 TRANSITIVELY_VISIBLE,
55 // The button is showed in the overflow menu.
56 OVERFLOWED
59 // Delegate to handle showing an ExtensionAction popup.
60 class PopupDelegate {
61 public:
62 // Called when the user selects the menu item which requests that the
63 // popup be shown and inspected.
64 // The delegate should know which popup to display.
65 virtual void InspectPopup() = 0;
67 protected:
68 virtual ~PopupDelegate() {}
71 // Creates a menu model for the given extension. If
72 // prefs::kExtensionsUIDeveloperMode is enabled then a menu item
73 // will be shown for "Inspect Popup" which, when selected, will cause
74 // ShowPopupForDevToolsWindow() to be called on |delegate|.
75 ExtensionContextMenuModel(const extensions::Extension* extension,
76 Browser* browser,
77 ButtonVisibility visibility,
78 PopupDelegate* delegate);
80 // Create a menu model for the given extension, without support
81 // for the "Inspect Popup" command.
82 ExtensionContextMenuModel(const extensions::Extension* extension,
83 Browser* browser);
85 // SimpleMenuModel::Delegate overrides.
86 bool IsCommandIdChecked(int command_id) const override;
87 bool IsCommandIdEnabled(int command_id) const override;
88 bool GetAcceleratorForCommandId(int command_id,
89 ui::Accelerator* accelerator) override;
90 void ExecuteCommand(int command_id, int event_flags) override;
92 // ExtensionUninstallDialog::Delegate:
93 void OnExtensionUninstallDialogClosed(bool did_start_uninstall,
94 const base::string16& error) override;
96 private:
97 friend class base::RefCounted<ExtensionContextMenuModel>;
98 friend class extensions::ExtensionContextMenuModelTest;
100 ~ExtensionContextMenuModel() override;
102 void InitMenu(const extensions::Extension* extension,
103 ButtonVisibility button_visibility_);
105 // Gets the extension we are displaying the menu for. Returns NULL if the
106 // extension has been uninstalled and no longer exists.
107 const extensions::Extension* GetExtension() const;
109 // Returns the active web contents.
110 content::WebContents* GetActiveWebContents() const;
112 // Appends the extension's context menu items.
113 void AppendExtensionItems();
115 // A copy of the extension's id.
116 std::string extension_id_;
118 // Whether the menu is for a component extension.
119 bool is_component_;
121 // The extension action of the extension we are displaying the menu for (if
122 // it has one, otherwise NULL).
123 ExtensionAction* extension_action_;
125 Browser* browser_;
127 Profile* profile_;
129 // The delegate which handles the 'inspect popup' menu command (or NULL).
130 PopupDelegate* delegate_;
132 // The type of extension action to which this context menu is attached.
133 ActionType action_type_;
135 // Keeps track of the extension uninstall dialog.
136 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_;
138 // Menu matcher for context menu items specified by the extension.
139 scoped_ptr<extensions::ContextMenuMatcher> extension_items_;
141 // Number of extension items in this menu. Used for testing.
142 int extension_items_count_;
144 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel);
147 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_