| 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 <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 if (type == content::PermissionType::AUDIO_CAPTURE) | 65 if (type == content::PermissionType::AUDIO_CAPTURE) |
| 66 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; | 66 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 67 | 67 |
| 68 if (type == content::PermissionType::VIDEO_CAPTURE) | 68 if (type == content::PermissionType::VIDEO_CAPTURE) |
| 69 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; | 69 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 70 | 70 |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 using PermissionActionCallback = | 74 using PermissionActionCallback = |
| 75 base::Callback<void(content::PermissionType, const GURL&, Profile*)>; | 75 base::Callback<void(content::PermissionType, const GURL&)>; |
| 76 | 76 |
| 77 void RecordSinglePermissionAction(const content::MediaStreamRequest& request, | 77 void RecordSinglePermissionAction(const content::MediaStreamRequest& request, |
| 78 content::PermissionType permission_type, | 78 content::PermissionType permission_type, |
| 79 Profile* profile, | |
| 80 PermissionActionCallback callback) { | 79 PermissionActionCallback callback) { |
| 81 if (ContentTypeIsRequested(permission_type, request)) { | 80 if (ContentTypeIsRequested(permission_type, request)) { |
| 82 callback.Run(permission_type, request.security_origin, profile); | 81 callback.Run(permission_type, request.security_origin); |
| 83 } | 82 } |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Calls |action_function| for each permission requested by |request|. | 85 // Calls |action_function| for each permission requested by |request|. |
| 87 void RecordPermissionAction(const content::MediaStreamRequest& request, | 86 void RecordPermissionAction(const content::MediaStreamRequest& request, |
| 88 Profile* profile, | |
| 89 PermissionActionCallback callback) { | 87 PermissionActionCallback callback) { |
| 90 RecordSinglePermissionAction(request, content::PermissionType::AUDIO_CAPTURE, | 88 RecordSinglePermissionAction(request, content::PermissionType::AUDIO_CAPTURE, |
| 91 profile, callback); | 89 callback); |
| 92 RecordSinglePermissionAction(request, content::PermissionType::VIDEO_CAPTURE, | 90 RecordSinglePermissionAction(request, content::PermissionType::VIDEO_CAPTURE, |
| 93 profile, callback); | 91 callback); |
| 94 } | 92 } |
| 95 | 93 |
| 96 // This helper class helps to measure the number of media stream requests that | 94 // This helper class helps to measure the number of media stream requests that |
| 97 // occur. It ensures that only one request will be recorded per navigation, per | 95 // occur. It ensures that only one request will be recorded per navigation, per |
| 98 // frame. TODO(raymes): Remove this when https://crbug.com/526324 is fixed. | 96 // frame. TODO(raymes): Remove this when https://crbug.com/526324 is fixed. |
| 99 class MediaPermissionRequestLogger : content::WebContentsObserver { | 97 class MediaPermissionRequestLogger : content::WebContentsObserver { |
| 100 // Map of <render process id, render frame id> -> | 98 // Map of <render process id, render frame id> -> |
| 101 // MediaPermissionRequestLogger. | 99 // MediaPermissionRequestLogger. |
| 102 using RequestMap = std::map<std::pair<int, int>, | 100 using RequestMap = std::map<std::pair<int, int>, |
| 103 std::unique_ptr<MediaPermissionRequestLogger>>; | 101 std::unique_ptr<MediaPermissionRequestLogger>>; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return; | 197 return; |
| 200 } | 198 } |
| 201 #endif | 199 #endif |
| 202 | 200 |
| 203 // Otherwise we can run the callback immediately. | 201 // Otherwise we can run the callback immediately. |
| 204 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); | 202 RunCallback(old_audio_setting_, old_video_setting_, denial_reason); |
| 205 } | 203 } |
| 206 | 204 |
| 207 MediaStreamDevicesController::~MediaStreamDevicesController() { | 205 MediaStreamDevicesController::~MediaStreamDevicesController() { |
| 208 if (!callback_.is_null()) { | 206 if (!callback_.is_null()) { |
| 209 RecordPermissionAction(request_, profile_, | 207 RecordPermissionAction( |
| 210 base::Bind(PermissionUmaUtil::PermissionIgnored)); | 208 request_, base::Bind(PermissionUmaUtil::PermissionIgnored)); |
| 211 callback_.Run(content::MediaStreamDevices(), | 209 callback_.Run(content::MediaStreamDevices(), |
| 212 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, | 210 content::MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
| 213 std::unique_ptr<content::MediaStreamUI>()); | 211 std::unique_ptr<content::MediaStreamUI>()); |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 // static | 215 // static |
| 218 void MediaStreamDevicesController::RegisterProfilePrefs( | 216 void MediaStreamDevicesController::RegisterProfilePrefs( |
| 219 user_prefs::PrefRegistrySyncable* prefs) { | 217 user_prefs::PrefRegistrySyncable* prefs) { |
| 220 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); | 218 prefs->RegisterBooleanPref(prefs::kVideoCaptureAllowed, true); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 else if (!IsAskingForVideo()) | 273 else if (!IsAskingForVideo()) |
| 276 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; | 274 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; |
| 277 return l10n_util::GetStringUTF16(message_id); | 275 return l10n_util::GetStringUTF16(message_id); |
| 278 } | 276 } |
| 279 | 277 |
| 280 GURL MediaStreamDevicesController::GetOrigin() const { | 278 GURL MediaStreamDevicesController::GetOrigin() const { |
| 281 return request_.security_origin; | 279 return request_.security_origin; |
| 282 } | 280 } |
| 283 | 281 |
| 284 void MediaStreamDevicesController::PermissionGranted() { | 282 void MediaStreamDevicesController::PermissionGranted() { |
| 285 RecordPermissionAction(request_, profile_, | 283 RecordPermissionAction( |
| 286 base::Bind(PermissionUmaUtil::PermissionGranted)); | 284 request_, base::Bind(PermissionUmaUtil::PermissionGranted)); |
| 287 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 285 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 288 old_audio_setting_, CONTENT_SETTING_ALLOW), | 286 old_audio_setting_, CONTENT_SETTING_ALLOW), |
| 289 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 287 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 290 old_video_setting_, CONTENT_SETTING_ALLOW), | 288 old_video_setting_, CONTENT_SETTING_ALLOW), |
| 291 content::MEDIA_DEVICE_PERMISSION_DENIED); | 289 content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 292 } | 290 } |
| 293 | 291 |
| 294 void MediaStreamDevicesController::PermissionDenied() { | 292 void MediaStreamDevicesController::PermissionDenied() { |
| 295 RecordPermissionAction(request_, profile_, | 293 RecordPermissionAction( |
| 296 base::Bind(PermissionUmaUtil::PermissionDenied)); | 294 request_, base::Bind(PermissionUmaUtil::PermissionDenied)); |
| 297 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 295 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 298 old_audio_setting_, CONTENT_SETTING_BLOCK), | 296 old_audio_setting_, CONTENT_SETTING_BLOCK), |
| 299 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 297 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 300 old_video_setting_, CONTENT_SETTING_BLOCK), | 298 old_video_setting_, CONTENT_SETTING_BLOCK), |
| 301 content::MEDIA_DEVICE_PERMISSION_DENIED); | 299 content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 302 } | 300 } |
| 303 | 301 |
| 304 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, | 302 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, |
| 305 bool video_accepted) { | 303 bool video_accepted) { |
| 306 RecordSinglePermissionAction( | 304 RecordSinglePermissionAction( |
| 307 request_, content::PermissionType::AUDIO_CAPTURE, profile_, | 305 request_, content::PermissionType::AUDIO_CAPTURE, |
| 308 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted | 306 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted |
| 309 : PermissionUmaUtil::PermissionDenied)); | 307 : PermissionUmaUtil::PermissionDenied)); |
| 310 RecordSinglePermissionAction( | 308 RecordSinglePermissionAction( |
| 311 request_, content::PermissionType::VIDEO_CAPTURE, profile_, | 309 request_, content::PermissionType::VIDEO_CAPTURE, |
| 312 base::Bind(video_accepted ? PermissionUmaUtil::PermissionGranted | 310 base::Bind(video_accepted ? PermissionUmaUtil::PermissionGranted |
| 313 : PermissionUmaUtil::PermissionDenied)); | 311 : PermissionUmaUtil::PermissionDenied)); |
| 314 | 312 |
| 315 ContentSetting audio_setting = | 313 ContentSetting audio_setting = |
| 316 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 314 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 317 ContentSetting video_setting = | 315 ContentSetting video_setting = |
| 318 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 316 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 319 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 317 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 320 old_audio_setting_, audio_setting), | 318 old_audio_setting_, audio_setting), |
| 321 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 319 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 322 old_video_setting_, video_setting), | 320 old_video_setting_, video_setting), |
| 323 content::MEDIA_DEVICE_PERMISSION_DENIED); | 321 content::MEDIA_DEVICE_PERMISSION_DENIED); |
| 324 } | 322 } |
| 325 | 323 |
| 326 void MediaStreamDevicesController::Cancelled() { | 324 void MediaStreamDevicesController::Cancelled() { |
| 327 RecordPermissionAction(request_, profile_, | 325 RecordPermissionAction( |
| 328 base::Bind(PermissionUmaUtil::PermissionDismissed)); | 326 request_, base::Bind(PermissionUmaUtil::PermissionDismissed)); |
| 329 RunCallback(old_audio_setting_, old_video_setting_, | 327 RunCallback(old_audio_setting_, old_video_setting_, |
| 330 content::MEDIA_DEVICE_PERMISSION_DISMISSED); | 328 content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
| 331 } | 329 } |
| 332 | 330 |
| 333 void MediaStreamDevicesController::RequestFinished() { | 331 void MediaStreamDevicesController::RequestFinished() { |
| 334 delete this; | 332 delete this; |
| 335 } | 333 } |
| 336 | 334 |
| 337 PermissionBubbleType MediaStreamDevicesController::GetPermissionBubbleType() | 335 PermissionBubbleType MediaStreamDevicesController::GetPermissionBubbleType() |
| 338 const { | 336 const { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 if (android_permission_blocked) | 632 if (android_permission_blocked) |
| 635 return false; | 633 return false; |
| 636 | 634 |
| 637 // Don't approve device requests if the tab was hidden. | 635 // Don't approve device requests if the tab was hidden. |
| 638 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 636 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 639 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 637 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
| 640 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 638 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 641 #endif | 639 #endif |
| 642 return true; | 640 return true; |
| 643 } | 641 } |
| OLD | NEW |