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_
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"
23 #if defined(ENABLE_EXTENSIONS)
24 #include "chrome/browser/extensions/context_menu_matcher.h"
25 #include "chrome/browser/extensions/menu_manager.h"
28 class PrintPreviewContextMenuObserver
;
30 class SpellingMenuObserver
;
31 class SpellCheckerSubMenuObserver
;
34 class RenderFrameHost
;
38 namespace extensions
{
48 struct WebMediaPlayerAction
;
49 struct WebPluginAction
;
52 class RenderViewContextMenu
: public RenderViewContextMenuBase
{
54 RenderViewContextMenu(content::RenderFrameHost
* render_frame_host
,
55 const content::ContextMenuParams
& params
);
57 ~RenderViewContextMenu() override
;
59 // SimpleMenuModel::Delegate:
60 bool IsCommandIdChecked(int command_id
) const override
;
61 bool IsCommandIdEnabled(int command_id
) const override
;
62 void ExecuteCommand(int command_id
, int event_flags
) override
;
65 Profile
* GetProfile();
67 #if defined(ENABLE_EXTENSIONS)
68 extensions::ContextMenuMatcher extension_items_
;
72 friend class RenderViewContextMenuTest
;
73 friend class RenderViewContextMenuPrefsTest
;
75 static bool IsDevToolsURL(const GURL
& url
);
76 static bool IsInternalResourcesURL(const GURL
& url
);
77 #if defined(ENABLE_EXTENSIONS)
78 static bool ExtensionContextAndPatternMatch(
79 const content::ContextMenuParams
& params
,
80 const extensions::MenuItem::ContextList
& contexts
,
81 const extensions::URLPatternSet
& target_url_patterns
);
82 static bool MenuItemMatchesParams(const content::ContextMenuParams
& params
,
83 const extensions::MenuItem
* item
);
86 // RenderViewContextMenuBase:
87 void InitMenu() override
;
88 void RecordShownItem(int id
) override
;
89 void RecordUsedItem(int id
) override
;
90 #if defined(ENABLE_PLUGINS)
91 void HandleAuthorizeAllPlugins() override
;
93 void NotifyMenuShown() override
;
94 void NotifyURLOpened(const GURL
& url
,
95 content::WebContents
* new_contents
) override
;
97 // Gets the extension (if any) associated with the WebContents that we're in.
98 const extensions::Extension
* GetExtension() const;
100 void AppendDeveloperItems();
101 void AppendDevtoolsForUnpackedExtensions();
102 void AppendLinkItems();
103 void AppendImageItems();
104 void AppendAudioItems();
105 void AppendCanvasItems();
106 void AppendVideoItems();
107 void AppendMediaItems();
108 void AppendPluginItems();
109 void AppendPageItems();
110 void AppendFrameItems();
111 void AppendCopyItem();
112 void AppendPrintItem();
113 void AppendRotationItems();
114 void AppendEditableItems();
115 void AppendSearchProvider();
116 #if defined(ENABLE_EXTENSIONS)
117 void AppendAllExtensionItems();
118 void AppendCurrentExtensionItems();
120 void AppendPrintPreviewItems();
121 void AppendSearchWebForImageItems();
122 void AppendSpellingSuggestionsSubMenu();
123 void AppendSpellcheckOptionsSubMenu();
124 void AppendProtocolHandlerSubMenu();
126 // Copy to the clipboard an image located at a point in the RenderView
127 void CopyImageAt(int x
, int y
);
129 // Get an image located at a point in the RenderView for search.
130 void GetImageThumbnailForSearch();
132 // Launch the inspector targeting a point in the RenderView
133 void Inspect(int x
, int y
);
135 // Writes the specified text/url to the system clipboard
136 void WriteURLToClipboard(const GURL
& url
);
138 void MediaPlayerActionAt(const gfx::Point
& location
,
139 const blink::WebMediaPlayerAction
& action
);
140 void PluginActionAt(const gfx::Point
& location
,
141 const blink::WebPluginAction
& action
);
143 bool IsDevCommandEnabled(int id
) const;
145 // Returns a list of registered ProtocolHandlers that can handle the clicked
147 ProtocolHandlerRegistry::ProtocolHandlerList
GetHandlersForLinkUrl();
149 // Returns a (possibly truncated) version of the current selection text
150 // suitable or putting in the title of a menu item.
151 base::string16
PrintableSelectionText();
153 // The destination URL to use if the user tries to search for or navigate to
155 GURL selection_navigation_url_
;
157 ui::SimpleMenuModel protocol_handler_submenu_model_
;
158 ProtocolHandlerRegistry
* protocol_handler_registry_
;
160 // An observer that handles spelling-menu items.
161 scoped_ptr
<SpellingMenuObserver
> spelling_menu_observer_
;
163 // An observer that handles a 'spell-checker options' submenu.
164 scoped_ptr
<SpellCheckerSubMenuObserver
> spellchecker_submenu_observer_
;
166 #if defined(ENABLE_PRINT_PREVIEW)
167 // An observer that disables menu items when print preview is active.
168 scoped_ptr
<PrintPreviewContextMenuObserver
> print_preview_menu_observer_
;
171 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu
);
174 #endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_