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

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

Issue 10918103: Give platform apps control over launcher right-click context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and fix conflicts Created 8 years, 2 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 (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_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 16 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
17 #include "chrome/browser/extensions/context_menu_matcher.h"
17 #include "chrome/browser/extensions/menu_manager.h" 18 #include "chrome/browser/extensions/menu_manager.h"
18 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" 19 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h"
19 #include "content/public/common/context_menu_params.h" 20 #include "content/public/common/context_menu_params.h"
20 #include "content/public/common/page_transition_types.h" 21 #include "content/public/common/page_transition_types.h"
21 #include "ui/base/models/simple_menu_model.h" 22 #include "ui/base/models/simple_menu_model.h"
22 #include "webkit/glue/window_open_disposition.h" 23 #include "webkit/glue/window_open_disposition.h"
23 24
24 class PrintPreviewContextMenuObserver; 25 class PrintPreviewContextMenuObserver;
25 class Profile; 26 class Profile;
26 class SpellingMenuObserver; 27 class SpellingMenuObserver;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 121
121 // Retrieve the given associated objects with a context menu. 122 // Retrieve the given associated objects with a context menu.
122 virtual content::RenderViewHost* GetRenderViewHost() const = 0; 123 virtual content::RenderViewHost* GetRenderViewHost() const = 0;
123 virtual content::WebContents* GetWebContents() const = 0; 124 virtual content::WebContents* GetWebContents() const = 0;
124 virtual Profile* GetProfile() const = 0; 125 virtual Profile* GetProfile() const = 0;
125 }; 126 };
126 127
127 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, 128 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
128 public RenderViewContextMenuProxy { 129 public RenderViewContextMenuProxy {
129 public: 130 public:
130 static const size_t kMaxExtensionItemTitleLength;
131 static const size_t kMaxSelectionTextLength; 131 static const size_t kMaxSelectionTextLength;
132 132
133 RenderViewContextMenu(content::WebContents* web_contents, 133 RenderViewContextMenu(content::WebContents* web_contents,
134 const content::ContextMenuParams& params); 134 const content::ContextMenuParams& params);
135 135
136 virtual ~RenderViewContextMenu(); 136 virtual ~RenderViewContextMenu();
137 137
138 // Initializes the context menu. 138 // Initializes the context menu.
139 void Init(); 139 void Init();
140 140
(...skipping 30 matching lines...) Expand all
171 void InitMenu(); 171 void InitMenu();
172 172
173 // Platform specific functions. 173 // Platform specific functions.
174 virtual void PlatformInit() = 0; 174 virtual void PlatformInit() = 0;
175 virtual void PlatformCancel() = 0; 175 virtual void PlatformCancel() = 0;
176 virtual bool GetAcceleratorForCommandId( 176 virtual bool GetAcceleratorForCommandId(
177 int command_id, 177 int command_id,
178 ui::Accelerator* accelerator) = 0; 178 ui::Accelerator* accelerator) = 0;
179 virtual void AppendPlatformEditableItems(); 179 virtual void AppendPlatformEditableItems();
180 180
181 // Attempts to get an MenuItem given the id of a context menu item.
182 extensions::MenuItem* GetExtensionMenuItem(int id) const;
183
184 content::ContextMenuParams params_; 181 content::ContextMenuParams params_;
185 content::WebContents* source_web_contents_; 182 content::WebContents* source_web_contents_;
186 Profile* profile_; 183 Profile* profile_;
187 184
188 ui::SimpleMenuModel menu_model_; 185 ui::SimpleMenuModel menu_model_;
186 extensions::ContextMenuMatcher extension_items_;
189 187
190 // True if we are showing for an external tab contents. The default is false. 188 // True if we are showing for an external tab contents. The default is false.
191 bool external_; 189 bool external_;
192 190
193 // Maps the id from a context menu item to the MenuItem's internal id.
194 std::map<int, extensions::MenuItem::Id> extension_item_map_;
195
196 private: 191 private:
197 friend class RenderViewContextMenuTest; 192 friend class RenderViewContextMenuTest;
198 193
199 static bool IsDevToolsURL(const GURL& url); 194 static bool IsDevToolsURL(const GURL& url);
200 static bool IsInternalResourcesURL(const GURL& url); 195 static bool IsInternalResourcesURL(const GURL& url);
201 static bool ExtensionContextAndPatternMatch( 196 static bool ExtensionContextAndPatternMatch(
202 const content::ContextMenuParams& params, 197 const content::ContextMenuParams& params,
203 extensions::MenuItem::ContextList contexts, 198 extensions::MenuItem::ContextList contexts,
204 const URLPatternSet& target_url_patterns); 199 const URLPatternSet& target_url_patterns);
205 static extensions::MenuItem::List GetRelevantExtensionItems( 200 static bool MenuItemMatchesParams(
206 const extensions::MenuItem::List& items,
207 const content::ContextMenuParams& params, 201 const content::ContextMenuParams& params,
208 Profile* profile, 202 const extensions::MenuItem* item);
209 bool can_cross_incognito);
210 203
211 // Gets the extension (if any) associated with the WebContents that we're in. 204 // Gets the extension (if any) associated with the WebContents that we're in.
212 const extensions::Extension* GetExtension() const; 205 const extensions::Extension* GetExtension() const;
213 void AppendPlatformAppItems(); 206 void AppendPlatformAppItems();
214 void AppendPopupExtensionItems(); 207 void AppendPopupExtensionItems();
215 bool AppendCustomItems(); 208 bool AppendCustomItems();
216 void AppendDeveloperItems(); 209 void AppendDeveloperItems();
217 void AppendLinkItems(); 210 void AppendLinkItems();
218 void AppendImageItems(); 211 void AppendImageItems();
219 void AppendAudioItems(); 212 void AppendAudioItems();
220 void AppendVideoItems(); 213 void AppendVideoItems();
221 void AppendMediaItems(); 214 void AppendMediaItems();
222 void AppendPluginItems(); 215 void AppendPluginItems();
223 void AppendPageItems(); 216 void AppendPageItems();
224 void AppendFrameItems(); 217 void AppendFrameItems();
225 void AppendCopyItem(); 218 void AppendCopyItem();
226 void AppendEditableItems(); 219 void AppendEditableItems();
227 void AppendSearchProvider(); 220 void AppendSearchProvider();
228 void AppendAllExtensionItems(); 221 void AppendAllExtensionItems();
229 void AppendSpellingSuggestionsSubMenu(); 222 void AppendSpellingSuggestionsSubMenu();
230 void AppendSpellcheckOptionsSubMenu(); 223 void AppendSpellcheckOptionsSubMenu();
231 void AppendSpeechInputOptionsSubMenu(); 224 void AppendSpeechInputOptionsSubMenu();
232 void AppendProtocolHandlerSubMenu(); 225 void AppendProtocolHandlerSubMenu();
233 226
234 // This is a helper function to append items for one particular extension.
235 // The |index| parameter is used for assigning id's, and is incremented for
236 // each item actually added.
237 void AppendExtensionItems(const std::string& extension_id, int* index);
238
239 // Used for recursively adding submenus of extension items.
240 void RecursivelyAppendExtensionItems(
241 const std::vector<extensions::MenuItem*>& items,
242 bool can_cross_incognito,
243 ui::SimpleMenuModel* menu_model,
244 int* index);
245 // This will set the icon on the most recently-added item in the menu_model_.
246 void SetExtensionIcon(const std::string& extension_id);
247
248 // Opens the specified URL string in a new tab. The |frame_id| specifies the 227 // Opens the specified URL string in a new tab. The |frame_id| specifies the
249 // frame in which the context menu was displayed, or 0 if the menu action is 228 // frame in which the context menu was displayed, or 0 if the menu action is
250 // independent of that frame (e.g. protocol handler settings). 229 // independent of that frame (e.g. protocol handler settings).
251 void OpenURL(const GURL& url, const GURL& referrer, int64 frame_id, 230 void OpenURL(const GURL& url, const GURL& referrer, int64 frame_id,
252 WindowOpenDisposition disposition, 231 WindowOpenDisposition disposition,
253 content::PageTransition transition); 232 content::PageTransition transition);
254 233
255 // Copy to the clipboard an image located at a point in the RenderView 234 // Copy to the clipboard an image located at a point in the RenderView
256 void CopyImageAt(int x, int y); 235 void CopyImageAt(int x, int y);
257 236
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // An observer that disables menu items when print preview is active. 273 // An observer that disables menu items when print preview is active.
295 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; 274 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
296 275
297 // Our observers. 276 // Our observers.
298 mutable ObserverList<RenderViewContextMenuObserver> observers_; 277 mutable ObserverList<RenderViewContextMenuObserver> observers_;
299 278
300 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); 279 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
301 }; 280 };
302 281
303 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ 282 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager.h ('k') | chrome/browser/tab_contents/render_view_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698