Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "extensions/shell/browser/media_capture_util.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "content/public/browser/media_capture_devices.h" | |
| 10 | |
| 11 using content::MediaCaptureDevices; | |
| 12 using content::MediaStreamDevices; | |
| 13 using content::MediaStreamUI; | |
| 14 | |
| 15 namespace extensions { | |
| 16 namespace media_capture_util { | |
| 17 | |
| 18 // See also Chrome's MediaCaptureDevicesDispatcher. | |
|
James Cook
2014/08/20 18:17:16
I looked at refactoring MediaCaptureDevicesDispatc
| |
| 19 void GrantMediaStreamRequestWithFirstDevice( | |
| 20 content::WebContents* web_contents, | |
| 21 const content::MediaStreamRequest& request, | |
| 22 const content::MediaResponseCallback& callback) { | |
| 23 // app_shell only supports audio and video capture, not tab or screen capture. | |
| 24 DCHECK(request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | |
| 25 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
| 26 | |
| 27 // app_shell does not support requesting a specific device ID. | |
| 28 DCHECK(request.requested_audio_device_id.empty() && | |
| 29 request.requested_video_device_id.empty()); | |
| 30 | |
| 31 MediaStreamDevices devices; | |
| 32 | |
| 33 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
| 34 // Use first available audio capture device. | |
| 35 const MediaStreamDevices& audio_devices = | |
| 36 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); | |
| 37 if (!audio_devices.empty()) | |
| 38 devices.push_back(audio_devices[0]); | |
| 39 } | |
| 40 | |
| 41 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | |
| 42 // Use first available video capture device. | |
| 43 const MediaStreamDevices& video_devices = | |
| 44 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); | |
| 45 if (!video_devices.empty()) | |
| 46 devices.push_back(video_devices[0]); | |
| 47 } | |
| 48 | |
| 49 // Don't show UI. | |
| 50 scoped_ptr<MediaStreamUI> ui; | |
| 51 callback.Run(devices, | |
| 52 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE | |
| 53 : content::MEDIA_DEVICE_OK, | |
| 54 ui.Pass()); | |
| 55 } | |
| 56 | |
| 57 } // namespace media_capture_util | |
| 58 } // namespace extensions | |
| OLD | NEW |