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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 { 45, IDC_CONTENT_CONTEXT_GOTOURL }, | 198 { 45, IDC_CONTENT_CONTEXT_GOTOURL }, |
199 { 46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS }, | 199 { 46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS }, |
200 { 47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS }, | 200 { 47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS }, |
201 { 48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE }, | 201 { 48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE }, |
202 { 52, IDC_CONTENT_CONTEXT_OPENLINKWITH }, | 202 { 52, IDC_CONTENT_CONTEXT_OPENLINKWITH }, |
203 { 53, IDC_CHECK_SPELLING_WHILE_TYPING }, | 203 { 53, IDC_CHECK_SPELLING_WHILE_TYPING }, |
204 { 54, IDC_SPELLCHECK_MENU }, | 204 { 54, IDC_SPELLCHECK_MENU }, |
205 { 55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE }, | 205 { 55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE }, |
206 { 56, IDC_SPELLCHECK_LANGUAGES_FIRST }, | 206 { 56, IDC_SPELLCHECK_LANGUAGES_FIRST }, |
207 { 57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE }, | 207 { 57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE }, |
| 208 { 58, IDC_SPELLCHECK_SUGGESTION_0 }, |
208 // Add new items here and use |enum_id| from the next line. | 209 // Add new items here and use |enum_id| from the next line. |
209 { 58, 0 }, // Must be the last. Increment |enum_id| when new IDC was added. | 210 { 59, 0 }, // Must be the last. Increment |enum_id| when new IDC was added. |
210 }; | 211 }; |
211 | 212 |
212 // Collapses large ranges of ids before looking for UMA enum. | 213 // Collapses large ranges of ids before looking for UMA enum. |
213 int CollapleCommandsForUMA(int id) { | 214 int CollapleCommandsForUMA(int id) { |
214 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 215 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
215 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 216 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
216 return IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 217 return IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
217 } | 218 } |
218 | 219 |
219 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 220 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
220 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 221 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
221 return IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | 222 return IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; |
222 } | 223 } |
223 | 224 |
224 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 225 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
225 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 226 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
226 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 227 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
227 } | 228 } |
228 | 229 |
229 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && | 230 if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && |
230 id <= IDC_SPELLCHECK_LANGUAGES_LAST) { | 231 id <= IDC_SPELLCHECK_LANGUAGES_LAST) { |
231 return IDC_SPELLCHECK_LANGUAGES_FIRST; | 232 return IDC_SPELLCHECK_LANGUAGES_FIRST; |
232 } | 233 } |
233 | 234 |
| 235 if (id >= IDC_SPELLCHECK_SUGGESTION_0 && |
| 236 id <= IDC_SPELLCHECK_SUGGESTION_LAST) { |
| 237 return IDC_SPELLCHECK_SUGGESTION_0; |
| 238 } |
| 239 |
234 return id; | 240 return id; |
235 } | 241 } |
236 | 242 |
237 // Returns UMA enum value for command specified by |id| or -1 if not found. | 243 // Returns UMA enum value for command specified by |id| or -1 if not found. |
238 int FindUMAEnumValueForCommand(int id) { | 244 int FindUMAEnumValueForCommand(int id) { |
239 id = CollapleCommandsForUMA(id); | 245 id = CollapleCommandsForUMA(id); |
240 const size_t kMappingSize = arraysize(kUmaEnumToControlId); | 246 const size_t kMappingSize = arraysize(kUmaEnumToControlId); |
241 for (size_t i = 0; i < kMappingSize; ++i) { | 247 for (size_t i = 0; i < kMappingSize; ++i) { |
242 if (kUmaEnumToControlId[i].control_id == id) { | 248 if (kUmaEnumToControlId[i].control_id == id) { |
243 return kUmaEnumToControlId[i].enum_id; | 249 return kUmaEnumToControlId[i].enum_id; |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1415 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
1410 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1416 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
1411 return extension_items_.IsCommandIdChecked(id); | 1417 return extension_items_.IsCommandIdChecked(id); |
1412 } | 1418 } |
1413 | 1419 |
1414 return false; | 1420 return false; |
1415 } | 1421 } |
1416 | 1422 |
1417 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { | 1423 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { |
1418 command_executed_ = true; | 1424 command_executed_ = true; |
| 1425 RecordUsedItem(id); |
| 1426 |
1419 // If this command is is added by one of our observers, we dispatch it to the | 1427 // If this command is is added by one of our observers, we dispatch it to the |
1420 // observer. | 1428 // observer. |
1421 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); | 1429 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); |
1422 RenderViewContextMenuObserver* observer; | 1430 RenderViewContextMenuObserver* observer; |
1423 while ((observer = it.GetNext()) != NULL) { | 1431 while ((observer = it.GetNext()) != NULL) { |
1424 if (observer->IsCommandIdSupported(id)) | 1432 if (observer->IsCommandIdSupported(id)) |
1425 return observer->ExecuteCommand(id); | 1433 return observer->ExecuteCommand(id); |
1426 } | 1434 } |
1427 | 1435 |
1428 RecordUsedItem(id); | |
1429 | |
1430 RenderFrameHost* render_frame_host = | 1436 RenderFrameHost* render_frame_host = |
1431 RenderFrameHost::FromID(render_process_id_, render_frame_id_); | 1437 RenderFrameHost::FromID(render_process_id_, render_frame_id_); |
1432 | 1438 |
1433 // Process custom actions range. | 1439 // Process custom actions range. |
1434 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1440 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
1435 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1441 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
1436 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 1442 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
1437 const content::CustomContextMenuContext& context = params_.custom_context; | 1443 const content::CustomContextMenuContext& context = params_.custom_context; |
1438 #if defined(ENABLE_PLUGINS) | 1444 #if defined(ENABLE_PLUGINS) |
1439 if (context.request_id && !context.is_pepper_menu) { | 1445 if (context.request_id && !context.is_pepper_menu) { |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 source_web_contents_->GetRenderViewHost()-> | 1993 source_web_contents_->GetRenderViewHost()-> |
1988 ExecuteMediaPlayerActionAtLocation(location, action); | 1994 ExecuteMediaPlayerActionAtLocation(location, action); |
1989 } | 1995 } |
1990 | 1996 |
1991 void RenderViewContextMenu::PluginActionAt( | 1997 void RenderViewContextMenu::PluginActionAt( |
1992 const gfx::Point& location, | 1998 const gfx::Point& location, |
1993 const WebPluginAction& action) { | 1999 const WebPluginAction& action) { |
1994 source_web_contents_->GetRenderViewHost()-> | 2000 source_web_contents_->GetRenderViewHost()-> |
1995 ExecutePluginActionAtLocation(location, action); | 2001 ExecutePluginActionAtLocation(location, action); |
1996 } | 2002 } |
OLD | NEW |