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 14 matching lines...) Expand all Loading... | |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/features.h" | 26 #include "chrome/common/features.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
30 #include "components/content_settings/core/common/content_settings_pattern.h" | 30 #include "components/content_settings/core/common/content_settings_pattern.h" |
31 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
32 #include "components/prefs/scoped_user_pref_update.h" | 32 #include "components/prefs/scoped_user_pref_update.h" |
33 #include "components/url_formatter/elide_url.h" | 33 #include "components/url_formatter/elide_url.h" |
34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/permission_type.h" | |
36 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
37 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
39 #include "content/public/common/media_stream_request.h" | 38 #include "content/public/common/media_stream_request.h" |
40 #include "content/public/common/origin_util.h" | 39 #include "content/public/common/origin_util.h" |
41 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
42 #include "grit/theme_resources.h" | 41 #include "grit/theme_resources.h" |
43 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
44 | 43 |
45 #if BUILDFLAG(ANDROID_JAVA_UI) | 44 #if BUILDFLAG(ANDROID_JAVA_UI) |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 if (!IsAskingForAudio()) | 249 if (!IsAskingForAudio()) |
251 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | 250 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
252 else if (!IsAskingForVideo()) | 251 else if (!IsAskingForVideo()) |
253 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | 252 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
254 return l10n_util::GetStringFUTF16( | 253 return l10n_util::GetStringFUTF16( |
255 message_id, | 254 message_id, |
256 url_formatter::FormatUrlForSecurityDisplay( | 255 url_formatter::FormatUrlForSecurityDisplay( |
257 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | 256 GetOrigin(), url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); |
258 } | 257 } |
259 | 258 |
259 content::PermissionType | |
260 MediaStreamDevicesController::GetPermissionTypeForContentSettingsType( | |
raymes
2016/08/18 06:10:00
We might as well use GetPermissionType from permis
dominickn
2016/08/18 06:38:20
Done.
raymes
2016/08/22 04:37:19
I think we should just remove this and use Permiss
dominickn
2016/08/23 20:13:16
GetPermissionType's signature is a little awkward;
| |
261 ContentSettingsType content_type) const { | |
262 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | |
263 return content::PermissionType::AUDIO_CAPTURE; | |
264 } else { | |
265 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, content_type); | |
266 return content::PermissionType::VIDEO_CAPTURE; | |
267 } | |
268 } | |
269 | |
270 void MediaStreamDevicesController::PermissionGranted(bool persist) { | |
271 base::AutoReset<bool> persist_permissions( | |
272 &persist_permission_changes_, persist); | |
273 PermissionGranted(); | |
274 } | |
275 | |
276 void MediaStreamDevicesController::PermissionDenied(bool persist) { | |
277 base::AutoReset<bool> persist_permissions( | |
278 &persist_permission_changes_, persist); | |
279 PermissionDenied(); | |
280 } | |
281 | |
260 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { | 282 void MediaStreamDevicesController::ForcePermissionDeniedTemporarily() { |
261 base::AutoReset<bool> persist_permissions( | 283 base::AutoReset<bool> persist_permissions( |
262 &persist_permission_changes_, false); | 284 &persist_permission_changes_, false); |
263 // TODO(tsergeant): Determine whether it is appropriate to record permission | 285 // TODO(tsergeant): Determine whether it is appropriate to record permission |
264 // action metrics here, as this is a different sort of user action. | 286 // action metrics here, as this is a different sort of user action. |
265 RunCallback(CONTENT_SETTING_BLOCK, | 287 RunCallback(CONTENT_SETTING_BLOCK, |
266 CONTENT_SETTING_BLOCK, | 288 CONTENT_SETTING_BLOCK, |
267 content::MEDIA_DEVICE_PERMISSION_DENIED); | 289 content::MEDIA_DEVICE_PERMISSION_DENIED); |
268 } | 290 } |
269 | 291 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 ContentSetting audio_setting, | 480 ContentSetting audio_setting, |
459 ContentSetting video_setting, | 481 ContentSetting video_setting, |
460 content::MediaStreamRequestResult denial_reason) { | 482 content::MediaStreamRequestResult denial_reason) { |
461 CHECK(!callback_.is_null()); | 483 CHECK(!callback_.is_null()); |
462 | 484 |
463 // If the kill switch is on we don't update the tab context or persist the | 485 // If the kill switch is on we don't update the tab context or persist the |
464 // setting. | 486 // setting. |
465 if (persist_permission_changes_ && | 487 if (persist_permission_changes_ && |
466 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { | 488 denial_reason != content::MEDIA_DEVICE_KILL_SWITCH_ON) { |
467 StorePermission(audio_setting, video_setting); | 489 StorePermission(audio_setting, video_setting); |
468 UpdateTabSpecificContentSettings(audio_setting, video_setting); | 490 UpdateTabSpecificContentSettings(audio_setting, video_setting); |
raymes
2016/08/18 06:10:00
Hmm, I'm worried that updating the tab context is
dominickn
2016/08/18 06:38:20
I'm not sure I know this code well enough to make
| |
469 } | 491 } |
470 | 492 |
471 content::MediaStreamDevices devices = | 493 content::MediaStreamDevices devices = |
472 GetDevices(audio_setting, video_setting); | 494 GetDevices(audio_setting, video_setting); |
473 | 495 |
474 // If either audio or video are allowed then the callback should report | 496 // If either audio or video are allowed then the callback should report |
475 // success, otherwise we report |denial_reason|. | 497 // success, otherwise we report |denial_reason|. |
476 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; | 498 content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
477 if (audio_setting != CONTENT_SETTING_ALLOW && | 499 if (audio_setting != CONTENT_SETTING_ALLOW && |
478 video_setting != CONTENT_SETTING_ALLOW) { | 500 video_setting != CONTENT_SETTING_ALLOW) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 594 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
573 requested_device_id = request.requested_audio_device_id; | 595 requested_device_id = request.requested_audio_device_id; |
574 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 596 else if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
575 requested_device_id = request.requested_video_device_id; | 597 requested_device_id = request.requested_video_device_id; |
576 | 598 |
577 if (!IsUserAcceptAllowed(content_type)) { | 599 if (!IsUserAcceptAllowed(content_type)) { |
578 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 600 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
579 return CONTENT_SETTING_BLOCK; | 601 return CONTENT_SETTING_BLOCK; |
580 } | 602 } |
581 | 603 |
582 content::PermissionType permission_type; | 604 content::PermissionType permission_type = |
583 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 605 GetPermissionTypeForContentSettingsType(content_type); |
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 | |
590 if (ContentTypeIsRequested(permission_type, request)) { | 606 if (ContentTypeIsRequested(permission_type, request)) { |
591 DCHECK(content::IsOriginSecure(request_.security_origin) || | 607 DCHECK(content::IsOriginSecure(request_.security_origin) || |
592 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); | 608 request_.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY); |
593 MediaPermission permission(content_type, request.security_origin, | 609 MediaPermission permission(content_type, request.security_origin, |
594 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); | 610 web_contents_->GetLastCommittedURL().GetOrigin(), profile_); |
595 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, | 611 return permission.GetPermissionStatusWithDeviceRequired(requested_device_id, |
596 denial_reason); | 612 denial_reason); |
597 } | 613 } |
598 // Return the default content setting if the device is not requested. | 614 // Return the default content setting if the device is not requested. |
599 return CONTENT_SETTING_DEFAULT; | 615 return CONTENT_SETTING_DEFAULT; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 if (android_permission_blocked) | 656 if (android_permission_blocked) |
641 return false; | 657 return false; |
642 | 658 |
643 // Don't approve device requests if the tab was hidden. | 659 // Don't approve device requests if the tab was hidden. |
644 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 660 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
645 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? | 661 // TODO(raymes): Shouldn't this apply to all permissions not just audio/video? |
646 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 662 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
647 #endif | 663 #endif |
648 return true; | 664 return true; |
649 } | 665 } |
OLD | NEW |