Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 7086005: Context menu for "Voice recognition options" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reverted changes in render_view_host and implemented instead in render_view_context_menu Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
19 #include "chrome/browser/autocomplete/autocomplete_edit.h" 19 #include "chrome/browser/autocomplete/autocomplete_edit.h"
20 #include "chrome/browser/autocomplete/autocomplete_match.h" 20 #include "chrome/browser/autocomplete/autocomplete_match.h"
21 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/download/download_manager.h" 22 #include "chrome/browser/download/download_manager.h"
23 #include "chrome/browser/download/download_util.h" 23 #include "chrome/browser/download/download_util.h"
24 #include "chrome/browser/download/save_package.h" 24 #include "chrome/browser/download/save_package.h"
25 #include "chrome/browser/extensions/extension_event_router.h" 25 #include "chrome/browser/extensions/extension_event_router.h"
26 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/google/google_util.h"
27 #include "chrome/browser/net/browser_url_util.h" 28 #include "chrome/browser/net/browser_url_util.h"
28 #include "chrome/browser/page_info_window.h" 29 #include "chrome/browser/page_info_window.h"
29 #include "chrome/browser/platform_util.h" 30 #include "chrome/browser/platform_util.h"
30 #include "chrome/browser/prefs/pref_member.h" 31 #include "chrome/browser/prefs/pref_member.h"
31 #include "chrome/browser/prefs/pref_service.h" 32 #include "chrome/browser/prefs/pref_service.h"
32 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/profiles/profile_io_data.h" 34 #include "chrome/browser/profiles/profile_io_data.h"
34 #include "chrome/browser/search_engines/template_url.h" 35 #include "chrome/browser/search_engines/template_url.h"
35 #include "chrome/browser/search_engines/template_url_service.h" 36 #include "chrome/browser/search_engines/template_url_service.h"
36 #include "chrome/browser/search_engines/template_url_service_factory.h" 37 #include "chrome/browser/search_engines/template_url_service_factory.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 187
187 RenderViewContextMenu::RenderViewContextMenu( 188 RenderViewContextMenu::RenderViewContextMenu(
188 TabContents* tab_contents, 189 TabContents* tab_contents,
189 const ContextMenuParams& params) 190 const ContextMenuParams& params)
190 : params_(params), 191 : params_(params),
191 source_tab_contents_(tab_contents), 192 source_tab_contents_(tab_contents),
192 profile_(tab_contents->profile()), 193 profile_(tab_contents->profile()),
193 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), 194 ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)),
194 external_(false), 195 external_(false),
195 ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)), 196 ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)),
197 ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_submenu_model_(this)),
196 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)), 198 ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)),
197 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)), 199 ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)),
198 protocol_handler_registry_( 200 protocol_handler_registry_(
199 tab_contents->profile()->GetProtocolHandlerRegistry()) { 201 tab_contents->profile()->GetProtocolHandlerRegistry()) {
200 } 202 }
201 203
202 RenderViewContextMenu::~RenderViewContextMenu() { 204 RenderViewContextMenu::~RenderViewContextMenu() {
203 } 205 }
204 206
205 // Menu construction functions ------------------------------------------------- 207 // Menu construction functions -------------------------------------------------
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 IDS_CONTENT_CONTEXT_DELETE); 788 IDS_CONTENT_CONTEXT_DELETE);
787 menu_model_.AddSeparator(); 789 menu_model_.AddSeparator();
788 790
789 if (!params_.keyword_url.is_empty()) { 791 if (!params_.keyword_url.is_empty()) {
790 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, 792 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE,
791 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); 793 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE);
792 menu_model_.AddSeparator(); 794 menu_model_.AddSeparator();
793 } 795 }
794 796
795 AppendSpellcheckOptionsSubMenu(); 797 AppendSpellcheckOptionsSubMenu();
798 AppendSpeechInputOptionsSubMenu();
796 799
797 #if defined(OS_MACOSX) 800 #if defined(OS_MACOSX)
798 // OS X provides a contextual menu to set writing direction for BiDi 801 // OS X provides a contextual menu to set writing direction for BiDi
799 // languages. 802 // languages.
800 // This functionality is exposed as a keyboard shortcut on Windows & Linux. 803 // This functionality is exposed as a keyboard shortcut on Windows & Linux.
801 AppendBidiSubMenu(); 804 AppendBidiSubMenu();
802 #endif // OS_MACOSX 805 #endif // OS_MACOSX
803 806
804 menu_model_.AddSeparator(); 807 menu_model_.AddSeparator();
805 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, 808 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : 849 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
847 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); 850 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
848 } 851 }
849 852
850 menu_model_.AddSubMenu( 853 menu_model_.AddSubMenu(
851 IDC_SPELLCHECK_MENU, 854 IDC_SPELLCHECK_MENU,
852 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), 855 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
853 &spellcheck_submenu_model_); 856 &spellcheck_submenu_model_);
854 } 857 }
855 858
859 void RenderViewContextMenu::AppendSpeechInputOptionsSubMenu() {
860 if (params_.speech_input_enabled) {
861 speech_input_submenu_model_.AddCheckItem(
862 IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS,
863 l10n_util::GetStringUTF16(
864 IDS_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS));
865
866 speech_input_submenu_model_.AddItemWithStringId(
867 IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT,
868 IDS_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT);
869
870 menu_model_.AddSubMenu(
871 IDC_SPEECH_INPUT_MENU,
872 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_INPUT_MENU),
873 &speech_input_submenu_model_);
874 }
875 }
876
856 #if defined(OS_MACOSX) 877 #if defined(OS_MACOSX)
857 void RenderViewContextMenu::AppendBidiSubMenu() { 878 void RenderViewContextMenu::AppendBidiSubMenu() {
858 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, 879 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT,
859 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); 880 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT));
860 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, 881 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR,
861 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); 882 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR));
862 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, 883 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL,
863 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); 884 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL));
864 885
865 menu_model_.AddSubMenu( 886 menu_model_.AddSubMenu(
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 case IDC_INPUT_METHODS_MENU: 1204 case IDC_INPUT_METHODS_MENU:
1184 return true; 1205 return true;
1185 #endif 1206 #endif
1186 1207
1187 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: 1208 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE:
1188 return !params_.keyword_url.is_empty(); 1209 return !params_.keyword_url.is_empty();
1189 1210
1190 case IDC_SPELLCHECK_MENU: 1211 case IDC_SPELLCHECK_MENU:
1191 return true; 1212 return true;
1192 1213
1214 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS:
1215 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT:
1216 case IDC_SPEECH_INPUT_MENU:
1217 return true;
1218
1193 case IDC_CONTENT_CONTEXT_OPENLINKWITH: 1219 case IDC_CONTENT_CONTEXT_OPENLINKWITH:
1194 return true; 1220 return true;
1195 1221
1196 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: 1222 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS:
1197 return true; 1223 return true;
1198 1224
1199 default: 1225 default:
1200 NOTREACHED(); 1226 NOTREACHED();
1201 return false; 1227 return false;
1202 } 1228 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY) 1269 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY)
1244 return false; 1270 return false;
1245 #endif // OS_MACOSX 1271 #endif // OS_MACOSX
1246 1272
1247 // Check box for 'Check the Spelling of this field'. 1273 // Check box for 'Check the Spelling of this field'.
1248 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { 1274 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) {
1249 return (params_.spellcheck_enabled && 1275 return (params_.spellcheck_enabled &&
1250 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); 1276 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
1251 } 1277 }
1252 1278
1279 // Check box for menu item 'Block offensive words'.
1280 if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS) {
1281 return profile_->GetPrefs()->GetBoolean(prefs::kSpeechInputCensorResults);
1282 }
1283
1253 // Don't bother getting the display language vector if this isn't a spellcheck 1284 // Don't bother getting the display language vector if this isn't a spellcheck
1254 // language. 1285 // language.
1255 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || 1286 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
1256 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) 1287 (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
1257 return false; 1288 return false;
1258 1289
1259 std::vector<std::string> languages; 1290 std::vector<std::string> languages;
1260 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == 1291 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) ==
1261 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); 1292 (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
1262 } 1293 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1655 if (tab_contents_wrapper && 1686 if (tab_contents_wrapper &&
1656 tab_contents_wrapper->search_engine_tab_helper() && 1687 tab_contents_wrapper->search_engine_tab_helper() &&
1657 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { 1688 tab_contents_wrapper->search_engine_tab_helper()->delegate()) {
1658 // Takes ownership of |template_url|. 1689 // Takes ownership of |template_url|.
1659 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> 1690 tab_contents_wrapper->search_engine_tab_helper()->delegate()->
1660 ConfirmAddSearchProvider(template_url.release(), profile_); 1691 ConfirmAddSearchProvider(template_url.release(), profile_);
1661 } 1692 }
1662 break; 1693 break;
1663 } 1694 }
1664 1695
1696 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS: {
1697 PrefService* prefs = profile_->GetPrefs();
1698 const bool censor =
1699 !prefs->GetBoolean(prefs::kSpeechInputCensorResults);
1700 prefs->SetBoolean(prefs::kSpeechInputCensorResults, censor);
1701 break;
1702 }
1703
1704 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: {
1705 GURL about_url(chrome::kSpeechInputAboutURL);
1706 GURL localized_about_url = google_util::AppendGoogleLocaleParam(about_url) ;
Satish 2011/07/20 15:23:13 line too long?
gshires 2011/07/20 17:16:10 Done.
1707 // Open URL with no referrer field (because user clicked on menu item).
1708 OpenURL(
1709 localized_about_url,
Satish 2011/07/20 15:23:13 suggest moving the first parameter to the previous
gshires 2011/07/20 17:16:10 Done.
1710 GURL(),
1711 NEW_FOREGROUND_TAB,
1712 PageTransition::LINK);
1713 break;
1714 }
1715
1665 default: 1716 default:
1666 NOTREACHED(); 1717 NOTREACHED();
1667 break; 1718 break;
1668 } 1719 }
1669 } 1720 }
1670 1721
1671 ProtocolHandlerRegistry::ProtocolHandlerList 1722 ProtocolHandlerRegistry::ProtocolHandlerList
1672 RenderViewContextMenu::GetHandlersForLinkUrl() { 1723 RenderViewContextMenu::GetHandlersForLinkUrl() {
1673 ProtocolHandlerRegistry::ProtocolHandlerList handlers = 1724 ProtocolHandlerRegistry::ProtocolHandlerList handlers =
1674 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); 1725 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 g_browser_process->clipboard()); 1804 g_browser_process->clipboard());
1754 } 1805 }
1755 1806
1756 void RenderViewContextMenu::MediaPlayerActionAt( 1807 void RenderViewContextMenu::MediaPlayerActionAt(
1757 const gfx::Point& location, 1808 const gfx::Point& location,
1758 const WebMediaPlayerAction& action) { 1809 const WebMediaPlayerAction& action) {
1759 RenderViewHost* rvh = source_tab_contents_->render_view_host(); 1810 RenderViewHost* rvh = source_tab_contents_->render_view_host();
1760 rvh->Send(new ViewMsg_MediaPlayerActionAt( 1811 rvh->Send(new ViewMsg_MediaPlayerActionAt(
1761 rvh->routing_id(), location, action)); 1812 rvh->routing_id(), location, action));
1762 } 1813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698