| 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/media/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/content_settings/content_settings_provider.h" | 8 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 10 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| 11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory
.h" | 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry_factory
.h" |
| 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 13 #include "chrome/browser/media/media_internals.h" | 14 #include "chrome/browser/media/media_internals.h" |
| 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/content_settings.h" | 18 #include "chrome/common/content_settings.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/common/media_stream_request.h" | 21 #include "content/public/common/media_stream_request.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 // TODO(xians): Remove this when the Omnibar UI has been completed. | |
| 25 // See http://crbug.com/167263 for more details. | |
| 26 #define ALLOW_STICKY_DENY 0 | |
| 27 | |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 bool HasAnyAvailableDevice() { | 27 bool HasAnyAvailableDevice() { |
| 31 MediaCaptureDevicesDispatcher* dispatcher = | 28 MediaCaptureDevicesDispatcher* dispatcher = |
| 32 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); | 29 MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher(); |
| 33 const content::MediaStreamDevices& audio_devices = | 30 const content::MediaStreamDevices& audio_devices = |
| 34 dispatcher->GetAudioCaptureDevices(); | 31 dispatcher->GetAudioCaptureDevices(); |
| 35 const content::MediaStreamDevices& video_devices = | 32 const content::MediaStreamDevices& video_devices = |
| 36 dispatcher->GetVideoCaptureDevices(); | 33 dispatcher->GetVideoCaptureDevices(); |
| 37 | 34 |
| 38 return !audio_devices.empty() || !video_devices.empty(); | 35 return !audio_devices.empty() || !video_devices.empty(); |
| 39 }; | 36 }; |
| 40 | 37 |
| 41 } // namespace | 38 } // namespace |
| 42 | 39 |
| 43 MediaStreamDevicesController::MediaStreamDevicesController( | 40 MediaStreamDevicesController::MediaStreamDevicesController( |
| 44 Profile* profile, | 41 Profile* profile, |
| 42 TabSpecificContentSettings* content_settings, |
| 45 const content::MediaStreamRequest& request, | 43 const content::MediaStreamRequest& request, |
| 46 const content::MediaResponseCallback& callback) | 44 const content::MediaResponseCallback& callback) |
| 47 : profile_(profile), | 45 : profile_(profile), |
| 46 content_settings_(content_settings), |
| 48 request_(request), | 47 request_(request), |
| 49 callback_(callback), | 48 callback_(callback), |
| 50 has_audio_(content::IsAudioMediaType(request.audio_type) && | 49 has_audio_(content::IsAudioMediaType(request.audio_type) && |
| 51 !IsAudioDeviceBlockedByPolicy()), | 50 !IsAudioDeviceBlockedByPolicy()), |
| 52 has_video_(content::IsVideoMediaType(request.video_type) && | 51 has_video_(content::IsVideoMediaType(request.video_type) && |
| 53 !IsVideoDeviceBlockedByPolicy()) { | 52 !IsVideoDeviceBlockedByPolicy()) { |
| 54 } | 53 } |
| 55 | 54 |
| 56 MediaStreamDevicesController::~MediaStreamDevicesController() {} | 55 MediaStreamDevicesController::~MediaStreamDevicesController() {} |
| 57 | 56 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 113 |
| 115 // Show the infobar. | 114 // Show the infobar. |
| 116 return false; | 115 return false; |
| 117 } | 116 } |
| 118 | 117 |
| 119 const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const { | 118 const std::string& MediaStreamDevicesController::GetSecurityOriginSpec() const { |
| 120 return request_.security_origin.spec(); | 119 return request_.security_origin.spec(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void MediaStreamDevicesController::Accept(bool update_content_setting) { | 122 void MediaStreamDevicesController::Accept(bool update_content_setting) { |
| 123 content_settings_->OnMediaStreamAccessed(); |
| 124 |
| 125 // Get the default devices for the request. |
| 124 content::MediaStreamDevices devices; | 126 content::MediaStreamDevices devices; |
| 125 if (has_audio_ || has_video_) { | 127 if (has_audio_ || has_video_) { |
| 126 switch (request_.request_type) { | 128 switch (request_.request_type) { |
| 127 case content::MEDIA_OPEN_DEVICE: | 129 case content::MEDIA_OPEN_DEVICE: |
| 128 // For open device request pick the desired device or fall back to the | 130 // For open device request pick the desired device or fall back to the |
| 129 // first available of the given type. | 131 // first available of the given type. |
| 130 media::GetRequestedDevice(request_.requested_device_id, | 132 media::GetRequestedDevice(request_.requested_device_id, |
| 131 has_audio_, | 133 has_audio_, |
| 132 has_video_, | 134 has_video_, |
| 133 &devices); | 135 &devices); |
| 134 break; | 136 break; |
| 135 case content::MEDIA_DEVICE_ACCESS: | 137 case content::MEDIA_DEVICE_ACCESS: |
| 136 case content::MEDIA_GENERATE_STREAM: | 138 case content::MEDIA_GENERATE_STREAM: |
| 137 case content::MEDIA_ENUMERATE_DEVICES: | 139 case content::MEDIA_ENUMERATE_DEVICES: |
| 138 // Get the default devices for the request. | 140 // Get the default devices for the request. |
| 139 media::GetDefaultDevicesForProfile(profile_, | 141 media::GetDefaultDevicesForProfile(profile_, |
| 140 has_audio_, | 142 has_audio_, |
| 141 has_video_, | 143 has_video_, |
| 142 &devices); | 144 &devices); |
| 143 break; | 145 break; |
| 144 } | 146 } |
| 145 | 147 |
| 146 if (update_content_setting && IsSchemeSecure() && !devices.empty()) | 148 if (update_content_setting && IsSchemeSecure() && !devices.empty()) |
| 147 SetPermission(true); | 149 SetPermission(true); |
| 148 } | 150 } |
| 149 | 151 |
| 150 callback_.Run(devices); | 152 callback_.Run(devices); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void MediaStreamDevicesController::Deny(bool update_content_setting) { | 155 void MediaStreamDevicesController::Deny(bool update_content_setting) { |
| 154 #if ALLOW_STICKY_DENY | 156 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the |
| 157 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and |
| 158 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. |
| 159 content_settings_->OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
| 160 std::string()); |
| 155 if (update_content_setting) | 161 if (update_content_setting) |
| 156 SetPermission(false); | 162 SetPermission(false); |
| 157 #endif | |
| 158 | 163 |
| 159 callback_.Run(content::MediaStreamDevices()); | 164 callback_.Run(content::MediaStreamDevices()); |
| 160 } | 165 } |
| 161 | 166 |
| 162 bool MediaStreamDevicesController::IsAudioDeviceBlockedByPolicy() const { | 167 bool MediaStreamDevicesController::IsAudioDeviceBlockedByPolicy() const { |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 164 return (!profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed) && | 169 return (!profile_->GetPrefs()->GetBoolean(prefs::kAudioCaptureAllowed) && |
| 165 profile_->GetPrefs()->IsManagedPreference( | 170 profile_->GetPrefs()->IsManagedPreference( |
| 166 prefs::kAudioCaptureAllowed)); | 171 prefs::kAudioCaptureAllowed)); |
| 167 } | 172 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 193 request_.security_origin, | 198 request_.security_origin, |
| 194 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 199 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 195 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_ALLOW) { | 200 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_ALLOW) { |
| 196 return false; | 201 return false; |
| 197 } | 202 } |
| 198 | 203 |
| 199 return true; | 204 return true; |
| 200 } | 205 } |
| 201 | 206 |
| 202 bool MediaStreamDevicesController::IsRequestBlockedByDefault() const { | 207 bool MediaStreamDevicesController::IsRequestBlockedByDefault() const { |
| 203 #if ALLOW_STICKY_DENY | |
| 204 if (has_audio_ && | 208 if (has_audio_ && |
| 205 profile_->GetHostContentSettingsMap()->GetContentSetting( | 209 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 206 request_.security_origin, | 210 request_.security_origin, |
| 207 request_.security_origin, | 211 request_.security_origin, |
| 208 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 212 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 209 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { | 213 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { |
| 210 return false; | 214 return false; |
| 211 } | 215 } |
| 212 | 216 |
| 213 if (has_video_ && | 217 if (has_video_ && |
| 214 profile_->GetHostContentSettingsMap()->GetContentSetting( | 218 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 215 request_.security_origin, | 219 request_.security_origin, |
| 216 request_.security_origin, | 220 request_.security_origin, |
| 217 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 221 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 218 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { | 222 NO_RESOURCE_IDENTIFIER) != CONTENT_SETTING_BLOCK) { |
| 219 return false; | 223 return false; |
| 220 } | 224 } |
| 221 | 225 |
| 222 return true; | 226 return true; |
| 223 #else | |
| 224 return false; | |
| 225 #endif | |
| 226 } | 227 } |
| 227 | 228 |
| 228 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const { | 229 bool MediaStreamDevicesController::IsDefaultMediaAccessBlocked() const { |
| 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 230 #if ALLOW_STICKY_DENY | 231 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the |
| 232 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and |
| 233 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. |
| 231 ContentSetting current_setting = | 234 ContentSetting current_setting = |
| 232 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 235 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
| 233 CONTENT_SETTINGS_TYPE_MEDIASTREAM, NULL); | 236 CONTENT_SETTINGS_TYPE_MEDIASTREAM, NULL); |
| 234 return (current_setting == CONTENT_SETTING_BLOCK); | 237 return (current_setting == CONTENT_SETTING_BLOCK); |
| 235 #else | |
| 236 return false; | |
| 237 #endif | |
| 238 } | 238 } |
| 239 | 239 |
| 240 void MediaStreamDevicesController::HandleTapMediaRequest() { | 240 void MediaStreamDevicesController::HandleTapMediaRequest() { |
| 241 // For tab media requests, we need to make sure the request came from the | 241 // For tab media requests, we need to make sure the request came from the |
| 242 // extension API, so we check the registry here. | 242 // extension API, so we check the registry here. |
| 243 extensions::TabCaptureRegistry* registry = | 243 extensions::TabCaptureRegistry* registry = |
| 244 extensions::TabCaptureRegistryFactory::GetForProfile(profile_); | 244 extensions::TabCaptureRegistryFactory::GetForProfile(profile_); |
| 245 | 245 |
| 246 if (!registry->VerifyRequest(request_.render_process_id, | 246 if (!registry->VerifyRequest(request_.render_process_id, |
| 247 request_.render_view_id)) { | 247 request_.render_view_id)) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 260 | 260 |
| 261 callback_.Run(devices); | 261 callback_.Run(devices); |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool MediaStreamDevicesController::IsSchemeSecure() const { | 265 bool MediaStreamDevicesController::IsSchemeSecure() const { |
| 266 return (request_.security_origin.SchemeIsSecure()); | 266 return (request_.security_origin.SchemeIsSecure()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool MediaStreamDevicesController::ShouldAlwaysAllowOrigin() const { | 269 bool MediaStreamDevicesController::ShouldAlwaysAllowOrigin() const { |
| 270 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the |
| 271 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and |
| 272 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA. |
| 270 return profile_->GetHostContentSettingsMap()->ShouldAllowAllContent( | 273 return profile_->GetHostContentSettingsMap()->ShouldAllowAllContent( |
| 271 request_.security_origin, request_.security_origin, | 274 request_.security_origin, request_.security_origin, |
| 272 CONTENT_SETTINGS_TYPE_MEDIASTREAM); | 275 CONTENT_SETTINGS_TYPE_MEDIASTREAM); |
| 273 } | 276 } |
| 274 | 277 |
| 275 void MediaStreamDevicesController::SetPermission(bool allowed) const { | 278 void MediaStreamDevicesController::SetPermission(bool allowed) const { |
| 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 277 ContentSettingsPattern primary_pattern = | 280 ContentSettingsPattern primary_pattern = |
| 278 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); | 281 ContentSettingsPattern::FromURLNoWildcard(request_.security_origin); |
| 279 // Check the pattern is valid or not. When the request is from a file access, | 282 // Check the pattern is valid or not. When the request is from a file access, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 293 } | 296 } |
| 294 if (has_video_) { | 297 if (has_video_) { |
| 295 profile_->GetHostContentSettingsMap()->SetContentSetting( | 298 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 296 primary_pattern, | 299 primary_pattern, |
| 297 ContentSettingsPattern::Wildcard(), | 300 ContentSettingsPattern::Wildcard(), |
| 298 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 301 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 299 std::string(), | 302 std::string(), |
| 300 content_setting); | 303 content_setting); |
| 301 } | 304 } |
| 302 } | 305 } |
| OLD | NEW |