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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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&)>; | 75 base::Callback<void(content::PermissionType, const GURL&)>; |
76 | 76 |
77 void RecordSinglePermissionAction(const content::MediaStreamRequest& request, | |
78 content::PermissionType permission_type, | |
79 PermissionActionCallback callback) { | |
80 if (ContentTypeIsRequested(permission_type, request)) { | |
81 callback.Run(permission_type, request.security_origin); | |
82 } | |
83 } | |
84 | |
77 // Calls |action_function| for each permission requested by |request|. | 85 // Calls |action_function| for each permission requested by |request|. |
78 void RecordPermissionAction(const content::MediaStreamRequest& request, | 86 void RecordPermissionAction(const content::MediaStreamRequest& request, |
79 PermissionActionCallback callback) { | 87 PermissionActionCallback callback) { |
80 if (ContentTypeIsRequested(content::PermissionType::VIDEO_CAPTURE, request)) { | 88 RecordSinglePermissionAction(request, content::PermissionType::AUDIO_CAPTURE, |
81 callback.Run(content::PermissionType::VIDEO_CAPTURE, | 89 callback); |
82 request.security_origin); | 90 RecordSinglePermissionAction(request, content::PermissionType::VIDEO_CAPTURE, |
83 } | 91 callback); |
84 if (ContentTypeIsRequested(content::PermissionType::AUDIO_CAPTURE, request)) { | |
85 callback.Run(content::PermissionType::AUDIO_CAPTURE, | |
86 request.security_origin); | |
87 } | |
88 } | 92 } |
89 | 93 |
90 // 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 |
91 // 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 |
92 // 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. |
93 class MediaPermissionRequestLogger : content::WebContentsObserver { | 97 class MediaPermissionRequestLogger : content::WebContentsObserver { |
94 // Map of <render process id, render frame id> -> | 98 // Map of <render process id, render frame id> -> |
95 // MediaPermissionRequestLogger. | 99 // MediaPermissionRequestLogger. |
96 using RequestMap = std::map<std::pair<int, int>, | 100 using RequestMap = std::map<std::pair<int, int>, |
97 std::unique_ptr<MediaPermissionRequestLogger>>; | 101 std::unique_ptr<MediaPermissionRequestLogger>>; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 void MediaStreamDevicesController::PermissionDenied() { | 292 void MediaStreamDevicesController::PermissionDenied() { |
289 RecordPermissionAction( | 293 RecordPermissionAction( |
290 request_, base::Bind(PermissionUmaUtil::PermissionDenied)); | 294 request_, base::Bind(PermissionUmaUtil::PermissionDenied)); |
291 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 295 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
292 old_audio_setting_, CONTENT_SETTING_BLOCK), | 296 old_audio_setting_, CONTENT_SETTING_BLOCK), |
293 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 297 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
294 old_video_setting_, CONTENT_SETTING_BLOCK), | 298 old_video_setting_, CONTENT_SETTING_BLOCK), |
295 content::MEDIA_DEVICE_PERMISSION_DENIED); | 299 content::MEDIA_DEVICE_PERMISSION_DENIED); |
296 } | 300 } |
297 | 301 |
302 void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, | |
Sergey Ulanov
2016/06/07 21:06:54
Do we still need PermissionGranted() and Permissio
tsergeant
2016/06/07 23:31:59
I think they are still necessary at the moment. On
| |
303 bool video_accepted) { | |
304 RecordSinglePermissionAction( | |
305 request_, content::PermissionType::AUDIO_CAPTURE, | |
306 base::Bind(audio_accepted ? PermissionUmaUtil::PermissionGranted | |
307 : PermissionUmaUtil::PermissionDenied)); | |
308 RecordSinglePermissionAction( | |
309 request_, content::PermissionType::VIDEO_CAPTURE, | |
310 base::Bind(video_accepted ? PermissionUmaUtil::PermissionGranted | |
311 : PermissionUmaUtil::PermissionDenied)); | |
312 | |
313 ContentSetting audio_setting = | |
314 audio_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | |
315 ContentSetting video_setting = | |
316 video_accepted ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | |
317 RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | |
318 old_audio_setting_, audio_setting), | |
319 GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | |
320 old_video_setting_, video_setting), | |
321 content::MEDIA_DEVICE_PERMISSION_DENIED); | |
322 } | |
323 | |
298 void MediaStreamDevicesController::Cancelled() { | 324 void MediaStreamDevicesController::Cancelled() { |
299 RecordPermissionAction( | 325 RecordPermissionAction( |
300 request_, base::Bind(PermissionUmaUtil::PermissionDismissed)); | 326 request_, base::Bind(PermissionUmaUtil::PermissionDismissed)); |
301 RunCallback(old_audio_setting_, old_video_setting_, | 327 RunCallback(old_audio_setting_, old_video_setting_, |
302 content::MEDIA_DEVICE_PERMISSION_DISMISSED); | 328 content::MEDIA_DEVICE_PERMISSION_DISMISSED); |
303 } | 329 } |
304 | 330 |
305 void MediaStreamDevicesController::RequestFinished() { | 331 void MediaStreamDevicesController::RequestFinished() { |
306 delete this; | 332 delete this; |
307 } | 333 } |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
615 if (android_permission_blocked) | 641 if (android_permission_blocked) |
616 return false; | 642 return false; |
617 | 643 |
618 // Don't approve device requests if the tab was hidden. | 644 // Don't approve device requests if the tab was hidden. |
619 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 645 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
620 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 646 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
621 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 647 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
622 #endif | 648 #endif |
623 return true; | 649 return true; |
624 } | 650 } |
OLD | NEW |