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 "android_webview/native/permission/media_access_permission_request.h" | |
6 | |
7 #include "android_webview/native/permission/aw_permission_request.h" | |
8 #include "content/public/browser/media_capture_devices.h" | |
9 | |
10 using content::MediaCaptureDevices; | |
11 using content::MediaStreamDevice; | |
12 using content::MediaStreamDevices; | |
13 | |
14 namespace android_webview { | |
15 | |
16 namespace { | |
17 | |
18 // Finds a device in |devices| that has |device_id|, or NULL if not found. | |
19 const content::MediaStreamDevice* FindDeviceById( | |
20 const MediaStreamDevices& devices, | |
21 const std::string& device_id) { | |
22 MediaStreamDevices::const_iterator iter = devices.begin(); | |
23 for (; iter != devices.end(); ++iter) { | |
24 if (iter->id == device_id) { | |
25 return &(*iter); | |
26 } | |
27 } | |
28 return NULL; | |
29 }; | |
30 | |
31 } // namespace | |
32 | |
33 MediaAccessPermissionRequest::MediaAccessPermissionRequest( | |
34 const content::MediaStreamRequest& request, | |
35 const content::MediaResponseCallback& callback) | |
36 : request_(request), | |
37 callback_(callback) { | |
38 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); | |
benm (inactive)
2014/04/16 14:51:10
Should we store the result? And why not video too?
michaelbai
2014/04/22 20:53:51
Sorry, we don't need this, removed.
On 2014/04/16
| |
39 } | |
40 | |
41 MediaAccessPermissionRequest::~MediaAccessPermissionRequest() { | |
42 } | |
43 | |
44 void MediaAccessPermissionRequest::OnRequestResult(bool allowed) { | |
45 scoped_ptr<content::MediaStreamUI> ui; | |
46 MediaStreamDevices devices; | |
47 if (!allowed) { | |
48 callback_.Run(devices, content::MEDIA_DEVICE_PERMISSION_DENIED, ui.Pass()); | |
49 return; | |
50 } | |
51 | |
52 if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { | |
53 const MediaStreamDevices& audio_devices = | |
54 MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); | |
55 if (!audio_devices.empty()) { | |
mkosiba (inactive)
2014/04/17 10:34:06
nit: early return would be cleaner
michaelbai
2014/04/22 20:53:51
Can't early return here, as video_devices might no
| |
56 bool audio_device_found = false; | |
57 if (!request_.requested_audio_device_id.empty()) { | |
58 const MediaStreamDevice* audio_device = FindDeviceById( | |
59 audio_devices, request_.requested_audio_device_id); | |
60 if (audio_device != NULL) { | |
61 devices.push_back(*audio_device); | |
62 audio_device_found = true; | |
63 } | |
64 } | |
65 if (!audio_device_found) | |
mkosiba (inactive)
2014/04/17 10:34:06
could you explain why this is desired?
michaelbai
2014/04/22 20:53:51
The device id in request is optional, clank choose
| |
66 devices.push_back(audio_devices[0]); | |
67 } | |
68 } | |
69 | |
70 if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { | |
71 const MediaStreamDevices& video_devices = | |
72 MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); | |
73 if (!video_devices.empty()) { | |
74 bool video_device_found = false; | |
75 if (!request_.requested_video_device_id.empty()) { | |
mkosiba (inactive)
2014/04/17 10:34:06
maybe encapsulate this into a findByIdOrGetFirst f
michaelbai
2014/04/22 20:53:51
Done.
| |
76 const MediaStreamDevice* video_device = FindDeviceById( | |
77 video_devices, request_.requested_video_device_id); | |
78 if (video_device != NULL) { | |
79 devices.push_back(*video_device); | |
80 video_device_found = true; | |
81 } | |
82 } | |
83 if (!video_device_found) | |
84 devices.push_back(video_devices[0]); | |
85 } | |
86 } | |
87 callback_.Run(devices, devices.empty() ? | |
88 content::MEDIA_DEVICE_NO_HARDWARE : content::MEDIA_DEVICE_OK, | |
89 ui.Pass()); | |
90 } | |
91 | |
92 const GURL& MediaAccessPermissionRequest::GetOrigin() { | |
93 return request_.security_origin; | |
94 } | |
95 | |
96 int64 MediaAccessPermissionRequest::GetResources() { | |
97 return (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ? | |
98 AwPermissionRequest::AudioCapture : 0) | | |
99 (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE ? | |
100 AwPermissionRequest::VideoCapture : 0); | |
101 } | |
102 | |
103 } // namespace android_webview | |
OLD | NEW |