Chromium Code Reviews| 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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 } | 77 } |
| 78 | 78 |
| 79 enum DevicePermissionActions { | 79 enum DevicePermissionActions { |
| 80 kAllowHttps = 0, | 80 kAllowHttps = 0, |
| 81 kAllowHttp, | 81 kAllowHttp, |
| 82 kDeny, | 82 kDeny, |
| 83 kCancel, | 83 kCancel, |
| 84 kPermissionActionsMax // Must always be last! | 84 kPermissionActionsMax // Must always be last! |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 // This is a wrapper around the call to | |
| 88 // TabSpecificContentSettings::OnMediaStreamPermissionSet, precomputing the | |
| 89 // information from |request_permissions| to a form which is understood by | |
| 90 // TabSpecificContentSettings. | |
| 91 void OnMediaStreamPermissionSet( | |
| 92 TabSpecificContentSettings* content_settings, | |
| 93 content::WebContents* web_contents, | |
| 94 const GURL& request_origin, | |
| 95 const MediaStreamDevicesController::MediaStreamTypeSettingsMap& | |
| 96 request_permissions) { | |
| 97 TabSpecificContentSettings::MicrophoneCameraState microphone_camera_state = | |
| 98 TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED; | |
| 99 std::string selected_audio_device; | |
| 100 std::string selected_video_device; | |
| 101 std::string requested_audio_device; | |
| 102 std::string requested_video_device; | |
| 103 | |
| 104 PrefService* prefs = Profile::FromBrowserContext( | |
| 105 web_contents->GetBrowserContext())->GetPrefs(); | |
|
no longer working on chromium
2014/10/29 10:09:42
indentation.
vabr (Chromium)
2014/10/29 10:30:21
I believe this is indented correctly.
See "Argumen
no longer working on chromium
2014/10/30 09:59:19
In some cases git cl format is not inline with the
vabr (Chromium)
2014/10/30 10:28:39
My point here was that this particular formatting
| |
| 106 MediaStreamDevicesController::MediaStreamTypeSettingsMap::const_iterator it = | |
|
Bernhard Bauer
2014/10/29 09:35:17
This seems like a good place for auto :)
vabr (Chromium)
2014/10/29 10:30:21
Auto-awesome! :)
Done.
| |
| 107 request_permissions.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); | |
| 108 if (it != request_permissions.end()) { | |
| 109 requested_audio_device = it->second.requested_device_id; | |
| 110 selected_audio_device = | |
|
no longer working on chromium
2014/10/29 10:09:42
I think the correct format should be
selected_aud
vabr (Chromium)
2014/10/29 10:30:21
I'm yielding, because of consistency with the rest
| |
| 111 requested_audio_device.empty() | |
| 112 ? prefs->GetString(prefs::kDefaultAudioCaptureDevice) | |
| 113 : requested_audio_device; | |
| 114 DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); | |
| 115 bool mic_allowed = | |
| 116 it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; | |
| 117 microphone_camera_state |= | |
| 118 TabSpecificContentSettings::MICROPHONE_ACCESSED | | |
| 119 (mic_allowed ? 0 : TabSpecificContentSettings::MICROPHONE_BLOCKED); | |
| 120 } | |
| 121 | |
| 122 it = request_permissions.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 123 if (it != request_permissions.end()) { | |
| 124 requested_video_device = it->second.requested_device_id; | |
| 125 selected_video_device = | |
|
no longer working on chromium
2014/10/29 10:09:42
ditto
vabr (Chromium)
2014/10/29 10:30:21
Done.
| |
| 126 requested_video_device.empty() | |
| 127 ? prefs->GetString(prefs::kDefaultVideoCaptureDevice) | |
| 128 : requested_video_device; | |
| 129 DCHECK_NE(MediaStreamDevicesController::MEDIA_NONE, it->second.permission); | |
| 130 bool cam_allowed = | |
| 131 it->second.permission == MediaStreamDevicesController::MEDIA_ALLOWED; | |
| 132 microphone_camera_state |= | |
| 133 TabSpecificContentSettings::CAMERA_ACCESSED | | |
| 134 (cam_allowed ? 0 : TabSpecificContentSettings::CAMERA_BLOCKED); | |
| 135 } | |
| 136 | |
| 137 content_settings->OnMediaStreamPermissionSet(request_origin, | |
| 138 microphone_camera_state, | |
| 139 selected_audio_device, | |
| 140 selected_video_device, | |
| 141 requested_audio_device, | |
| 142 requested_video_device); | |
| 143 } | |
| 144 | |
| 87 } // namespace | 145 } // namespace |
| 88 | 146 |
| 89 MediaStreamDevicesController::MediaStreamTypeSettings::MediaStreamTypeSettings( | 147 MediaStreamDevicesController::MediaStreamTypeSettings::MediaStreamTypeSettings( |
| 90 Permission permission, const std::string& requested_device_id): | 148 Permission permission, const std::string& requested_device_id): |
| 91 permission(permission), requested_device_id(requested_device_id) {} | 149 permission(permission), requested_device_id(requested_device_id) {} |
| 92 | 150 |
| 93 MediaStreamDevicesController::MediaStreamTypeSettings:: | 151 MediaStreamDevicesController::MediaStreamTypeSettings:: |
| 94 MediaStreamTypeSettings(): permission(MEDIA_NONE) {} | 152 MediaStreamTypeSettings(): permission(MEDIA_NONE) {} |
| 95 | 153 |
| 96 MediaStreamDevicesController::MediaStreamTypeSettings:: | 154 MediaStreamDevicesController::MediaStreamTypeSettings:: |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 630 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 573 std::string(), | 631 std::string(), |
| 574 content_setting); | 632 content_setting); |
| 575 } | 633 } |
| 576 } | 634 } |
| 577 | 635 |
| 578 void MediaStreamDevicesController::NotifyUIRequestAccepted() const { | 636 void MediaStreamDevicesController::NotifyUIRequestAccepted() const { |
| 579 if (!content_settings_) | 637 if (!content_settings_) |
| 580 return; | 638 return; |
| 581 | 639 |
| 582 content_settings_->OnMediaStreamPermissionSet(request_.security_origin, | 640 OnMediaStreamPermissionSet(content_settings_, |
| 583 request_permissions_); | 641 web_contents_, |
| 642 request_.security_origin, | |
| 643 request_permissions_); | |
| 584 } | 644 } |
| 585 | 645 |
| 586 void MediaStreamDevicesController::NotifyUIRequestDenied() { | 646 void MediaStreamDevicesController::NotifyUIRequestDenied() { |
| 587 if (!content_settings_) | 647 if (!content_settings_) |
| 588 return; | 648 return; |
| 589 | 649 |
| 590 if (IsDeviceAudioCaptureRequestedAndAllowed()) { | 650 if (IsDeviceAudioCaptureRequestedAndAllowed()) { |
| 591 request_permissions_[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = | 651 request_permissions_[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission = |
| 592 MEDIA_BLOCKED_BY_USER; | 652 MEDIA_BLOCKED_BY_USER; |
| 593 } | 653 } |
| 594 if (IsDeviceVideoCaptureRequestedAndAllowed()) { | 654 if (IsDeviceVideoCaptureRequestedAndAllowed()) { |
| 595 request_permissions_[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission = | 655 request_permissions_[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission = |
| 596 MEDIA_BLOCKED_BY_USER; | 656 MEDIA_BLOCKED_BY_USER; |
| 597 } | 657 } |
| 598 | 658 |
| 599 content_settings_->OnMediaStreamPermissionSet(request_.security_origin, | 659 OnMediaStreamPermissionSet(content_settings_, |
| 600 request_permissions_); | 660 web_contents_, |
| 661 request_.security_origin, | |
| 662 request_permissions_); | |
| 601 } | 663 } |
| 602 | 664 |
| 603 bool MediaStreamDevicesController::IsDeviceAudioCaptureRequestedAndAllowed() | 665 bool MediaStreamDevicesController::IsDeviceAudioCaptureRequestedAndAllowed() |
| 604 const { | 666 const { |
| 605 MediaStreamTypeSettingsMap::const_iterator it = | 667 MediaStreamTypeSettingsMap::const_iterator it = |
| 606 request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); | 668 request_permissions_.find(content::MEDIA_DEVICE_AUDIO_CAPTURE); |
| 607 return (it != request_permissions_.end() && IsCaptureDeviceRequestAllowed() && | 669 return (it != request_permissions_.end() && IsCaptureDeviceRequestAllowed() && |
| 608 it->second.permission == MEDIA_ALLOWED); | 670 it->second.permission == MEDIA_ALLOWED); |
| 609 } | 671 } |
| 610 | 672 |
| 611 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed() | 673 bool MediaStreamDevicesController::IsDeviceVideoCaptureRequestedAndAllowed() |
| 612 const { | 674 const { |
| 613 MediaStreamTypeSettingsMap::const_iterator it = | 675 MediaStreamTypeSettingsMap::const_iterator it = |
| 614 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); | 676 request_permissions_.find(content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 615 return (it != request_permissions_.end() && IsCaptureDeviceRequestAllowed() && | 677 return (it != request_permissions_.end() && IsCaptureDeviceRequestAllowed() && |
| 616 it->second.permission == MEDIA_ALLOWED); | 678 it->second.permission == MEDIA_ALLOWED); |
| 617 } | 679 } |
| 618 | 680 |
| 619 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const { | 681 bool MediaStreamDevicesController::IsCaptureDeviceRequestAllowed() const { |
| 620 #if defined(OS_ANDROID) | 682 #if defined(OS_ANDROID) |
| 621 // Don't approve device requests if the tab was hidden. | 683 // Don't approve device requests if the tab was hidden. |
| 622 // TODO(qinmin): Add a test for this. http://crbug.com/396869. | 684 // TODO(qinmin): Add a test for this. http://crbug.com/396869. |
| 623 return web_contents_->GetRenderWidgetHostView()->IsShowing(); | 685 return web_contents_->GetRenderWidgetHostView()->IsShowing(); |
| 624 #endif | 686 #endif |
| 625 return true; | 687 return true; |
| 626 } | 688 } |
| OLD | NEW |