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 #include "extensions/common/permissions/permissions_data.h" |
| 11 |
| 12 using content::MediaCaptureDevices; |
| 13 using content::MediaStreamDevices; |
| 14 using content::MediaStreamUI; |
| 15 |
| 16 namespace extensions { |
| 17 namespace media_capture_util { |
| 18 |
| 19 // See also Chrome's MediaCaptureDevicesDispatcher. |
| 20 void GrantMediaStreamRequestWithFirstDevice( |
| 21 content::WebContents* web_contents, |
| 22 const content::MediaStreamRequest& request, |
| 23 const content::MediaResponseCallback& callback, |
| 24 const Extension* extension) { |
| 25 // app_shell only supports audio and video capture, not tab or screen capture. |
| 26 DCHECK(request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 27 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 28 |
| 29 // app_shell does not support requesting a specific device ID. |
| 30 DCHECK(request.requested_audio_device_id.empty() && |
| 31 request.requested_video_device_id.empty()); |
| 32 |
| 33 MediaStreamDevices devices; |
| 34 const PermissionsData* permissions_data = extension->permissions_data(); |
| 35 |
| 36 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 37 // app_shell has no UI surface to show an error, and on an embedded device |
| 38 // it's better to crash than to have a feature not work. |
| 39 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) |
| 40 << "Audio capture request but no audioCapture permission in manifest."; |
| 41 |
| 42 // Use first available audio capture device. |
| 43 const MediaStreamDevices& audio_devices = |
| 44 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); |
| 45 if (!audio_devices.empty()) |
| 46 devices.push_back(audio_devices[0]); |
| 47 } |
| 48 |
| 49 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 50 // See APIPermission::kAudioCapture check above. |
| 51 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) |
| 52 << "Video capture request but no videoCapture permission in manifest."; |
| 53 |
| 54 // Use first available video capture device. |
| 55 const MediaStreamDevices& video_devices = |
| 56 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); |
| 57 if (!video_devices.empty()) |
| 58 devices.push_back(video_devices[0]); |
| 59 } |
| 60 |
| 61 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? |
| 62 scoped_ptr<MediaStreamUI> ui; |
| 63 callback.Run(devices, |
| 64 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
| 65 : content::MEDIA_DEVICE_OK, |
| 66 ui.Pass()); |
| 67 } |
| 68 |
| 69 } // namespace media_capture_util |
| 70 } // namespace extensions |
OLD | NEW |