Chromium Code Reviews| 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/speech/chrome_speech_recognition_manager_delegate.h" | 5 #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
| 17 #include "chrome/common/chrome_view_type.h" | 17 #include "chrome/browser/view_type_utils.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_view_host_delegate.h" | |
| 22 #include "content/public/browser/resource_context.h" | 21 #include "content/public/browser/resource_context.h" |
| 23 #include "content/public/browser/speech_recognition_manager.h" | 22 #include "content/public/browser/speech_recognition_manager.h" |
| 24 #include "content/public/browser/speech_recognition_session_config.h" | 23 #include "content/public/browser/speech_recognition_session_config.h" |
| 25 #include "content/public/browser/speech_recognition_session_context.h" | 24 #include "content/public/browser/speech_recognition_session_context.h" |
| 25 #include "content/public/browser/web_contents.h" | |
| 26 #include "content/public/common/speech_recognition_error.h" | 26 #include "content/public/common/speech_recognition_error.h" |
| 27 #include "content/public/common/speech_recognition_result.h" | 27 #include "content/public/common/speech_recognition_result.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 | 31 |
| 32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 33 #include "chrome/installer/util/wmi.h" | 33 #include "chrome/installer/util/wmi.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 using content::SpeechRecognitionManager; | 37 using content::SpeechRecognitionManager; |
| 38 using content::WebContents; | |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 const int kNoActiveBubble = | 41 const int kNoActiveBubble = |
| 41 content::SpeechRecognitionManager::kSessionIDInvalid; | 42 content::SpeechRecognitionManager::kSessionIDInvalid; |
| 42 } // namespace | 43 } // namespace |
| 43 | 44 |
| 44 namespace speech { | 45 namespace speech { |
| 45 | 46 |
| 46 // Asynchronously fetches the PC and audio hardware/driver info if | 47 // Asynchronously fetches the PC and audio hardware/driver info if |
| 47 // the user has opted into UMA. This information is sent with speech input | 48 // the user has opted into UMA. This information is sent with speech input |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 ChromeSpeechRecognitionManagerDelegate::GetEventListener() { | 303 ChromeSpeechRecognitionManagerDelegate::GetEventListener() { |
| 303 return this; | 304 return this; |
| 304 } | 305 } |
| 305 | 306 |
| 306 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( | 307 void ChromeSpeechRecognitionManagerDelegate::CheckRenderViewType( |
| 307 int session_id, | 308 int session_id, |
| 308 base::Callback<void(int session_id, bool is_allowed)> callback, | 309 base::Callback<void(int session_id, bool is_allowed)> callback, |
| 309 int render_process_id, | 310 int render_process_id, |
| 310 int render_view_id) { | 311 int render_view_id) { |
| 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 312 const content::RenderViewHost* render_view_host = | 313 content::RenderViewHost* render_view_host = |
|
Avi (use Gerrit)
2012/05/23 04:40:35
Since you fixed FromRenderViewHost you could leave
jam
2012/05/23 05:08:16
Done.
| |
| 313 content::RenderViewHost::FromID(render_process_id, render_view_id); | 314 content::RenderViewHost::FromID(render_process_id, render_view_id); |
| 314 | 315 bool allowed = false; |
| 315 // For host delegates other than VIEW_TYPE_TAB_CONTENTS we can't reliably show | 316 if (render_view_host) { |
| 316 // a popup, including the speech input bubble. In these cases for privacy | 317 // For host delegates other than VIEW_TYPE_TAB_CONTENTS we can't reliably |
| 317 // reasons we don't want to start recording if the user can't be properly | 318 // show a popup, including the speech input bubble. In these cases for |
| 318 // notified. An example of this is trying to show the speech input bubble | 319 // privacy reasons we don't want to start recording if the user can't be |
| 319 // within an extension popup: http://crbug.com/92083. In these situations the | 320 // properly notified. An example of this is trying to show the speech input |
| 320 // speech input extension API should be used instead. | 321 // bubble within an extension popup: http://crbug.com/92083. In these |
| 321 | 322 // situations the speech input extension API should be used instead. |
| 322 const bool allowed = (render_view_host != NULL && | 323 WebContents* web_contents = |
| 323 render_view_host->GetDelegate() != NULL && | 324 WebContents::FromRenderViewHost(render_view_host); |
| 324 render_view_host->GetDelegate()->GetRenderViewType() == | 325 chrome::ViewType view_type = chrome::GetViewType(web_contents); |
| 325 chrome::VIEW_TYPE_TAB_CONTENTS); | 326 if (view_type == chrome::VIEW_TYPE_TAB_CONTENTS) |
| 327 allowed = true; | |
| 328 } | |
| 326 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 329 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 327 base::Bind(callback, session_id, allowed)); | 330 base::Bind(callback, session_id, allowed)); |
| 328 } | 331 } |
| 329 | 332 |
| 330 } // namespace speech | 333 } // namespace speech |
| OLD | NEW |