| 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_matcher.h" | |
| 18 #include "chrome/browser/extensions/menu_manager.h" | 17 #include "chrome/browser/extensions/menu_manager.h" |
| 19 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" | 18 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h" |
| 20 #include "content/public/common/context_menu_params.h" | 19 #include "content/public/common/context_menu_params.h" |
| 21 #include "content/public/common/page_transition_types.h" | 20 #include "content/public/common/page_transition_types.h" |
| 22 #include "ui/base/models/simple_menu_model.h" | 21 #include "ui/base/models/simple_menu_model.h" |
| 23 #include "webkit/glue/window_open_disposition.h" | 22 #include "webkit/glue/window_open_disposition.h" |
| 24 | 23 |
| 25 class PrintPreviewContextMenuObserver; | 24 class PrintPreviewContextMenuObserver; |
| 26 class Profile; | 25 class Profile; |
| 27 class SpellingMenuObserver; | 26 class SpellingMenuObserver; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 120 |
| 122 // Retrieve the given associated objects with a context menu. | 121 // Retrieve the given associated objects with a context menu. |
| 123 virtual content::RenderViewHost* GetRenderViewHost() const = 0; | 122 virtual content::RenderViewHost* GetRenderViewHost() const = 0; |
| 124 virtual content::WebContents* GetWebContents() const = 0; | 123 virtual content::WebContents* GetWebContents() const = 0; |
| 125 virtual Profile* GetProfile() const = 0; | 124 virtual Profile* GetProfile() const = 0; |
| 126 }; | 125 }; |
| 127 | 126 |
| 128 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, | 127 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, |
| 129 public RenderViewContextMenuProxy { | 128 public RenderViewContextMenuProxy { |
| 130 public: | 129 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 Loading... |
| 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 |
| 181 content::ContextMenuParams params_; | 184 content::ContextMenuParams params_; |
| 182 content::WebContents* source_web_contents_; | 185 content::WebContents* source_web_contents_; |
| 183 Profile* profile_; | 186 Profile* profile_; |
| 184 | 187 |
| 185 ui::SimpleMenuModel menu_model_; | 188 ui::SimpleMenuModel menu_model_; |
| 186 extensions::ContextMenuMatcher extension_items_; | |
| 187 | 189 |
| 188 // True if we are showing for an external tab contents. The default is false. | 190 // True if we are showing for an external tab contents. The default is false. |
| 189 bool external_; | 191 bool external_; |
| 190 | 192 |
| 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 |
| 191 private: | 196 private: |
| 192 friend class RenderViewContextMenuTest; | 197 friend class RenderViewContextMenuTest; |
| 193 | 198 |
| 194 static bool IsDevToolsURL(const GURL& url); | 199 static bool IsDevToolsURL(const GURL& url); |
| 195 static bool IsInternalResourcesURL(const GURL& url); | 200 static bool IsInternalResourcesURL(const GURL& url); |
| 196 static bool ExtensionContextAndPatternMatch( | 201 static bool ExtensionContextAndPatternMatch( |
| 197 const content::ContextMenuParams& params, | 202 const content::ContextMenuParams& params, |
| 198 extensions::MenuItem::ContextList contexts, | 203 extensions::MenuItem::ContextList contexts, |
| 199 const URLPatternSet& target_url_patterns); | 204 const URLPatternSet& target_url_patterns); |
| 200 static bool MenuItemMatchesParams( | 205 static extensions::MenuItem::List GetRelevantExtensionItems( |
| 206 const extensions::MenuItem::List& items, |
| 201 const content::ContextMenuParams& params, | 207 const content::ContextMenuParams& params, |
| 202 const extensions::MenuItem* item); | 208 Profile* profile, |
| 209 bool can_cross_incognito); |
| 203 | 210 |
| 204 // Gets the extension (if any) associated with the WebContents that we're in. | 211 // Gets the extension (if any) associated with the WebContents that we're in. |
| 205 const extensions::Extension* GetExtension() const; | 212 const extensions::Extension* GetExtension() const; |
| 206 void AppendPlatformAppItems(); | 213 void AppendPlatformAppItems(); |
| 207 void AppendPopupExtensionItems(); | 214 void AppendPopupExtensionItems(); |
| 208 bool AppendCustomItems(); | 215 bool AppendCustomItems(); |
| 209 void AppendDeveloperItems(); | 216 void AppendDeveloperItems(); |
| 210 void AppendLinkItems(); | 217 void AppendLinkItems(); |
| 211 void AppendImageItems(); | 218 void AppendImageItems(); |
| 212 void AppendAudioItems(); | 219 void AppendAudioItems(); |
| 213 void AppendVideoItems(); | 220 void AppendVideoItems(); |
| 214 void AppendMediaItems(); | 221 void AppendMediaItems(); |
| 215 void AppendPluginItems(); | 222 void AppendPluginItems(); |
| 216 void AppendPageItems(); | 223 void AppendPageItems(); |
| 217 void AppendFrameItems(); | 224 void AppendFrameItems(); |
| 218 void AppendCopyItem(); | 225 void AppendCopyItem(); |
| 219 void AppendEditableItems(); | 226 void AppendEditableItems(); |
| 220 void AppendSearchProvider(); | 227 void AppendSearchProvider(); |
| 221 void AppendAllExtensionItems(); | 228 void AppendAllExtensionItems(); |
| 222 void AppendSpellingSuggestionsSubMenu(); | 229 void AppendSpellingSuggestionsSubMenu(); |
| 223 void AppendSpellcheckOptionsSubMenu(); | 230 void AppendSpellcheckOptionsSubMenu(); |
| 224 void AppendSpeechInputOptionsSubMenu(); | 231 void AppendSpeechInputOptionsSubMenu(); |
| 225 void AppendProtocolHandlerSubMenu(); | 232 void AppendProtocolHandlerSubMenu(); |
| 226 | 233 |
| 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 |
| 227 // Opens the specified URL string in a new tab. The |frame_id| specifies the | 248 // Opens the specified URL string in a new tab. The |frame_id| specifies the |
| 228 // frame in which the context menu was displayed, or 0 if the menu action is | 249 // frame in which the context menu was displayed, or 0 if the menu action is |
| 229 // independent of that frame (e.g. protocol handler settings). | 250 // independent of that frame (e.g. protocol handler settings). |
| 230 void OpenURL(const GURL& url, const GURL& referrer, int64 frame_id, | 251 void OpenURL(const GURL& url, const GURL& referrer, int64 frame_id, |
| 231 WindowOpenDisposition disposition, | 252 WindowOpenDisposition disposition, |
| 232 content::PageTransition transition); | 253 content::PageTransition transition); |
| 233 | 254 |
| 234 // Copy to the clipboard an image located at a point in the RenderView | 255 // Copy to the clipboard an image located at a point in the RenderView |
| 235 void CopyImageAt(int x, int y); | 256 void CopyImageAt(int x, int y); |
| 236 | 257 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // An observer that disables menu items when print preview is active. | 294 // An observer that disables menu items when print preview is active. |
| 274 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; | 295 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; |
| 275 | 296 |
| 276 // Our observers. | 297 // Our observers. |
| 277 mutable ObserverList<RenderViewContextMenuObserver> observers_; | 298 mutable ObserverList<RenderViewContextMenuObserver> observers_; |
| 278 | 299 |
| 279 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); | 300 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); |
| 280 }; | 301 }; |
| 281 | 302 |
| 282 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ | 303 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ |
| OLD | NEW |