Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / renderer_context_menu / render_view_context_menu.h
bloba8038b99735b480e4b70c3d5abc813bcb1553d18
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
15 #include "components/renderer_context_menu/context_menu_content_type.h"
16 #include "components/renderer_context_menu/render_view_context_menu_base.h"
17 #include "components/renderer_context_menu/render_view_context_menu_observer.h"
18 #include "components/renderer_context_menu/render_view_context_menu_proxy.h"
19 #include "content/public/common/context_menu_params.h"
20 #include "ui/base/models/simple_menu_model.h"
21 #include "ui/base/window_open_disposition.h"
22 #include "ui/gfx/geometry/vector2d.h"
24 #if defined(ENABLE_EXTENSIONS)
25 #include "chrome/browser/extensions/context_menu_matcher.h"
26 #include "chrome/browser/extensions/menu_manager.h"
27 #endif
29 class PrintPreviewContextMenuObserver;
30 class Profile;
31 class SpellingMenuObserver;
32 class SpellCheckerSubMenuObserver;
34 namespace content {
35 class RenderFrameHost;
36 class WebContents;
39 namespace extensions {
40 class Extension;
41 class MenuItem;
44 namespace gfx {
45 class Point;
48 namespace blink {
49 struct WebMediaPlayerAction;
50 struct WebPluginAction;
53 class RenderViewContextMenu : public RenderViewContextMenuBase {
54 public:
55 RenderViewContextMenu(content::RenderFrameHost* render_frame_host,
56 const content::ContextMenuParams& params);
58 ~RenderViewContextMenu() override;
60 // Returns the offset amount if the context menu requires off-setting.
62 // If |render_frame_host| belongs to a WebContents that is nested within
63 // other WebContents(s), then this value is the offset between the topmost
64 // WebContents and the frame's WebContents.
65 static gfx::Vector2d GetOffset(content::RenderFrameHost* render_frame_host);
67 // SimpleMenuModel::Delegate:
68 bool IsCommandIdChecked(int command_id) const override;
69 bool IsCommandIdEnabled(int command_id) const override;
70 void ExecuteCommand(int command_id, int event_flags) override;
72 protected:
73 Profile* GetProfile();
75 // Returns a (possibly truncated) version of the current selection text
76 // suitable for putting in the title of a menu item.
77 base::string16 PrintableSelectionText();
79 // Helper function to escape "&" as "&&".
80 void EscapeAmpersands(base::string16* text);
82 #if defined(ENABLE_EXTENSIONS)
83 extensions::ContextMenuMatcher extension_items_;
84 #endif
86 private:
87 friend class RenderViewContextMenuTest;
88 friend class RenderViewContextMenuPrefsTest;
90 static bool IsDevToolsURL(const GURL& url);
91 static bool IsInternalResourcesURL(const GURL& url);
92 #if defined(ENABLE_EXTENSIONS)
93 static bool ExtensionContextAndPatternMatch(
94 const content::ContextMenuParams& params,
95 const extensions::MenuItem::ContextList& contexts,
96 const extensions::URLPatternSet& target_url_patterns);
97 static bool MenuItemMatchesParams(const content::ContextMenuParams& params,
98 const extensions::MenuItem* item);
99 #endif
101 // RenderViewContextMenuBase:
102 void InitMenu() override;
103 void RecordShownItem(int id) override;
104 void RecordUsedItem(int id) override;
105 #if defined(ENABLE_PLUGINS)
106 void HandleAuthorizeAllPlugins() override;
107 #endif
108 void NotifyMenuShown() override;
109 void NotifyURLOpened(const GURL& url,
110 content::WebContents* new_contents) override;
112 // Gets the extension (if any) associated with the WebContents that we're in.
113 const extensions::Extension* GetExtension() const;
115 void AppendDeveloperItems();
116 void AppendDevtoolsForUnpackedExtensions();
117 void AppendLinkItems();
118 void AppendImageItems();
119 void AppendAudioItems();
120 void AppendCanvasItems();
121 void AppendVideoItems();
122 void AppendMediaItems();
123 void AppendPluginItems();
124 void AppendPageItems();
125 void AppendFrameItems();
126 void AppendCopyItem();
127 void AppendPrintItem();
128 void AppendRotationItems();
129 void AppendEditableItems();
130 void AppendSearchProvider();
131 #if defined(ENABLE_EXTENSIONS)
132 void AppendAllExtensionItems();
133 void AppendCurrentExtensionItems();
134 #endif
135 void AppendPrintPreviewItems();
136 void AppendSearchWebForImageItems();
137 void AppendSpellingSuggestionsSubMenu();
138 void AppendSpellcheckOptionsSubMenu();
139 void AppendProtocolHandlerSubMenu();
140 void AppendPasswordItems();
142 // Copy to the clipboard an image located at a point in the RenderView
143 void CopyImageAt(int x, int y);
145 // Load the original image located at a point in the RenderView.
146 void LoadOriginalImage();
148 // Get an image located at a point in the RenderView for search.
149 void GetImageThumbnailForSearch();
151 // Launch the inspector targeting a point in the RenderView
152 void Inspect(int x, int y);
154 // Writes the specified text/url to the system clipboard
155 void WriteURLToClipboard(const GURL& url);
157 void MediaPlayerActionAt(const gfx::Point& location,
158 const blink::WebMediaPlayerAction& action);
159 void PluginActionAt(const gfx::Point& location,
160 const blink::WebPluginAction& action);
162 bool IsDevCommandEnabled(int id) const;
164 // Returns a list of registered ProtocolHandlers that can handle the clicked
165 // on URL.
166 ProtocolHandlerRegistry::ProtocolHandlerList GetHandlersForLinkUrl();
168 // The destination URL to use if the user tries to search for or navigate to
169 // a text selection.
170 GURL selection_navigation_url_;
172 ui::SimpleMenuModel protocol_handler_submenu_model_;
173 ProtocolHandlerRegistry* protocol_handler_registry_;
175 // An observer that handles spelling-menu items.
176 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
178 // An observer that handles a 'spell-checker options' submenu.
179 scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_;
181 #if defined(ENABLE_PRINT_PREVIEW)
182 // An observer that disables menu items when print preview is active.
183 scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
184 #endif
186 // In the case of a MimeHandlerView this will point to the WebContents that
187 // embeds the MimeHandlerViewGuest. Otherwise this will be the same as
188 // |source_web_contents_|.
189 content::WebContents* const embedder_web_contents_;
191 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
194 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_