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 // app_shell has no UI surface to show an error, and on an embedded device |
James Cook
2014/09/12 20:43:11
Why not call VerifyMediaAccessPermission(request.a
Henrik Grunell
2014/09/15 11:33:48
Yep, thanks, Done.
| |
49 // it's better to crash than to have a feature not work. | 49 // it's better to crash than to have a feature not work. |
50 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) | 50 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) |
51 << "Audio capture request but no audioCapture permission in manifest."; | 51 << "Audio capture request but no audioCapture permission in manifest."; |
52 | 52 |
53 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( | 53 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( |
54 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), | 54 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), |
55 request.requested_audio_device_id); | 55 request.requested_audio_device_id); |
56 if (device) | 56 if (device) |
57 devices.push_back(*device); | 57 devices.push_back(*device); |
58 } | 58 } |
59 | 59 |
60 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | 60 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
61 // See APIPermission::kAudioCapture check above. | 61 // See APIPermission::kAudioCapture check above. |
James Cook
2014/09/12 20:43:11
ditto for request.video_type here?
Henrik Grunell
2014/09/15 11:33:48
Done.
| |
62 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) | 62 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) |
63 << "Video capture request but no videoCapture permission in manifest."; | 63 << "Video capture request but no videoCapture permission in manifest."; |
64 | 64 |
65 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( | 65 const MediaStreamDevice* device = GetRequestedDeviceOrDefault( |
66 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), | 66 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), |
67 request.requested_video_device_id); | 67 request.requested_video_device_id); |
68 if (device) | 68 if (device) |
69 devices.push_back(*device); | 69 devices.push_back(*device); |
70 } | 70 } |
71 | 71 |
72 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? | 72 // TODO(jamescook): Should we show a recording icon somewhere? If so, where? |
73 scoped_ptr<MediaStreamUI> ui; | 73 scoped_ptr<MediaStreamUI> ui; |
74 callback.Run(devices, | 74 callback.Run(devices, |
75 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE | 75 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE |
76 : content::MEDIA_DEVICE_OK, | 76 : content::MEDIA_DEVICE_OK, |
77 ui.Pass()); | 77 ui.Pass()); |
78 } | 78 } |
79 | 79 |
80 void VerifyMediaAccessPermission(content::MediaStreamType type, | |
81 const Extension* extension) { | |
82 const PermissionsData* permissions_data = extension->permissions_data(); | |
83 if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
84 // app_shell has no UI surface to show an error, and on an embedded device | |
85 // it's better to crash than to have a feature not work. | |
86 CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) | |
87 << "Audio capture request but no audioCapture permission in manifest."; | |
88 } else { | |
89 DCHECK(type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
90 CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) | |
91 << "Video capture request but no videoCapture permission in manifest."; | |
92 } | |
93 } | |
94 | |
80 } // namespace media_capture_util | 95 } // namespace media_capture_util |
81 } // namespace extensions | 96 } // namespace extensions |
OLD | NEW |