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/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 17 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
19 #include "chrome/browser/media/webrtc/media_permission.h" | 19 #include "chrome/browser/media/webrtc/media_permission.h" |
20 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 20 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
21 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 21 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
22 #include "chrome/browser/permissions/permission_uma_util.h" | 22 #include "chrome/browser/permissions/permission_uma_util.h" |
23 #include "chrome/browser/permissions/permission_util.h" | |
24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/features.h" | 26 #include "chrome/common/features.h" |
28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
29 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
30 #include "chrome/grit/theme_resources.h" | 29 #include "chrome/grit/theme_resources.h" |
31 #include "components/content_settings/core/browser/host_content_settings_map.h" | 30 #include "components/content_settings/core/browser/host_content_settings_map.h" |
32 #include "components/content_settings/core/common/content_settings_pattern.h" | 31 #include "components/content_settings/core/common/content_settings_pattern.h" |
33 #include "components/pref_registry/pref_registry_syncable.h" | 32 #include "components/pref_registry/pref_registry_syncable.h" |
34 #include "components/prefs/scoped_user_pref_update.h" | 33 #include "components/prefs/scoped_user_pref_update.h" |
35 #include "components/url_formatter/elide_url.h" | 34 #include "components/url_formatter/elide_url.h" |
36 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/permission_type.h" |
37 #include "content/public/browser/render_frame_host.h" | 37 #include "content/public/browser/render_frame_host.h" |
38 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/render_widget_host_view.h" | 39 #include "content/public/browser/render_widget_host_view.h" |
40 #include "content/public/common/media_stream_request.h" | 40 #include "content/public/common/media_stream_request.h" |
41 #include "content/public/common/origin_util.h" | 41 #include "content/public/common/origin_util.h" |
42 #include "extensions/common/constants.h" | 42 #include "extensions/common/constants.h" |
43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
44 | 44 |
45 #if BUILDFLAG(ANDROID_JAVA_UI) | 45 #if BUILDFLAG(ANDROID_JAVA_UI) |
46 #include <vector> | 46 #include <vector> |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 158 |
159 } // namespace | 159 } // namespace |
160 | 160 |
161 MediaStreamDevicesController::MediaStreamDevicesController( | 161 MediaStreamDevicesController::MediaStreamDevicesController( |
162 content::WebContents* web_contents, | 162 content::WebContents* web_contents, |
163 const content::MediaStreamRequest& request, | 163 const content::MediaStreamRequest& request, |
164 const content::MediaResponseCallback& callback) | 164 const content::MediaResponseCallback& callback) |
165 : web_contents_(web_contents), | 165 : web_contents_(web_contents), |
166 request_(request), | 166 request_(request), |
167 callback_(callback), | 167 callback_(callback), |
168 persist_(true) { | 168 persist_permission_changes_(true) { |
169 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { | 169 if (request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { |
170 MediaPermissionRequestLogger::LogRequest( | 170 MediaPermissionRequestLogger::LogRequest( |
171 web_contents, request.render_process_id, request.render_frame_id, | 171 web_contents, request.render_process_id, request.render_frame_id, |
172 content::IsOriginSecure(request_.security_origin)); | 172 content::IsOriginSecure(request_.security_origin)); |
173 } | 173 } |
174 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 174 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
175 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); | 175 content_settings_ = TabSpecificContentSettings::FromWebContents(web_contents); |
176 | 176 |
177 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; | 177 content::MediaStreamRequestResult denial_reason = content::MEDIA_DEVICE_OK; |
178 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 178 old_audio_setting_ = GetContentSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 if (!IsAskingForAudio()) | 250 if (!IsAskingForAudio()) |
251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
252 else if (!IsAskingForVideo()) | 252 else if (!IsAskingForVideo()) |
253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
254 return l10n_util::GetStringFUTF16( | 254 return l10n_util::GetStringFUTF16( |
255 message_id, | 255 message_id, |
256 url_formatter::FormatUrlForSecurityDisplay( | 256 url_formatter::FormatUrlForSecurityDisplay( |
257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
258 } | 258 } |
259 | 259 |
260 content::PermissionType | |
261 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType( | |
262 ContentSettingsType content_type) const { | |
263 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | |
264 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
265 content::PermissionType permission = content::PermissionType::NUM; | |
266 DCHECK(PermissionUtil::GetPermissionType(content_type, &permission)); | |
267 return permission; | |
268 } | |
269 | |
270 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { | 260 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { |
271 base::AutoReset<bool> persist_permissions(&persist_, false); | 261 base::AutoReset<bool> persist_permissions( |
| 262 &persist_permission_changes_, false); |
272 // TODO(tsergeant): Determine whether it is appropriate to record permission | 263 // TODO(tsergeant): Determine whether it is appropriate to record permission |
273 // action metrics here, as this is a different sort of user action. | 264 // action metrics here, as this is a different sort of user action. |
274 RunCallback(CONTENT_SETTING_BLOCK, | 265 RunCallback(CONTENT_SETTING_BLOCK, |
275 CONTENT_SETTING_BLOCK, | 266 CONTENT_SETTING_BLOCK, |
276 content::MEDIA_DEVICE_PERMISSION_DENIED); | 267 content::MEDIA_DEVICE_PERMISSION_DENIED); |
277 } | 268 } |
278 | 269 |
279 int MediaStreamDevicesController::GetIconId() const { | 270 int MediaStreamDevicesController::GetIconId() const { |
280 if (IsAskingForVideo()) | 271 if (IsAskingForVideo()) |
281 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; | 272 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 455 } |
465 | 456 |
466 void MediaStreamDevicesController::RunCallback( | 457 void MediaStreamDevicesController::RunCallback( |
467 ContentSetting audio_setting, | 458 ContentSetting audio_setting, |
468 ContentSetting video_setting, | 459 ContentSetting video_setting, |
469 content::MediaStreamRequestResult denial_reason) { | 460 content::MediaStreamRequestResult denial_reason) { |
470 CHECK(!callback_.is_null()); | 461 CHECK(!callback_.is_null()); |
471 | 462 |
472 // If the kill switch is on we don't update the tab context or persist the | 463 // If the kill switch is on we don't update the tab context or persist the |
473 // setting. | 464 // setting. |
474 if (denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { | 465 if (persist_permission_changes_ && |
475 if (persist()) | 466 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { |
476 StorePermission(audio_setting, video_setting); | 467 StorePermission(audio_setting, video_setting); |
477 UpdateTabSpecificContentSettings(audio_setting, video_setting); | 468 UpdateTabSpecificContentSettings(audio_setting, video_setting); |
478 } | 469 } |
479 | 470 |
480 content::MediaStreamDevices devices = | 471 content::MediaStreamDevices devices = |
481 GetDevices(audio_setting, video_setting); | 472 GetDevices(audio_setting, video_setting); |
482 | 473 |
483 // If either audio or video are allowed then the callback should report | 474 // If either audio or video are allowed then the callback should report |
484 // success, otherwise we report |denial_reason|. | 475 // success, otherwise we report |denial_reason|. |
485 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; | 476 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
486 if (audio_setting != CONTENT_SETTING_ALLOW && | 477 if (audio_setting != CONTENT_SETTING_ALLOW && |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 572 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
582 requested_device_id = request.requested_audio_device_id; | 573 requested_device_id = request.requested_audio_device_id; |
583 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 574 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
584 requested_device_id = request.requested_video_device_id; | 575 requested_device_id = request.requested_video_device_id; |
585 | 576 |
586 if (!IsUserAcceptAllowed(content_type)) { | 577 if (!IsUserAcceptAllowed(content_type)) { |
587 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 578 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
588 return CONTENT_SETTING_BLOCK; | 579 return CONTENT_SETTING_BLOCK; |
589 } | 580 } |
590 | 581 |
591 content::PermissionType permission_type = | 582 content::PermissionType permission_type; |
592 GetPermissionTypeForContentSettingsType(content_type); | 583 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 584 permission_type = content::PermissionType::AUDIO_CAPTURE; |
| 585 } else { |
| 586 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 587 permission_type = content::PermissionType::VIDEO_CAPTURE; |
| 588 } |
| 589 |
593 if (ContentTypeIsRequested(permission_type, request)) { | 590 if (ContentTypeIsRequested(permission_type, request)) { |
594 DCHECK(content::IsOriginSecure(request_.security_origin) || | 591 DCHECK(content::IsOriginSecure(request_.security_origin) || |
595 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); | 592 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
596 MediaPermission permission(content_type, request.security_origin, | 593 MediaPermission permission(content_type, request.security_origin, |
597 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); | 594 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); |
598 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, | 595 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, |
599 denial_reason); | 596 denial_reason); |
600 } | 597 } |
601 // Return the default content setting if the device is not requested. | 598 // Return the default content setting if the device is not requested. |
602 return CONTENT_SETTING_DEFAULT; | 599 return CONTENT_SETTING_DEFAULT; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 if (android_permission_blocked) | 640 if (android_permission_blocked) |
644 return false; | 641 return false; |
645 | 642 |
646 // Don't approve device requests if the tab was hidden. | 643 // Don't approve device requests if the tab was hidden. |
647 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 644 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
648 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 645 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
649 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 646 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
650 #endif | 647 #endif |
651 return true; | 648 return true; |
652 } | 649 } |
OLD | NEW |