Index: chrome/browser/ui/media_stream_infobar_delegate.cc |
diff --git a/chrome/browser/ui/media_stream_infobar_delegate.cc b/chrome/browser/ui/media_stream_infobar_delegate.cc |
index 91e5bead716f14c9b472b4da57aaf1880475b3ab..826d58adb271a3647407e29af04052bf9f10a154 100644 |
--- a/chrome/browser/ui/media_stream_infobar_delegate.cc |
+++ b/chrome/browser/ui/media_stream_infobar_delegate.cc |
@@ -6,6 +6,7 @@ |
#include <functional> |
#include "base/logging.h" |
+#include "chrome/browser/media/media_stream_devices_prefs.h" |
#include "chrome/browser/ui/media_stream_infobar_delegate.h" |
#include "content/public/common/media_stream_request.h" |
#include "googleurl/src/gurl.h" |
@@ -34,11 +35,13 @@ class DeviceIdEquals { |
MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( |
InfoBarTabHelper* tab_helper, |
+ Profile* profile, |
const content::MediaStreamRequest* request, |
const content::MediaResponseCallback& callback) |
: InfoBarDelegate(tab_helper), |
request_(request), |
- callback_(callback) { |
+ callback_(callback), |
+ prefs_(profile) { |
DCHECK(request_); |
has_audio_ = request_->devices.count( |
content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) != 0; |
@@ -73,18 +76,35 @@ const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const { |
return request_->security_origin; |
} |
+bool MediaStreamInfoBarDelegate::ShouldShowInfoBar() { |
Evan Stade
2012/06/12 01:51:12
it's unexpected that a function called ShouldShowI
no longer working on chromium
2012/06/14 13:03:25
The name has been changed to DismissInfoBarAndTake
|
+ DCHECK(has_audio_ || has_video_); |
+ if (prefs_.IsMediaDeviceBlocked()){ |
+ // Users has blocked the access to the media device in content settings, |
Bernhard Bauer
2012/06/11 18:16:00
Nit: "The user has blocked […]"
no longer working on chromium
2012/06/14 13:03:25
Done.
|
+ // deny the request without showing the infobar. |
+ Deny(); |
+ return false; |
+ } |
+ |
+ std::string audio_id, video_id; |
+ if (GetAlwaysAllowedDevices(&audio_id, &video_id)) { |
+ // There are always allowed devices available for this request, grant the |
+ // permission immediately without showing the infobar. |
+ Accept(audio_id, video_id, false); |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id, |
- const std::string& video_id) { |
+ const std::string& video_id, |
+ bool always_allow) { |
content::MediaStreamDevices devices; |
+ GetDevicesWithId(audio_id, video_id, &devices); |
+ DCHECK(devices.size()); |
- if (has_audio_) { |
- AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, |
- audio_id, &devices); |
- } |
- if (has_video_) { |
- AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
- video_id, &devices); |
- } |
+ if (always_allow) |
+ prefs_.WhitelistOriginAndDevices(request_->security_origin, devices); |
callback_.Run(devices); |
} |
@@ -93,6 +113,20 @@ void MediaStreamInfoBarDelegate::Deny() { |
callback_.Run(content::MediaStreamDevices()); |
} |
+void MediaStreamInfoBarDelegate::GetDevicesWithId( |
+ const std::string& audio_id, |
+ const std::string& video_id, |
+ content::MediaStreamDevices* devices) { |
+ if (has_audio_) { |
+ AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, |
+ audio_id, devices); |
+ } |
+ if (has_video_) { |
+ AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
+ video_id, devices); |
+ } |
+} |
+ |
void MediaStreamInfoBarDelegate::AddDeviceWithId( |
content::MediaStreamDeviceType type, |
const std::string& id, |
@@ -108,6 +142,34 @@ void MediaStreamInfoBarDelegate::AddDeviceWithId( |
} |
} |
+bool MediaStreamInfoBarDelegate::GetAlwaysAllowedDevices( |
Evan Stade
2012/06/12 01:51:12
with the addition of these new methods, this class
no longer working on chromium
2012/06/14 13:03:25
Added a MediaStreamDevicesController, moved most o
|
+ std::string* audio_id, std::string* video_id) { |
+ // Check if the |origin| is in content settings exception list. |
+ if (!prefs_.IsOriginAlwaysAllowed(request_->security_origin)) { |
+ // Remove the |origin| if it exists in the device whitelists. |
+ prefs_.RemoveOriginFromWhitelists(request_->security_origin); |
+ return false; |
+ } |
+ |
+ // Check if the always allowed devices are available. |
+ if (has_audio_) { |
+ content::MediaStreamDevices devices = GetAudioDevices(); |
+ *audio_id = prefs_.GetAlwaysAllowedAudioDevice(request_->security_origin, |
+ devices); |
+ if (audio_id->empty()) |
+ return false; |
+ } |
+ if (has_video_) { |
+ content::MediaStreamDevices devices = GetVideoDevices(); |
+ *video_id = prefs_.GetAlwaysAllowedVideoDevice(request_->security_origin, |
+ devices); |
+ if (video_id->empty()) |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
// MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific |
// files. |