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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 content::MEDIA_DEVICE_VIDEO_CAPTURE, | 124 content::MEDIA_DEVICE_VIDEO_CAPTURE, |
125 MediaStreamTypeSettings(MEDIA_ALLOWED, | 125 MediaStreamTypeSettings(MEDIA_ALLOWED, |
126 request.requested_video_device_id))); | 126 request.requested_video_device_id))); |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 MediaStreamDevicesController::~MediaStreamDevicesController() { | 131 MediaStreamDevicesController::~MediaStreamDevicesController() { |
132 if (!callback_.is_null()) { | 132 if (!callback_.is_null()) { |
133 callback_.Run(content::MediaStreamDevices(), | 133 callback_.Run(content::MediaStreamDevices(), |
| 134 content::MEDIA_DEVICE_INVALID_STATE, |
134 scoped_ptr<content::MediaStreamUI>()); | 135 scoped_ptr<content::MediaStreamUI>()); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 // static | 139 // static |
139 void MediaStreamDevicesController::RegisterProfilePrefs( | 140 void MediaStreamDevicesController::RegisterProfilePrefs( |
140 user_prefs::PrefRegistrySyncable* prefs) { | 141 user_prefs::PrefRegistrySyncable* prefs) { |
141 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, | 142 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, |
142 true, | 143 true, |
143 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 144 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
144 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, | 145 prefs->RegisterBooleanPref(prefs::kAudioCaptureAllowed, |
145 true, | 146 true, |
146 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 147 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
147 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls, | 148 prefs->RegisterListPref(prefs::kVideoCaptureAllowedUrls, |
148 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 149 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
149 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls, | 150 prefs->RegisterListPref(prefs::kAudioCaptureAllowedUrls, |
150 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 151 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
151 } | 152 } |
152 | 153 |
153 // TODO(gbillock): rename? doesn't actually dismiss. More of a 'check profile | 154 // TODO(gbillock): rename? doesn't actually dismiss. More of a 'check profile |
154 // and system for compatibility' thing. | 155 // and system for compatibility' thing. |
155 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { | 156 bool MediaStreamDevicesController::DismissInfoBarAndTakeActionOnSettings() { |
156 // Tab capture is allowed for extensions only and infobar is not shown for | 157 // Tab capture is allowed for extensions only and infobar is not shown for |
157 // extensions. | 158 // extensions. |
158 if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || | 159 if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || |
159 request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { | 160 request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
160 Deny(false); | 161 Deny(false, content::MEDIA_DEVICE_INVALID_STATE); |
161 return true; | 162 return true; |
162 } | 163 } |
163 | 164 |
164 // Deny the request if the security origin is empty, this happens with | 165 // Deny the request if the security origin is empty, this happens with |
165 // file access without |--allow-file-access-from-files| flag. | 166 // file access without |--allow-file-access-from-files| flag. |
166 if (request_.security_origin.is_empty()) { | 167 if (request_.security_origin.is_empty()) { |
167 Deny(false); | 168 Deny(false, content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN); |
168 return true; | 169 return true; |
169 } | 170 } |
170 | 171 |
171 // Deny the request if there is no device attached to the OS. | 172 // Deny the request if there is no device attached to the OS. |
172 if (!HasAnyAvailableDevice()) { | 173 if (!HasAnyAvailableDevice()) { |
173 Deny(false); | 174 Deny(false, content::MEDIA_DEVICE_NO_HARDWARE); |
174 return true; | 175 return true; |
175 } | 176 } |
176 | 177 |
177 // Check if any allow exception has been made for this request. | 178 // Check if any allow exception has been made for this request. |
178 if (IsRequestAllowedByDefault()) { | 179 if (IsRequestAllowedByDefault()) { |
179 Accept(false); | 180 Accept(false); |
180 return true; | 181 return true; |
181 } | 182 } |
182 | 183 |
183 // Filter any parts of the request that have been blocked by default and deny | 184 // Filter any parts of the request that have been blocked by default and deny |
184 // it if nothing is left to accept. | 185 // it if nothing is left to accept. |
185 if (FilterBlockedByDefaultDevices() == 0) { | 186 if (FilterBlockedByDefaultDevices() == 0) { |
186 Deny(false); | 187 Deny(false, content::MEDIA_DEVICE_PERMISSION_DENIED); |
187 return true; | 188 return true; |
188 } | 189 } |
189 | 190 |
190 // Check if the media default setting is set to block. | 191 // Check if the media default setting is set to block. |
191 if (IsDefaultMediaAccessBlocked()) { | 192 if (IsDefaultMediaAccessBlocked()) { |
192 Deny(false); | 193 Deny(false, content::MEDIA_DEVICE_PERMISSION_DENIED); |
193 return true; | 194 return true; |
194 } | 195 } |
195 | 196 |
196 if (request_.request_type == content::MEDIA_OPEN_DEVICE) { | 197 if (request_.request_type == content::MEDIA_OPEN_DEVICE) { |
197 bool no_matched_audio_device = | 198 bool no_matched_audio_device = |
198 (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE && | 199 (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE && |
199 !request_.requested_audio_device_id.empty() && | 200 !request_.requested_audio_device_id.empty() && |
200 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedAudioDevice( | 201 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedAudioDevice( |
201 request_.requested_audio_device_id) == NULL); | 202 request_.requested_audio_device_id) == NULL); |
202 bool no_matched_video_device = | 203 bool no_matched_video_device = |
203 (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE && | 204 (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE && |
204 !request_.requested_video_device_id.empty() && | 205 !request_.requested_video_device_id.empty() && |
205 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice( | 206 MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedVideoDevice( |
206 request_.requested_video_device_id) == NULL); | 207 request_.requested_video_device_id) == NULL); |
207 if (no_matched_audio_device || no_matched_video_device) { | 208 if (no_matched_audio_device || no_matched_video_device) { |
208 Deny(false); | 209 Deny(false, content::MEDIA_DEVICE_PERMISSION_DENIED); |
209 return true; | 210 return true; |
210 } | 211 } |
211 } | 212 } |
212 | 213 |
213 // Show the infobar. | 214 // Show the infobar. |
214 return false; | 215 return false; |
215 } | 216 } |
216 | 217 |
217 bool MediaStreamDevicesController::HasAudio() const { | 218 bool MediaStreamDevicesController::HasAudio() const { |
218 return IsDeviceAudioCaptureRequestedAndAllowed(); | 219 return IsDeviceAudioCaptureRequestedAndAllowed(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 329 } |
329 | 330 |
330 scoped_ptr<content::MediaStreamUI> ui; | 331 scoped_ptr<content::MediaStreamUI> ui; |
331 if (!devices.empty()) { | 332 if (!devices.empty()) { |
332 ui = MediaCaptureDevicesDispatcher::GetInstance()-> | 333 ui = MediaCaptureDevicesDispatcher::GetInstance()-> |
333 GetMediaStreamCaptureIndicator()->RegisterMediaStream( | 334 GetMediaStreamCaptureIndicator()->RegisterMediaStream( |
334 web_contents_, devices); | 335 web_contents_, devices); |
335 } | 336 } |
336 content::MediaResponseCallback cb = callback_; | 337 content::MediaResponseCallback cb = callback_; |
337 callback_.Reset(); | 338 callback_.Reset(); |
338 cb.Run(devices, ui.Pass()); | 339 cb.Run(devices, content::MEDIA_DEVICE_OK, ui.Pass()); |
339 } | 340 } |
340 | 341 |
341 void MediaStreamDevicesController::Deny(bool update_content_setting) { | 342 void MediaStreamDevicesController::Deny( |
| 343 bool update_content_setting, |
| 344 content::MediaStreamRequestResult result) { |
| 345 DLOG(WARNING) << "MediaStreamDevicesController::Deny: " << result; |
342 NotifyUIRequestDenied(); | 346 NotifyUIRequestDenied(); |
343 | 347 |
344 if (update_content_setting) | 348 if (update_content_setting) |
345 SetPermission(false); | 349 SetPermission(false); |
346 | 350 |
347 content::MediaResponseCallback cb = callback_; | 351 content::MediaResponseCallback cb = callback_; |
348 callback_.Reset(); | 352 callback_.Reset(); |
349 cb.Run(content::MediaStreamDevices(), scoped_ptr<content::MediaStreamUI>()); | 353 cb.Run(content::MediaStreamDevices(), |
| 354 result, |
| 355 scoped_ptr<content::MediaStreamUI>()); |
350 } | 356 } |
351 | 357 |
352 int MediaStreamDevicesController::GetIconID() const { | 358 int MediaStreamDevicesController::GetIconID() const { |
353 if (HasVideo()) | 359 if (HasVideo()) |
354 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; | 360 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; |
355 | 361 |
356 return IDR_INFOBAR_MEDIA_STREAM_MIC; | 362 return IDR_INFOBAR_MEDIA_STREAM_MIC; |
357 } | 363 } |
358 | 364 |
359 base::string16 MediaStreamDevicesController::GetMessageText() const { | 365 base::string16 MediaStreamDevicesController::GetMessageText() const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } else { | 398 } else { |
393 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 399 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
394 kAllowHttp, kPermissionActionsMax); | 400 kAllowHttp, kPermissionActionsMax); |
395 } | 401 } |
396 Accept(true); | 402 Accept(true); |
397 } | 403 } |
398 | 404 |
399 void MediaStreamDevicesController::PermissionDenied() { | 405 void MediaStreamDevicesController::PermissionDenied() { |
400 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 406 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
401 kDeny, kPermissionActionsMax); | 407 kDeny, kPermissionActionsMax); |
402 Deny(true); | 408 Deny(true, content::MEDIA_DEVICE_PERMISSION_DENIED); |
403 } | 409 } |
404 | 410 |
405 void MediaStreamDevicesController::Cancelled() { | 411 void MediaStreamDevicesController::Cancelled() { |
406 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", | 412 UMA_HISTOGRAM_ENUMERATION("Media.DevicePermissionActions", |
407 kCancel, kPermissionActionsMax); | 413 kCancel, kPermissionActionsMax); |
408 Deny(true); | 414 Deny(true, content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
409 } | 415 } |
410 | 416 |
411 void MediaStreamDevicesController::RequestFinished() { | 417 void MediaStreamDevicesController::RequestFinished() { |
412 delete this; | 418 delete this; |
413 } | 419 } |
414 | 420 |
415 MediaStreamDevicesController::DevicePolicy | 421 MediaStreamDevicesController::DevicePolicy |
416 MediaStreamDevicesController::GetDevicePolicy( | 422 MediaStreamDevicesController::GetDevicePolicy( |
417 const char* policy_name, | 423 const char* policy_name, |
418 const char* whitelist_policy_name) const { | 424 const char* whitelist_policy_name) const { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 it->second.permission == MEDIA_ALLOWED); | 632 it->second.permission == MEDIA_ALLOWED); |
627 } | 633 } |
628 | 634 |
629 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed() | 635 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed() |
630 const { | 636 const { |
631 MediaStreamTypeSettingsMap::const_iterator it = | 637 MediaStreamTypeSettingsMap::const_iterator it = |
632 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); | 638 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); |
633 return (it != request_permissions_.end() && | 639 return (it != request_permissions_.end() && |
634 it->second.permission == MEDIA_ALLOWED); | 640 it->second.permission == MEDIA_ALLOWED); |
635 } | 641 } |
OLD | NEW |