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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
18 #include "chrome/browser/media/media_permission.h" | 18 #include "chrome/browser/media/media_permission.h" |
19 #include "chrome/browser/media/media_stream_capture_indicator.h" | 19 #include "chrome/browser/media/media_stream_capture_indicator.h" |
20 #include "chrome/browser/media/media_stream_device_permissions.h" | 20 #include "chrome/browser/media/media_stream_device_permissions.h" |
21 #include "chrome/browser/permissions/permission_uma_util.h" | 21 #include "chrome/browser/permissions/permission_uma_util.h" |
22 #include "chrome/browser/permissions/permission_util.h" | |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/features.h" | 26 #include "chrome/common/features.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
29 #include "components/content_settings/core/common/content_settings_pattern.h" | 30 #include "components/content_settings/core/common/content_settings_pattern.h" |
30 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
31 #include "components/prefs/scoped_user_pref_update.h" | 32 #include "components/prefs/scoped_user_pref_update.h" |
32 #include "components/url_formatter/elide_url.h" | 33 #include "components/url_formatter/elide_url.h" |
33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/permission_type.h" | |
35 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
36 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
37 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
38 #include "content/public/common/media_stream_request.h" | 38 #include "content/public/common/media_stream_request.h" |
39 #include "content/public/common/origin_util.h" | 39 #include "content/public/common/origin_util.h" |
40 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
41 #include "grit/theme_resources.h" | 41 #include "grit/theme_resources.h" |
42 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
43 | 43 |
44 #if BUILDFLAG(ANDROID_JAVA_UI) | 44 #if BUILDFLAG(ANDROID_JAVA_UI) |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 if (!IsAskingForAudio()) | 248 if (!IsAskingForAudio()) |
249 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 249 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
250 else if (!IsAskingForVideo()) | 250 else if (!IsAskingForVideo()) |
251 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 251 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
252 return l10n_util::GetStringFUTF16( | 252 return l10n_util::GetStringFUTF16( |
253 message_id, | 253 message_id, |
254 url_formatter::FormatUrlForSecurityDisplay( | 254 url_formatter::FormatUrlForSecurityDisplay( |
255 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 255 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
256 } | 256 } |
257 | 257 |
258 content::PermissionType | |
259 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType( | |
260 ContentSettingsType content_type) const { | |
261 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | |
262 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
263 content::PermissionType permission = content::PermissionType::NUM; | |
264 DCHECK(PermissionUtil::GetPermissionType(content_type, &permission)); | |
265 return permission; | |
266 } | |
267 | |
258 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { | 268 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { |
259 set_persist(false); | 269 set_persist(false); |
260 // TODO(tsergeant): Determine whether it is appropriate to record permission | 270 // TODO(tsergeant): Determine whether it is appropriate to record permission |
261 // action metrics here, as this is a different sort of user action. | 271 // action metrics here, as this is a different sort of user action. |
262 RunCallback(CONTENT_SETTING_BLOCK, | 272 RunCallback(CONTENT_SETTING_BLOCK, |
263 CONTENT_SETTING_BLOCK, | 273 CONTENT_SETTING_BLOCK, |
264 content::MEDIA_DEVICE_PERMISSION_DENIED); | 274 content::MEDIA_DEVICE_PERMISSION_DENIED); |
265 set_persist(true); | 275 set_persist(true); |
266 } | 276 } |
267 | 277 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 } | 467 } |
458 | 468 |
459 void MediaStreamDevicesController::RunCallback( | 469 void MediaStreamDevicesController::RunCallback( |
460 ContentSetting audio_setting, | 470 ContentSetting audio_setting, |
461 ContentSetting video_setting, | 471 ContentSetting video_setting, |
462 content::MediaStreamRequestResult denial_reason) { | 472 content::MediaStreamRequestResult denial_reason) { |
463 CHECK(!callback_.is_null()); | 473 CHECK(!callback_.is_null()); |
464 | 474 |
465 // If the kill switch is on we don't update the tab context or persist the | 475 // If the kill switch is on we don't update the tab context or persist the |
466 // setting. | 476 // setting. |
467 if (persist() && denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { | 477 if (denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { |
468 StorePermission(audio_setting, video_setting); | 478 if (persist()) |
raymes
2016/08/22 04:37:19
I don't see persist/set_persist defined anywhere.
dominickn
2016/08/22 05:30:02
It's defined in PermissionRequest.
raymes
2016/08/22 05:35:23
Oh..it's in the dependent CL. I feel like it could
dominickn
2016/08/22 06:00:15
I considered that. The problem would be that Permi
raymes
2016/08/22 06:59:11
I think that's a reasonable argument. My main conc
dominickn
2016/08/22 07:08:44
MediaStreamDevicesController currently has the per
| |
479 StorePermission(audio_setting, video_setting); | |
469 UpdateTabSpecificContentSettings(audio_setting, video_setting); | 480 UpdateTabSpecificContentSettings(audio_setting, video_setting); |
raymes
2016/08/22 04:37:19
I'm not sure this should actually be in this block
dominickn
2016/08/22 05:30:02
Acknowledged. +kcarattini to look at.
kcarattini
2016/08/22 05:44:38
This was done to suppress the Page Action icon fro
dominickn
2016/08/22 06:00:15
Acknowledged.
| |
470 } | 481 } |
471 | 482 |
472 content::MediaStreamDevices devices = | 483 content::MediaStreamDevices devices = |
473 GetDevices(audio_setting, video_setting); | 484 GetDevices(audio_setting, video_setting); |
474 | 485 |
475 // If either audio or video are allowed then the callback should report | 486 // If either audio or video are allowed then the callback should report |
476 // success, otherwise we report |denial_reason|. | 487 // success, otherwise we report |denial_reason|. |
477 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; | 488 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
478 if (audio_setting != CONTENT_SETTING_ALLOW && | 489 if (audio_setting != CONTENT_SETTING_ALLOW && |
479 video_setting != CONTENT_SETTING_ALLOW) { | 490 video_setting != CONTENT_SETTING_ALLOW) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 584 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
574 requested_device_id = request.requested_audio_device_id; | 585 requested_device_id = request.requested_audio_device_id; |
575 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 586 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
576 requested_device_id = request.requested_video_device_id; | 587 requested_device_id = request.requested_video_device_id; |
577 | 588 |
578 if (!IsUserAcceptAllowed(content_type)) { | 589 if (!IsUserAcceptAllowed(content_type)) { |
579 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 590 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
580 return CONTENT_SETTING_BLOCK; | 591 return CONTENT_SETTING_BLOCK; |
581 } | 592 } |
582 | 593 |
583 content::PermissionType permission_type; | 594 content::PermissionType permission_type = |
584 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 595 GetPermissionTypeForContentSettingsType(content_type); |
585 permission_type = content::PermissionType::AUDIO_CAPTURE; | |
586 } else { | |
587 DCHECK(content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
588 permission_type = content::PermissionType::VIDEO_CAPTURE; | |
589 } | |
590 | |
591 if (ContentTypeIsRequested(permission_type, request)) { | 596 if (ContentTypeIsRequested(permission_type, request)) { |
592 DCHECK(content::IsOriginSecure(request_.security_origin) || | 597 DCHECK(content::IsOriginSecure(request_.security_origin) || |
593 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); | 598 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
594 MediaPermission permission(content_type, request.security_origin, | 599 MediaPermission permission(content_type, request.security_origin, |
595 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); | 600 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); |
596 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, | 601 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, |
597 denial_reason); | 602 denial_reason); |
598 } | 603 } |
599 // Return the default content setting if the device is not requested. | 604 // Return the default content setting if the device is not requested. |
600 return CONTENT_SETTING_DEFAULT; | 605 return CONTENT_SETTING_DEFAULT; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 if (android_permission_blocked) | 646 if (android_permission_blocked) |
642 return false; | 647 return false; |
643 | 648 |
644 // Don't approve device requests if the tab was hidden. | 649 // Don't approve device requests if the tab was hidden. |
645 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 650 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
646 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 651 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
647 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 652 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
648 #endif | 653 #endif |
649 return true; | 654 return true; |
650 } | 655 } |
OLD | NEW |