OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 8 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 RenderViewContextMenu::RenderViewContextMenu( | 187 RenderViewContextMenu::RenderViewContextMenu( |
188 TabContents* tab_contents, | 188 TabContents* tab_contents, |
189 const ContextMenuParams& params) | 189 const ContextMenuParams& params) |
190 : params_(params), | 190 : params_(params), |
191 source_tab_contents_(tab_contents), | 191 source_tab_contents_(tab_contents), |
192 profile_(tab_contents->profile()), | 192 profile_(tab_contents->profile()), |
193 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), | 193 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), |
194 external_(false), | 194 external_(false), |
195 ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)), | 195 ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)), |
| 196 ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_submenu_model_(this)), |
196 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), | 197 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), |
197 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), | 198 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), |
198 protocol_handler_registry_( | 199 protocol_handler_registry_( |
199 tab_contents->profile()->GetProtocolHandlerRegistry()) { | 200 tab_contents->profile()->GetProtocolHandlerRegistry()) { |
200 } | 201 } |
201 | 202 |
202 RenderViewContextMenu::~RenderViewContextMenu() { | 203 RenderViewContextMenu::~RenderViewContextMenu() { |
203 } | 204 } |
204 | 205 |
205 // Menu construction functions ------------------------------------------------- | 206 // Menu construction functions ------------------------------------------------- |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 IDS_CONTENT_CONTEXT_DELETE); | 787 IDS_CONTENT_CONTEXT_DELETE); |
787 menu_model_.AddSeparator(); | 788 menu_model_.AddSeparator(); |
788 | 789 |
789 if (!params_.keyword_url.is_empty()) { | 790 if (!params_.keyword_url.is_empty()) { |
790 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, | 791 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, |
791 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); | 792 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); |
792 menu_model_.AddSeparator(); | 793 menu_model_.AddSeparator(); |
793 } | 794 } |
794 | 795 |
795 AppendSpellcheckOptionsSubMenu(); | 796 AppendSpellcheckOptionsSubMenu(); |
| 797 AppendSpeechInputOptionsSubMenu(); |
796 | 798 |
797 #if defined(OS_MACOSX) | 799 #if defined(OS_MACOSX) |
798 // OS X provides a contextual menu to set writing direction for BiDi | 800 // OS X provides a contextual menu to set writing direction for BiDi |
799 // languages. | 801 // languages. |
800 // This functionality is exposed as a keyboard shortcut on Windows & Linux. | 802 // This functionality is exposed as a keyboard shortcut on Windows & Linux. |
801 AppendBidiSubMenu(); | 803 AppendBidiSubMenu(); |
802 #endif // OS_MACOSX | 804 #endif // OS_MACOSX |
803 | 805 |
804 menu_model_.AddSeparator(); | 806 menu_model_.AddSeparator(); |
805 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, | 807 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : | 848 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : |
847 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); | 849 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); |
848 } | 850 } |
849 | 851 |
850 menu_model_.AddSubMenu( | 852 menu_model_.AddSubMenu( |
851 IDC_SPELLCHECK_MENU, | 853 IDC_SPELLCHECK_MENU, |
852 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), | 854 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), |
853 &spellcheck_submenu_model_); | 855 &spellcheck_submenu_model_); |
854 } | 856 } |
855 | 857 |
| 858 void RenderViewContextMenu::AppendSpeechInputOptionsSubMenu() { |
| 859 if (params_.speech_input_enabled) { |
| 860 speech_input_submenu_model_.AddCheckItem( |
| 861 IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS, |
| 862 l10n_util::GetStringUTF16( |
| 863 IDS_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS)); |
| 864 |
| 865 speech_input_submenu_model_.AddItemWithStringId( |
| 866 IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT, |
| 867 IDS_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT); |
| 868 |
| 869 menu_model_.AddSubMenu( |
| 870 IDC_SPEECH_INPUT_MENU, |
| 871 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_INPUT_MENU), |
| 872 &speech_input_submenu_model_); |
| 873 } |
| 874 } |
| 875 |
856 #if defined(OS_MACOSX) | 876 #if defined(OS_MACOSX) |
857 void RenderViewContextMenu::AppendBidiSubMenu() { | 877 void RenderViewContextMenu::AppendBidiSubMenu() { |
858 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, | 878 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, |
859 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); | 879 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); |
860 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, | 880 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, |
861 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); | 881 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); |
862 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, | 882 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, |
863 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); | 883 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); |
864 | 884 |
865 menu_model_.AddSubMenu( | 885 menu_model_.AddSubMenu( |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 case IDC_INPUT_METHODS_MENU: | 1203 case IDC_INPUT_METHODS_MENU: |
1184 return true; | 1204 return true; |
1185 #endif | 1205 #endif |
1186 | 1206 |
1187 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: | 1207 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: |
1188 return !params_.keyword_url.is_empty(); | 1208 return !params_.keyword_url.is_empty(); |
1189 | 1209 |
1190 case IDC_SPELLCHECK_MENU: | 1210 case IDC_SPELLCHECK_MENU: |
1191 return true; | 1211 return true; |
1192 | 1212 |
| 1213 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS: |
| 1214 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: |
| 1215 case IDC_SPEECH_INPUT_MENU: |
| 1216 return true; |
| 1217 |
1193 case IDC_CONTENT_CONTEXT_OPENLINKWITH: | 1218 case IDC_CONTENT_CONTEXT_OPENLINKWITH: |
1194 return true; | 1219 return true; |
1195 | 1220 |
1196 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: | 1221 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: |
1197 return true; | 1222 return true; |
1198 | 1223 |
1199 default: | 1224 default: |
1200 NOTREACHED(); | 1225 NOTREACHED(); |
1201 return false; | 1226 return false; |
1202 } | 1227 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY) | 1268 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY) |
1244 return false; | 1269 return false; |
1245 #endif // OS_MACOSX | 1270 #endif // OS_MACOSX |
1246 | 1271 |
1247 // Check box for 'Check the Spelling of this field'. | 1272 // Check box for 'Check the Spelling of this field'. |
1248 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { | 1273 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { |
1249 return (params_.spellcheck_enabled && | 1274 return (params_.spellcheck_enabled && |
1250 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); | 1275 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); |
1251 } | 1276 } |
1252 | 1277 |
| 1278 // Check box for menu item 'Block offensive words'. |
| 1279 if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS) { |
| 1280 return profile_->GetPrefs()->GetBoolean(prefs::kSpeechInputCensorResults); |
| 1281 } |
| 1282 |
1253 // Don't bother getting the display language vector if this isn't a spellcheck | 1283 // Don't bother getting the display language vector if this isn't a spellcheck |
1254 // language. | 1284 // language. |
1255 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || | 1285 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || |
1256 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) | 1286 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) |
1257 return false; | 1287 return false; |
1258 | 1288 |
1259 std::vector<std::string> languages; | 1289 std::vector<std::string> languages; |
1260 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == | 1290 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == |
1261 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); | 1291 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); |
1262 } | 1292 } |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 if (tab_contents_wrapper && | 1685 if (tab_contents_wrapper && |
1656 tab_contents_wrapper->search_engine_tab_helper() && | 1686 tab_contents_wrapper->search_engine_tab_helper() && |
1657 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { | 1687 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { |
1658 // Takes ownership of |template_url|. | 1688 // Takes ownership of |template_url|. |
1659 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> | 1689 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> |
1660 ConfirmAddSearchProvider(template_url.release(), profile_); | 1690 ConfirmAddSearchProvider(template_url.release(), profile_); |
1661 } | 1691 } |
1662 break; | 1692 break; |
1663 } | 1693 } |
1664 | 1694 |
| 1695 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS: { |
| 1696 PrefService* prefs = profile_->GetPrefs(); |
| 1697 const bool censor = |
| 1698 !prefs->GetBoolean(prefs::kSpeechInputCensorResults); |
| 1699 prefs->SetBoolean(prefs::kSpeechInputCensorResults, censor); |
| 1700 break; |
| 1701 } |
| 1702 |
| 1703 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: { |
| 1704 rvh->SpeechInputAbout(); |
| 1705 break; |
| 1706 } |
| 1707 |
1665 default: | 1708 default: |
1666 NOTREACHED(); | 1709 NOTREACHED(); |
1667 break; | 1710 break; |
1668 } | 1711 } |
1669 } | 1712 } |
1670 | 1713 |
1671 ProtocolHandlerRegistry::ProtocolHandlerList | 1714 ProtocolHandlerRegistry::ProtocolHandlerList |
1672 RenderViewContextMenu::GetHandlersForLinkUrl() { | 1715 RenderViewContextMenu::GetHandlersForLinkUrl() { |
1673 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1716 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
1674 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); | 1717 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 g_browser_process->clipboard()); | 1796 g_browser_process->clipboard()); |
1754 } | 1797 } |
1755 | 1798 |
1756 void RenderViewContextMenu::MediaPlayerActionAt( | 1799 void RenderViewContextMenu::MediaPlayerActionAt( |
1757 const gfx::Point& location, | 1800 const gfx::Point& location, |
1758 const WebMediaPlayerAction& action) { | 1801 const WebMediaPlayerAction& action) { |
1759 RenderViewHost* rvh = source_tab_contents_->render_view_host(); | 1802 RenderViewHost* rvh = source_tab_contents_->render_view_host(); |
1760 rvh->Send(new ViewMsg_MediaPlayerActionAt( | 1803 rvh->Send(new ViewMsg_MediaPlayerActionAt( |
1761 rvh->routing_id(), location, action)); | 1804 rvh->routing_id(), location, action)); |
1762 } | 1805 } |
OLD | NEW |