e234867fc61f00539575048dced9ea06e0166be0
[platform/framework/web/crosswalk.git] / src / chrome / browser / renderer_context_menu / render_view_context_menu.h
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.
4
5 #ifndef CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_
7
8 #include <map>
9 #include <string>
10
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 "chrome/browser/extensions/context_menu_matcher.h"
16 #include "chrome/browser/extensions/menu_manager.h"
17 #include "components/renderer_context_menu/context_menu_content_type.h"
18 #include "components/renderer_context_menu/render_view_context_menu_base.h"
19 #include "components/renderer_context_menu/render_view_context_menu_observer.h"
20 #include "components/renderer_context_menu/render_view_context_menu_proxy.h"
21 #include "content/public/common/context_menu_params.h"
22 #include "content/public/common/page_transition_types.h"
23 #include "ui/base/models/simple_menu_model.h"
24 #include "ui/base/window_open_disposition.h"
25
26 class PrintPreviewContextMenuObserver;
27 class Profile;
28 class SpellingMenuObserver;
29 class SpellCheckerSubMenuObserver;
30
31 namespace content {
32 class RenderFrameHost;
33 class WebContents;
34 }
35
36 namespace extensions {
37 class Extension;
38 class MenuItem;
39 }
40
41 namespace gfx {
42 class Point;
43 }
44
45 namespace blink {
46 struct WebMediaPlayerAction;
47 struct WebPluginAction;
48 }
49
50 class RenderViewContextMenu : public RenderViewContextMenuBase {
51  public:
52   RenderViewContextMenu(content::RenderFrameHost* render_frame_host,
53                         const content::ContextMenuParams& params);
54
55   virtual ~RenderViewContextMenu();
56
57   // SimpleMenuModel::Delegate:
58   virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
59   virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
60   virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
61
62  protected:
63   Profile* GetProfile();
64   extensions::ContextMenuMatcher extension_items_;
65
66  private:
67   friend class RenderViewContextMenuTest;
68   friend class RenderViewContextMenuPrefsTest;
69
70   static bool IsDevToolsURL(const GURL& url);
71   static bool IsInternalResourcesURL(const GURL& url);
72   static bool ExtensionContextAndPatternMatch(
73       const content::ContextMenuParams& params,
74       extensions::MenuItem::ContextList contexts,
75       const extensions::URLPatternSet& target_url_patterns);
76   static bool MenuItemMatchesParams(const content::ContextMenuParams& params,
77                                     const extensions::MenuItem* item);
78
79   // RenderViewContextMenuBase:
80   virtual void InitMenu() OVERRIDE;
81   virtual void RecordShownItem(int id) OVERRIDE;
82   virtual void RecordUsedItem(int id) OVERRIDE;
83 #if defined(ENABLE_PLUGINS)
84   virtual void HandleAuthorizeAllPlugins() OVERRIDE;
85 #endif
86   virtual void NotifyMenuShown() OVERRIDE;
87   virtual void NotifyURLOpened(const GURL& url,
88                                content::WebContents* new_contents) OVERRIDE;
89
90   // Gets the extension (if any) associated with the WebContents that we're in.
91   const extensions::Extension* GetExtension() const;
92
93   void AppendDeveloperItems();
94   void AppendDevtoolsForUnpackedExtensions();
95   void AppendLinkItems();
96   void AppendImageItems();
97   void AppendAudioItems();
98   void AppendCanvasItems();
99   void AppendVideoItems();
100   void AppendMediaItems();
101   void AppendPluginItems();
102   void AppendPageItems();
103   void AppendFrameItems();
104   void AppendCopyItem();
105   void AppendPrintItem();
106   void AppendEditableItems();
107   void AppendSearchProvider();
108   void AppendAllExtensionItems();
109   void AppendCurrentExtensionItems();
110   void AppendPrintPreviewItems();
111   void AppendSearchWebForImageItems();
112   void AppendSpellingSuggestionsSubMenu();
113   void AppendSpellcheckOptionsSubMenu();
114   void AppendProtocolHandlerSubMenu();
115
116   // Copy to the clipboard an image located at a point in the RenderView
117   void CopyImageAt(int x, int y);
118
119   // Get an image located at a point in the RenderView for search.
120   void GetImageThumbnailForSearch();
121
122   // Launch the inspector targeting a point in the RenderView
123   void Inspect(int x, int y);
124
125   // Writes the specified text/url to the system clipboard
126   void WriteURLToClipboard(const GURL& url);
127
128   void MediaPlayerActionAt(const gfx::Point& location,
129                            const blink::WebMediaPlayerAction& action);
130   void PluginActionAt(const gfx::Point& location,
131                       const blink::WebPluginAction& action);
132
133   bool IsDevCommandEnabled(int id) const;
134
135   // Returns a list of registered ProtocolHandlers that can handle the clicked
136   // on URL.
137   ProtocolHandlerRegistry::ProtocolHandlerList GetHandlersForLinkUrl();
138
139   // Returns a (possibly truncated) version of the current selection text
140   // suitable or putting in the title of a menu item.
141   base::string16 PrintableSelectionText();
142
143   // The destination URL to use if the user tries to search for or navigate to
144   // a text selection.
145   GURL selection_navigation_url_;
146
147   ui::SimpleMenuModel protocol_handler_submenu_model_;
148   ProtocolHandlerRegistry* protocol_handler_registry_;
149
150   // An observer that handles spelling-menu items.
151   scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
152
153   // An observer that handles a 'spell-checker options' submenu.
154   scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_;
155
156 #if defined(ENABLE_FULL_PRINTING)
157   // An observer that disables menu items when print preview is active.
158   scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_;
159 #endif
160
161   DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
162 };
163
164 #endif  // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_H_