Commit b8249aa9 authored by qinmin@chromium.org's avatar qinmin@chromium.org

Turn webspeech off when tab goes background

This change adds a toggle to turn webspeech off when tab goes background.
And further request to turn media capture devices on will be denied.
So Both WebRTC and webSpeech won't be able to initiate new requests when tab is in background.

BUG=396054
R=dalecurtis@chromium.org, jam@chromium.org

Review URL: https://codereview.chromium.org/415433002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285072 0039d316-1c4b-4281-b951-d872f2087c98
parent d8e67f3e
......@@ -23,6 +23,7 @@
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/common/media_stream_request.h"
#include "extensions/common/constants.h"
#include "grit/generated_resources.h"
......@@ -662,7 +663,7 @@ bool MediaStreamDevicesController::IsDeviceAudioCaptureRequestedAndAllowed()
const {
MediaStreamTypeSettingsMap::const_iterator it =
request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE);
return (it != request_permissions_.end() &&
return (it != request_permissions_.end() && IsCaptureDeviceRequestAllowed() &&
it->second.permission == MEDIA_ALLOWED);
}
......@@ -670,6 +671,15 @@ bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed()
const {
MediaStreamTypeSettingsMap::const_iterator it =
request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE);
return (it != request_permissions_.end() &&
return (it != request_permissions_.end() && IsCaptureDeviceRequestAllowed() &&
it->second.permission == MEDIA_ALLOWED);
}
bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const {
#if defined(OS_ANDROID)
// Don't approve device requests if the tab was hidden.
// TODO(qinmin): Add a test for this. http://crbug.com/396869.
return web_contents_->GetRenderWidgetHostView()->IsShowing();
#endif
return true;
}
......@@ -138,6 +138,10 @@ class MediaStreamDevicesController : public PermissionBubbleRequest {
bool IsDeviceAudioCaptureRequestedAndAllowed() const;
bool IsDeviceVideoCaptureRequestedAndAllowed() const;
// Returns true if media capture device is allowed to be used. This could
// return false when tab goes to background.
bool IsCaptureDeviceRequestAllowed() const;
content::WebContents* web_contents_;
// The owner of this class needs to make sure it does not outlive the profile.
......
......@@ -3563,6 +3563,7 @@ void RenderViewImpl::OnWasHidden() {
#if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
RenderThreadImpl::current()->video_capture_impl_manager()->
SuspendDevices(true);
speech_recognition_dispatcher_->AbortAllRecognitions();
#endif
if (webview())
......
......@@ -35,6 +35,15 @@ SpeechRecognitionDispatcher::SpeechRecognitionDispatcher(
SpeechRecognitionDispatcher::~SpeechRecognitionDispatcher() {
}
void SpeechRecognitionDispatcher::AbortAllRecognitions() {
for (HandleMap::iterator iter = handle_map_.begin();
iter != handle_map_.end();
++iter) {
// OnEnd event will be sent to the SpeechRecognition object later.
abort(iter->second, recognizer_client_);
}
}
bool SpeechRecognitionDispatcher::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
......
......@@ -28,6 +28,9 @@ class SpeechRecognitionDispatcher : public RenderViewObserver,
explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view);
virtual ~SpeechRecognitionDispatcher();
// Aborts all speech recognitions.
void AbortAllRecognitions();
private:
// RenderViewObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment