OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/ui/app_list/start_page_observer.h" | 23 #include "chrome/browser/ui/app_list/start_page_observer.h" |
24 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 24 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
28 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
29 #include "content/public/browser/notification_observer.h" | 29 #include "content/public/browser/notification_observer.h" |
30 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/speech_recognition_session_preamble.h" |
33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
34 #include "content/public/browser/web_contents_delegate.h" | 35 #include "content/public/browser/web_contents_delegate.h" |
35 #include "extensions/browser/extension_system_provider.h" | 36 #include "extensions/browser/extension_system_provider.h" |
36 #include "extensions/browser/extensions_browser_client.h" | 37 #include "extensions/browser/extensions_browser_client.h" |
37 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
38 #include "ui/app_list/app_list_switches.h" | 39 #include "ui/app_list/app_list_switches.h" |
39 | 40 |
40 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
41 #include "chromeos/audio/cras_audio_handler.h" | 42 #include "chromeos/audio/cras_audio_handler.h" |
42 #endif | 43 #endif |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (HotwordService::IsExperimentalHotwordingEnabled() && | 215 if (HotwordService::IsExperimentalHotwordingEnabled() && |
215 speech_recognizer_) { | 216 speech_recognizer_) { |
216 speech_recognizer_->Stop(); | 217 speech_recognizer_->Stop(); |
217 } | 218 } |
218 | 219 |
219 #if defined(OS_CHROMEOS) | 220 #if defined(OS_CHROMEOS) |
220 audio_status_.reset(); | 221 audio_status_.reset(); |
221 #endif | 222 #endif |
222 } | 223 } |
223 | 224 |
224 void StartPageService::ToggleSpeechRecognition() { | 225 void StartPageService::ToggleSpeechRecognition( |
| 226 const scoped_refptr<content::SpeechRecognitionSessionPreamble>& preamble) { |
225 DCHECK(contents_); | 227 DCHECK(contents_); |
226 speech_button_toggled_manually_ = true; | 228 speech_button_toggled_manually_ = true; |
227 | 229 |
228 // Speech recognition under V2 hotwording does not depend in any way on the | 230 // Speech recognition under V2 hotwording does not depend in any way on the |
229 // start page web contents. Do this code path first to make this explicit and | 231 // start page web contents. Do this code path first to make this explicit and |
230 // easier to identify what code needs to be deleted when V2 hotwording is | 232 // easier to identify what code needs to be deleted when V2 hotwording is |
231 // stable. | 233 // stable. |
232 if (HotwordService::IsExperimentalHotwordingEnabled()) { | 234 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
233 if (!speech_recognizer_) { | 235 if (!speech_recognizer_) { |
234 std::string profile_locale; | 236 std::string profile_locale; |
235 #if defined(OS_CHROMEOS) | 237 #if defined(OS_CHROMEOS) |
236 profile_locale = profile_->GetPrefs()->GetString( | 238 profile_locale = profile_->GetPrefs()->GetString( |
237 prefs::kApplicationLocale); | 239 prefs::kApplicationLocale); |
238 #endif | 240 #endif |
239 if (profile_locale.empty()) | 241 if (profile_locale.empty()) |
240 profile_locale = g_browser_process->GetApplicationLocale(); | 242 profile_locale = g_browser_process->GetApplicationLocale(); |
241 | 243 |
242 speech_recognizer_.reset( | 244 speech_recognizer_.reset( |
243 new SpeechRecognizer(weak_factory_.GetWeakPtr(), | 245 new SpeechRecognizer(weak_factory_.GetWeakPtr(), |
244 profile_->GetRequestContext(), | 246 profile_->GetRequestContext(), |
245 profile_locale)); | 247 profile_locale)); |
246 } | 248 } |
247 | 249 |
248 speech_recognizer_->Start(); | 250 speech_recognizer_->Start(preamble); |
249 return; | 251 return; |
250 } | 252 } |
251 | 253 |
252 if (!contents_->GetWebUI()) | 254 if (!contents_->GetWebUI()) |
253 return; | 255 return; |
254 | 256 |
255 if (!webui_finished_loading_) { | 257 if (!webui_finished_loading_) { |
256 pending_webui_callbacks_.push_back( | 258 pending_webui_callbacks_.push_back( |
257 base::Bind(&StartPageService::ToggleSpeechRecognition, | 259 base::Bind(&StartPageService::ToggleSpeechRecognition, |
258 base::Unretained(this))); | 260 base::Unretained(this), |
| 261 preamble)); |
259 return; | 262 return; |
260 } | 263 } |
261 | 264 |
262 contents_->GetWebUI()->CallJavascriptFunction( | 265 contents_->GetWebUI()->CallJavascriptFunction( |
263 "appList.startPage.toggleSpeechRecognition"); | 266 "appList.startPage.toggleSpeechRecognition"); |
264 } | 267 } |
265 | 268 |
266 bool StartPageService::HotwordEnabled() { | 269 bool StartPageService::HotwordEnabled() { |
267 // Voice input for the launcher is unsupported on non-ChromeOS platforms. | 270 // Voice input for the launcher is unsupported on non-ChromeOS platforms. |
268 // TODO(amistry): Make speech input, and hotwording, work on non-ChromeOS. | 271 // TODO(amistry): Make speech input, and hotwording, work on non-ChromeOS. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 397 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
395 std::string()); | 398 std::string()); |
396 } | 399 } |
397 | 400 |
398 void StartPageService::UnloadContents() { | 401 void StartPageService::UnloadContents() { |
399 contents_.reset(); | 402 contents_.reset(); |
400 webui_finished_loading_ = false; | 403 webui_finished_loading_ = false; |
401 } | 404 } |
402 | 405 |
403 } // namespace app_list | 406 } // namespace app_list |
OLD | NEW |