summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents/render_view_context_menu.h
blob: 82a1778149adf6bbc62031cb7e88ca15b60f55af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_

#include "base/string16.h"
#include "chrome/common/page_transition_types.h"
#include "webkit/glue/context_menu.h"
#include "webkit/glue/window_open_disposition.h"

class Profile;
class TabContents;
struct MediaPlayerAction;

class RenderViewContextMenu {
 public:
  RenderViewContextMenu(
      TabContents* tab_contents,
      const ContextMenuParams& params);

  virtual ~RenderViewContextMenu();

  // Initializes the context menu.
  void Init();

 protected:
  void InitMenu(ContextNodeType node, ContextMenuMediaParams media_params);

  // Functions to be implemented by platform-specific subclasses ---------------

  // Platform specific initialization goes here.
  virtual void DoInit() {}

  // Append a normal menu item, taking the name from the id.
  virtual void AppendMenuItem(int id) = 0;

  // Append a normal menu item, using |label| for the name.
  virtual void AppendMenuItem(int id, const string16& label) = 0;

  // Append a radio menu item.
  virtual void AppendRadioMenuItem(int id, const string16& label) = 0;

  // Append a checkbox menu item.
  virtual void AppendCheckboxMenuItem(int id, const string16& label) = 0;

  // Append a separator.
  virtual void AppendSeparator() = 0;

  // Start creating a submenu. Any calls to Append*() between calls to
  // StartSubMenu() and FinishSubMenu() will apply to the submenu rather than
  // the main menu we are building. We only support at most single-depth
  // submenus, so calls to StartSubMenu() while we are already building a
  // submenu will be ignored.
  virtual void StartSubMenu(int id, const string16& label) = 0;

  // Finish creating the submenu and attach it to the main menu.
  virtual void FinishSubMenu() = 0;

  // Delegate functions --------------------------------------------------------

  bool IsItemCommandEnabled(int id) const;
  bool ItemIsChecked(int id) const;
  virtual void ExecuteItemCommand(int id);

 protected:
  ContextMenuParams params_;
  TabContents* source_tab_contents_;
  Profile* profile_;

 private:
  void AppendDeveloperItems();
  void AppendLinkItems();
  void AppendImageItems();
  void AppendAudioItems(ContextMenuMediaParams media_params);
  void AppendVideoItems(ContextMenuMediaParams media_params);
  void AppendMediaItems(ContextMenuMediaParams media_params);
  void AppendPageItems();
  void AppendFrameItems();
  void AppendCopyItem();
  void AppendEditableItems();
  void AppendSearchProvider();

  // Opens the specified URL string in a new tab.  If |in_current_window| is
  // false, a new window is created to hold the new tab.
  void OpenURL(const GURL& url,
               WindowOpenDisposition disposition,
               PageTransition::Type transition);

  // Copy to the clipboard an image located at a point in the RenderView
  void CopyImageAt(int x, int y);

  // Launch the inspector targeting a point in the RenderView
  void Inspect(int x, int y);

  // Writes the specified text/url to the system clipboard
  void WriteURLToClipboard(const GURL& url);

  void MediaPlayerActionAt(int x, int y, const MediaPlayerAction& action);

  bool IsDevCommandEnabled(int id) const;

  DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
};

#endif  // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_