Chromium Code Reviews| 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/context_menu_matcher.h" | |
|
Devlin
2014/07/01 20:54:24
Nit: prefer forward declaration instead of include
gpdavis
2014/07/02 01:17:46
Done.
| |
| 11 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 12 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 13 #include "chrome/browser/extensions/menu_manager.h" | |
|
Devlin
2014/07/01 20:54:24
same here.
gpdavis
2014/07/02 01:17:46
Done.
| |
| 12 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
| 13 | 15 |
| 14 class Browser; | 16 class Browser; |
| 15 class ExtensionAction; | 17 class ExtensionAction; |
| 16 class Profile; | 18 class Profile; |
| 17 | 19 |
| 18 namespace extensions { | 20 namespace extensions { |
| 19 class Extension; | 21 class Extension; |
| 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 enum ActionType { | |
|
Devlin
2014/07/01 20:54:24
Comment.
gpdavis
2014/07/02 01:17:46
Done.
| |
| 41 NO_ACTION = 0, | |
| 42 BROWSER_ACTION, | |
| 43 PAGE_ACTION | |
| 44 }; | |
| 45 | |
| 38 // Delegate to handle showing an ExtensionAction popup. | 46 // Delegate to handle showing an ExtensionAction popup. |
| 39 class PopupDelegate { | 47 class PopupDelegate { |
| 40 public: | 48 public: |
| 41 // Called when the user selects the menu item which requests that the | 49 // Called when the user selects the menu item which requests that the |
| 42 // popup be shown and inspected. | 50 // popup be shown and inspected. |
| 43 virtual void InspectPopup(ExtensionAction* action) = 0; | 51 virtual void InspectPopup(ExtensionAction* action) = 0; |
| 44 | 52 |
| 45 protected: | 53 protected: |
| 46 virtual ~PopupDelegate() {} | 54 virtual ~PopupDelegate() {} |
| 47 }; | 55 }; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 74 private: | 82 private: |
| 75 friend class base::RefCounted<ExtensionContextMenuModel>; | 83 friend class base::RefCounted<ExtensionContextMenuModel>; |
| 76 virtual ~ExtensionContextMenuModel(); | 84 virtual ~ExtensionContextMenuModel(); |
| 77 | 85 |
| 78 void InitMenu(const extensions::Extension* extension); | 86 void InitMenu(const extensions::Extension* extension); |
| 79 | 87 |
| 80 // 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 |
| 81 // extension has been uninstalled and no longer exists. | 89 // extension has been uninstalled and no longer exists. |
| 82 const extensions::Extension* GetExtension() const; | 90 const extensions::Extension* GetExtension() const; |
| 83 | 91 |
| 92 void AppendExtensionItems(); | |
|
Devlin
2014/07/01 20:54:24
Comment.
gpdavis
2014/07/02 01:17:46
Done.
| |
| 93 | |
| 94 // Determines whether this context menu was created for a browser action or | |
| 95 // a page action. | |
| 96 ActionType GetActionType(const extensions::Extension* extension); | |
| 97 | |
| 98 // Matches extensions menu items by ActionType. | |
| 99 static bool MenuItemMatchesExtension(ActionType type, | |
|
Devlin
2014/07/01 20:54:24
This should probably be an anonymous function in t
gpdavis
2014/07/02 01:17:46
Done.
| |
| 100 const extensions::Extension* extension, | |
| 101 const extensions::MenuItem* item); | |
| 102 | |
| 84 // A copy of the extension's id. | 103 // A copy of the extension's id. |
| 85 std::string extension_id_; | 104 std::string extension_id_; |
| 86 | 105 |
| 87 // The extension action of the extension we are displaying the menu for (if | 106 // The extension action of the extension we are displaying the menu for (if |
| 88 // it has one, otherwise NULL). | 107 // it has one, otherwise NULL). |
| 89 ExtensionAction* extension_action_; | 108 ExtensionAction* extension_action_; |
| 90 | 109 |
| 91 Browser* browser_; | 110 Browser* browser_; |
| 92 | 111 |
| 93 Profile* profile_; | 112 Profile* profile_; |
| 94 | 113 |
| 95 // The delegate which handles the 'inspect popup' menu command (or NULL). | 114 // The delegate which handles the 'inspect popup' menu command (or NULL). |
| 96 PopupDelegate* delegate_; | 115 PopupDelegate* delegate_; |
| 97 | 116 |
| 117 ActionType action_type_; | |
| 118 | |
| 98 // Keeps track of the extension uninstall dialog. | 119 // Keeps track of the extension uninstall dialog. |
| 99 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; | 120 scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_; |
| 100 | 121 |
| 122 // Menu matcher for context menu items specified by the extension. | |
| 123 scoped_ptr<extensions::ContextMenuMatcher> extension_items_; | |
| 124 | |
| 101 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); | 125 DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel); |
| 102 }; | 126 }; |
| 103 | 127 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ | 128 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_ |
| OLD | NEW |