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 using content::MediaCaptureDevices; | |
no longer working on chromium
2014/08/22 19:22:27
nit, add an empty line before using content::Media
James Cook
2014/08/22 20:11:00
Oops, done.
| |
12 using content::MediaStreamDevices; | |
13 using content::MediaStreamUI; | |
14 | |
15 namespace extensions { | |
16 namespace media_capture_util { | |
17 | |
18 // See also Chrome's MediaCaptureDevicesDispatcher. | |
19 void GrantMediaStreamRequestWithFirstDevice( | |
20 content::WebContents* web_contents, | |
21 const content::MediaStreamRequest& request, | |
22 const content::MediaResponseCallback& callback, | |
23 const Extension* extension) { | |
24 // app_shell only supports audio and video capture, not tab or screen capture. | |
25 DCHECK(request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | |
26 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | |
27 | |
28 // app_shell does not support requesting a specific device ID. | |
29 DCHECK(request.requested_audio_device_id.empty() && | |
30 request.requested_video_device_id.empty()); | |
31 | |
32 MediaStreamDevices devices; | |
33 const PermissionsData* permissions_data = extension->permissions_data(); | |
34 | |
35 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
36 if (permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) { | |
no longer working on chromium
2014/08/22 19:22:26
If I understand your comment correctly, app_shell
James Cook
2014/08/22 20:11:00
Yes, I think a CHECK here is better. Done.
| |
37 const MediaStreamDevices& audio_devices = | |
38 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); | |
39 // Use first available audio capture device. | |
40 if (!audio_devices.empty()) | |
41 devices.push_back(audio_devices[0]); | |
42 } else { | |
43 // app_shell has no UI surface to show the error, so log it. | |
44 LOG(WARNING) << "Audio capture request but no audioCapture permission."; | |
45 } | |
46 } | |
47 | |
48 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | |
49 if (permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) { | |
50 const MediaStreamDevices& video_devices = | |
51 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); | |
52 // Use first available video capture device. | |
53 if (!video_devices.empty()) | |
54 devices.push_back(video_devices[0]); | |
55 } else { | |
56 // app_shell has no UI surface to show the error, so log it. | |
57 LOG(WARNING) << "Video capture request but no videoCapture permission."; | |
58 } | |
59 } | |
60 | |
61 // Don't show UI. | |
62 scoped_ptr<MediaStreamUI> ui; | |
63 callback.Run(devices, | |
no longer working on chromium
2014/08/22 19:22:26
Just FTR, for a website, Chrome will show some not
James Cook
2014/08/22 20:11:00
Yeah, unfortunately we don't have a good UI surfac
| |
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 |