Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5718)

Unified Diff: chrome/browser/media/media_capture_devices_dispatcher.cc

Issue 585263002: Change two media request "invalid state" results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/media_capture_devices_dispatcher.cc
diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc
index def0efa240eadcec162d11fc3b25e436fe2ac12d..7982a8254fbd776bc013cbda1fb167dcb3ce8ff0 100644
--- a/chrome/browser/media/media_capture_devices_dispatcher.cc
+++ b/chrome/browser/media/media_capture_devices_dispatcher.cc
@@ -566,6 +566,14 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest(
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAllowHttpScreenCapture);
+ // If basic conditions (screen capturing is enabled and origin is secure)
+ // aren't fulfilled, we'll use "invalid state" as result. Otherwise, we set
+ // it after checking permission.
+ // TODO(grunell): It would be good to change this result for something else,
+ // probably a new one.
+ content::MediaStreamRequestResult result =
+ content::MEDIA_DEVICE_INVALID_STATE;
+
// Approve request only when the following conditions are met:
// 1. Screen capturing is enabled via command line switch or white-listed for
// the given origin.
@@ -626,14 +634,16 @@ void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest(
ui = GetDevicesForDesktopCapture(devices, screen_id, capture_audio,
display_notification, application_title,
application_title);
+ DCHECK(!devices.empty());
}
+
+ // The only case when devices can be empty is if the user has denied
+ // permission.
+ result = devices.empty() ? content::MEDIA_DEVICE_PERMISSION_DENIED
+ : content::MEDIA_DEVICE_OK;
}
- callback.Run(
- devices,
- devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE :
- content::MEDIA_DEVICE_OK,
- ui.Pass());
+ callback.Run(devices, result, ui.Pass());
}
void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest(
@@ -711,7 +721,21 @@ void MediaCaptureDevicesDispatcher::
content::MediaStreamDevices devices;
+ // Set an initial error result. If neither audio or video is allowed, we'll
+ // never try to get any device below but will just create |ui| and return an
+ // empty list with "invalid state" result. If at least one is allowed, we'll
+ // try to get device(s), and if failure, we want to return "no hardware"
+ // result.
+ // TODO(grunell): The invalid state result should be changed to a new denied
+ // result + a dcheck to ensure at least one of audio or video types is
+ // capture.
+ content::MediaStreamRequestResult result =
+ (audio_allowed || video_allowed) ? content::MEDIA_DEVICE_NO_HARDWARE
+ : content::MEDIA_DEVICE_INVALID_STATE;
+
// Get the exact audio or video device if an id is specified.
+ // We only set any error result here and before running the callback change
+ // it to OK if we have any device.
if (audio_allowed && !request.requested_audio_device_id.empty()) {
const content::MediaStreamDevice* audio_device =
GetRequestedAudioDevice(request.requested_audio_device_id);
@@ -742,14 +766,12 @@ void MediaCaptureDevicesDispatcher::
scoped_ptr<content::MediaStreamUI> ui;
if (!devices.empty()) {
+ result = content::MEDIA_DEVICE_OK;
ui = media_stream_capture_indicator_->RegisterMediaStream(
web_contents, devices);
}
- callback.Run(
- devices,
- devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE :
- content::MEDIA_DEVICE_OK,
- ui.Pass());
+
+ callback.Run(devices, result, ui.Pass());
}
void MediaCaptureDevicesDispatcher::ProcessRegularMediaAccessRequest(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698