Bypass http cache for concurrent range requests.
[chromium-blink-merge.git] / athena / content / render_view_context_menu_impl.cc
blob6c2f2b60a5be0d55c89d2db1905da73beeab8ea6
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 #include "athena/content/render_view_context_menu_impl.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/renderer_context_menu/context_menu_content_type.h"
9 #include "components/renderer_context_menu/views/toolkit_delegate_views.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/web_contents.h"
12 #include "third_party/WebKit/public/web/WebContextMenuData.h"
14 namespace athena {
15 using blink::WebContextMenuData;
17 namespace {
19 enum {
20 // Nativation
21 CMD_BACK = 0,
22 CMD_FORWARD,
23 CMD_RELOAD,
24 CMD_VIEW_SOURCE,
26 // Link
27 CMD_OPEN_LINK_NEW_ACTIVITY,
29 // Edit
30 CMD_UNDO,
31 CMD_REDO,
32 CMD_CUT,
33 CMD_COPY,
34 CMD_PASTE,
35 CMD_PASTE_AND_MATCH_STYLE,
36 CMD_DELETE,
37 CMD_SELECT_ALL,
38 CMD_LAST,
41 // Max number of custom command ids allowd.
42 const int kNumCustomCommandIds = 1000;
44 // TODO(oshima): Move IDS for context menus to components/renderer_context_menu
45 // and replace hardcoded strings below.
46 void AppendPageItems(ui::SimpleMenuModel* menu_model) {
47 menu_model->AddItem(CMD_BACK, base::ASCIIToUTF16("Back"));
48 menu_model->AddItem(CMD_FORWARD, base::ASCIIToUTF16("Forward"));
49 menu_model->AddItem(CMD_RELOAD, base::ASCIIToUTF16("Reload"));
50 menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
51 menu_model->AddItem(CMD_VIEW_SOURCE, base::ASCIIToUTF16("View Source"));
54 void AppendLinkItems(const content::ContextMenuParams& params,
55 ui::SimpleMenuModel* menu_model) {
56 if (!params.link_url.is_empty())
57 menu_model->AddItem(CMD_OPEN_LINK_NEW_ACTIVITY,
58 base::ASCIIToUTF16("Open Link In New Activity"));
61 void AppendEditableItems(ui::SimpleMenuModel* menu_model) {
62 menu_model->AddItem(CMD_UNDO, base::ASCIIToUTF16("Undo"));
63 menu_model->AddItem(CMD_REDO, base::ASCIIToUTF16("Redo"));
64 menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
65 menu_model->AddItem(CMD_CUT, base::ASCIIToUTF16("Cut"));
66 menu_model->AddItem(CMD_COPY, base::ASCIIToUTF16("Copy"));
67 menu_model->AddItem(CMD_PASTE, base::ASCIIToUTF16("Paste"));
68 menu_model->AddItem(CMD_PASTE_AND_MATCH_STYLE,
69 base::ASCIIToUTF16("Paste as plain text"));
70 menu_model->AddItem(CMD_DELETE, base::ASCIIToUTF16("Delete"));
71 menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
72 menu_model->AddItem(CMD_SELECT_ALL, base::ASCIIToUTF16("Select All"));
75 } // namespace
77 RenderViewContextMenuImpl::RenderViewContextMenuImpl(
78 content::RenderFrameHost* render_frame_host,
79 const content::ContextMenuParams& params)
80 : RenderViewContextMenuBase(render_frame_host, params) {
81 SetContentCustomCommandIdRange(CMD_LAST, CMD_LAST + kNumCustomCommandIds);
82 // TODO(oshima): Support other types
83 set_content_type(
84 new ContextMenuContentType(source_web_contents_, params, true));
85 set_toolkit_delegate(scoped_ptr<ToolkitDelegate>(new ToolkitDelegateViews));
88 RenderViewContextMenuImpl::~RenderViewContextMenuImpl() {
91 void RenderViewContextMenuImpl::RunMenuAt(views::Widget* parent,
92 const gfx::Point& point,
93 ui::MenuSourceType type) {
94 static_cast<ToolkitDelegateViews*>(toolkit_delegate())
95 ->RunMenuAt(parent, point, type);
98 void RenderViewContextMenuImpl::InitMenu() {
99 RenderViewContextMenuBase::InitMenu();
100 bool needs_separator = false;
101 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) {
102 AppendPageItems(&menu_model_);
103 needs_separator = true;
106 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK)) {
107 if (needs_separator)
108 AddSeparator();
109 AppendLinkItems(params_, &menu_model_);
110 needs_separator = true;
113 if (content_type_->SupportsGroup(
114 ContextMenuContentType::ITEM_GROUP_EDITABLE)) {
115 if (needs_separator)
116 AddSeparator();
117 AppendEditableItems(&menu_model_);
121 void RenderViewContextMenuImpl::RecordShownItem(int id) {
122 // TODO(oshima): Imelement UMA stats. crbug.com/401673
123 NOTIMPLEMENTED();
126 void RenderViewContextMenuImpl::RecordUsedItem(int id) {
127 // TODO(oshima): Imelement UMA stats. crbug.com/401673
128 NOTIMPLEMENTED();
131 #if defined(ENABLE_PLUGINS)
132 void RenderViewContextMenuImpl::HandleAuthorizeAllPlugins() {
134 #endif
136 void RenderViewContextMenuImpl::NotifyMenuShown() {
139 void RenderViewContextMenuImpl::NotifyURLOpened(
140 const GURL& url,
141 content::WebContents* new_contents) {
144 bool RenderViewContextMenuImpl::GetAcceleratorForCommandId(
145 int command_id,
146 ui::Accelerator* accelerator) {
147 NOTIMPLEMENTED();
148 return false;
151 bool RenderViewContextMenuImpl::IsCommandIdChecked(int command_id) const {
152 return false;
155 bool RenderViewContextMenuImpl::IsCommandIdEnabled(int command_id) const {
157 bool enabled = false;
158 if (RenderViewContextMenuBase::IsCommandIdKnown(command_id, &enabled))
159 return enabled;
161 switch (command_id) {
162 // Navigation
163 case CMD_BACK:
164 return source_web_contents_->GetController().CanGoBack();
165 case CMD_FORWARD:
166 return source_web_contents_->GetController().CanGoForward();
167 case CMD_RELOAD:
168 return true;
169 case CMD_VIEW_SOURCE:
170 return source_web_contents_->GetController().CanViewSource();
172 // Link
173 case CMD_OPEN_LINK_NEW_ACTIVITY:
174 return params_.link_url.is_valid();
176 // Editable
177 case CMD_UNDO:
178 return !!(params_.edit_flags & WebContextMenuData::CanUndo);
180 case CMD_REDO:
181 return !!(params_.edit_flags & WebContextMenuData::CanRedo);
183 case CMD_CUT:
184 return !!(params_.edit_flags & WebContextMenuData::CanCut);
186 case CMD_COPY:
187 return !!(params_.edit_flags & WebContextMenuData::CanCopy);
189 case CMD_PASTE:
190 case CMD_PASTE_AND_MATCH_STYLE:
191 return !!(params_.edit_flags & WebContextMenuData::CanPaste);
193 case CMD_DELETE:
194 return !!(params_.edit_flags & WebContextMenuData::CanDelete);
196 case CMD_SELECT_ALL:
197 return !!(params_.edit_flags & WebContextMenuData::CanSelectAll);
199 return false;
202 void RenderViewContextMenuImpl::ExecuteCommand(int command_id,
203 int event_flags) {
204 RenderViewContextMenuBase::ExecuteCommand(command_id, event_flags);
205 if (command_executed_)
206 return;
207 command_executed_ = true;
208 switch (command_id) {
209 // Navigation
210 case CMD_BACK:
211 source_web_contents_->GetController().GoBack();
212 break;
213 case CMD_FORWARD:
214 source_web_contents_->GetController().GoForward();
215 break;
216 case CMD_RELOAD:
217 source_web_contents_->GetController().Reload(true);
218 break;
219 case CMD_VIEW_SOURCE:
220 source_web_contents_->ViewSource();
221 break;
223 // Link
224 case CMD_OPEN_LINK_NEW_ACTIVITY:
225 OpenURL(
226 params_.link_url,
227 params_.frame_url.is_empty() ? params_.page_url : params_.frame_url,
228 NEW_FOREGROUND_TAB,
229 content::PAGE_TRANSITION_LINK);
230 break;
232 // Editable
233 case CMD_UNDO:
234 source_web_contents_->Undo();
235 break;
237 case CMD_REDO:
238 source_web_contents_->Redo();
239 break;
241 case CMD_CUT:
242 source_web_contents_->Cut();
243 break;
245 case CMD_COPY:
246 source_web_contents_->Copy();
247 break;
249 case CMD_PASTE:
250 source_web_contents_->Paste();
251 break;
253 case CMD_PASTE_AND_MATCH_STYLE:
254 source_web_contents_->PasteAndMatchStyle();
255 break;
257 case CMD_DELETE:
258 source_web_contents_->Delete();
259 break;
261 case CMD_SELECT_ALL:
262 source_web_contents_->SelectAll();
263 break;
267 } // namespace athena