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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu.h

Issue 432003007: Separate chrome independent part from RVContextMenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: exclude android webview 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
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/render_view_context_menu.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_ 6 #define CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_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" 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
15 #include "chrome/browser/extensions/context_menu_matcher.h" 15 #include "chrome/browser/extensions/context_menu_matcher.h"
16 #include "chrome/browser/extensions/menu_manager.h" 16 #include "chrome/browser/extensions/menu_manager.h"
17 #include "components/renderer_context_menu/context_menu_content_type.h" 17 #include "components/renderer_context_menu/context_menu_content_type.h"
18 #include "components/renderer_context_menu/render_view_context_menu_base.h"
18 #include "components/renderer_context_menu/render_view_context_menu_observer.h" 19 #include "components/renderer_context_menu/render_view_context_menu_observer.h"
19 #include "components/renderer_context_menu/render_view_context_menu_proxy.h" 20 #include "components/renderer_context_menu/render_view_context_menu_proxy.h"
20 #include "content/public/common/context_menu_params.h" 21 #include "content/public/common/context_menu_params.h"
21 #include "content/public/common/page_transition_types.h" 22 #include "content/public/common/page_transition_types.h"
22 #include "ui/base/models/simple_menu_model.h" 23 #include "ui/base/models/simple_menu_model.h"
23 #include "ui/base/window_open_disposition.h" 24 #include "ui/base/window_open_disposition.h"
24 25
25 class PrintPreviewContextMenuObserver; 26 class PrintPreviewContextMenuObserver;
26 class Profile; 27 class Profile;
27 class SpellingMenuObserver; 28 class SpellingMenuObserver;
(...skipping 11 matching lines...) Expand all
39 40
40 namespace gfx { 41 namespace gfx {
41 class Point; 42 class Point;
42 } 43 }
43 44
44 namespace blink { 45 namespace blink {
45 struct WebMediaPlayerAction; 46 struct WebMediaPlayerAction;
46 struct WebPluginAction; 47 struct WebPluginAction;
47 } 48 }
48 49
49 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, 50 class RenderViewContextMenu : public RenderViewContextMenuBase {
50 public RenderViewContextMenuProxy {
51 public: 51 public:
52 // A delegate interface to communicate with the toolkit used by
53 // the embedder.
54 class ToolkitDelegate {
55 public:
56 virtual ~ToolkitDelegate() {}
57 // Initialize the toolkit's menu.
58 virtual void Init(ui::SimpleMenuModel* menu_model) = 0;
59
60 virtual void Cancel() = 0;
61
62 // Updates the actual menu items controlled by the toolkit.
63 virtual void UpdateMenuItem(int command_id,
64 bool enabled,
65 bool hidden,
66 const base::string16& title) = 0;
67 };
68
69 static const size_t kMaxSelectionTextLength;
70
71 // Convert a command ID so that it fits within the range for
72 // content context menu.
73 static int ConvertToContentCustomCommandId(int id);
74
75 // True if the given id is the one generated for content context menu.
76 static bool IsContentCustomCommandId(int id);
77
78 RenderViewContextMenu(content::RenderFrameHost* render_frame_host, 52 RenderViewContextMenu(content::RenderFrameHost* render_frame_host,
79 const content::ContextMenuParams& params); 53 const content::ContextMenuParams& params);
80 54
81 virtual ~RenderViewContextMenu(); 55 virtual ~RenderViewContextMenu();
82 56
83 // Initializes the context menu. 57 // SimpleMenuModel::Delegate:
84 void Init();
85
86 // Programmatically closes the context menu.
87 void Cancel();
88
89 const ui::SimpleMenuModel& menu_model() const { return menu_model_; }
90 const content::ContextMenuParams& params() const { return params_; }
91
92 // SimpleMenuModel::Delegate implementation.
93 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 58 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
94 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 59 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
95 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 60 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
96 virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
97 virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE;
98
99 // RenderViewContextMenuProxy implementation.
100 virtual void AddMenuItem(int command_id,
101 const base::string16& title) OVERRIDE;
102 virtual void AddCheckItem(int command_id,
103 const base::string16& title) OVERRIDE;
104 virtual void AddSeparator() OVERRIDE;
105 virtual void AddSubMenu(int command_id,
106 const base::string16& label,
107 ui::MenuModel* model) OVERRIDE;
108 virtual void UpdateMenuItem(int command_id,
109 bool enabled,
110 bool hidden,
111 const base::string16& title) OVERRIDE;
112 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE;
113 virtual content::WebContents* GetWebContents() const OVERRIDE;
114 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
115 61
116 protected: 62 protected:
117 void set_toolkit_delegate(scoped_ptr<ToolkitDelegate> delegate) {
118 toolkit_delegate_ = delegate.Pass();
119 }
120
121 ToolkitDelegate* toolkit_delegate() {
122 return toolkit_delegate_.get();
123 }
124
125 void InitMenu();
126 Profile* GetProfile(); 63 Profile* GetProfile();
127
128 // Platform specific functions.
129 virtual bool GetAcceleratorForCommandId(
130 int command_id,
131 ui::Accelerator* accelerator) = 0;
132 virtual void AppendPlatformEditableItems();
133
134 content::ContextMenuParams params_;
135 content::WebContents* source_web_contents_;
136 // The RenderFrameHost's IDs.
137 int render_process_id_;
138 int render_frame_id_;
139 content::BrowserContext* browser_context_;
140
141 ui::SimpleMenuModel menu_model_;
142 extensions::ContextMenuMatcher extension_items_; 64 extensions::ContextMenuMatcher extension_items_;
143 65
144 private: 66 private:
145 friend class RenderViewContextMenuTest; 67 friend class RenderViewContextMenuTest;
146 friend class RenderViewContextMenuPrefsTest; 68 friend class RenderViewContextMenuPrefsTest;
147 69
148 static bool IsDevToolsURL(const GURL& url); 70 static bool IsDevToolsURL(const GURL& url);
149 static bool IsInternalResourcesURL(const GURL& url); 71 static bool IsInternalResourcesURL(const GURL& url);
150 static bool ExtensionContextAndPatternMatch( 72 static bool ExtensionContextAndPatternMatch(
151 const content::ContextMenuParams& params, 73 const content::ContextMenuParams& params,
152 extensions::MenuItem::ContextList contexts, 74 extensions::MenuItem::ContextList contexts,
153 const extensions::URLPatternSet& target_url_patterns); 75 const extensions::URLPatternSet& target_url_patterns);
154 static bool MenuItemMatchesParams(const content::ContextMenuParams& params, 76 static bool MenuItemMatchesParams(const content::ContextMenuParams& params,
155 const extensions::MenuItem* item); 77 const extensions::MenuItem* item);
156 78
79 // RenderViewContextMenuBase:
80 virtual void InitMenu() OVERRIDE;
81 virtual void RecordShownItem(int id) OVERRIDE;
82 virtual void RecordUsedItem(int id) OVERRIDE;
83 #if defined(ENABLE_PLUGINS)
84 virtual void HandleAuthorizeAllPlugins() OVERRIDE;
85 #endif
86 virtual void NotifyMenuShown() OVERRIDE;
87 virtual void NotifyURLOpened(const GURL& url,
88 content::WebContents* new_contents) OVERRIDE;
89
157 // Gets the extension (if any) associated with the WebContents that we're in. 90 // Gets the extension (if any) associated with the WebContents that we're in.
158 const extensions::Extension* GetExtension() const; 91 const extensions::Extension* GetExtension() const;
159 bool AppendCustomItems();
160 92
161 void AppendDeveloperItems(); 93 void AppendDeveloperItems();
162 void AppendDevtoolsForUnpackedExtensions(); 94 void AppendDevtoolsForUnpackedExtensions();
163 void AppendLinkItems(); 95 void AppendLinkItems();
164 void AppendImageItems(); 96 void AppendImageItems();
165 void AppendAudioItems(); 97 void AppendAudioItems();
166 void AppendCanvasItems(); 98 void AppendCanvasItems();
167 void AppendVideoItems(); 99 void AppendVideoItems();
168 void AppendMediaItems(); 100 void AppendMediaItems();
169 void AppendPluginItems(); 101 void AppendPluginItems();
170 void AppendPageItems(); 102 void AppendPageItems();
171 void AppendFrameItems(); 103 void AppendFrameItems();
172 void AppendCopyItem(); 104 void AppendCopyItem();
173 void AppendPrintItem(); 105 void AppendPrintItem();
174 void AppendEditableItems(); 106 void AppendEditableItems();
175 void AppendSearchProvider(); 107 void AppendSearchProvider();
176 void AppendAllExtensionItems(); 108 void AppendAllExtensionItems();
177 void AppendCurrentExtensionItems(); 109 void AppendCurrentExtensionItems();
178 void AppendPrintPreviewItems(); 110 void AppendPrintPreviewItems();
179 void AppendSearchWebForImageItems(); 111 void AppendSearchWebForImageItems();
180 void AppendSpellingSuggestionsSubMenu(); 112 void AppendSpellingSuggestionsSubMenu();
181 void AppendSpellcheckOptionsSubMenu(); 113 void AppendSpellcheckOptionsSubMenu();
182 void AppendProtocolHandlerSubMenu(); 114 void AppendProtocolHandlerSubMenu();
183 115
184 // Opens the specified URL string in a new tab.
185 void OpenURL(const GURL& url, const GURL& referrer,
186 WindowOpenDisposition disposition,
187 content::PageTransition transition);
188
189 // Copy to the clipboard an image located at a point in the RenderView 116 // Copy to the clipboard an image located at a point in the RenderView
190 void CopyImageAt(int x, int y); 117 void CopyImageAt(int x, int y);
191 118
192 // Get an image located at a point in the RenderView for search. 119 // Get an image located at a point in the RenderView for search.
193 void GetImageThumbnailForSearch(); 120 void GetImageThumbnailForSearch();
194 121
195 // Launch the inspector targeting a point in the RenderView 122 // Launch the inspector targeting a point in the RenderView
196 void Inspect(int x, int y); 123 void Inspect(int x, int y);
197 124
198 // Writes the specified text/url to the system clipboard 125 // Writes the specified text/url to the system clipboard
(...skipping 25 matching lines...) Expand all
224 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_; 151 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
225 152
226 // An observer that handles a 'spell-checker options' submenu. 153 // An observer that handles a 'spell-checker options' submenu.
227 scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_; 154 scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_;
228 155
229 #if defined(ENABLE_FULL_PRINTING) 156 #if defined(ENABLE_FULL_PRINTING)
230 // An observer that disables menu items when print preview is active. 157 // An observer that disables menu items when print preview is active.
231 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; 158 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
232 #endif 159 #endif
233 160
234 // Our observers.
235 mutable ObserverList<RenderViewContextMenuObserver> observers_;
236
237 // Whether a command has been executed. Used to track whether menu observers
238 // should be notified of menu closing without execution.
239 bool command_executed_;
240
241 scoped_ptr<ContextMenuContentType> content_type_;
242
243 scoped_ptr<ToolkitDelegate> toolkit_delegate_;
244
245 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); 161 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
246 }; 162 };
247 163
248 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_ 164 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/render_view_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698