| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/shell/browser/media_capture_util.h" | 5 #include "extensions/shell/browser/media_capture_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 const content::MediaResponseCallback& callback, | 38 const content::MediaResponseCallback& callback, |
| 39 const Extension* extension) { | 39 const Extension* extension) { |
| 40 // app_shell only supports audio and video capture, not tab or screen capture. | 40 // app_shell only supports audio and video capture, not tab or screen capture. |
| 41 DCHECK(request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 41 DCHECK(request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 42 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 42 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 43 | 43 |
| 44 MediaStreamDevices devices; | 44 MediaStreamDevices devices; |
| 45 const PermissionsData* permissions_data = extension->permissions_data(); | 45 const PermissionsData* permissions_data = extension->permissions_data(); |
| 46 | 46 |
| 47 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | 47 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 48 // app_shell has no UI surface to show an error, and on an embedded device | 48 VerifyMediaAccessPermission(request.audio_type, extension); |
| 49 // it's better to crash than to have a feature not work. | |
| 50 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) | |
| 51 << "Audio capture request but no audioCapture permission in manifest."; | |
| 52 | |
| 53 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( | 49 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( |
| 54 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), | 50 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), |
| 55 request.requested_audio_device_id); | 51 request.requested_audio_device_id); |
| 56 if (device) | 52 if (device) |
| 57 devices.push_back(*device); | 53 devices.push_back(*device); |
| 58 } | 54 } |
| 59 | 55 |
| 60 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | 56 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 61 // See APIPermission::kAudioCapture check above. | 57 VerifyMediaAccessPermission(request.video_type, extension); |
| 62 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) | |
| 63 << "Video capture request but no videoCapture permission in manifest."; | |
| 64 | |
| 65 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( | 58 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( |
| 66 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), | 59 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), |
| 67 request.requested_video_device_id); | 60 request.requested_video_device_id); |
| 68 if (device) | 61 if (device) |
| 69 devices.push_back(*device); | 62 devices.push_back(*device); |
| 70 } | 63 } |
| 71 | 64 |
| 72 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? | 65 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? |
| 73 scoped_ptr<MediaStreamUI> ui; | 66 scoped_ptr<MediaStreamUI> ui; |
| 74 callback.Run(devices, | 67 callback.Run(devices, |
| 75 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE | 68 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
| 76 : content::MEDIA_DEVICE_OK, | 69 : content::MEDIA_DEVICE_OK, |
| 77 ui.Pass()); | 70 ui.Pass()); |
| 78 } | 71 } |
| 79 | 72 |
| 73 void VerifyMediaAccessPermission(content::MediaStreamType type, |
| 74 const Extension* extension) { |
| 75 const PermissionsData* permissions_data = extension->permissions_data(); |
| 76 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 77 // app_shell has no UI surface to show an error, and on an embedded device |
| 78 // it's better to crash than to have a feature not work. |
| 79 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) |
| 80 << "Audio capture request but no audioCapture permission in manifest."; |
| 81 } else { |
| 82 DCHECK(type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 83 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) |
| 84 << "Video capture request but no videoCapture permission in manifest."; |
| 85 } |
| 86 } |
| 87 |
| 80 } // namespace media_capture_util | 88 } // namespace media_capture_util |
| 81 } // namespace extensions | 89 } // namespace extensions |
| OLD | NEW |