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 9a867c301c00791fd34809f48f475edc0d427cda..cb0f2e664f9ef7034a428a30ed13384310738335 100644 |
| --- a/chrome/browser/media/webrtc/media_stream_devices_controller.cc |
| +++ b/chrome/browser/media/webrtc/media_stream_devices_controller.cc |
| @@ -8,6 +8,7 @@ |
| #include <utility> |
| #include "base/callback_helpers.h" |
| +#include "base/feature_list.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -23,7 +24,7 @@ |
| #include "chrome/browser/permissions/permission_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| -#include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/chrome_features.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "components/content_settings/core/browser/host_content_settings_map.h" |
| @@ -387,6 +388,29 @@ void MediaStreamDevicesController::PromptAnswered(ContentSetting setting, |
| RunCallback(); |
| } |
| +void MediaStreamDevicesController::PromptAnsweredGroupedRequest( |
| + const std::vector<ContentSetting>& response) { |
| + DCHECK(response.size() == 1 || response.size() == 2); |
| + |
| + // The audio setting will always be the first one in the vector, if it was |
| + // requested. |
| + if (audio_setting_ == CONTENT_SETTING_ASK) |
| + audio_setting_ = response.front(); |
| + |
| + if (video_setting_ == CONTENT_SETTING_ASK) |
| + video_setting_ = response.back(); |
| + |
| + if (audio_setting_ == CONTENT_SETTING_BLOCK || |
|
Timothy Loh
2017/04/24 04:18:57
Should this be an &&? Looks like RunCallback() wil
raymes
2017/04/26 00:10:30
We should only really be updating |denial_reason_|
Timothy Loh
2017/04/26 01:40:25
OK, sounds reasonable.
|
| + video_setting_ == CONTENT_SETTING_BLOCK) { |
| + denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| + } else if (audio_setting_ == CONTENT_SETTING_ASK || |
| + video_setting_ == CONTENT_SETTING_ASK) { |
| + denial_reason_ = content::MEDIA_DEVICE_PERMISSION_DISMISSED; |
| + } |
| + |
| + RunCallback(); |
| +} |
| + |
| #if defined(OS_ANDROID) |
| void MediaStreamDevicesController::AndroidOSPromptAnswered(bool allowed) { |
| DCHECK(audio_setting_ != CONTENT_SETTING_ASK && |
| @@ -416,10 +440,10 @@ void MediaStreamDevicesController::RequestPermissionsWithDelegate( |
| const content::MediaStreamRequest& request, |
| const content::MediaResponseCallback& callback, |
| PermissionPromptDelegate* delegate) { |
| + content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
| + request.render_process_id, request.render_frame_id); |
| content::WebContents* web_contents = |
| - content::WebContents::FromRenderFrameHost( |
| - content::RenderFrameHost::FromID(request.render_process_id, |
| - request.render_frame_id)); |
| + content::WebContents::FromRenderFrameHost(rfh); |
| if (request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { |
| MediaPermissionRequestLogger::LogRequest( |
| web_contents, request.render_process_id, request.render_frame_id, |
| @@ -433,13 +457,32 @@ void MediaStreamDevicesController::RequestPermissionsWithDelegate( |
| if (controller->IsAskingForAudio() || controller->IsAskingForVideo()) { |
| Profile* profile = |
| Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| - delegate->ShowPrompt( |
| - request.user_gesture, web_contents, |
| - base::MakeUnique<Request>( |
| - profile, controller->IsAskingForAudio(), |
| - controller->IsAskingForVideo(), request.security_origin, |
| - base::Bind(&MediaStreamDevicesController::PromptAnswered, |
| - base::Passed(&controller)))); |
| + if (base::FeatureList::IsEnabled( |
| + features::kUsePermissionManagerForMediaRequests)) { |
| + std::vector<ContentSettingsType> content_settings_types; |
| + |
| + if (controller->IsAskingForAudio()) |
| + content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| + if (controller->IsAskingForVideo()) { |
| + content_settings_types.push_back( |
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| + } |
| + |
| + PermissionManager::Get(profile)->RequestPermissions( |
| + content_settings_types, rfh, request.security_origin, |
| + request.user_gesture, |
| + base::Bind( |
| + &MediaStreamDevicesController::PromptAnsweredGroupedRequest, |
| + base::Passed(&controller))); |
| + } else { |
| + delegate->ShowPrompt( |
| + request.user_gesture, web_contents, |
| + base::MakeUnique<Request>( |
| + profile, controller->IsAskingForAudio(), |
| + controller->IsAskingForVideo(), request.security_origin, |
| + base::Bind(&MediaStreamDevicesController::PromptAnswered, |
| + base::Passed(&controller)))); |
| + } |
| return; |
| } |