Chromium Code Reviews| Index: chrome/browser/media/webrtc/media_stream_devices_controller.cc |
| diff --git a/chrome/browser/media/webrtc/media_stream_devices_controller.cc b/chrome/browser/media/webrtc/media_stream_devices_controller.cc |
| index 3e10d38733c5840f7d4b0863188ca0c9c4a39b4a..79ad99acd8bc91f5adbcebc4d7949e259058f9eb 100644 |
| --- a/chrome/browser/media/webrtc/media_stream_devices_controller.cc |
| +++ b/chrome/browser/media/webrtc/media_stream_devices_controller.cc |
| @@ -15,6 +15,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| +#include "chrome/browser/media/webrtc/desktop_streams_registry.h" |
| #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| #include "chrome/browser/media/webrtc/media_permission.h" |
| #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| @@ -40,6 +41,7 @@ |
| #include "content/public/common/media_stream_request.h" |
| #include "content/public/common/origin_util.h" |
| #include "extensions/common/constants.h" |
| +#include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #if BUILDFLAG(ANDROID_JAVA_UI) |
| @@ -204,6 +206,10 @@ MediaStreamDevicesController::MediaStreamDevicesController( |
| web_contents, content_settings_types)) { |
| return; |
| } |
| + |
| + // Always show infobar for screen capture on Android. |
| + if (request.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) |
| + return; |
| #endif |
| // Otherwise we can run the callback immediately. |
| @@ -245,12 +251,20 @@ bool MediaStreamDevicesController::IsAskingForVideo() const { |
| return old_video_setting_ == CONTENT_SETTING_ASK; |
| } |
| +bool MediaStreamDevicesController::IsAskingForScreenCapture() const { |
| + return request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE; |
| +} |
| + |
| base::string16 MediaStreamDevicesController::GetMessageText() const { |
| int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; |
| - if (!IsAskingForAudio()) |
| + if (IsAskingForScreenCapture()) { |
| + message_id = IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT; |
| + } else if (!IsAskingForAudio()) { |
| message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; |
| - else if (!IsAskingForVideo()) |
| + } else if (!IsAskingForVideo()) { |
| message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; |
| + } |
| + |
| return l10n_util::GetStringFUTF16( |
| message_id, |
| url_formatter::FormatUrlForSecurityDisplay( |
| @@ -290,21 +304,31 @@ GURL MediaStreamDevicesController::GetOrigin() const { |
| void MediaStreamDevicesController::PermissionGranted() { |
| RecordPermissionAction(request_, profile_, |
| base::Bind(PermissionUmaUtil::PermissionGranted)); |
| - RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| - old_audio_setting_, CONTENT_SETTING_ALLOW), |
| - GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| - old_video_setting_, CONTENT_SETTING_ALLOW), |
| - content::MEDIA_DEVICE_PERMISSION_DENIED); |
| + if (IsAskingForScreenCapture()) { |
| + RunCallback(old_audio_setting_, old_video_setting_, |
| + content::MEDIA_DEVICE_OK); |
| + } else { |
| + RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| + old_audio_setting_, CONTENT_SETTING_ALLOW), |
| + GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| + old_video_setting_, CONTENT_SETTING_ALLOW), |
| + content::MEDIA_DEVICE_PERMISSION_DENIED); |
| + } |
| } |
| void MediaStreamDevicesController::PermissionDenied() { |
| RecordPermissionAction(request_, profile_, |
| base::Bind(PermissionUmaUtil::PermissionDenied)); |
| - RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| - old_audio_setting_, CONTENT_SETTING_BLOCK), |
| - GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| - old_video_setting_, CONTENT_SETTING_BLOCK), |
| - content::MEDIA_DEVICE_PERMISSION_DENIED); |
| + if (IsAskingForScreenCapture()) { |
| + RunCallback(old_audio_setting_, old_video_setting_, |
| + content::MEDIA_DEVICE_PERMISSION_DENIED); |
| + } else { |
| + RunCallback(GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| + old_audio_setting_, CONTENT_SETTING_BLOCK), |
| + GetNewSetting(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| + old_video_setting_, CONTENT_SETTING_BLOCK), |
| + content::MEDIA_DEVICE_PERMISSION_DENIED); |
| + } |
| } |
| void MediaStreamDevicesController::GroupedRequestFinished(bool audio_accepted, |
| @@ -471,11 +495,21 @@ void MediaStreamDevicesController::RunCallback( |
| content::MediaStreamDevices devices = |
| GetDevices(audio_setting, video_setting); |
| - // If either audio or video are allowed then the callback should report |
| - // success, otherwise we report |denial_reason|. |
| content::MediaStreamRequestResult request_result = content::MEDIA_DEVICE_OK; |
| - if (audio_setting != CONTENT_SETTING_ALLOW && |
| - video_setting != CONTENT_SETTING_ALLOW) { |
| + if (IsAskingForScreenCapture()) { |
|
tsergeant
2016/09/13 05:06:23
My suggestion would be to avoid modifying media_st
braveyao
2016/09/15 21:29:31
Done.
|
| + request_result = denial_reason; |
| + if (request_result == content::MEDIA_DEVICE_OK) { |
| + content::DesktopMediaID screen_id; |
| + screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, |
| + webrtc::kFullDesktopScreenId); |
| + devices.push_back( |
| + content::MediaStreamDevice(content::MEDIA_DESKTOP_VIDEO_CAPTURE, |
| + screen_id.ToString(), "Screen")); |
| + } |
| + } else if (audio_setting != CONTENT_SETTING_ALLOW && |
| + video_setting != CONTENT_SETTING_ALLOW) { |
| + // If either audio or video are allowed then the callback should report |
| + // success, otherwise we report |denial_reason|. |
| DCHECK_NE(content::MEDIA_DEVICE_OK, denial_reason); |
| request_result = denial_reason; |
| } else if (devices.empty()) { |