OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/extensions/devtools_util.h" | 31 #include "chrome/browser/extensions/devtools_util.h" |
32 #include "chrome/browser/extensions/extension_service.h" | 32 #include "chrome/browser/extensions/extension_service.h" |
33 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 33 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" | 34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact
ory.h" |
35 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 35 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
36 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 36 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
37 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
38 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/browser/profiles/profile_io_data.h" | 39 #include "chrome/browser/profiles/profile_io_data.h" |
40 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory
.h" | 40 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory
.h" |
41 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" | |
42 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" | 41 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" |
43 #include "chrome/browser/search/search.h" | 42 #include "chrome/browser/search/search.h" |
44 #include "chrome/browser/search_engines/template_url_service_factory.h" | 43 #include "chrome/browser/search_engines/template_url_service_factory.h" |
45 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 44 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
46 #include "chrome/browser/spellchecker/spellcheck_service.h" | 45 #include "chrome/browser/spellchecker/spellcheck_service.h" |
47 #include "chrome/browser/ssl/security_state_model.h" | 46 #include "chrome/browser/ssl/security_state_model.h" |
48 #include "chrome/browser/tab_contents/retargeting_details.h" | 47 #include "chrome/browser/tab_contents/retargeting_details.h" |
49 #include "chrome/browser/translate/chrome_translate_client.h" | 48 #include "chrome/browser/translate/chrome_translate_client.h" |
50 #include "chrome/browser/translate/translate_service.h" | 49 #include "chrome/browser/translate/translate_service.h" |
51 #include "chrome/browser/ui/browser.h" | 50 #include "chrome/browser/ui/browser.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 using content::RenderViewHost; | 138 using content::RenderViewHost; |
140 using content::SSLStatus; | 139 using content::SSLStatus; |
141 using content::WebContents; | 140 using content::WebContents; |
142 using extensions::ContextMenuMatcher; | 141 using extensions::ContextMenuMatcher; |
143 using extensions::Extension; | 142 using extensions::Extension; |
144 using extensions::MenuItem; | 143 using extensions::MenuItem; |
145 using extensions::MenuManager; | 144 using extensions::MenuManager; |
146 | 145 |
147 namespace { | 146 namespace { |
148 | 147 |
| 148 // Whether to return the general enum_id or context_specific_enum_id |
| 149 // in the FindUMAEnumValueForCommand lookup function. |
| 150 enum UmaEnumIdLookupType { |
| 151 GENERAL_ENUM_ID, |
| 152 CONTEXT_SPECIFIC_ENUM_ID, |
| 153 }; |
| 154 |
149 const int kImageSearchThumbnailMinSize = 300 * 300; | 155 const int kImageSearchThumbnailMinSize = 300 * 300; |
150 const int kImageSearchThumbnailMaxWidth = 600; | 156 const int kImageSearchThumbnailMaxWidth = 600; |
151 const int kImageSearchThumbnailMaxHeight = 600; | 157 const int kImageSearchThumbnailMaxHeight = 600; |
152 | 158 |
153 // Maps UMA enumeration to IDC. IDC could be changed so we can't use | 159 // Maps UMA enumeration to IDC. IDC could be changed so we can't use |
154 // just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|. | 160 // just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|. |
155 // Never change mapping or reuse |enum_id|. Always push back new items. | 161 // Never change mapping or reuse |enum_id|. Always push back new items. |
156 // Items that is not used any more by |RenderViewContextMenu.ExecuteCommand| | 162 // Items that is not used any more by |RenderViewContextMenu.ExecuteCommand| |
157 // could be deleted, but don't change the rest of |kUmaEnumToControlId|. | 163 // could be deleted, but don't change the rest of |kUmaEnumToControlId|. |
| 164 // |
| 165 // |context_specific_enum_id| matches the ContextMenuOption histogram enum. |
| 166 // Used to track command usage under specific contexts, specifically Menu |
| 167 // items under 'link + image' and 'selected text'. Should be set to -1 if |
| 168 // command is not context specific tracked. |
158 const struct UmaEnumCommandIdPair { | 169 const struct UmaEnumCommandIdPair { |
159 int enum_id; | 170 int enum_id; |
| 171 int context_specific_enum_id; |
160 int control_id; | 172 int control_id; |
161 } kUmaEnumToControlId[] = { | 173 } kUmaEnumToControlId[] = { |
162 /* | 174 /* |
163 enum id for 0, 1 are detected using | 175 enum id for 0, 1 are detected using |
164 RenderViewContextMenu::IsContentCustomCommandId and | 176 RenderViewContextMenu::IsContentCustomCommandId and |
165 ContextMenuMatcher::IsExtensionsCustomCommandId | 177 ContextMenuMatcher::IsExtensionsCustomCommandId |
166 */ | 178 */ |
167 {2, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST}, | 179 {2, -1, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST}, |
168 {3, IDC_CONTENT_CONTEXT_OPENLINKNEWTAB}, | 180 {3, 0, IDC_CONTENT_CONTEXT_OPENLINKNEWTAB}, |
169 {4, IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW}, | 181 {4, 15, IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW}, |
170 {5, IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD}, | 182 {5, 1, IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD}, |
171 {6, IDC_CONTENT_CONTEXT_SAVELINKAS}, | 183 {6, 5, IDC_CONTENT_CONTEXT_SAVELINKAS}, |
172 {7, IDC_CONTENT_CONTEXT_SAVEAVAS}, | 184 {7, 17, IDC_CONTENT_CONTEXT_SAVEAVAS}, |
173 {8, IDC_CONTENT_CONTEXT_SAVEIMAGEAS}, | 185 {8, 6, IDC_CONTENT_CONTEXT_SAVEIMAGEAS}, |
174 {9, IDC_CONTENT_CONTEXT_COPYLINKLOCATION}, | 186 {9, 2, IDC_CONTENT_CONTEXT_COPYLINKLOCATION}, |
175 {10, IDC_CONTENT_CONTEXT_COPYIMAGELOCATION}, | 187 {10, 10, IDC_CONTENT_CONTEXT_COPYIMAGELOCATION}, |
176 {11, IDC_CONTENT_CONTEXT_COPYAVLOCATION}, | 188 {11, -1, IDC_CONTENT_CONTEXT_COPYAVLOCATION}, |
177 {12, IDC_CONTENT_CONTEXT_COPYIMAGE}, | 189 {12, 9, IDC_CONTENT_CONTEXT_COPYIMAGE}, |
178 {13, IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB}, | 190 {13, 8, IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB}, |
179 {14, IDC_CONTENT_CONTEXT_OPENAVNEWTAB}, | 191 {14, -1, IDC_CONTENT_CONTEXT_OPENAVNEWTAB}, |
180 {15, IDC_CONTENT_CONTEXT_PLAYPAUSE}, | 192 {15, -1, IDC_CONTENT_CONTEXT_PLAYPAUSE}, |
181 {16, IDC_CONTENT_CONTEXT_MUTE}, | 193 {16, -1, IDC_CONTENT_CONTEXT_MUTE}, |
182 {17, IDC_CONTENT_CONTEXT_LOOP}, | 194 {17, -1, IDC_CONTENT_CONTEXT_LOOP}, |
183 {18, IDC_CONTENT_CONTEXT_CONTROLS}, | 195 {18, -1, IDC_CONTENT_CONTEXT_CONTROLS}, |
184 {19, IDC_CONTENT_CONTEXT_ROTATECW}, | 196 {19, -1, IDC_CONTENT_CONTEXT_ROTATECW}, |
185 {20, IDC_CONTENT_CONTEXT_ROTATECCW}, | 197 {20, -1, IDC_CONTENT_CONTEXT_ROTATECCW}, |
186 {21, IDC_BACK}, | 198 {21, -1, IDC_BACK}, |
187 {22, IDC_FORWARD}, | 199 {22, -1, IDC_FORWARD}, |
188 {23, IDC_SAVE_PAGE}, | 200 {23, -1, IDC_SAVE_PAGE}, |
189 {24, IDC_RELOAD}, | 201 {24, -1, IDC_RELOAD}, |
190 {25, IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP}, | 202 {25, -1, IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP}, |
191 {26, IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP}, | 203 {26, -1, IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP}, |
192 {27, IDC_PRINT}, | 204 {27, 16, IDC_PRINT}, |
193 {28, IDC_VIEW_SOURCE}, | 205 {28, -1, IDC_VIEW_SOURCE}, |
194 {29, IDC_CONTENT_CONTEXT_INSPECTELEMENT}, | 206 {29, -1, IDC_CONTENT_CONTEXT_INSPECTELEMENT}, |
195 {30, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE}, | 207 {30, -1, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE}, |
196 {31, IDC_CONTENT_CONTEXT_VIEWPAGEINFO}, | 208 {31, -1, IDC_CONTENT_CONTEXT_VIEWPAGEINFO}, |
197 {32, IDC_CONTENT_CONTEXT_TRANSLATE}, | 209 {32, -1, IDC_CONTENT_CONTEXT_TRANSLATE}, |
198 {33, IDC_CONTENT_CONTEXT_RELOADFRAME}, | 210 {33, -1, IDC_CONTENT_CONTEXT_RELOADFRAME}, |
199 {34, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE}, | 211 {34, -1, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE}, |
200 {35, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO}, | 212 {35, -1, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO}, |
201 {36, IDC_CONTENT_CONTEXT_UNDO}, | 213 {36, -1, IDC_CONTENT_CONTEXT_UNDO}, |
202 {37, IDC_CONTENT_CONTEXT_REDO}, | 214 {37, -1, IDC_CONTENT_CONTEXT_REDO}, |
203 {38, IDC_CONTENT_CONTEXT_CUT}, | 215 {38, -1, IDC_CONTENT_CONTEXT_CUT}, |
204 {39, IDC_CONTENT_CONTEXT_COPY}, | 216 {39, 4, IDC_CONTENT_CONTEXT_COPY}, |
205 {40, IDC_CONTENT_CONTEXT_PASTE}, | 217 {40, -1, IDC_CONTENT_CONTEXT_PASTE}, |
206 {41, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE}, | 218 {41, -1, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE}, |
207 {42, IDC_CONTENT_CONTEXT_DELETE}, | 219 {42, -1, IDC_CONTENT_CONTEXT_DELETE}, |
208 {43, IDC_CONTENT_CONTEXT_SELECTALL}, | 220 {43, -1, IDC_CONTENT_CONTEXT_SELECTALL}, |
209 {44, IDC_CONTENT_CONTEXT_SEARCHWEBFOR}, | 221 {44, 17, IDC_CONTENT_CONTEXT_SEARCHWEBFOR}, |
210 {45, IDC_CONTENT_CONTEXT_GOTOURL}, | 222 {45, -1, IDC_CONTENT_CONTEXT_GOTOURL}, |
211 {46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS}, | 223 {46, -1, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS}, |
212 {47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS}, | 224 {47, -1, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS}, |
213 {48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE}, | 225 {48, -1, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE}, |
214 {52, IDC_CONTENT_CONTEXT_OPENLINKWITH}, | 226 {52, -1, IDC_CONTENT_CONTEXT_OPENLINKWITH}, |
215 {53, IDC_CHECK_SPELLING_WHILE_TYPING}, | 227 {53, -1, IDC_CHECK_SPELLING_WHILE_TYPING}, |
216 {54, IDC_SPELLCHECK_MENU}, | 228 {54, -1, IDC_SPELLCHECK_MENU}, |
217 {55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE}, | 229 {55, -1, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE}, |
218 {56, IDC_SPELLCHECK_LANGUAGES_FIRST}, | 230 {56, -1, IDC_SPELLCHECK_LANGUAGES_FIRST}, |
219 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, | 231 {57, 11, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, |
220 {58, IDC_SPELLCHECK_SUGGESTION_0}, | 232 {58, -1, IDC_SPELLCHECK_SUGGESTION_0}, |
221 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, | 233 {59, -1, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, |
222 {60, IDC_SPELLPANEL_TOGGLE}, | 234 {60, -1, IDC_SPELLPANEL_TOGGLE}, |
223 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, | 235 {61, -1, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, |
224 {62, IDC_WRITING_DIRECTION_MENU}, | 236 {62, -1, IDC_WRITING_DIRECTION_MENU}, |
225 {63, IDC_WRITING_DIRECTION_DEFAULT}, | 237 {63, -1, IDC_WRITING_DIRECTION_DEFAULT}, |
226 {64, IDC_WRITING_DIRECTION_LTR}, | 238 {64, -1, IDC_WRITING_DIRECTION_LTR}, |
227 {65, IDC_WRITING_DIRECTION_RTL}, | 239 {65, -1, IDC_WRITING_DIRECTION_RTL}, |
228 {66, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, | 240 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, |
229 {67, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, | 241 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, |
230 // Add new items here and use |enum_id| from the next line. | 242 // Add new items here and use |enum_id| from the next line. |
231 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. | 243 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. |
232 {68, 0}, // Must be the last. Increment |enum_id| when new IDC was added. | 244 {68, -1, 0}, // Must be the last. Increment |enum_id| when new IDC |
| 245 // was added. |
233 }; | 246 }; |
234 | 247 |
235 // Collapses large ranges of ids before looking for UMA enum. | 248 // Collapses large ranges of ids before looking for UMA enum. |
236 int CollapseCommandsForUMA(int id) { | 249 int CollapseCommandsForUMA(int id) { |
237 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); | 250 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); |
238 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); | 251 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); |
239 | 252 |
240 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 253 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
241 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 254 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
242 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 255 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
243 } | 256 } |
244 | 257 |
245 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && | 258 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && |
246 id <= IDC_SPELLCHECK_LANGUAGES_LAST) { | 259 id <= IDC_SPELLCHECK_LANGUAGES_LAST) { |
247 return IDC_SPELLCHECK_LANGUAGES_FIRST; | 260 return IDC_SPELLCHECK_LANGUAGES_FIRST; |
248 } | 261 } |
249 | 262 |
250 if (id >= IDC_SPELLCHECK_SUGGESTION_0 && | 263 if (id >= IDC_SPELLCHECK_SUGGESTION_0 && |
251 id <= IDC_SPELLCHECK_SUGGESTION_LAST) { | 264 id <= IDC_SPELLCHECK_SUGGESTION_LAST) { |
252 return IDC_SPELLCHECK_SUGGESTION_0; | 265 return IDC_SPELLCHECK_SUGGESTION_0; |
253 } | 266 } |
254 | 267 |
255 return id; | 268 return id; |
256 } | 269 } |
257 | 270 |
258 // Returns UMA enum value for command specified by |id| or -1 if not found. | 271 // Returns UMA enum value for command specified by |id| or -1 if not found. |
259 int FindUMAEnumValueForCommand(int id) { | 272 // |use_specific_context_enum| set to true returns the context_specific_enum_id. |
| 273 int FindUMAEnumValueForCommand(int id, UmaEnumIdLookupType enum_lookup_type) { |
260 if (RenderViewContextMenu::IsContentCustomCommandId(id)) | 274 if (RenderViewContextMenu::IsContentCustomCommandId(id)) |
261 return 0; | 275 return 0; |
262 | 276 |
263 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) | 277 if (ContextMenuMatcher::IsExtensionsCustomCommandId(id)) |
264 return 1; | 278 return 1; |
265 | 279 |
266 id = CollapseCommandsForUMA(id); | 280 id = CollapseCommandsForUMA(id); |
267 const size_t kMappingSize = arraysize(kUmaEnumToControlId); | 281 const size_t kMappingSize = arraysize(kUmaEnumToControlId); |
268 for (size_t i = 0; i < kMappingSize; ++i) { | 282 for (size_t i = 0; i < kMappingSize; ++i) { |
269 if (kUmaEnumToControlId[i].control_id == id) { | 283 if (kUmaEnumToControlId[i].control_id == id) { |
270 return kUmaEnumToControlId[i].enum_id; | 284 if (enum_lookup_type == GENERAL_ENUM_ID) { |
| 285 return kUmaEnumToControlId[i].enum_id; |
| 286 } else if (enum_lookup_type == CONTEXT_SPECIFIC_ENUM_ID && |
| 287 kUmaEnumToControlId[i].context_specific_enum_id > -1) { |
| 288 return kUmaEnumToControlId[i].context_specific_enum_id; |
| 289 } |
271 } | 290 } |
272 } | 291 } |
| 292 |
273 return -1; | 293 return -1; |
274 } | 294 } |
275 | 295 |
276 // Usually a new tab is expected where this function is used, | 296 // Usually a new tab is expected where this function is used, |
277 // however users should be able to open a tab in background | 297 // however users should be able to open a tab in background |
278 // or in a new window. | 298 // or in a new window. |
279 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( | 299 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( |
280 int event_flags) { | 300 int event_flags) { |
281 WindowOpenDisposition disposition = | 301 WindowOpenDisposition disposition = |
282 ui::DispositionFromEventFlags(event_flags); | 302 ui::DispositionFromEventFlags(event_flags); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 : url_formatter::FormatUrl( | 354 : url_formatter::FormatUrl( |
335 url, languages, url_formatter::kFormatUrlOmitNothing, | 355 url, languages, url_formatter::kFormatUrlOmitNothing, |
336 net::UnescapeRule::NONE, nullptr, nullptr, nullptr); | 356 net::UnescapeRule::NONE, nullptr, nullptr, nullptr); |
337 | 357 |
338 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); | 358 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); |
339 scw.WriteURL(text); | 359 scw.WriteURL(text); |
340 } | 360 } |
341 | 361 |
342 bool g_custom_id_ranges_initialized = false; | 362 bool g_custom_id_ranges_initialized = false; |
343 | 363 |
344 const int kSpellcheckRadioGroup = 1; | |
345 | |
346 } // namespace | 364 } // namespace |
347 | 365 |
348 // static | 366 // static |
349 gfx::Vector2d RenderViewContextMenu::GetOffset( | 367 gfx::Vector2d RenderViewContextMenu::GetOffset( |
350 RenderFrameHost* render_frame_host) { | 368 RenderFrameHost* render_frame_host) { |
351 gfx::Vector2d offset; | 369 gfx::Vector2d offset; |
352 #if defined(ENABLE_EXTENSIONS) | 370 #if defined(ENABLE_EXTENSIONS) |
353 WebContents* web_contents = | 371 WebContents* web_contents = |
354 WebContents::FromRenderFrameHost(render_frame_host); | 372 WebContents::FromRenderFrameHost(render_frame_host); |
355 WebContents* top_level_web_contents = | 373 WebContents* top_level_web_contents = |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 false /* is_action_menu */); | 569 false /* is_action_menu */); |
552 } | 570 } |
553 #endif // defined(ENABLE_EXTENSIONS) | 571 #endif // defined(ENABLE_EXTENSIONS) |
554 | 572 |
555 void RenderViewContextMenu::InitMenu() { | 573 void RenderViewContextMenu::InitMenu() { |
556 RenderViewContextMenuBase::InitMenu(); | 574 RenderViewContextMenuBase::InitMenu(); |
557 | 575 |
558 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) | 576 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) |
559 AppendPageItems(); | 577 AppendPageItems(); |
560 | 578 |
561 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_FRAME)) { | |
562 // Merge in frame items with page items if we clicked within a frame that | |
563 // needs them. | |
564 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
565 AppendFrameItems(); | |
566 } | |
567 | |
568 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK)) { | 579 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK)) { |
569 AppendLinkItems(); | 580 AppendLinkItems(); |
570 if (params_.media_type != WebContextMenuData::MediaTypeNone) | 581 if (params_.media_type != WebContextMenuData::MediaTypeNone) |
571 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 582 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
572 } | 583 } |
573 | 584 |
574 if (content_type_->SupportsGroup( | 585 if (content_type_->SupportsGroup( |
575 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) { | 586 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) { |
576 AppendImageItems(); | 587 AppendImageItems(); |
577 } | 588 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 DCHECK(!content_type_->SupportsGroup( | 621 DCHECK(!content_type_->SupportsGroup( |
611 ContextMenuContentType::ITEM_GROUP_EDITABLE)); | 622 ContextMenuContentType::ITEM_GROUP_EDITABLE)); |
612 AppendCopyItem(); | 623 AppendCopyItem(); |
613 } | 624 } |
614 | 625 |
615 if (content_type_->SupportsGroup( | 626 if (content_type_->SupportsGroup( |
616 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER)) { | 627 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER)) { |
617 AppendSearchProvider(); | 628 AppendSearchProvider(); |
618 } | 629 } |
619 | 630 |
620 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) | 631 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT) && |
| 632 !content_type_->SupportsGroup( |
| 633 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) { |
621 AppendPrintItem(); | 634 AppendPrintItem(); |
| 635 } |
| 636 |
| 637 if (content_type_->SupportsGroup( |
| 638 ContextMenuContentType::ITEM_GROUP_EDITABLE)) { |
| 639 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 640 AppendPlatformEditableItems(); |
| 641 AppendLanguageSettings(); |
| 642 } |
622 | 643 |
623 if (content_type_->SupportsGroup( | 644 if (content_type_->SupportsGroup( |
624 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) { | 645 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) { |
625 AppendRotationItems(); | 646 AppendRotationItems(); |
626 } | 647 } |
627 | 648 |
628 if (content_type_->SupportsGroup( | 649 if (content_type_->SupportsGroup( |
629 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)) { | 650 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)) { |
630 DCHECK(!content_type_->SupportsGroup( | 651 DCHECK(!content_type_->SupportsGroup( |
631 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)); | 652 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)); |
(...skipping 26 matching lines...) Expand all Loading... |
658 ContextMenuContentType::ITEM_GROUP_PASSWORD)) { | 679 ContextMenuContentType::ITEM_GROUP_PASSWORD)) { |
659 AppendPasswordItems(); | 680 AppendPasswordItems(); |
660 } | 681 } |
661 } | 682 } |
662 | 683 |
663 Profile* RenderViewContextMenu::GetProfile() { | 684 Profile* RenderViewContextMenu::GetProfile() { |
664 return Profile::FromBrowserContext(browser_context_); | 685 return Profile::FromBrowserContext(browser_context_); |
665 } | 686 } |
666 | 687 |
667 void RenderViewContextMenu::RecordUsedItem(int id) { | 688 void RenderViewContextMenu::RecordUsedItem(int id) { |
668 int enum_id = FindUMAEnumValueForCommand(id); | 689 int enum_id = FindUMAEnumValueForCommand(id, GENERAL_ENUM_ID); |
669 if (enum_id != -1) { | 690 if (enum_id != -1) { |
670 const size_t kMappingSize = arraysize(kUmaEnumToControlId); | 691 const size_t kMappingSize = arraysize(kUmaEnumToControlId); |
671 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Used", enum_id, | 692 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Used", enum_id, |
672 kUmaEnumToControlId[kMappingSize - 1].enum_id); | 693 kUmaEnumToControlId[kMappingSize - 1].enum_id); |
| 694 // Record to additional context specific histograms. |
| 695 enum_id = FindUMAEnumValueForCommand(id, CONTEXT_SPECIFIC_ENUM_ID); |
| 696 |
| 697 // Linked image context. |
| 698 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK) && |
| 699 content_type_->SupportsGroup( |
| 700 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) { |
| 701 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.ImageLink", enum_id, |
| 702 kUmaEnumToControlId[kMappingSize - 1].enum_id); |
| 703 } |
| 704 // Selected text context. |
| 705 if (content_type_->SupportsGroup( |
| 706 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER) && |
| 707 content_type_->SupportsGroup( |
| 708 ContextMenuContentType::ITEM_GROUP_PRINT)) { |
| 709 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.SelectedText", |
| 710 enum_id, |
| 711 kUmaEnumToControlId[kMappingSize - 1].enum_id); |
| 712 } |
673 } else { | 713 } else { |
674 NOTREACHED() << "Update kUmaEnumToControlId. Unhanded IDC: " << id; | 714 NOTREACHED() << "Update kUmaEnumToControlId. Unhanded IDC: " << id; |
675 } | 715 } |
676 } | 716 } |
677 | 717 |
678 void RenderViewContextMenu::RecordShownItem(int id) { | 718 void RenderViewContextMenu::RecordShownItem(int id) { |
679 int enum_id = FindUMAEnumValueForCommand(id); | 719 int enum_id = FindUMAEnumValueForCommand(id, GENERAL_ENUM_ID); |
680 if (enum_id != -1) { | 720 if (enum_id != -1) { |
681 const size_t kMappingSize = arraysize(kUmaEnumToControlId); | 721 const size_t kMappingSize = arraysize(kUmaEnumToControlId); |
682 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Shown", enum_id, | 722 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Shown", enum_id, |
683 kUmaEnumToControlId[kMappingSize - 1].enum_id); | 723 kUmaEnumToControlId[kMappingSize - 1].enum_id); |
684 } else { | 724 } else { |
685 // Just warning here. It's harder to maintain list of all possibly | 725 // Just warning here. It's harder to maintain list of all possibly |
686 // visible items than executable items. | 726 // visible items than executable items. |
687 DLOG(ERROR) << "Update kUmaEnumToControlId. Unhanded IDC: " << id; | 727 DLOG(ERROR) << "Update kUmaEnumToControlId. Unhanded IDC: " << id; |
688 } | 728 } |
689 } | 729 } |
(...skipping 29 matching lines...) Expand all Loading... |
719 #if defined(DEBUG_DEVTOOLS) | 759 #if defined(DEBUG_DEVTOOLS) |
720 show_developer_items = true; | 760 show_developer_items = true; |
721 #endif | 761 #endif |
722 | 762 |
723 if (!show_developer_items) | 763 if (!show_developer_items) |
724 return; | 764 return; |
725 | 765 |
726 // In the DevTools popup menu, "developer items" is normally the only | 766 // In the DevTools popup menu, "developer items" is normally the only |
727 // section, so omit the separator there. | 767 // section, so omit the separator there. |
728 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 768 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 769 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) |
| 770 menu_model_.AddItemWithStringId(IDC_VIEW_SOURCE, |
| 771 IDS_CONTENT_CONTEXT_VIEWPAGESOURCE); |
| 772 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_FRAME)) |
| 773 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE, |
| 774 IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE); |
729 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT, | 775 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT, |
730 IDS_CONTENT_CONTEXT_INSPECTELEMENT); | 776 IDS_CONTENT_CONTEXT_INSPECTELEMENT); |
731 } | 777 } |
732 | 778 |
733 void RenderViewContextMenu::AppendDevtoolsForUnpackedExtensions() { | 779 void RenderViewContextMenu::AppendDevtoolsForUnpackedExtensions() { |
734 // Add a separator if there are any items already in the menu. | 780 // Add a separator if there are any items already in the menu. |
735 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 781 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
736 | 782 |
737 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP, | 783 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP, |
738 IDS_CONTENT_CONTEXT_RELOAD_PACKAGED_APP); | 784 IDS_CONTENT_CONTEXT_RELOAD_PACKAGED_APP); |
(...skipping 21 matching lines...) Expand all Loading... |
760 } | 806 } |
761 | 807 |
762 menu_model_.AddItemWithStringId( | 808 menu_model_.AddItemWithStringId( |
763 IDC_CONTENT_CONTEXT_COPYLINKLOCATION, | 809 IDC_CONTENT_CONTEXT_COPYLINKLOCATION, |
764 params_.link_url.SchemeIs(url::kMailToScheme) ? | 810 params_.link_url.SchemeIs(url::kMailToScheme) ? |
765 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS : | 811 IDS_CONTENT_CONTEXT_COPYEMAILADDRESS : |
766 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); | 812 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); |
767 } | 813 } |
768 | 814 |
769 void RenderViewContextMenu::AppendImageItems() { | 815 void RenderViewContextMenu::AppendImageItems() { |
770 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, | |
771 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); | |
772 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, | |
773 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); | |
774 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, | |
775 IDS_CONTENT_CONTEXT_COPYIMAGE); | |
776 std::map<std::string, std::string>::const_iterator it = | 816 std::map<std::string, std::string>::const_iterator it = |
777 params_.properties.find(data_reduction_proxy::chrome_proxy_header()); | 817 params_.properties.find(data_reduction_proxy::chrome_proxy_header()); |
778 if (it != params_.properties.end() && it->second == | 818 if (it != params_.properties.end() && it->second == |
779 data_reduction_proxy::chrome_proxy_lo_fi_directive()) { | 819 data_reduction_proxy::chrome_proxy_lo_fi_directive()) { |
780 menu_model_.AddItemWithStringId( | 820 menu_model_.AddItemWithStringId( |
781 IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE, | 821 IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE, |
782 IDS_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE); | 822 IDS_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE); |
783 } | 823 } |
784 DataReductionProxyChromeSettings* settings = | 824 DataReductionProxyChromeSettings* settings = |
785 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 825 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
786 browser_context_); | 826 browser_context_); |
787 if (settings && settings->CanUseDataReductionProxy(params_.src_url)) { | 827 if (settings && settings->CanUseDataReductionProxy(params_.src_url)) { |
788 menu_model_.AddItemWithStringId( | 828 menu_model_.AddItemWithStringId( |
789 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB, | 829 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB, |
790 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB); | 830 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB); |
791 } else { | 831 } else { |
792 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, | 832 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, |
793 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 833 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
794 } | 834 } |
| 835 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, |
| 836 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 837 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, |
| 838 IDS_CONTENT_CONTEXT_COPYIMAGE); |
| 839 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, |
| 840 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); |
795 } | 841 } |
796 | 842 |
797 void RenderViewContextMenu::AppendSearchWebForImageItems() { | 843 void RenderViewContextMenu::AppendSearchWebForImageItems() { |
798 TemplateURLService* service = | 844 TemplateURLService* service = |
799 TemplateURLServiceFactory::GetForProfile(GetProfile()); | 845 TemplateURLServiceFactory::GetForProfile(GetProfile()); |
800 const TemplateURL* const default_provider = | 846 const TemplateURL* const default_provider = |
801 service->GetDefaultSearchProvider(); | 847 service->GetDefaultSearchProvider(); |
802 if (params_.has_image_contents && default_provider && | 848 if (params_.has_image_contents && default_provider && |
803 !default_provider->image_url().empty() && | 849 !default_provider->image_url().empty() && |
804 default_provider->image_url_ref().IsValid(service->search_terms_data())) { | 850 default_provider->image_url_ref().IsValid(service->search_terms_data())) { |
805 menu_model_.AddItem( | 851 menu_model_.AddItem( |
806 IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, | 852 IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, |
807 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, | 853 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, |
808 default_provider->short_name())); | 854 default_provider->short_name())); |
809 } | 855 } |
810 } | 856 } |
811 | 857 |
812 void RenderViewContextMenu::AppendAudioItems() { | 858 void RenderViewContextMenu::AppendAudioItems() { |
813 AppendMediaItems(); | |
814 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 859 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 860 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, |
| 861 IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB); |
815 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, | 862 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
816 IDS_CONTENT_CONTEXT_SAVEAUDIOAS); | 863 IDS_CONTENT_CONTEXT_SAVEAUDIOAS); |
817 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, | 864 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, |
818 IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); | 865 IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); |
819 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, | |
820 IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB); | |
821 } | 866 } |
822 | 867 |
823 void RenderViewContextMenu::AppendCanvasItems() { | 868 void RenderViewContextMenu::AppendCanvasItems() { |
824 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, | 869 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, |
825 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); | 870 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); |
826 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, | 871 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, |
827 IDS_CONTENT_CONTEXT_COPYIMAGE); | 872 IDS_CONTENT_CONTEXT_COPYIMAGE); |
828 } | 873 } |
829 | 874 |
830 void RenderViewContextMenu::AppendVideoItems() { | 875 void RenderViewContextMenu::AppendVideoItems() { |
831 AppendMediaItems(); | |
832 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 876 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 877 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, |
| 878 IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB); |
833 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, | 879 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
834 IDS_CONTENT_CONTEXT_SAVEVIDEOAS); | 880 IDS_CONTENT_CONTEXT_SAVEVIDEOAS); |
835 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, | 881 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, |
836 IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); | 882 IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); |
837 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, | |
838 IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB); | |
839 } | |
840 | |
841 void RenderViewContextMenu::AppendMediaItems() { | |
842 int media_flags = params_.media_flags; | |
843 | |
844 menu_model_.AddItemWithStringId( | |
845 IDC_CONTENT_CONTEXT_PLAYPAUSE, | |
846 media_flags & WebContextMenuData::MediaPaused ? | |
847 IDS_CONTENT_CONTEXT_PLAY : | |
848 IDS_CONTENT_CONTEXT_PAUSE); | |
849 | |
850 menu_model_.AddItemWithStringId( | |
851 IDC_CONTENT_CONTEXT_MUTE, | |
852 media_flags & WebContextMenuData::MediaMuted ? | |
853 IDS_CONTENT_CONTEXT_UNMUTE : | |
854 IDS_CONTENT_CONTEXT_MUTE); | |
855 | |
856 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_LOOP, | |
857 IDS_CONTENT_CONTEXT_LOOP); | |
858 menu_model_.AddCheckItemWithStringId(IDC_CONTENT_CONTEXT_CONTROLS, | |
859 IDS_CONTENT_CONTEXT_CONTROLS); | |
860 } | 883 } |
861 | 884 |
862 void RenderViewContextMenu::AppendPluginItems() { | 885 void RenderViewContextMenu::AppendPluginItems() { |
863 if (params_.page_url == params_.src_url || | 886 if (params_.page_url == params_.src_url || |
864 guest_view::GuestViewBase::IsGuest(source_web_contents_)) { | 887 guest_view::GuestViewBase::IsGuest(source_web_contents_)) { |
865 // Full page plugin, so show page menu items. | 888 // Full page plugin, so show page menu items. |
866 if (params_.link_url.is_empty() && params_.selection_text.empty()) | 889 if (params_.link_url.is_empty() && params_.selection_text.empty()) |
867 AppendPageItems(); | 890 AppendPageItems(); |
868 } else { | 891 } else { |
869 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, | 892 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
(...skipping 18 matching lines...) Expand all Loading... |
888 | 911 |
889 if (TranslateService::IsTranslatableURL(params_.page_url)) { | 912 if (TranslateService::IsTranslatableURL(params_.page_url)) { |
890 std::string locale = g_browser_process->GetApplicationLocale(); | 913 std::string locale = g_browser_process->GetApplicationLocale(); |
891 locale = translate::TranslateDownloadManager::GetLanguageCode(locale); | 914 locale = translate::TranslateDownloadManager::GetLanguageCode(locale); |
892 base::string16 language = | 915 base::string16 language = |
893 l10n_util::GetDisplayNameForLocale(locale, locale, true); | 916 l10n_util::GetDisplayNameForLocale(locale, locale, true); |
894 menu_model_.AddItem( | 917 menu_model_.AddItem( |
895 IDC_CONTENT_CONTEXT_TRANSLATE, | 918 IDC_CONTENT_CONTEXT_TRANSLATE, |
896 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language)); | 919 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language)); |
897 } | 920 } |
898 | |
899 menu_model_.AddItemWithStringId(IDC_VIEW_SOURCE, | |
900 IDS_CONTENT_CONTEXT_VIEWPAGESOURCE); | |
901 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, | |
902 IDS_CONTENT_CONTEXT_VIEWPAGEINFO); | |
903 } | |
904 | |
905 void RenderViewContextMenu::AppendFrameItems() { | |
906 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOADFRAME, | |
907 IDS_CONTENT_CONTEXT_RELOADFRAME); | |
908 // These two menu items have yet to be implemented. | |
909 // http://code.google.com/p/chromium/issues/detail?id=11827 | |
910 // IDS_CONTENT_CONTEXT_SAVEFRAMEAS | |
911 // IDS_CONTENT_CONTEXT_PRINTFRAME | |
912 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE, | |
913 IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE); | |
914 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMEINFO, | |
915 IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); | |
916 } | 921 } |
917 | 922 |
918 void RenderViewContextMenu::AppendCopyItem() { | 923 void RenderViewContextMenu::AppendCopyItem() { |
| 924 if (menu_model_.GetItemCount()) |
| 925 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
919 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, | 926 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, |
920 IDS_CONTENT_CONTEXT_COPY); | 927 IDS_CONTENT_CONTEXT_COPY); |
921 } | 928 } |
922 | 929 |
923 void RenderViewContextMenu::AppendPrintItem() { | 930 void RenderViewContextMenu::AppendPrintItem() { |
924 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && | 931 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && |
925 (params_.media_type == WebContextMenuData::MediaTypeNone || | 932 (params_.media_type == WebContextMenuData::MediaTypeNone || |
926 params_.media_flags & WebContextMenuData::MediaCanPrint)) { | 933 params_.media_flags & WebContextMenuData::MediaCanPrint)) { |
927 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 934 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
928 } | 935 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 } | 993 } |
987 } | 994 } |
988 } | 995 } |
989 | 996 |
990 void RenderViewContextMenu::AppendEditableItems() { | 997 void RenderViewContextMenu::AppendEditableItems() { |
991 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); | 998 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); |
992 | 999 |
993 if (use_spellcheck_and_search) | 1000 if (use_spellcheck_and_search) |
994 AppendSpellingSuggestionsSubMenu(); | 1001 AppendSpellingSuggestionsSubMenu(); |
995 | 1002 |
996 if (!IsDevToolsURL(params_.page_url)) { | 1003 // 'Undo' and 'Redo' for text input with no suggestions and no text selected. |
| 1004 // We make an exception for OS X as context clicking will select the closest |
| 1005 // word. In this case both items are always shown. |
| 1006 #if defined(OS_MACOSX) |
| 1007 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, |
| 1008 IDS_CONTENT_CONTEXT_UNDO); |
| 1009 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, |
| 1010 IDS_CONTENT_CONTEXT_REDO); |
| 1011 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 1012 #else |
| 1013 if (!IsDevToolsURL(params_.page_url) && !menu_model_.GetItemCount() && |
| 1014 !content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) { |
997 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, | 1015 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, |
998 IDS_CONTENT_CONTEXT_UNDO); | 1016 IDS_CONTENT_CONTEXT_UNDO); |
999 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, | 1017 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, |
1000 IDS_CONTENT_CONTEXT_REDO); | 1018 IDS_CONTENT_CONTEXT_REDO); |
1001 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 1019 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
1002 } | 1020 } |
| 1021 #endif |
1003 | 1022 |
1004 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_CUT, | 1023 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_CUT, |
1005 IDS_CONTENT_CONTEXT_CUT); | 1024 IDS_CONTENT_CONTEXT_CUT); |
1006 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, | 1025 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, |
1007 IDS_CONTENT_CONTEXT_COPY); | 1026 IDS_CONTENT_CONTEXT_COPY); |
1008 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE, | 1027 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE, |
1009 IDS_CONTENT_CONTEXT_PASTE); | 1028 IDS_CONTENT_CONTEXT_PASTE); |
1010 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, | 1029 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, |
1011 IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE); | 1030 IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE); |
1012 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_DELETE, | 1031 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, |
1013 IDS_CONTENT_CONTEXT_DELETE); | 1032 IDS_CONTENT_CONTEXT_SELECTALL); |
| 1033 |
1014 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 1034 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 1035 } |
1015 | 1036 |
1016 if (use_spellcheck_and_search && !params_.keyword_url.is_empty()) { | 1037 void RenderViewContextMenu::AppendLanguageSettings() { |
1017 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, | 1038 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); |
1018 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); | |
1019 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
1020 } | |
1021 | 1039 |
1022 #if defined(OS_MACOSX) | |
1023 if (use_spellcheck_and_search) | 1040 if (use_spellcheck_and_search) |
1024 AppendSpellcheckOptionsSubMenu(); | |
1025 #else | |
1026 if (chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) { | |
1027 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, | 1041 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, |
1028 IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); | 1042 IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); |
1029 } else if (use_spellcheck_and_search) { | |
1030 AppendSpellcheckOptionsSubMenu(); | |
1031 } | |
1032 #endif // defined(OS_MACOSX) | |
1033 | |
1034 AppendPlatformEditableItems(); | |
1035 | |
1036 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
1037 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, | |
1038 IDS_CONTENT_CONTEXT_SELECTALL); | |
1039 } | 1043 } |
1040 | 1044 |
1041 void RenderViewContextMenu::AppendSpellingSuggestionsSubMenu() { | 1045 void RenderViewContextMenu::AppendSpellingSuggestionsSubMenu() { |
1042 if (!spelling_menu_observer_.get()) | 1046 if (!spelling_menu_observer_.get()) |
1043 spelling_menu_observer_.reset(new SpellingMenuObserver(this)); | 1047 spelling_menu_observer_.reset(new SpellingMenuObserver(this)); |
1044 observers_.AddObserver(spelling_menu_observer_.get()); | 1048 observers_.AddObserver(spelling_menu_observer_.get()); |
1045 spelling_menu_observer_->InitMenu(params_); | 1049 spelling_menu_observer_->InitMenu(params_); |
1046 } | 1050 } |
1047 | 1051 |
1048 void RenderViewContextMenu::AppendSpellcheckOptionsSubMenu() { | |
1049 if (!spellchecker_submenu_observer_.get()) { | |
1050 spellchecker_submenu_observer_.reset(new SpellCheckerSubMenuObserver( | |
1051 this, this, kSpellcheckRadioGroup)); | |
1052 } | |
1053 spellchecker_submenu_observer_->InitMenu(params_); | |
1054 observers_.AddObserver(spellchecker_submenu_observer_.get()); | |
1055 } | |
1056 | |
1057 void RenderViewContextMenu::AppendProtocolHandlerSubMenu() { | 1052 void RenderViewContextMenu::AppendProtocolHandlerSubMenu() { |
1058 const ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1053 const ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
1059 GetHandlersForLinkUrl(); | 1054 GetHandlersForLinkUrl(); |
1060 if (handlers.empty()) | 1055 if (handlers.empty()) |
1061 return; | 1056 return; |
1062 size_t max = IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST - | 1057 size_t max = IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST - |
1063 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 1058 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
1064 for (size_t i = 0; i < handlers.size() && i <= max; i++) { | 1059 for (size_t i = 0; i < handlers.size() && i <= max; i++) { |
1065 protocol_handler_submenu_model_.AddItem( | 1060 protocol_handler_submenu_model_.AddItem( |
1066 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST + i, | 1061 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST + i, |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 source_web_contents_->GetRenderViewHost()-> | 1954 source_web_contents_->GetRenderViewHost()-> |
1960 ExecuteMediaPlayerActionAtLocation(location, action); | 1955 ExecuteMediaPlayerActionAtLocation(location, action); |
1961 } | 1956 } |
1962 | 1957 |
1963 void RenderViewContextMenu::PluginActionAt( | 1958 void RenderViewContextMenu::PluginActionAt( |
1964 const gfx::Point& location, | 1959 const gfx::Point& location, |
1965 const WebPluginAction& action) { | 1960 const WebPluginAction& action) { |
1966 source_web_contents_->GetRenderViewHost()-> | 1961 source_web_contents_->GetRenderViewHost()-> |
1967 ExecutePluginActionAtLocation(location, action); | 1962 ExecutePluginActionAtLocation(location, action); |
1968 } | 1963 } |
OLD | NEW |