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

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: No changes (Just trying to get commit-bot to wake up) 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
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 13 #include "base/stl_util.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/debugger/devtools_window.h" 22 #include "chrome/browser/debugger/devtools_window.h"
23 #include "chrome/browser/download/download_manager.h" 23 #include "chrome/browser/download/download_manager.h"
24 #include "chrome/browser/download/download_util.h" 24 #include "chrome/browser/download/download_util.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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 IDS_CONTENT_CONTEXT_DELETE); 785 IDS_CONTENT_CONTEXT_DELETE);
784 menu_model_.AddSeparator(); 786 menu_model_.AddSeparator();
785 787
786 if (!params_.keyword_url.is_empty()) { 788 if (!params_.keyword_url.is_empty()) {
787 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE, 789 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ADDSEARCHENGINE,
788 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE); 790 IDS_CONTENT_CONTEXT_ADDSEARCHENGINE);
789 menu_model_.AddSeparator(); 791 menu_model_.AddSeparator();
790 } 792 }
791 793
792 AppendSpellcheckOptionsSubMenu(); 794 AppendSpellcheckOptionsSubMenu();
795 AppendSpeechInputOptionsSubMenu();
793 796
794 #if defined(OS_MACOSX) 797 #if defined(OS_MACOSX)
795 // OS X provides a contextual menu to set writing direction for BiDi 798 // OS X provides a contextual menu to set writing direction for BiDi
796 // languages. 799 // languages.
797 // This functionality is exposed as a keyboard shortcut on Windows & Linux. 800 // This functionality is exposed as a keyboard shortcut on Windows & Linux.
798 AppendBidiSubMenu(); 801 AppendBidiSubMenu();
799 #endif // OS_MACOSX 802 #endif // OS_MACOSX
800 803
801 menu_model_.AddSeparator(); 804 menu_model_.AddSeparator();
802 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL, 805 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SELECTALL,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : 846 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
844 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); 847 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
845 } 848 }
846 849
847 menu_model_.AddSubMenu( 850 menu_model_.AddSubMenu(
848 IDC_SPELLCHECK_MENU, 851 IDC_SPELLCHECK_MENU,
849 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), 852 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
850 &spellcheck_submenu_model_); 853 &spellcheck_submenu_model_);
851 } 854 }
852 855
856 void RenderViewContextMenu::AppendSpeechInputOptionsSubMenu() {
857 if (params_.speech_input_enabled) {
858 speech_input_submenu_model_.AddCheckItem(
859 IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS,
860 l10n_util::GetStringUTF16(
861 IDS_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS));
862
863 speech_input_submenu_model_.AddItemWithStringId(
864 IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT,
865 IDS_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT);
866
867 menu_model_.AddSubMenu(
868 IDC_SPEECH_INPUT_MENU,
869 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPEECH_INPUT_MENU),
870 &speech_input_submenu_model_);
871 }
872 }
873
853 #if defined(OS_MACOSX) 874 #if defined(OS_MACOSX)
854 void RenderViewContextMenu::AppendBidiSubMenu() { 875 void RenderViewContextMenu::AppendBidiSubMenu() {
855 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, 876 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT,
856 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); 877 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT));
857 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, 878 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR,
858 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); 879 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR));
859 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, 880 bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL,
860 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); 881 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL));
861 882
862 menu_model_.AddSubMenu( 883 menu_model_.AddSubMenu(
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 case IDC_INPUT_METHODS_MENU: 1201 case IDC_INPUT_METHODS_MENU:
1181 return true; 1202 return true;
1182 #endif 1203 #endif
1183 1204
1184 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: 1205 case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE:
1185 return !params_.keyword_url.is_empty(); 1206 return !params_.keyword_url.is_empty();
1186 1207
1187 case IDC_SPELLCHECK_MENU: 1208 case IDC_SPELLCHECK_MENU:
1188 return true; 1209 return true;
1189 1210
1211 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS:
1212 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT:
1213 case IDC_SPEECH_INPUT_MENU:
1214 return true;
1215
1190 case IDC_CONTENT_CONTEXT_OPENLINKWITH: 1216 case IDC_CONTENT_CONTEXT_OPENLINKWITH:
1191 return true; 1217 return true;
1192 1218
1193 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: 1219 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS:
1194 return true; 1220 return true;
1195 1221
1196 default: 1222 default:
1197 NOTREACHED(); 1223 NOTREACHED();
1198 return false; 1224 return false;
1199 } 1225 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY) 1266 if (id == IDC_CONTENT_CONTEXT_LOOK_UP_IN_DICTIONARY)
1241 return false; 1267 return false;
1242 #endif // OS_MACOSX 1268 #endif // OS_MACOSX
1243 1269
1244 // Check box for 'Check the Spelling of this field'. 1270 // Check box for 'Check the Spelling of this field'.
1245 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) { 1271 if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) {
1246 return (params_.spellcheck_enabled && 1272 return (params_.spellcheck_enabled &&
1247 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)); 1273 profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
1248 } 1274 }
1249 1275
1276 // Check box for menu item 'Block offensive words'.
1277 if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS) {
1278 return profile_->GetPrefs()->GetBoolean(prefs::kSpeechInputCensorResults);
1279 }
1280
1250 // Don't bother getting the display language vector if this isn't a spellcheck 1281 // Don't bother getting the display language vector if this isn't a spellcheck
1251 // language. 1282 // language.
1252 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || 1283 if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
1253 (id >= IDC_SPELLCHECK_LANGUAGES_LAST)) 1284 (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
1254 return false; 1285 return false;
1255 1286
1256 std::vector<std::string> languages; 1287 std::vector<std::string> languages;
1257 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) == 1288 return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) ==
1258 (id - IDC_SPELLCHECK_LANGUAGES_FIRST); 1289 (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
1259 } 1290 }
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 if (tab_contents_wrapper && 1688 if (tab_contents_wrapper &&
1658 tab_contents_wrapper->search_engine_tab_helper() && 1689 tab_contents_wrapper->search_engine_tab_helper() &&
1659 tab_contents_wrapper->search_engine_tab_helper()->delegate()) { 1690 tab_contents_wrapper->search_engine_tab_helper()->delegate()) {
1660 // Takes ownership of |template_url|. 1691 // Takes ownership of |template_url|.
1661 tab_contents_wrapper->search_engine_tab_helper()->delegate()-> 1692 tab_contents_wrapper->search_engine_tab_helper()->delegate()->
1662 ConfirmAddSearchProvider(template_url.release(), profile_); 1693 ConfirmAddSearchProvider(template_url.release(), profile_);
1663 } 1694 }
1664 break; 1695 break;
1665 } 1696 }
1666 1697
1698 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_CENSOR_RESULTS: {
1699 PrefService* prefs = profile_->GetPrefs();
1700 const bool censor = !prefs->GetBoolean(prefs::kSpeechInputCensorResults);
1701 prefs->SetBoolean(prefs::kSpeechInputCensorResults, censor);
1702 break;
1703 }
1704
1705 case IDC_CONTENT_CONTEXT_SPEECH_INPUT_ABOUT: {
1706 GURL url(chrome::kSpeechInputAboutURL);
1707 GURL localized_url = google_util::AppendGoogleLocaleParam(url);
1708 // Open URL with no referrer field (because user clicked on menu item).
1709 OpenURL(localized_url, GURL(), 0, NEW_FOREGROUND_TAB,
1710 PageTransition::LINK);
1711 break;
1712 }
1713
1667 default: 1714 default:
1668 NOTREACHED(); 1715 NOTREACHED();
1669 break; 1716 break;
1670 } 1717 }
1671 } 1718 }
1672 1719
1673 ProtocolHandlerRegistry::ProtocolHandlerList 1720 ProtocolHandlerRegistry::ProtocolHandlerList
1674 RenderViewContextMenu::GetHandlersForLinkUrl() { 1721 RenderViewContextMenu::GetHandlersForLinkUrl() {
1675 ProtocolHandlerRegistry::ProtocolHandlerList handlers = 1722 ProtocolHandlerRegistry::ProtocolHandlerList handlers =
1676 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); 1723 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 g_browser_process->clipboard()); 1815 g_browser_process->clipboard());
1769 } 1816 }
1770 1817
1771 void RenderViewContextMenu::MediaPlayerActionAt( 1818 void RenderViewContextMenu::MediaPlayerActionAt(
1772 const gfx::Point& location, 1819 const gfx::Point& location,
1773 const WebMediaPlayerAction& action) { 1820 const WebMediaPlayerAction& action) {
1774 RenderViewHost* rvh = source_tab_contents_->render_view_host(); 1821 RenderViewHost* rvh = source_tab_contents_->render_view_host();
1775 rvh->Send(new ViewMsg_MediaPlayerActionAt( 1822 rvh->Send(new ViewMsg_MediaPlayerActionAt(
1776 rvh->routing_id(), location, action)); 1823 rvh->routing_id(), location, action));
1777 } 1824 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698