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 24 matching lines...) Expand all Loading... |
35 // See also Chrome's MediaCaptureDevicesDispatcher. | 35 // See also Chrome's MediaCaptureDevicesDispatcher. |
36 void GrantMediaStreamRequest(content::WebContents* web_contents, | 36 void GrantMediaStreamRequest(content::WebContents* web_contents, |
37 const content::MediaStreamRequest& request, | 37 const content::MediaStreamRequest& request, |
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(); | |
46 | 45 |
47 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | 46 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 | 47 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( | 48 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( |
54 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), | 49 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), |
55 request.requested_audio_device_id); | 50 request.requested_audio_device_id); |
56 if (device) | 51 if (device) |
57 devices.push_back(*device); | 52 devices.push_back(*device); |
58 } | 53 } |
59 | 54 |
60 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | 55 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
61 // See APIPermission::kAudioCapture check above. | 56 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( | 57 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( |
66 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), | 58 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), |
67 request.requested_video_device_id); | 59 request.requested_video_device_id); |
68 if (device) | 60 if (device) |
69 devices.push_back(*device); | 61 devices.push_back(*device); |
70 } | 62 } |
71 | 63 |
72 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? | 64 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? |
73 scoped_ptr<MediaStreamUI> ui; | 65 scoped_ptr<MediaStreamUI> ui; |
74 callback.Run(devices, | 66 callback.Run(devices, |
75 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE | 67 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
76 : content::MEDIA_DEVICE_OK, | 68 : content::MEDIA_DEVICE_OK, |
77 ui.Pass()); | 69 ui.Pass()); |
78 } | 70 } |
79 | 71 |
| 72 void VerifyMediaAccessPermission(content::MediaStreamType type, |
| 73 const Extension* extension) { |
| 74 const PermissionsData* permissions_data = extension->permissions_data(); |
| 75 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 76 // app_shell has no UI surface to show an error, and on an embedded device |
| 77 // it's better to crash than to have a feature not work. |
| 78 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) |
| 79 << "Audio capture request but no audioCapture permission in manifest."; |
| 80 } else { |
| 81 DCHECK(type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 82 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) |
| 83 << "Video capture request but no videoCapture permission in manifest."; |
| 84 } |
| 85 } |
| 86 |
80 } // namespace media_capture_util | 87 } // namespace media_capture_util |
81 } // namespace extensions | 88 } // namespace extensions |
OLD | NEW |