summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Wu <rob@robwu.nl>2014-11-20 15:43:16 +0100
committerRob Wu <rob@robwu.nl>2014-11-20 14:44:07 +0000
commitf6615419dd8f0dd89e02a5cb456523674b5fe695 (patch)
tree50cd14a3b1b81168d52d238b4d11ccad22f263de
parent103b157a850f4cd6f3d33721d260bbb3297674df (diff)
downloadchromium_src-f6615419dd8f0dd89e02a5cb456523674b5fe695.zip
chromium_src-f6615419dd8f0dd89e02a5cb456523674b5fe695.tar.gz
chromium_src-f6615419dd8f0dd89e02a5cb456523674b5fe695.tar.bz2
Always show cam/mic access in the media content setting bubble
With https://codereview.chromium.org/588153003, the content setting bubble always showed the state of the last permission request. Consequently, when the page is denied access to te cam/mic, the bubble shows that the page was denied access to the cam/mic regardless of whether a previous request was accepted. This patch brings the mic/cam options back; i.e. the radio labels in the content setting bubble always shows the devices from the last request plus the active devices instead of just the devices from the last request. Added a regression test for https://crbug.com/426026#c1 (now "accessing cam & mic" is shown instead of "accessing cam" without mic). BUG=426026 TEST=MediaStreamDevicesControllerTest.* (or manually, see linked bug) Review URL: https://codereview.chromium.org/707373002 Cr-Commit-Position: refs/heads/master@{#303474} (cherry picked from commit 2d36d9f85f28b77e68750dfa46ce6f0185da0f7e) Review URL: https://codereview.chromium.org/744693002 Cr-Commit-Position: refs/branch-heads/2214@{#90} Cr-Branched-From: 03655fd3f6d72165dc3c9bd2c89807305316fe6c-refs/heads/master@{#303346}
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.cc14
-rw-r--r--chrome/browser/content_settings/tab_specific_content_settings.h6
-rw-r--r--chrome/browser/media/media_stream_devices_controller_browsertest.cc74
3 files changed, 91 insertions, 3 deletions
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index c4c7d8a..d15e385 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -511,7 +511,19 @@ void TabSpecificContentSettings::OnProtectedMediaIdentifierPermissionSet(
TabSpecificContentSettings::MicrophoneCameraState
TabSpecificContentSettings::GetMicrophoneCameraState() const {
- return microphone_camera_state_;
+ MicrophoneCameraState state = microphone_camera_state_;
+
+ // Include capture devices in the state if there are still consumers of the
+ // approved media stream.
+ scoped_refptr<MediaStreamCaptureIndicator> media_indicator =
+ MediaCaptureDevicesDispatcher::GetInstance()->
+ GetMediaStreamCaptureIndicator();
+ if (media_indicator->IsCapturingAudio(web_contents()))
+ state |= MICROPHONE_ACCESSED;
+ if (media_indicator->IsCapturingVideo(web_contents()))
+ state |= CAMERA_ACCESSED;
+
+ return state;
}
bool TabSpecificContentSettings::IsMicrophoneCameraStateChanged() const {
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.h b/chrome/browser/content_settings/tab_specific_content_settings.h
index 063b525..707bacfb 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.h
+++ b/chrome/browser/content_settings/tab_specific_content_settings.h
@@ -228,10 +228,12 @@ class TabSpecificContentSettings
}
// Returns the state of the camera and microphone usage.
+ // The return value always includes all active media capture devices, on top
+ // of the devices from the last request.
MicrophoneCameraState GetMicrophoneCameraState() const;
- // Returns whether the state of the camera and microphone usage or device has
- // changed.
+ // Returns whether the camera or microphone permission or media device setting
+ // has changed since the last permission request.
bool IsMicrophoneCameraStateChanged() const;
// Returns the ContentSettingsUsagesState that controls the
diff --git a/chrome/browser/media/media_stream_devices_controller_browsertest.cc b/chrome/browser/media/media_stream_devices_controller_browsertest.cc
index b12c1b7..57fc46e 100644
--- a/chrome/browser/media/media_stream_devices_controller_browsertest.cc
+++ b/chrome/browser/media/media_stream_devices_controller_browsertest.cc
@@ -7,6 +7,8 @@
#include "base/bind.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
+#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/media/media_stream_capture_indicator.h"
#include "chrome/browser/media/media_stream_device_permissions.h"
#include "chrome/browser/media/media_stream_devices_controller.h"
#include "chrome/browser/media/webrtc_browsertest_base.h"
@@ -396,3 +398,75 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
EXPECT_EQ(example_audio_id(),
GetContentSettings()->media_stream_selected_audio_device());
}
+
+// Denying mic access after camera access should still show the camera as state.
+IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
+ DenyMicDoesNotChangeCam) {
+ // Request cam and allow
+ SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED);
+ MediaStreamDevicesController cam_controller(
+ GetWebContents(),
+ CreateRequest(std::string(), example_video_id()),
+ base::Bind(&OnMediaStreamResponse));
+ NotifyTabSpecificContentSettings(&cam_controller);
+ EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
+ EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
+ EXPECT_EQ(example_video_id(),
+ GetContentSettings()->media_stream_requested_video_device());
+ EXPECT_EQ(example_video_id(),
+ GetContentSettings()->media_stream_selected_video_device());
+ EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED,
+ GetContentSettings()->GetMicrophoneCameraState());
+
+ // Simulate that an a video stream is now being captured.
+ content::MediaStreamDevice fake_video_device(
+ content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id(),
+ example_video_id());
+ content::MediaStreamDevices video_devices(1, fake_video_device);
+ MediaCaptureDevicesDispatcher* dispatcher =
+ MediaCaptureDevicesDispatcher::GetInstance();
+ dispatcher->SetTestVideoCaptureDevices(video_devices);
+ scoped_ptr<content::MediaStreamUI> video_stream_ui =
+ dispatcher->GetMediaStreamCaptureIndicator()->
+ RegisterMediaStream(GetWebContents(), video_devices);
+ video_stream_ui->OnStarted(base::Closure());
+
+ // Request mic and deny.
+ SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED);
+ MediaStreamDevicesController mic_controller(
+ GetWebContents(),
+ CreateRequest(example_audio_id(), std::string()),
+ base::Bind(&OnMediaStreamResponse));
+ NotifyTabSpecificContentSettings(&mic_controller);
+ EXPECT_FALSE(GetContentSettings()->IsContentAllowed(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
+ EXPECT_TRUE(GetContentSettings()->IsContentBlocked(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
+ EXPECT_EQ(example_audio_id(),
+ GetContentSettings()->media_stream_requested_audio_device());
+ EXPECT_EQ(example_audio_id(),
+ GetContentSettings()->media_stream_selected_audio_device());
+
+ // Cam should still be included in the state.
+ EXPECT_TRUE(GetContentSettings()->IsContentAllowed(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
+ EXPECT_FALSE(GetContentSettings()->IsContentBlocked(
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
+ EXPECT_EQ(example_video_id(),
+ GetContentSettings()->media_stream_requested_video_device());
+ EXPECT_EQ(example_video_id(),
+ GetContentSettings()->media_stream_selected_video_device());
+ EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
+ TabSpecificContentSettings::MICROPHONE_BLOCKED |
+ TabSpecificContentSettings::CAMERA_ACCESSED,
+ GetContentSettings()->GetMicrophoneCameraState());
+
+ // After ending the camera capture, the camera permission is no longer
+ // relevant, so it should no be included in the mic/cam state.
+ video_stream_ui.reset();
+ EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
+ TabSpecificContentSettings::MICROPHONE_BLOCKED,
+ GetContentSettings()->GetMicrophoneCameraState());
+}