OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 using content::RenderViewHost; | 110 using content::RenderViewHost; |
111 using content::SSLStatus; | 111 using content::SSLStatus; |
112 using content::UserMetricsAction; | 112 using content::UserMetricsAction; |
113 using content::WebContents; | 113 using content::WebContents; |
114 using extensions::Extension; | 114 using extensions::Extension; |
115 using extensions::MenuItem; | 115 using extensions::MenuItem; |
116 using extensions::MenuManager; | 116 using extensions::MenuManager; |
117 | 117 |
118 namespace { | 118 namespace { |
119 | 119 |
| 120 // Maps UMA enumeration to IDC. IDC could be changed so we can't use |
| 121 // just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|. |
| 122 // Never change mapping or reuse |enum_id|. Always push back new items. |
| 123 // Items that is not used any more by |RenderViewContextMenu.ExecuteCommand| |
| 124 // could be deleted, but don't change the rest of |kUmaEnumToCommand|. |
| 125 const struct UmaEnumCommandIdPair { |
| 126 int enum_id; |
| 127 int command_id; |
| 128 } kUmaEnumToCommand[] = { |
| 129 { 0, IDC_CONTENT_CONTEXT_CUSTOM_FIRST }, |
| 130 { 1, IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST }, |
| 131 { 2, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST }, |
| 132 { 3, IDC_CONTENT_CONTEXT_OPENLINKNEWTAB }, |
| 133 { 4, IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW }, |
| 134 { 5, IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD }, |
| 135 { 6, IDC_CONTENT_CONTEXT_SAVELINKAS }, |
| 136 { 7, IDC_CONTENT_CONTEXT_SAVEAVAS }, |
| 137 { 8, IDC_CONTENT_CONTEXT_SAVEIMAGEAS }, |
| 138 { 9, IDC_CONTENT_CONTEXT_COPYLINKLOCATION }, |
| 139 { 10, IDC_CONTENT_CONTEXT_COPYIMAGELOCATION }, |
| 140 { 11, IDC_CONTENT_CONTEXT_COPYAVLOCATION }, |
| 141 { 12, IDC_CONTENT_CONTEXT_COPYIMAGE }, |
| 142 { 13, IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB }, |
| 143 { 14, IDC_CONTENT_CONTEXT_OPENAVNEWTAB }, |
| 144 { 15, IDC_CONTENT_CONTEXT_PLAYPAUSE }, |
| 145 { 16, IDC_CONTENT_CONTEXT_MUTE }, |
| 146 { 17, IDC_CONTENT_CONTEXT_LOOP }, |
| 147 { 18, IDC_CONTENT_CONTEXT_CONTROLS }, |
| 148 { 19, IDC_CONTENT_CONTEXT_ROTATECW }, |
| 149 { 20, IDC_CONTENT_CONTEXT_ROTATECCW }, |
| 150 { 21, IDC_BACK }, |
| 151 { 22, IDC_FORWARD }, |
| 152 { 23, IDC_SAVE_PAGE }, |
| 153 { 24, IDC_RELOAD }, |
| 154 { 25, IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP }, |
| 155 { 26, IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP }, |
| 156 { 27, IDC_PRINT }, |
| 157 { 28, IDC_VIEW_SOURCE }, |
| 158 { 29, IDC_CONTENT_CONTEXT_INSPECTELEMENT }, |
| 159 { 30, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE }, |
| 160 { 31, IDC_CONTENT_CONTEXT_VIEWPAGEINFO }, |
| 161 { 32, IDC_CONTENT_CONTEXT_TRANSLATE }, |
| 162 { 33, IDC_CONTENT_CONTEXT_RELOADFRAME }, |
| 163 { 34, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE }, |
| 164 { 35, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO }, |
| 165 { 36, IDC_CONTENT_CONTEXT_UNDO }, |
| 166 { 37, IDC_CONTENT_CONTEXT_REDO }, |
| 167 { 38, IDC_CONTENT_CONTEXT_CUT }, |
| 168 { 39, IDC_CONTENT_CONTEXT_COPY }, |
| 169 { 40, IDC_CONTENT_CONTEXT_PASTE }, |
| 170 { 41, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE }, |
| 171 { 42, IDC_CONTENT_CONTEXT_DELETE }, |
| 172 { 43, IDC_CONTENT_CONTEXT_SELECTALL }, |
| 173 { 44, IDC_CONTENT_CONTEXT_SEARCHWEBFOR }, |
| 174 { 45, IDC_CONTENT_CONTEXT_GOTOURL }, |
| 175 { 46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS }, |
| 176 { 47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS }, |
| 177 { 48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE }, |
| 178 { 49, IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES }, |
| 179 { 50, IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT }, |
| 180 // Add new items here and use |enum_id| from the next line. |
| 181 { 51, 0 }, // Must be the last. Increment |enum_id| when new IDC was added. |
| 182 }; |
| 183 |
| 184 // Increments histogram value for context menu command specified by |id|. |
| 185 void RecordExecutedContextItem(int id) { |
| 186 // Collapse large ranges of ids. |
| 187 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 188 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 189 id = IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 190 } else if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 191 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 192 id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; |
| 193 } else if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 194 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 195 id = IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
| 196 } |
| 197 const size_t kMappingSize = arraysize(kUmaEnumToCommand); |
| 198 for (size_t i = 0; i < kMappingSize; ++i) { |
| 199 if (kUmaEnumToCommand[i].command_id == id) { |
| 200 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.ExecuteCommand", |
| 201 kUmaEnumToCommand[i].enum_id, |
| 202 kUmaEnumToCommand[kMappingSize - 1].enum_id); |
| 203 return; |
| 204 } |
| 205 } |
| 206 NOTREACHED() << "Update kUmaEnumToCommand"; |
| 207 } |
| 208 |
120 // Usually a new tab is expected where this function is used, | 209 // Usually a new tab is expected where this function is used, |
121 // however users should be able to open a tab in background | 210 // however users should be able to open a tab in background |
122 // or in a new window. | 211 // or in a new window. |
123 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( | 212 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( |
124 int event_flags) { | 213 int event_flags) { |
125 WindowOpenDisposition disposition = | 214 WindowOpenDisposition disposition = |
126 ui::DispositionFromEventFlags(event_flags); | 215 ui::DispositionFromEventFlags(event_flags); |
127 return disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition; | 216 return disposition == CURRENT_TAB ? NEW_FOREGROUND_TAB : disposition; |
128 } | 217 } |
129 | 218 |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { | 1419 void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { |
1331 // If this command is is added by one of our observers, we dispatch it to the | 1420 // If this command is is added by one of our observers, we dispatch it to the |
1332 // observer. | 1421 // observer. |
1333 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); | 1422 ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_); |
1334 RenderViewContextMenuObserver* observer; | 1423 RenderViewContextMenuObserver* observer; |
1335 while ((observer = it.GetNext()) != NULL) { | 1424 while ((observer = it.GetNext()) != NULL) { |
1336 if (observer->IsCommandIdSupported(id)) | 1425 if (observer->IsCommandIdSupported(id)) |
1337 return observer->ExecuteCommand(id); | 1426 return observer->ExecuteCommand(id); |
1338 } | 1427 } |
1339 | 1428 |
| 1429 RecordExecutedContextItem(id); |
| 1430 |
1340 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); | 1431 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); |
1341 | 1432 |
1342 // Process custom actions range. | 1433 // Process custom actions range. |
1343 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1434 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
1344 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1435 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
1345 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 1436 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
1346 const content::CustomContextMenuContext& context = params_.custom_context; | 1437 const content::CustomContextMenuContext& context = params_.custom_context; |
1347 #if defined(ENABLE_PLUGINS) | 1438 #if defined(ENABLE_PLUGINS) |
1348 if (context.request_id && !context.is_pepper_menu) { | 1439 if (context.request_id && !context.is_pepper_menu) { |
1349 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 1440 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 source_web_contents_->GetRenderViewHost()-> | 1983 source_web_contents_->GetRenderViewHost()-> |
1893 ExecuteMediaPlayerActionAtLocation(location, action); | 1984 ExecuteMediaPlayerActionAtLocation(location, action); |
1894 } | 1985 } |
1895 | 1986 |
1896 void RenderViewContextMenu::PluginActionAt( | 1987 void RenderViewContextMenu::PluginActionAt( |
1897 const gfx::Point& location, | 1988 const gfx::Point& location, |
1898 const WebPluginAction& action) { | 1989 const WebPluginAction& action) { |
1899 source_web_contents_->GetRenderViewHost()-> | 1990 source_web_contents_->GetRenderViewHost()-> |
1900 ExecutePluginActionAtLocation(location, action); | 1991 ExecutePluginActionAtLocation(location, action); |
1901 } | 1992 } |
OLD | NEW |