| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
| 7 | 7 |
| 8 #include "app/menus/simple_menu_model.h" | 8 #include "app/menus/simple_menu_model.h" |
| 9 #include "chrome/browser/extensions/extension_install_ui.h" | 9 #include "chrome/browser/extensions/extension_install_ui.h" |
| 10 | 10 |
| 11 class Browser; |
| 11 class Extension; | 12 class Extension; |
| 12 class ExtensionAction; | 13 class ExtensionAction; |
| 13 class PrefService; | 14 class Profile; |
| 14 | 15 |
| 15 // The menu model for the context menu for extension action icons (browser and | 16 // The menu model for the context menu for extension action icons (browser and |
| 16 // page actions). | 17 // page actions). |
| 17 class ExtensionActionContextMenuModel | 18 class ExtensionContextMenuModel |
| 18 : public menus::SimpleMenuModel, | 19 : public menus::SimpleMenuModel, |
| 19 public menus::SimpleMenuModel::Delegate, | 20 public menus::SimpleMenuModel::Delegate, |
| 20 public ExtensionInstallUI::Delegate { | 21 public ExtensionInstallUI::Delegate { |
| 21 public: | 22 public: |
| 22 // Delegate to handle menu commands. | 23 // Delegate to handle showing an ExtensionAction popup. |
| 23 class MenuDelegate { | 24 class PopupDelegate { |
| 24 public: | 25 public: |
| 25 // Called when the user selects the menu item which requests that the | 26 // Called when the user selects the menu item which requests that the |
| 26 // popup be shown and inspected. | 27 // popup be shown and inspected. |
| 27 virtual void ShowPopupForDevToolsWindow(Extension* extension, | 28 virtual void InspectPopup(ExtensionAction* action) = 0; |
| 28 ExtensionAction* extension_action) { | |
| 29 } | |
| 30 }; | 29 }; |
| 31 | 30 |
| 32 // |extension_action|, |prefs|, & |delegate| call all be NULL. If valid | 31 // Creates a menu model for the given extension action. If |
| 33 // values are provided for all three, and prefs::kExtensionsUIDeveloperMode | 32 // prefs::kExtensionsUIDeveloperMode is enabled then a menu item |
| 34 // is enabled in the PrefService, a menu item will be shown for "Inspect | 33 // will be shown for "Inspect Popup" which, when selected, will cause |
| 35 // Popup" which, when selected, will cause ShowPopupForDevToolsWindow() to be | 34 // ShowPopupForDevToolsWindow() to be called on |delegate|. |
| 36 // called on |delegate|. | 35 ExtensionContextMenuModel(Extension* extension, |
| 37 ExtensionActionContextMenuModel(Extension* extension, | 36 Browser* browser, |
| 38 ExtensionAction* extension_action, | 37 PopupDelegate* delegate); |
| 39 PrefService* prefs, | 38 virtual ~ExtensionContextMenuModel(); |
| 40 MenuDelegate* delegate); | |
| 41 ~ExtensionActionContextMenuModel(); | |
| 42 | 39 |
| 43 // SimpleMenuModel behavior overrides. | 40 // SimpleMenuModel::Delegate overrides. |
| 44 virtual bool IsCommandIdChecked(int command_id) const; | 41 virtual bool IsCommandIdChecked(int command_id) const; |
| 45 virtual bool IsCommandIdEnabled(int command_id) const; | 42 virtual bool IsCommandIdEnabled(int command_id) const; |
| 46 virtual bool GetAcceleratorForCommandId(int command_id, | 43 virtual bool GetAcceleratorForCommandId(int command_id, |
| 47 menus::Accelerator* accelerator); | 44 menus::Accelerator* accelerator); |
| 48 virtual void ExecuteCommand(int command_id); | 45 virtual void ExecuteCommand(int command_id); |
| 49 | 46 |
| 50 // ExtensionInstallUI::Delegate overrides. | 47 // ExtensionInstallUI::Delegate overrides. |
| 51 virtual void InstallUIProceed(bool create_app); | 48 virtual void InstallUIProceed(bool create_app); |
| 52 virtual void InstallUIAbort() {} | 49 virtual void InstallUIAbort() {} |
| 53 | 50 |
| 54 private: | 51 private: |
| 55 // The extension we are displaying the context menu for. | 52 void InitCommonCommands(); |
| 53 |
| 54 // The extension we are displaying the menu for. |
| 56 Extension* extension_; | 55 Extension* extension_; |
| 57 | 56 |
| 58 // The extension action we are displaying the context menu for. | 57 // The extension action we are displaying the menu for (or NULL). |
| 59 ExtensionAction* extension_action_; | 58 ExtensionAction* extension_action_; |
| 60 | 59 |
| 61 // The delegate which handles the 'inspect popup' menu command. | 60 Browser* browser_; |
| 62 MenuDelegate* delegate_; | |
| 63 | 61 |
| 64 DISALLOW_COPY_AND_ASSIGN(ExtensionActionContextMenuModel); | 62 Profile* profile_; |
| 63 |
| 64 // The delegate which handles the 'inspect popup' menu command (or NULL). |
| 65 PopupDelegate* delegate_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); |
| 65 }; | 68 }; |
| 66 | 69 |
| 67 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_MODEL_H_ | 70 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
| OLD | NEW |