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