Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_manager.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 Loading... | |
| 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 29 matching lines...) Expand all Loading... | |
| 170 protected: | 170 protected: |
| 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 | 179 |
| 180 // Attempts to get an MenuItem given the id of a context menu item. | |
| 181 extensions::MenuItem* GetExtensionMenuItem(int id) const; | |
| 182 | |
| 183 content::ContextMenuParams params_; | 180 content::ContextMenuParams params_; |
| 184 content::WebContents* source_web_contents_; | 181 content::WebContents* source_web_contents_; |
| 185 Profile* profile_; | 182 Profile* profile_; |
| 186 | 183 |
| 187 ui::SimpleMenuModel menu_model_; | 184 ui::SimpleMenuModel menu_model_; |
| 185 extensions::ContextMenuManager menu_manager_; | |
|
asargent_no_longer_on_chrome
2012/09/10 20:25:20
nit: let's name this variable extension_items_ or
Marijn Kruisselbrink
2012/09/10 23:16:57
Done.
| |
| 188 | 186 |
| 189 // True if we are showing for an external tab contents. The default is false. | 187 // True if we are showing for an external tab contents. The default is false. |
| 190 bool external_; | 188 bool external_; |
| 191 | 189 |
| 192 // Maps the id from a context menu item to the MenuItem's internal id. | |
| 193 std::map<int, extensions::MenuItem::Id> extension_item_map_; | |
| 194 | |
| 195 private: | 190 private: |
| 196 friend class RenderViewContextMenuTest; | 191 friend class RenderViewContextMenuTest; |
| 197 | 192 |
| 198 static bool IsDevToolsURL(const GURL& url); | 193 static bool IsDevToolsURL(const GURL& url); |
| 199 static bool IsInternalResourcesURL(const GURL& url); | 194 static bool IsInternalResourcesURL(const GURL& url); |
| 200 static bool ExtensionContextAndPatternMatch( | 195 static bool ExtensionContextAndPatternMatch( |
| 201 const content::ContextMenuParams& params, | 196 const content::ContextMenuParams& params, |
| 202 extensions::MenuItem::ContextList contexts, | 197 extensions::MenuItem::ContextList contexts, |
| 203 const URLPatternSet& target_url_patterns); | 198 const URLPatternSet& target_url_patterns); |
| 204 static extensions::MenuItem::List GetRelevantExtensionItems( | 199 static bool MenuItemMatchesParams( |
| 205 const extensions::MenuItem::List& items, | |
| 206 const content::ContextMenuParams& params, | 200 const content::ContextMenuParams& params, |
| 207 Profile* profile, | 201 const extensions::MenuItem* item); |
| 208 bool can_cross_incognito); | |
| 209 | 202 |
| 210 // Gets the extension (if any) associated with the WebContents that we're in. | 203 // Gets the extension (if any) associated with the WebContents that we're in. |
| 211 const extensions::Extension* GetExtension() const; | 204 const extensions::Extension* GetExtension() const; |
| 212 void AppendPlatformAppItems(); | 205 void AppendPlatformAppItems(); |
| 213 void AppendPopupExtensionItems(); | 206 void AppendPopupExtensionItems(); |
| 214 bool AppendCustomItems(); | 207 bool AppendCustomItems(); |
| 215 void AppendDeveloperItems(); | 208 void AppendDeveloperItems(); |
| 216 void AppendLinkItems(); | 209 void AppendLinkItems(); |
| 217 void AppendImageItems(); | 210 void AppendImageItems(); |
| 218 void AppendAudioItems(); | 211 void AppendAudioItems(); |
| 219 void AppendVideoItems(); | 212 void AppendVideoItems(); |
| 220 void AppendMediaItems(); | 213 void AppendMediaItems(); |
| 221 void AppendPluginItems(); | 214 void AppendPluginItems(); |
| 222 void AppendPageItems(); | 215 void AppendPageItems(); |
| 223 void AppendFrameItems(); | 216 void AppendFrameItems(); |
| 224 void AppendCopyItem(); | 217 void AppendCopyItem(); |
| 225 void AppendEditableItems(); | 218 void AppendEditableItems(); |
| 226 void AppendSearchProvider(); | 219 void AppendSearchProvider(); |
| 227 void AppendAllExtensionItems(); | 220 void AppendAllExtensionItems(); |
| 228 void AppendSpellingSuggestionsSubMenu(); | 221 void AppendSpellingSuggestionsSubMenu(); |
| 229 void AppendSpellcheckOptionsSubMenu(); | 222 void AppendSpellcheckOptionsSubMenu(); |
| 230 void AppendSpeechInputOptionsSubMenu(); | 223 void AppendSpeechInputOptionsSubMenu(); |
| 231 // Add writing direction sub menu (only used on Mac). | 224 // Add writing direction sub menu (only used on Mac). |
| 232 void AppendBidiSubMenu(); | 225 void AppendBidiSubMenu(); |
| 233 void AppendProtocolHandlerSubMenu(); | 226 void AppendProtocolHandlerSubMenu(); |
| 234 | 227 |
| 235 // This is a helper function to append items for one particular extension. | |
| 236 // The |index| parameter is used for assigning id's, and is incremented for | |
| 237 // each item actually added. | |
| 238 void AppendExtensionItems(const std::string& extension_id, int* index); | |
| 239 | |
| 240 // Used for recursively adding submenus of extension items. | |
| 241 void RecursivelyAppendExtensionItems( | |
| 242 const std::vector<extensions::MenuItem*>& items, | |
| 243 bool can_cross_incognito, | |
| 244 ui::SimpleMenuModel* menu_model, | |
| 245 int* index); | |
| 246 // This will set the icon on the most recently-added item in the menu_model_. | |
| 247 void SetExtensionIcon(const std::string& extension_id); | |
| 248 | |
| 249 // Opens the specified URL string in a new tab. The |frame_id| specifies the | 228 // Opens the specified URL string in a new tab. The |frame_id| specifies the |
| 250 // frame in which the context menu was displayed, or 0 if the menu action is | 229 // frame in which the context menu was displayed, or 0 if the menu action is |
| 251 // independent of that frame (e.g. protocol handler settings). | 230 // independent of that frame (e.g. protocol handler settings). |
| 252 void OpenURL(const GURL& url, const GURL& referrer, int64 frame_id, | 231 void OpenURL(const GURL& url, const GURL& referrer, int64 frame_id, |
| 253 WindowOpenDisposition disposition, | 232 WindowOpenDisposition disposition, |
| 254 content::PageTransition transition); | 233 content::PageTransition transition); |
| 255 | 234 |
| 256 // Copy to the clipboard an image located at a point in the RenderView | 235 // Copy to the clipboard an image located at a point in the RenderView |
| 257 void CopyImageAt(int x, int y); | 236 void CopyImageAt(int x, int y); |
| 258 | 237 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 // An observer that disables menu items when print preview is active. | 275 // An observer that disables menu items when print preview is active. |
| 297 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; | 276 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; |
| 298 | 277 |
| 299 // Our observers. | 278 // Our observers. |
| 300 mutable ObserverList<RenderViewContextMenuObserver> observers_; | 279 mutable ObserverList<RenderViewContextMenuObserver> observers_; |
| 301 | 280 |
| 302 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); | 281 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); |
| 303 }; | 282 }; |
| 304 | 283 |
| 305 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ | 284 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ |
| OLD | NEW |