context_menu_params.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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
3// found in the LICENSE file.
4
5#ifndef CONTENT_PUBLIC_COMMON_CONTEXT_MENU_PARAMS_H_
6#define CONTENT_PUBLIC_COMMON_CONTEXT_MENU_PARAMS_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/strings/string16.h"
12#include "content/common/content_export.h"
13#include "content/public/common/menu_item.h"
14#include "content/public/common/page_state.h"
15#include "content/public/common/ssl_status.h"
16#include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
17#include "third_party/WebKit/public/web/WebContextMenuData.h"
18#include "ui/base/ui_base_types.h"
19#include "url/gurl.h"
20
21#if defined(OS_ANDROID)
22#include "ui/gfx/point.h"
23#endif
24
25namespace content {
26
27struct CONTENT_EXPORT CustomContextMenuContext {
28  static const int32 kCurrentRenderWidget;
29
30  CustomContextMenuContext();
31
32  bool is_pepper_menu;
33  int request_id;
34  // The routing ID of the render widget on which the context menu is shown.
35  // It could also be |kCurrentRenderWidget|, which means the render widget that
36  // the corresponding ViewHostMsg_ContextMenu is sent to.
37  int32 render_widget_id;
38};
39
40// FIXME(beng): This would be more useful in the future and more efficient
41//              if the parameters here weren't so literally mapped to what
42//              they contain for the ContextMenu task. It might be better
43//              to make the string fields more generic so that this object
44//              could be used for more contextual actions.
45struct CONTENT_EXPORT ContextMenuParams {
46  ContextMenuParams();
47  ~ContextMenuParams();
48
49  // This is the type of Context Node that the context menu was invoked on.
50  WebKit::WebContextMenuData::MediaType media_type;
51
52  // These values represent the coordinates of the mouse when the context menu
53  // was invoked.  Coords are relative to the associated RenderView's origin.
54  int x;
55  int y;
56
57  // This is the URL of the link that encloses the node the context menu was
58  // invoked on.
59  GURL link_url;
60
61  // The text associated with the link. May be an empty string if the contents
62  // of the link are an image.
63  // Will be empty if link_url is empty.
64  string16 link_text;
65
66  // The link URL to be used ONLY for "copy link address". We don't validate
67  // this field in the frontend process.
68  GURL unfiltered_link_url;
69
70  // This is the source URL for the element that the context menu was
71  // invoked on.  Example of elements with source URLs are img, audio, and
72  // video.
73  GURL src_url;
74
75  // This is true if the context menu was invoked on a blocked image.
76  bool is_image_blocked;
77
78  // This is the URL of the top level page that the context menu was invoked
79  // on.
80  GURL page_url;
81
82  // This is the absolute keyword search URL including the %s search tag when
83  // the "Add as search engine..." option is clicked (left empty if not used).
84  GURL keyword_url;
85
86  // This is the URL of the subframe that the context menu was invoked on.
87  GURL frame_url;
88
89  // This is the ID of the subframe that the context menu was invoked on.
90  int64 frame_id;
91
92  // This is the page state of the frame on which the context menu was invoked.
93  PageState frame_page_state;
94
95  // These are the parameters for the media element that the context menu
96  // was invoked on.
97  int media_flags;
98
99  // This is the text of the selection that the context menu was invoked on.
100  string16 selection_text;
101
102  // The misspelled word under the cursor, if any. Used to generate the
103  // |dictionary_suggestions| list.
104  string16 misspelled_word;
105
106  // The identifier of the misspelling under the cursor, if any.
107  uint32 misspelling_hash;
108
109  // Suggested replacements for a misspelled word under the cursor.
110  // This vector gets populated in the render process host
111  // by intercepting ViewHostMsg_ContextMenu in ResourceMessageFilter
112  // and populating dictionary_suggestions if the type is EDITABLE
113  // and the misspelled_word is not empty.
114  std::vector<string16> dictionary_suggestions;
115
116  // If editable, flag for whether node is speech-input enabled.
117  bool speech_input_enabled;
118
119  // If editable, flag for whether spell check is enabled or not.
120  bool spellcheck_enabled;
121
122  // Whether context is editable.
123  bool is_editable;
124
125#if defined(OS_MACOSX)
126  // Writing direction menu items.
127  // Currently only used on OS X.
128  int writing_direction_default;
129  int writing_direction_left_to_right;
130  int writing_direction_right_to_left;
131#endif  // OS_MACOSX
132
133  // These flags indicate to the browser whether the renderer believes it is
134  // able to perform the corresponding action.
135  int edit_flags;
136
137  // The security info for the resource we are showing the menu on.
138  SSLStatus security_info;
139
140  // The character encoding of the frame on which the menu is invoked.
141  std::string frame_charset;
142
143  // The referrer policy of the frame on which the menu is invoked.
144  WebKit::WebReferrerPolicy referrer_policy;
145
146  CustomContextMenuContext custom_context;
147  std::vector<MenuItem> custom_items;
148
149  ui::MenuSourceType source_type;
150
151#if defined(OS_ANDROID)
152  // Points representing the coordinates in the document space of the start and
153  // end of the selection, if there is one.
154  gfx::Point selection_start;
155  gfx::Point selection_end;
156#endif
157
158};
159
160}  // namespace content
161
162#endif  // CONTENT_PUBLIC_COMMON_CONTEXT_MENU_PARAMS_H_
163