OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_CONTEXT_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 11 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
12 #include "ui/base/models/simple_menu_model.h" | 12 #include "ui/base/models/simple_menu_model.h" |
13 | 13 |
14 class Browser; | 14 class Browser; |
15 class ExtensionAction; | 15 class ExtensionAction; |
16 class Profile; | 16 class Profile; |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 class Extension; | 19 class Extension; |
| 20 class ContextMenuMatcher; |
| 21 class ExtensionContextMenuModelTest; |
20 } | 22 } |
21 | 23 |
22 // The context menu model for extension icons. | 24 // The context menu model for extension icons. |
23 class ExtensionContextMenuModel | 25 class ExtensionContextMenuModel |
24 : public base::RefCounted<ExtensionContextMenuModel>, | 26 : public base::RefCounted<ExtensionContextMenuModel>, |
25 public ui::SimpleMenuModel, | 27 public ui::SimpleMenuModel, |
26 public ui::SimpleMenuModel::Delegate, | 28 public ui::SimpleMenuModel::Delegate, |
27 public extensions::ExtensionUninstallDialog::Delegate { | 29 public extensions::ExtensionUninstallDialog::Delegate { |
28 public: | 30 public: |
29 enum MenuEntries { | 31 enum MenuEntries { |
30 NAME = 0, | 32 NAME = 0, |
31 CONFIGURE, | 33 CONFIGURE, |
32 HIDE, | 34 HIDE, |
33 UNINSTALL, | 35 UNINSTALL, |
34 MANAGE, | 36 MANAGE, |
35 INSPECT_POPUP | 37 INSPECT_POPUP |
36 }; | 38 }; |
37 | 39 |
| 40 // Type of action the extension icon represents. |
| 41 enum ActionType { NO_ACTION = 0, BROWSER_ACTION, PAGE_ACTION }; |
| 42 |
38 // Delegate to handle showing an ExtensionAction popup. | 43 // Delegate to handle showing an ExtensionAction popup. |
39 class PopupDelegate { | 44 class PopupDelegate { |
40 public: | 45 public: |
41 // Called when the user selects the menu item which requests that the | 46 // Called when the user selects the menu item which requests that the |
42 // popup be shown and inspected. | 47 // popup be shown and inspected. |
43 // The delegate should know which popup to display. | 48 // The delegate should know which popup to display. |
44 virtual void InspectPopup() = 0; | 49 virtual void InspectPopup() = 0; |
45 | 50 |
46 protected: | 51 protected: |
47 virtual ~PopupDelegate() {} | 52 virtual ~PopupDelegate() {} |
(...skipping 19 matching lines...) Expand all Loading... |
67 int command_id, | 72 int command_id, |
68 ui::Accelerator* accelerator) OVERRIDE; | 73 ui::Accelerator* accelerator) OVERRIDE; |
69 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | 74 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
70 | 75 |
71 // ExtensionUninstallDialog::Delegate: | 76 // ExtensionUninstallDialog::Delegate: |
72 virtual void ExtensionUninstallAccepted() OVERRIDE; | 77 virtual void ExtensionUninstallAccepted() OVERRIDE; |
73 virtual void ExtensionUninstallCanceled() OVERRIDE; | 78 virtual void ExtensionUninstallCanceled() OVERRIDE; |
74 | 79 |
75 private: | 80 private: |
76 friend class base::RefCounted<ExtensionContextMenuModel>; | 81 friend class base::RefCounted<ExtensionContextMenuModel>; |
| 82 friend class extensions::ExtensionContextMenuModelTest; |
| 83 |
77 virtual ~ExtensionContextMenuModel(); | 84 virtual ~ExtensionContextMenuModel(); |
78 | 85 |
79 void InitMenu(const extensions::Extension* extension); | 86 void InitMenu(const extensions::Extension* extension); |
80 | 87 |
81 // Gets the extension we are displaying the menu for. Returns NULL if the | 88 // Gets the extension we are displaying the menu for. Returns NULL if the |
82 // extension has been uninstalled and no longer exists. | 89 // extension has been uninstalled and no longer exists. |
83 const extensions::Extension* GetExtension() const; | 90 const extensions::Extension* GetExtension() const; |
84 | 91 |
| 92 // Appends the extension's context menu items. |
| 93 void AppendExtensionItems(); |
| 94 |
85 // A copy of the extension's id. | 95 // A copy of the extension's id. |
86 std::string extension_id_; | 96 std::string extension_id_; |
87 | 97 |
88 // The extension action of the extension we are displaying the menu for (if | 98 // The extension action of the extension we are displaying the menu for (if |
89 // it has one, otherwise NULL). | 99 // it has one, otherwise NULL). |
90 ExtensionAction* extension_action_; | 100 ExtensionAction* extension_action_; |
91 | 101 |
92 Browser* browser_; | 102 Browser* browser_; |
93 | 103 |
94 Profile* profile_; | 104 Profile* profile_; |
95 | 105 |
96 // The delegate which handles the 'inspect popup' menu command (or NULL). | 106 // The delegate which handles the 'inspect popup' menu command (or NULL). |
97 PopupDelegate* delegate_; | 107 PopupDelegate* delegate_; |
98 | 108 |
| 109 // The type of extension action to which this context menu is attached. |
| 110 ActionType action_type_; |
| 111 |
99 // Keeps track of the extension uninstall dialog. | 112 // Keeps track of the extension uninstall dialog. |
100 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; | 113 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; |
101 | 114 |
| 115 // Menu matcher for context menu items specified by the extension. |
| 116 scoped_ptr<extensions::ContextMenuMatcher> extension_items_; |
| 117 |
| 118 // Number of extension items in this menu. Used for testing. |
| 119 int extension_items_count_; |
| 120 |
102 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); | 121 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); |
103 }; | 122 }; |
104 | 123 |
105 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ | 124 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
OLD | NEW |