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

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: 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 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 52 static void InitCustomIdRnages();
lazyboy 2014/08/01 07:59:34 Ranges typo.
oshima 2014/08/01 10:38:44 This was no longer necessary. removed.
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 53
78 RenderViewContextMenu(content::RenderFrameHost* render_frame_host, 54 RenderViewContextMenu(content::RenderFrameHost* render_frame_host,
79 const content::ContextMenuParams& params); 55 const content::ContextMenuParams& params);
80 56
81 virtual ~RenderViewContextMenu(); 57 virtual ~RenderViewContextMenu();
82 58
83 // Initializes the context menu. 59 // 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; 60 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
94 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 61 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
95 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 62 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.em
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 63
116 protected: 64 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(); 65 Profile* GetProfile();
127 66
128 // Platform specific functions. 67 // 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_; 68 extensions::ContextMenuMatcher extension_items_;
143 69
144 private: 70 private:
145 friend class RenderViewContextMenuTest; 71 friend class RenderViewContextMenuTest;
146 friend class RenderViewContextMenuPrefsTest; 72 friend class RenderViewContextMenuPrefsTest;
147 73
148 static bool IsDevToolsURL(const GURL& url); 74 static bool IsDevToolsURL(const GURL& url);
149 static bool IsInternalResourcesURL(const GURL& url); 75 static bool IsInternalResourcesURL(const GURL& url);
150 static bool ExtensionContextAndPatternMatch( 76 static bool ExtensionContextAndPatternMatch(
151 const content::ContextMenuParams& params, 77 const content::ContextMenuParams& params,
152 extensions::MenuItem::ContextList contexts, 78 extensions::MenuItem::ContextList contexts,
153 const extensions::URLPatternSet& target_url_patterns); 79 const extensions::URLPatternSet& target_url_patterns);
154 static bool MenuItemMatchesParams(const content::ContextMenuParams& params, 80 static bool MenuItemMatchesParams(const content::ContextMenuParams& params,
155 const extensions::MenuItem* item); 81 const extensions::MenuItem* item);
156 82
83 // RenderViewContextMenu:
lazyboy 2014/08/01 07:59:34 RenderViewContextMenuBase nit: also sort them?
oshima 2014/08/01 10:38:44 Done
84 virtual void RecordUsedItem(int id) OVERRIDE;
85 virtual void RecordShownItem(int id) OVERRIDE;
86 virtual void HandleAuthorizeAllPlugins() OVERRIDE;
87 virtual void InitMenu() OVERRIDE;
88 virtual void NotifyMenuShown() OVERRIDE;
89 virtual void NotifyURLOpened(const GURL& url,
90 content::WebContents* new_contents) OVERRIDE;
91
157 // Gets the extension (if any) associated with the WebContents that we're in. 92 // Gets the extension (if any) associated with the WebContents that we're in.
158 const extensions::Extension* GetExtension() const; 93 const extensions::Extension* GetExtension() const;
159 bool AppendCustomItems();
160 94
161 void AppendDeveloperItems(); 95 void AppendDeveloperItems();
162 void AppendDevtoolsForUnpackedExtensions(); 96 void AppendDevtoolsForUnpackedExtensions();
163 void AppendLinkItems(); 97 void AppendLinkItems();
164 void AppendImageItems(); 98 void AppendImageItems();
165 void AppendAudioItems(); 99 void AppendAudioItems();
166 void AppendCanvasItems(); 100 void AppendCanvasItems();
167 void AppendVideoItems(); 101 void AppendVideoItems();
168 void AppendMediaItems(); 102 void AppendMediaItems();
169 void AppendPluginItems(); 103 void AppendPluginItems();
170 void AppendPageItems(); 104 void AppendPageItems();
171 void AppendFrameItems(); 105 void AppendFrameItems();
172 void AppendCopyItem(); 106 void AppendCopyItem();
173 void AppendPrintItem(); 107 void AppendPrintItem();
174 void AppendEditableItems(); 108 void AppendEditableItems();
175 void AppendSearchProvider(); 109 void AppendSearchProvider();
176 void AppendAllExtensionItems(); 110 void AppendAllExtensionItems();
177 void AppendCurrentExtensionItems(); 111 void AppendCurrentExtensionItems();
178 void AppendPrintPreviewItems(); 112 void AppendPrintPreviewItems();
179 void AppendSearchWebForImageItems(); 113 void AppendSearchWebForImageItems();
180 void AppendSpellingSuggestionsSubMenu(); 114 void AppendSpellingSuggestionsSubMenu();
181 void AppendSpellcheckOptionsSubMenu(); 115 void AppendSpellcheckOptionsSubMenu();
182 void AppendProtocolHandlerSubMenu(); 116 void AppendProtocolHandlerSubMenu();
183 117
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 118 // Copy to the clipboard an image located at a point in the RenderView
190 void CopyImageAt(int x, int y); 119 void CopyImageAt(int x, int y);
191 120
192 // Get an image located at a point in the RenderView for search. 121 // Get an image located at a point in the RenderView for search.
193 void GetImageThumbnailForSearch(); 122 void GetImageThumbnailForSearch();
194 123
195 // Launch the inspector targeting a point in the RenderView 124 // Launch the inspector targeting a point in the RenderView
196 void Inspect(int x, int y); 125 void Inspect(int x, int y);
197 126
198 // Writes the specified text/url to the system clipboard 127 // Writes the specified text/url to the system clipboard
(...skipping 25 matching lines...) Expand all
224 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_; 153 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
225 154
226 // An observer that handles a 'spell-checker options' submenu. 155 // An observer that handles a 'spell-checker options' submenu.
227 scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_; 156 scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_;
228 157
229 #if defined(ENABLE_FULL_PRINTING) 158 #if defined(ENABLE_FULL_PRINTING)
230 // An observer that disables menu items when print preview is active. 159 // An observer that disables menu items when print preview is active.
231 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; 160 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
232 #endif 161 #endif
233 162
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); 163 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
246 }; 164 };
247 165
248 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_ 166 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698