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 virtual void InspectPopup(ExtensionAction* action) = 0; | 48 virtual void InspectPopup(ExtensionAction* action) = 0; |
44 | 49 |
45 protected: | 50 protected: |
46 virtual ~PopupDelegate() {} | 51 virtual ~PopupDelegate() {} |
47 }; | 52 }; |
(...skipping 18 matching lines...) Expand all Loading... | |
66 int command_id, | 71 int command_id, |
67 ui::Accelerator* accelerator) OVERRIDE; | 72 ui::Accelerator* accelerator) OVERRIDE; |
68 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | 73 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
69 | 74 |
70 // ExtensionUninstallDialog::Delegate: | 75 // ExtensionUninstallDialog::Delegate: |
71 virtual void ExtensionUninstallAccepted() OVERRIDE; | 76 virtual void ExtensionUninstallAccepted() OVERRIDE; |
72 virtual void ExtensionUninstallCanceled() OVERRIDE; | 77 virtual void ExtensionUninstallCanceled() OVERRIDE; |
73 | 78 |
74 private: | 79 private: |
75 friend class base::RefCounted<ExtensionContextMenuModel>; | 80 friend class base::RefCounted<ExtensionContextMenuModel>; |
81 friend class extensions::ExtensionContextMenuModelTest; | |
82 | |
76 virtual ~ExtensionContextMenuModel(); | 83 virtual ~ExtensionContextMenuModel(); |
77 | 84 |
78 void InitMenu(const extensions::Extension* extension); | 85 void InitMenu(const extensions::Extension* extension); |
79 | 86 |
80 // Gets the extension we are displaying the menu for. Returns NULL if the | 87 // Gets the extension we are displaying the menu for. Returns NULL if the |
81 // extension has been uninstalled and no longer exists. | 88 // extension has been uninstalled and no longer exists. |
82 const extensions::Extension* GetExtension() const; | 89 const extensions::Extension* GetExtension() const; |
83 | 90 |
91 // Appends the extension's context menu items. | |
92 void AppendExtensionItems(); | |
93 | |
84 // A copy of the extension's id. | 94 // A copy of the extension's id. |
85 std::string extension_id_; | 95 std::string extension_id_; |
86 | 96 |
87 // The extension action of the extension we are displaying the menu for (if | 97 // The extension action of the extension we are displaying the menu for (if |
88 // it has one, otherwise NULL). | 98 // it has one, otherwise NULL). |
89 ExtensionAction* extension_action_; | 99 ExtensionAction* extension_action_; |
90 | 100 |
91 Browser* browser_; | 101 Browser* browser_; |
92 | 102 |
93 Profile* profile_; | 103 Profile* profile_; |
94 | 104 |
95 // The delegate which handles the 'inspect popup' menu command (or NULL). | 105 // The delegate which handles the 'inspect popup' menu command (or NULL). |
96 PopupDelegate* delegate_; | 106 PopupDelegate* delegate_; |
97 | 107 |
108 // The type of extension action to which this context menu is attached. | |
109 ActionType action_type_; | |
110 | |
98 // Keeps track of the extension uninstall dialog. | 111 // Keeps track of the extension uninstall dialog. |
99 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; | 112 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; |
100 | 113 |
114 // Menu matcher for context menu items specified by the extension. | |
115 scoped_ptr<extensions::ContextMenuMatcher> extension_items_; | |
116 | |
117 // Number of extension items in this menu. Used for testing. | |
118 int extension_items_count_ = 0; | |
Devlin
2014/07/24 21:51:27
Don't initialize values in the class definition li
gpdavis
2014/07/28 21:08:22
My mistake. I did this because the Google C++ sty
| |
119 | |
101 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); | 120 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); |
102 }; | 121 }; |
103 | 122 |
104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ | 123 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
OLD | NEW |