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

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

Issue 405483003: Respect device ids in handling requests from extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 136139a4d68ce254809c377c010face81becb097..c2a599d194ade33c4ee32d31e3a098b7b60a7db1 100644
--- a/chrome/browser/media/media_capture_devices_dispatcher.cc
+++ b/chrome/browser/media/media_capture_devices_dispatcher.cc
@@ -585,20 +585,52 @@ void MediaCaptureDevicesDispatcher::
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback,
const extensions::Extension* extension) {
- content::MediaStreamDevices devices;
- Profile* profile =
- Profile::FromBrowserContext(web_contents->GetBrowserContext());
- if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE &&
+ // TODO(vrk): This code is largely duplicated in
+ // MediaStreamDevicesController::Accept(). Move this code into a shared method
+ // between the two classes.
+
+ bool audio_allowed =
+ request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE &&
extension->permissions_data()->HasAPIPermission(
- extensions::APIPermission::kAudioCapture)) {
- GetDefaultDevicesForProfile(profile, true, false, &devices);
+ extensions::APIPermission::kAudioCapture);
+ bool video_allowed =
+ request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
+ extension->permissions_data()->HasAPIPermission(
+ extensions::APIPermission::kVideoCapture);
+
+ bool get_default_audio_device = audio_allowed;
+ bool get_default_video_device = video_allowed;
+
+ content::MediaStreamDevices devices;
+
+ // Get the exact audio or video device if an id is specified.
+ if (audio_allowed && !request.requested_audio_device_id.empty()) {
+ const content::MediaStreamDevice* audio_device =
+ GetRequestedAudioDevice(request.requested_audio_device_id);
+ if (audio_device) {
+ devices.push_back(*audio_device);
+ get_default_audio_device = false;
+ }
+ }
+ if (video_allowed && !request.requested_video_device_id.empty()) {
+ const content::MediaStreamDevice* video_device =
+ GetRequestedVideoDevice(request.requested_video_device_id);
+ if (video_device) {
+ devices.push_back(*video_device);
+ get_default_video_device = false;
+ }
}
- if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
- extension->permissions_data()->HasAPIPermission(
- extensions::APIPermission::kVideoCapture)) {
- GetDefaultDevicesForProfile(profile, false, true, &devices);
+ // If either or both audio and video devices were requested but not
+ // specified by id, get the default devices.
+ if (get_default_audio_device || get_default_video_device) {
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ GetDefaultDevicesForProfile(profile,
+ get_default_audio_device,
+ get_default_video_device,
+ &devices);
}
scoped_ptr<content::MediaStreamUI> ui;
« 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