| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 #include "ui/base/clipboard/clipboard.h" | 113 #include "ui/base/clipboard/clipboard.h" |
| 114 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 114 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 115 #include "ui/base/l10n/l10n_util.h" | 115 #include "ui/base/l10n/l10n_util.h" |
| 116 #include "ui/gfx/canvas.h" | 116 #include "ui/gfx/canvas.h" |
| 117 #include "ui/gfx/favicon_size.h" | 117 #include "ui/gfx/favicon_size.h" |
| 118 #include "ui/gfx/geometry/point.h" | 118 #include "ui/gfx/geometry/point.h" |
| 119 #include "ui/gfx/geometry/size.h" | 119 #include "ui/gfx/geometry/size.h" |
| 120 #include "ui/gfx/path.h" | 120 #include "ui/gfx/path.h" |
| 121 #include "ui/gfx/text_elider.h" | 121 #include "ui/gfx/text_elider.h" |
| 122 | 122 |
| 123 #if !defined(USE_BROWSER_SPELLCHECKER) |
| 124 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" |
| 125 #endif |
| 126 |
| 123 #if defined(ENABLE_EXTENSIONS) | 127 #if defined(ENABLE_EXTENSIONS) |
| 124 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | 128 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
| 125 #endif | 129 #endif |
| 126 | 130 |
| 127 #if defined(ENABLE_PRINTING) | 131 #if defined(ENABLE_PRINTING) |
| 128 #include "chrome/browser/printing/print_view_manager_common.h" | 132 #include "chrome/browser/printing/print_view_manager_common.h" |
| 129 #include "components/printing/common/print_messages.h" | 133 #include "components/printing/common/print_messages.h" |
| 130 | 134 |
| 131 #if defined(ENABLE_PRINT_PREVIEW) | 135 #if defined(ENABLE_PRINT_PREVIEW) |
| 132 #include "chrome/browser/printing/print_preview_context_menu_observer.h" | 136 #include "chrome/browser/printing/print_preview_context_menu_observer.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 {62, -1, IDC_WRITING_DIRECTION_MENU}, | 267 {62, -1, IDC_WRITING_DIRECTION_MENU}, |
| 264 {63, -1, IDC_WRITING_DIRECTION_DEFAULT}, | 268 {63, -1, IDC_WRITING_DIRECTION_DEFAULT}, |
| 265 {64, -1, IDC_WRITING_DIRECTION_LTR}, | 269 {64, -1, IDC_WRITING_DIRECTION_LTR}, |
| 266 {65, -1, IDC_WRITING_DIRECTION_RTL}, | 270 {65, -1, IDC_WRITING_DIRECTION_RTL}, |
| 267 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, | 271 {66, -1, IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE}, |
| 268 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, | 272 {67, -1, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, |
| 269 {68, -1, IDC_ROUTE_MEDIA}, | 273 {68, -1, IDC_ROUTE_MEDIA}, |
| 270 {69, -1, IDC_CONTENT_CONTEXT_COPYLINKTEXT}, | 274 {69, -1, IDC_CONTENT_CONTEXT_COPYLINKTEXT}, |
| 271 {70, -1, IDC_CONTENT_CONTEXT_OPENLINKINPROFILE}, | 275 {70, -1, IDC_CONTENT_CONTEXT_OPENLINKINPROFILE}, |
| 272 {71, -1, IDC_OPEN_LINK_IN_PROFILE_FIRST}, | 276 {71, -1, IDC_OPEN_LINK_IN_PROFILE_FIRST}, |
| 277 {72, -1, IDC_SPELLCHECK_MULTI_LINGUAL}, |
| 273 // Add new items here and use |enum_id| from the next line. | 278 // Add new items here and use |enum_id| from the next line. |
| 274 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. | 279 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. |
| 275 {72, -1, 0}, // Must be the last. Increment |enum_id| when new IDC | 280 {73, -1, 0}, // Must be the last. Increment |enum_id| when new IDC |
| 276 // was added. | 281 // was added. |
| 277 }; | 282 }; |
| 278 | 283 |
| 279 // Collapses large ranges of ids before looking for UMA enum. | 284 // Collapses large ranges of ids before looking for UMA enum. |
| 280 int CollapseCommandsForUMA(int id) { | 285 int CollapseCommandsForUMA(int id) { |
| 281 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); | 286 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); |
| 282 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); | 287 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); |
| 283 | 288 |
| 284 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 289 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 285 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 290 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL, | 1181 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL, |
| 1177 printable_selection_text)); | 1182 printable_selection_text)); |
| 1178 } | 1183 } |
| 1179 } | 1184 } |
| 1180 } | 1185 } |
| 1181 | 1186 |
| 1182 void RenderViewContextMenu::AppendEditableItems() { | 1187 void RenderViewContextMenu::AppendEditableItems() { |
| 1183 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); | 1188 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); |
| 1184 | 1189 |
| 1185 if (use_spellcheck_and_search) | 1190 if (use_spellcheck_and_search) |
| 1186 AppendSpellingSuggestionsSubMenu(); | 1191 AppendSpellcheckSuggestionItems(); |
| 1187 | 1192 |
| 1188 // 'Undo' and 'Redo' for text input with no suggestions and no text selected. | 1193 // 'Undo' and 'Redo' for text input with no suggestions and no text selected. |
| 1189 // We make an exception for OS X as context clicking will select the closest | 1194 // We make an exception for OS X as context clicking will select the closest |
| 1190 // word. In this case both items are always shown. | 1195 // word. In this case both items are always shown. |
| 1191 #if defined(OS_MACOSX) | 1196 #if defined(OS_MACOSX) |
| 1192 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, | 1197 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_UNDO, |
| 1193 IDS_CONTENT_CONTEXT_UNDO); | 1198 IDS_CONTENT_CONTEXT_UNDO); |
| 1194 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, | 1199 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_REDO, |
| 1195 IDS_CONTENT_CONTEXT_REDO); | 1200 IDS_CONTENT_CONTEXT_REDO); |
| 1196 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 1201 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1214 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, | 1219 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE, |
| 1215 IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE); | 1220 IDS_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE); |
| 1216 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, | 1221 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, |
| 1217 IDS_CONTENT_CONTEXT_SELECTALL); | 1222 IDS_CONTENT_CONTEXT_SELECTALL); |
| 1218 | 1223 |
| 1219 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 1224 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 1220 } | 1225 } |
| 1221 | 1226 |
| 1222 void RenderViewContextMenu::AppendLanguageSettings() { | 1227 void RenderViewContextMenu::AppendLanguageSettings() { |
| 1223 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); | 1228 const bool use_spellcheck_and_search = !chrome::IsRunningInForcedAppMode(); |
| 1229 if (!use_spellcheck_and_search) |
| 1230 return; |
| 1224 | 1231 |
| 1225 if (use_spellcheck_and_search) | 1232 #if defined(USE_BROWSER_SPELLCHECKER) |
| 1226 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, | 1233 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, |
| 1227 IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); | 1234 IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); |
| 1235 #else |
| 1236 if (!spellchecker_submenu_observer_.get()) { |
| 1237 const int kSpellcheckRadioGroup = 1; |
| 1238 spellchecker_submenu_observer_.reset( |
| 1239 new SpellCheckerSubMenuObserver(this, this, kSpellcheckRadioGroup)); |
| 1240 } |
| 1241 |
| 1242 spellchecker_submenu_observer_->InitMenu(params_); |
| 1243 observers_.AddObserver(spellchecker_submenu_observer_.get()); |
| 1244 #endif |
| 1228 } | 1245 } |
| 1229 | 1246 |
| 1230 void RenderViewContextMenu::AppendSpellingSuggestionsSubMenu() { | 1247 void RenderViewContextMenu::AppendSpellcheckSuggestionItems() { |
| 1231 if (!spelling_menu_observer_.get()) | 1248 if (!spelling_menu_observer_.get()) |
| 1232 spelling_menu_observer_.reset(new SpellingMenuObserver(this)); | 1249 spelling_menu_observer_.reset(new SpellingMenuObserver(this)); |
| 1233 observers_.AddObserver(spelling_menu_observer_.get()); | 1250 observers_.AddObserver(spelling_menu_observer_.get()); |
| 1234 spelling_menu_observer_->InitMenu(params_); | 1251 spelling_menu_observer_->InitMenu(params_); |
| 1235 } | 1252 } |
| 1236 | 1253 |
| 1237 void RenderViewContextMenu::AppendProtocolHandlerSubMenu() { | 1254 void RenderViewContextMenu::AppendProtocolHandlerSubMenu() { |
| 1238 const ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1255 const ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1239 GetHandlersForLinkUrl(); | 1256 GetHandlersForLinkUrl(); |
| 1240 if (handlers.empty()) | 1257 if (handlers.empty()) |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 source_web_contents_->GetRenderViewHost()-> | 2200 source_web_contents_->GetRenderViewHost()-> |
| 2184 ExecuteMediaPlayerActionAtLocation(location, action); | 2201 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2185 } | 2202 } |
| 2186 | 2203 |
| 2187 void RenderViewContextMenu::PluginActionAt( | 2204 void RenderViewContextMenu::PluginActionAt( |
| 2188 const gfx::Point& location, | 2205 const gfx::Point& location, |
| 2189 const WebPluginAction& action) { | 2206 const WebPluginAction& action) { |
| 2190 source_web_contents_->GetRenderViewHost()-> | 2207 source_web_contents_->GetRenderViewHost()-> |
| 2191 ExecutePluginActionAtLocation(location, action); | 2208 ExecutePluginActionAtLocation(location, action); |
| 2192 } | 2209 } |
| OLD | NEW |