Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / extension_context_menu_model.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_
7
8 #include <string>
9
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"
13
14 class Browser;
15 class ExtensionAction;
16 class Profile;
17
18 namespace content {
19 class WebContents;
20 }
21
22 namespace extensions {
23 class Extension;
24 class ContextMenuMatcher;
25 class ExtensionContextMenuModelTest;
26 }
27
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 {
34  public:
35   enum MenuEntries {
36     NAME = 0,
37     CONFIGURE,
38     TOGGLE_VISIBILITY,
39     UNINSTALL,
40     MANAGE,
41     INSPECT_POPUP,
42     ALWAYS_RUN
43   };
44
45   // Type of action the extension icon represents.
46   enum ActionType { NO_ACTION = 0, BROWSER_ACTION, PAGE_ACTION };
47
48   // Delegate to handle showing an ExtensionAction popup.
49   class PopupDelegate {
50    public:
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;
55
56    protected:
57     virtual ~PopupDelegate() {}
58   };
59
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,
65                             Browser* browser,
66                             PopupDelegate* delegate);
67
68   // Create a menu model for the given extension, without support
69   // for the "Inspect Popup" command.
70   ExtensionContextMenuModel(const extensions::Extension* extension,
71                             Browser* browser);
72
73   // SimpleMenuModel::Delegate overrides.
74   bool IsCommandIdChecked(int command_id) const override;
75   bool IsCommandIdEnabled(int command_id) const override;
76   bool GetAcceleratorForCommandId(int command_id,
77                                   ui::Accelerator* accelerator) override;
78   void ExecuteCommand(int command_id, int event_flags) override;
79
80   // ExtensionUninstallDialog::Delegate:
81   void ExtensionUninstallAccepted() override;
82   void ExtensionUninstallCanceled() override;
83
84  private:
85   friend class base::RefCounted<ExtensionContextMenuModel>;
86   friend class extensions::ExtensionContextMenuModelTest;
87
88   ~ExtensionContextMenuModel() override;
89
90   void InitMenu(const extensions::Extension* extension);
91
92   // Gets the extension we are displaying the menu for. Returns NULL if the
93   // extension has been uninstalled and no longer exists.
94   const extensions::Extension* GetExtension() const;
95
96   // Returns the active web contents.
97   content::WebContents* GetActiveWebContents() const;
98
99   // Appends the extension's context menu items.
100   void AppendExtensionItems();
101
102   // A copy of the extension's id.
103   std::string extension_id_;
104
105   // The extension action of the extension we are displaying the menu for (if
106   // it has one, otherwise NULL).
107   ExtensionAction* extension_action_;
108
109   Browser* browser_;
110
111   Profile* profile_;
112
113   // The delegate which handles the 'inspect popup' menu command (or NULL).
114   PopupDelegate* delegate_;
115
116   // The type of extension action to which this context menu is attached.
117   ActionType action_type_;
118
119   // Keeps track of the extension uninstall dialog.
120   scoped_ptr<extensions::ExtensionUninstallDialog> extension_uninstall_dialog_;
121
122   // Menu matcher for context menu items specified by the extension.
123   scoped_ptr<extensions::ContextMenuMatcher> extension_items_;
124
125   // Number of extension items in this menu. Used for testing.
126   int extension_items_count_;
127
128   DISALLOW_COPY_AND_ASSIGN(ExtensionContextMenuModel);
129 };
130
131 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_CONTEXT_MENU_MODEL_H_