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/webrtc/media_stream_devices_controller.h" | 5 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #else // !defined(OS_ANDROID) | 51 #else // !defined(OS_ANDROID) |
52 #include "ui/vector_icons/vector_icons.h" | 52 #include "ui/vector_icons/vector_icons.h" |
53 #endif | 53 #endif |
54 | 54 |
55 using content::BrowserThread; | 55 using content::BrowserThread; |
56 | 56 |
57 namespace { | 57 namespace { |
58 | 58 |
59 // Returns true if the given ContentSettingsType is being requested in | 59 // Returns true if the given ContentSettingsType is being requested in |
60 // |request|. | 60 // |request|. |
61 bool ContentTypeIsRequested(content::PermissionType type, | 61 bool ContentTypeIsRequested(ContentSettingsType type, |
62 const content::MediaStreamRequest& request) { | 62 const content::MediaStreamRequest& request) { |
63 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) | 63 if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) |
64 return true; | 64 return true; |
65 | 65 |
66 if (type == content::PermissionType::AUDIO_CAPTURE) | 66 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
67 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; | 67 return request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE; |
68 | 68 |
69 if (type == content::PermissionType::VIDEO_CAPTURE) | 69 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
70 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; | 70 return request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE; |
71 | 71 |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 using PermissionActionCallback = | 75 using PermissionActionCallback = |
76 base::Callback<void(content::PermissionType, | 76 base::Callback<void(ContentSettingsType, |
77 PermissionRequestGestureType, | 77 PermissionRequestGestureType, |
78 const GURL&, | 78 const GURL&, |
79 Profile*)>; | 79 Profile*)>; |
80 | 80 |
81 void RecordSinglePermissionAction(const content::MediaStreamRequest& request, | 81 void RecordSinglePermissionAction(const content::MediaStreamRequest& request, |
82 content::PermissionType permission_type, | 82 ContentSettingsType content_type, |
83 Profile* profile, | 83 Profile* profile, |
84 PermissionActionCallback callback) { | 84 PermissionActionCallback callback) { |
85 if (ContentTypeIsRequested(permission_type, request)) { | 85 if (ContentTypeIsRequested(content_type, request)) { |
86 // TODO(stefanocs): Pass the actual |gesture_type| once this file has been | 86 // TODO(stefanocs): Pass the actual |gesture_type| once this file has been |
87 // refactored into PermissionContext. | 87 // refactored into PermissionContext. |
88 callback.Run(permission_type, PermissionRequestGestureType::UNKNOWN, | 88 callback.Run(content_type, PermissionRequestGestureType::UNKNOWN, |
89 request.security_origin, profile); | 89 request.security_origin, profile); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 // Calls |action_function| for each permission requested by |request|. | 93 // Calls |action_function| for each permission requested by |request|. |
94 void RecordPermissionAction(const content::MediaStreamRequest& request, | 94 void RecordPermissionAction(const content::MediaStreamRequest& request, |
95 Profile* profile, | 95 Profile* profile, |
96 PermissionActionCallback callback) { | 96 PermissionActionCallback callback) { |
97 RecordSinglePermissionAction(request, content::PermissionType::AUDIO_CAPTURE, | 97 RecordSinglePermissionAction(request, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
98 profile, callback); | 98 profile, callback); |
99 RecordSinglePermissionAction(request, content::PermissionType::VIDEO_CAPTURE, | 99 RecordSinglePermissionAction( |
100 profile, callback); | 100 request, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, profile, callback); |
101 } | 101 } |
102 | 102 |
103 // This helper class helps to measure the number of media stream requests that | 103 // This helper class helps to measure the number of media stream requests that |
104 // occur. It ensures that only one request will be recorded per navigation, per | 104 // occur. It ensures that only one request will be recorded per navigation, per |
105 // frame. TODO(raymes): Remove this when https://crbug.com/526324 is fixed. | 105 // frame. TODO(raymes): Remove this when https://crbug.com/526324 is fixed. |
106 class MediaPermissionRequestLogger : content::WebContentsObserver { | 106 class MediaPermissionRequestLogger : content::WebContentsObserver { |
107 // Map of <render process id, render frame id> -> | 107 // Map of <render process id, render frame id> -> |
108 // MediaPermissionRequestLogger. | 108 // MediaPermissionRequestLogger. |
109 using RequestMap = std::map<std::pair<int, int>, | 109 using RequestMap = std::map<std::pair<int, int>, |
110 std::unique_ptr<MediaPermissionRequestLogger>>; | 110 std::unique_ptr<MediaPermissionRequestLogger>>; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if (!IsAskingForAudio()) | 249 if (!IsAskingForAudio()) |
250 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 250 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
251 else if (!IsAskingForVideo()) | 251 else if (!IsAskingForVideo()) |
252 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 252 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
253 return l10n_util::GetStringFUTF16( | 253 return l10n_util::GetStringFUTF16( |
254 message_id, | 254 message_id, |
255 url_formatter::FormatUrlForSecurityDisplay( | 255 url_formatter::FormatUrlForSecurityDisplay( |
256 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 256 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
257 } | 257 } |
258 | 258 |
259 content::PermissionType | |
260 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType( | |
261 ContentSettingsType content_type) const { | |
262 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | |
263 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
264 content::PermissionType permission = content::PermissionType::NUM; | |
265 CHECK(PermissionUtil::GetPermissionType(content_type, &permission)); | |
266 return permission; | |
267 } | |
268 | |
269 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { | 259 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { |
270 set_persist(false); | 260 set_persist(false); |
271 // TODO(tsergeant): Determine whether it is appropriate to record permission | 261 // TODO(tsergeant): Determine whether it is appropriate to record permission |
272 // action metrics here, as this is a different sort of user action. | 262 // action metrics here, as this is a different sort of user action. |
273 RunCallback(CONTENT_SETTING_BLOCK, | 263 RunCallback(CONTENT_SETTING_BLOCK, |
274 CONTENT_SETTING_BLOCK, | 264 CONTENT_SETTING_BLOCK, |
275 content::MEDIA_DEVICE_PERMISSION_DENIED); | 265 content::MEDIA_DEVICE_PERMISSION_DENIED); |
276 set_persist(true); | 266 set_persist(true); |
277 } | 267 } |
278 | 268 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 550 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
561 requested_device_id = request.requested_audio_device_id; | 551 requested_device_id = request.requested_audio_device_id; |
562 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 552 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
563 requested_device_id = request.requested_video_device_id; | 553 requested_device_id = request.requested_video_device_id; |
564 | 554 |
565 if (!IsUserAcceptAllowed(content_type)) { | 555 if (!IsUserAcceptAllowed(content_type)) { |
566 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 556 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
567 return CONTENT_SETTING_BLOCK; | 557 return CONTENT_SETTING_BLOCK; |
568 } | 558 } |
569 | 559 |
570 content::PermissionType permission_type = | 560 if (ContentTypeIsRequested(content_type, request)) { |
571 GetPermissionTypeForContentSettingsType(content_type); | |
572 if (ContentTypeIsRequested(permission_type, request)) { | |
573 DCHECK(content::IsOriginSecure(request_.security_origin) || | 561 DCHECK(content::IsOriginSecure(request_.security_origin) || |
574 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); | 562 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
575 MediaPermission permission(content_type, request.security_origin, | 563 MediaPermission permission(content_type, request.security_origin, |
576 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); | 564 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); |
577 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, | 565 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, |
578 denial_reason); | 566 denial_reason); |
579 } | 567 } |
580 // Return the default content setting if the device is not requested. | 568 // Return the default content setting if the device is not requested. |
581 return CONTENT_SETTING_DEFAULT; | 569 return CONTENT_SETTING_DEFAULT; |
582 } | 570 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 if (android_permission_blocked) | 610 if (android_permission_blocked) |
623 return false; | 611 return false; |
624 | 612 |
625 // Don't approve device requests if the tab was hidden. | 613 // Don't approve device requests if the tab was hidden. |
626 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 614 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
627 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 615 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
628 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 616 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
629 #endif | 617 #endif |
630 return true; | 618 return true; |
631 } | 619 } |
OLD | NEW |