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_
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"
15 class ExtensionAction
;
22 namespace extensions
{
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
{
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.
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;
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
,
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
,
73 // SimpleMenuModel::Delegate overrides.
74 virtual bool IsCommandIdChecked(int command_id
) const override
;
75 virtual bool IsCommandIdEnabled(int command_id
) const override
;
76 virtual bool GetAcceleratorForCommandId(
78 ui::Accelerator
* accelerator
) override
;
79 virtual void ExecuteCommand(int command_id
, int event_flags
) override
;
81 // ExtensionUninstallDialog::Delegate:
82 virtual void ExtensionUninstallAccepted() override
;
83 virtual void ExtensionUninstallCanceled() override
;
86 friend class base::RefCounted
<ExtensionContextMenuModel
>;
87 friend class extensions::ExtensionContextMenuModelTest
;
89 virtual ~ExtensionContextMenuModel();
91 void InitMenu(const extensions::Extension
* extension
);
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 extensions::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 // The extension action of the extension we are displaying the menu for (if
107 // it has one, otherwise NULL).
108 ExtensionAction
* extension_action_
;
114 // The delegate which handles the 'inspect popup' menu command (or NULL).
115 PopupDelegate
* delegate_
;
117 // The type of extension action to which this context menu is attached.
118 ActionType action_type_
;
120 // Keeps track of the extension uninstall dialog.
121 scoped_ptr
<extensions::ExtensionUninstallDialog
> extension_uninstall_dialog_
;
123 // Menu matcher for context menu items specified by the extension.
124 scoped_ptr
<extensions::ContextMenuMatcher
> extension_items_
;
126 // Number of extension items in this menu. Used for testing.
127 int extension_items_count_
;
129 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel
);
132 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_