Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/renderer_context_menu/render_view_context_menu_base.h

Issue 432003007: Separate chrome independent part from RVContextMenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_ 5 #ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_
6 #define CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_ 6 #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
15 #include "chrome/browser/extensions/context_menu_matcher.h"
16 #include "chrome/browser/extensions/menu_manager.h"
17 #include "components/renderer_context_menu/context_menu_content_type.h" 14 #include "components/renderer_context_menu/context_menu_content_type.h"
18 #include "components/renderer_context_menu/render_view_context_menu_observer.h" 15 #include "components/renderer_context_menu/render_view_context_menu_observer.h"
19 #include "components/renderer_context_menu/render_view_context_menu_proxy.h" 16 #include "components/renderer_context_menu/render_view_context_menu_proxy.h"
20 #include "content/public/common/context_menu_params.h" 17 #include "content/public/common/context_menu_params.h"
21 #include "content/public/common/page_transition_types.h" 18 #include "content/public/common/page_transition_types.h"
22 #include "ui/base/models/simple_menu_model.h" 19 #include "ui/base/models/simple_menu_model.h"
23 #include "ui/base/window_open_disposition.h" 20 #include "ui/base/window_open_disposition.h"
24 21
25 class PrintPreviewContextMenuObserver;
26 class Profile;
27 class SpellingMenuObserver;
28 class SpellCheckerSubMenuObserver;
29
30 namespace content { 22 namespace content {
31 class RenderFrameHost; 23 class RenderFrameHost;
32 class WebContents; 24 class WebContents;
33 } 25 }
34 26
35 namespace extensions {
36 class Extension;
37 class MenuItem;
38 }
39
40 namespace gfx { 27 namespace gfx {
41 class Point; 28 class Point;
42 } 29 }
43 30
44 namespace blink { 31 namespace blink {
45 struct WebMediaPlayerAction; 32 struct WebMediaPlayerAction;
46 struct WebPluginAction; 33 struct WebPluginAction;
47 } 34 }
48 35
49 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, 36 class RenderViewContextMenuBase : public ui::SimpleMenuModel::Delegate,
50 public RenderViewContextMenuProxy { 37 public RenderViewContextMenuProxy {
51 public: 38 public:
52 // A delegate interface to communicate with the toolkit used by 39 // A delegate interface to communicate with the toolkit used by
53 // the embedder. 40 // the embedder.
54 class ToolkitDelegate { 41 class ToolkitDelegate {
55 public: 42 public:
56 virtual ~ToolkitDelegate() {} 43 virtual ~ToolkitDelegate() {}
57 // Initialize the toolkit's menu. 44 // Initialize the toolkit's menu.
58 virtual void Init(ui::SimpleMenuModel* menu_model) = 0; 45 virtual void Init(ui::SimpleMenuModel* menu_model) = 0;
59 46
60 virtual void Cancel() = 0; 47 virtual void Cancel() = 0;
61 48
62 // Updates the actual menu items controlled by the toolkit. 49 // Updates the actual menu items controlled by the toolkit.
63 virtual void UpdateMenuItem(int command_id, 50 virtual void UpdateMenuItem(int command_id,
64 bool enabled, 51 bool enabled,
65 bool hidden, 52 bool hidden,
66 const base::string16& title) = 0; 53 const base::string16& title) = 0;
67 }; 54 };
68 55
69 static const size_t kMaxSelectionTextLength; 56 static const size_t kMaxSelectionTextLength;
70 57
58 static void SetContentCustomCommandIdRange(int first, int last);
59
71 // Convert a command ID so that it fits within the range for 60 // Convert a command ID so that it fits within the range for
72 // content context menu. 61 // content context menu.
73 static int ConvertToContentCustomCommandId(int id); 62 static int ConvertToContentCustomCommandId(int id);
74 63
75 // True if the given id is the one generated for content context menu. 64 // True if the given id is the one generated for content context menu.
76 static bool IsContentCustomCommandId(int id); 65 static bool IsContentCustomCommandId(int id);
77 66
78 RenderViewContextMenu(content::RenderFrameHost* render_frame_host, 67 RenderViewContextMenuBase(content::RenderFrameHost* render_frame_host,
79 const content::ContextMenuParams& params); 68 const content::ContextMenuParams& params);
80 69
81 virtual ~RenderViewContextMenu(); 70 virtual ~RenderViewContextMenuBase();
82 71
83 // Initializes the context menu. 72 // Initializes the context menu.
84 void Init(); 73 void Init();
85 74
86 // Programmatically closes the context menu. 75 // Programmatically closes the context menu.
87 void Cancel(); 76 void Cancel();
88 77
89 const ui::SimpleMenuModel& menu_model() const { return menu_model_; } 78 const ui::SimpleMenuModel& menu_model() const { return menu_model_; }
90 const content::ContextMenuParams& params() const { return params_; } 79 const content::ContextMenuParams& params() const { return params_; }
91 80
(...skipping 15 matching lines...) Expand all
107 ui::MenuModel* model) OVERRIDE; 96 ui::MenuModel* model) OVERRIDE;
108 virtual void UpdateMenuItem(int command_id, 97 virtual void UpdateMenuItem(int command_id,
109 bool enabled, 98 bool enabled,
110 bool hidden, 99 bool hidden,
111 const base::string16& title) OVERRIDE; 100 const base::string16& title) OVERRIDE;
112 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE; 101 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE;
113 virtual content::WebContents* GetWebContents() const OVERRIDE; 102 virtual content::WebContents* GetWebContents() const OVERRIDE;
114 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; 103 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
115 104
116 protected: 105 protected:
106 friend class RenderViewContextMenuTest;
107 friend class RenderViewContextMenuPrefsTest;
108
109 void set_content_type(ContextMenuContentType* content_type) {
110 content_type_.reset(content_type);
111 }
112
117 void set_toolkit_delegate(scoped_ptr<ToolkitDelegate> delegate) { 113 void set_toolkit_delegate(scoped_ptr<ToolkitDelegate> delegate) {
118 toolkit_delegate_ = delegate.Pass(); 114 toolkit_delegate_ = delegate.Pass();
119 } 115 }
120 116
121 ToolkitDelegate* toolkit_delegate() { 117 ToolkitDelegate* toolkit_delegate() {
122 return toolkit_delegate_.get(); 118 return toolkit_delegate_.get();
123 } 119 }
124 120
125 void InitMenu(); 121 // TODO(oshima): Make these methods delegate.
126 Profile* GetProfile();
127 122
128 // Platform specific functions. 123 // Increments histogram value for used items specified by |id|.
124 virtual void RecordUsedItem(int id) = 0;
125
126 // Increments histogram value for visible context menu item specified by |id|.
127 virtual void RecordShownItem(int id) = 0;
128
129 virtual void HandleAuthorizeAllPlugins() = 0;
lazyboy 2014/08/01 07:59:34 This needs to be guarded by defined(ENABLE_PLUGINS
oshima 2014/08/01 10:38:45 Thank you for the catch. Fixed.
130
131 // Returns the accelerator for given |command_id|.
129 virtual bool GetAcceleratorForCommandId( 132 virtual bool GetAcceleratorForCommandId(
130 int command_id, 133 int command_id,
131 ui::Accelerator* accelerator) = 0; 134 ui::Accelerator* accelerator) = 0;
132 virtual void AppendPlatformEditableItems();
133 135
134 content::ContextMenuParams params_; 136 // Subclasses should send notification.
135 content::WebContents* source_web_contents_; 137 virtual void NotifyMenuShown() = 0;
136 // The RenderFrameHost's IDs. 138 virtual void NotifyURLOpened(const GURL& url,
137 int render_process_id_; 139 content::WebContents* new_contents) = 0;
138 int render_frame_id_;
139 content::BrowserContext* browser_context_;
140 140
141 ui::SimpleMenuModel menu_model_; 141 // Menu Construction.
142 extensions::ContextMenuMatcher extension_items_; 142 virtual void InitMenu();
143 143
144 private: 144 // TODO(oshima): Remove this.
145 friend class RenderViewContextMenuTest; 145 virtual void AppendPlatformEditableItems() {}
146 friend class RenderViewContextMenuPrefsTest;
147 146
148 static bool IsDevToolsURL(const GURL& url); 147 content::RenderFrameHost* GetRenderFrameHost();
149 static bool IsInternalResourcesURL(const GURL& url);
150 static bool ExtensionContextAndPatternMatch(
151 const content::ContextMenuParams& params,
152 extensions::MenuItem::ContextList contexts,
153 const extensions::URLPatternSet& target_url_patterns);
154 static bool MenuItemMatchesParams(const content::ContextMenuParams& params,
155 const extensions::MenuItem* item);
156 148
157 // Gets the extension (if any) associated with the WebContents that we're in. 149 bool IsCustomItemChecked(int id) const;
158 const extensions::Extension* GetExtension() const; 150 bool IsCustomItemEnabled(int id) const;
159 bool AppendCustomItems();
160
161 void AppendDeveloperItems();
162 void AppendDevtoolsForUnpackedExtensions();
163 void AppendLinkItems();
164 void AppendImageItems();
165 void AppendAudioItems();
166 void AppendCanvasItems();
167 void AppendVideoItems();
168 void AppendMediaItems();
169 void AppendPluginItems();
170 void AppendPageItems();
171 void AppendFrameItems();
172 void AppendCopyItem();
173 void AppendPrintItem();
174 void AppendEditableItems();
175 void AppendSearchProvider();
176 void AppendAllExtensionItems();
177 void AppendCurrentExtensionItems();
178 void AppendPrintPreviewItems();
179 void AppendSearchWebForImageItems();
180 void AppendSpellingSuggestionsSubMenu();
181 void AppendSpellcheckOptionsSubMenu();
182 void AppendProtocolHandlerSubMenu();
183 151
184 // Opens the specified URL string in a new tab. 152 // Opens the specified URL string in a new tab.
185 void OpenURL(const GURL& url, const GURL& referrer, 153 void OpenURL(const GURL& url, const GURL& referrer,
186 WindowOpenDisposition disposition, 154 WindowOpenDisposition disposition,
187 content::PageTransition transition); 155 content::PageTransition transition);
188 156
189 // Copy to the clipboard an image located at a point in the RenderView 157 content::ContextMenuParams params_;
190 void CopyImageAt(int x, int y); 158 content::WebContents* source_web_contents_;
159 content::BrowserContext* browser_context_;
191 160
192 // Get an image located at a point in the RenderView for search. 161 ui::SimpleMenuModel menu_model_;
193 void GetImageThumbnailForSearch(); 162 // extensions::ContextMenuMatcher extension_items_;
lazyboy 2014/08/01 07:59:34 remove
oshima 2014/08/01 10:38:45 Done.
194
195 // Launch the inspector targeting a point in the RenderView
196 void Inspect(int x, int y);
197
198 // Writes the specified text/url to the system clipboard
199 void WriteURLToClipboard(const GURL& url);
200
201 void MediaPlayerActionAt(const gfx::Point& location,
202 const blink::WebMediaPlayerAction& action);
203 void PluginActionAt(const gfx::Point& location,
204 const blink::WebPluginAction& action);
205
206 bool IsDevCommandEnabled(int id) const;
207
208 // Returns a list of registered ProtocolHandlers that can handle the clicked
209 // on URL.
210 ProtocolHandlerRegistry::ProtocolHandlerList GetHandlersForLinkUrl();
211
212 // Returns a (possibly truncated) version of the current selection text
213 // suitable or putting in the title of a menu item.
214 base::string16 PrintableSelectionText();
215
216 // The destination URL to use if the user tries to search for or navigate to
217 // a text selection.
218 GURL selection_navigation_url_;
219
220 ui::SimpleMenuModel protocol_handler_submenu_model_;
221 ProtocolHandlerRegistry* protocol_handler_registry_;
222
223 // An observer that handles spelling-menu items.
224 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
225
226 // An observer that handles a 'spell-checker options' submenu.
227 scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_;
228
229 #if defined(ENABLE_FULL_PRINTING)
230 // An observer that disables menu items when print preview is active.
231 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
232 #endif
233 163
234 // Our observers. 164 // Our observers.
235 mutable ObserverList<RenderViewContextMenuObserver> observers_; 165 mutable ObserverList<RenderViewContextMenuObserver> observers_;
236 166
237 // Whether a command has been executed. Used to track whether menu observers 167 // Whether a command has been executed. Used to track whether menu observers
238 // should be notified of menu closing without execution. 168 // should be notified of menu closing without execution.
239 bool command_executed_; 169 bool command_executed_;
240 170
241 scoped_ptr<ContextMenuContentType> content_type_; 171 scoped_ptr<ContextMenuContentType> content_type_;
242 172
173 private:
174 bool AppendCustomItems();
175
176 // The RenderFrameHost's IDs.
177 int render_process_id_;
178 int render_frame_id_;
179
243 scoped_ptr<ToolkitDelegate> toolkit_delegate_; 180 scoped_ptr<ToolkitDelegate> toolkit_delegate_;
244 181
245 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); 182 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuBase);
246 }; 183 };
247 184
248 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_ 185 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698