| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/media/device_request_message_filter.h" | 5 #include "content/browser/renderer_host/media/device_request_message_filter.h" |
| 6 | 6 |
| 7 #include "content/browser/browser_main_loop.h" | 7 #include "content/browser/browser_main_loop.h" |
| 8 #include "content/browser/renderer_host/media/media_stream_manager.h" | 8 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 9 #include "content/common/media/media_stream_messages.h" | 9 #include "content/common/media/media_stream_messages.h" |
| 10 #include "content/public/browser/media_device_id.h" | |
| 11 #include "content/public/browser/resource_context.h" | 10 #include "content/public/browser/resource_context.h" |
| 12 | 11 |
| 13 // Clears the MediaStreamDevice.name from all devices in |device_list|. | 12 // Clears the MediaStreamDevice.name from all devices in |device_list|. |
| 14 static void ClearDeviceLabels(content::StreamDeviceInfoArray* devices) { | 13 static void ClearDeviceLabels(content::StreamDeviceInfoArray* devices) { |
| 15 for (content::StreamDeviceInfoArray::iterator device_itr = devices->begin(); | 14 for (content::StreamDeviceInfoArray::iterator device_itr = devices->begin(); |
| 16 device_itr != devices->end(); | 15 device_itr != devices->end(); |
| 17 ++device_itr) { | 16 ++device_itr) { |
| 18 device_itr->device.name.clear(); | 17 device_itr->device.name.clear(); |
| 19 } | 18 } |
| 20 } | 19 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 89 } |
| 91 DCHECK(request_it != requests_.end()); | 90 DCHECK(request_it != requests_.end()); |
| 92 | 91 |
| 93 StreamDeviceInfoArray* audio_devices = &request_it->audio_devices; | 92 StreamDeviceInfoArray* audio_devices = &request_it->audio_devices; |
| 94 StreamDeviceInfoArray* video_devices = &request_it->video_devices; | 93 StreamDeviceInfoArray* video_devices = &request_it->video_devices; |
| 95 | 94 |
| 96 // Store hmac'd device ids instead of raw device ids. | 95 // Store hmac'd device ids instead of raw device ids. |
| 97 if (label == request_it->audio_devices_label) { | 96 if (label == request_it->audio_devices_label) { |
| 98 request_it->has_audio_returned = true; | 97 request_it->has_audio_returned = true; |
| 99 DCHECK(audio_devices->empty()); | 98 DCHECK(audio_devices->empty()); |
| 100 HmacDeviceIds(request_it->origin, new_devices, audio_devices); | 99 *audio_devices = new_devices; |
| 101 } else { | 100 } else { |
| 102 DCHECK(label == request_it->video_devices_label); | 101 DCHECK(label == request_it->video_devices_label); |
| 103 request_it->has_video_returned = true; | 102 request_it->has_video_returned = true; |
| 104 DCHECK(video_devices->empty()); | 103 DCHECK(video_devices->empty()); |
| 105 HmacDeviceIds(request_it->origin, new_devices, video_devices); | 104 *video_devices = new_devices; |
| 106 } | 105 } |
| 107 | 106 |
| 108 if (!request_it->has_audio_returned || !request_it->has_video_returned) { | 107 if (!request_it->has_audio_returned || !request_it->has_video_returned) { |
| 109 // Wait for the rest of the devices to complete. | 108 // Wait for the rest of the devices to complete. |
| 110 return; | 109 return; |
| 111 } | 110 } |
| 112 | 111 |
| 113 // Query for mic and camera permissions. | 112 // Query for mic and camera permissions. |
| 114 if (!resource_context_->AllowMicAccess(request_it->origin)) | 113 if (!resource_context_->AllowMicAccess(request_it->origin)) |
| 115 ClearDeviceLabels(audio_devices); | 114 ClearDeviceLabels(audio_devices); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 144 return handled; | 143 return handled; |
| 145 } | 144 } |
| 146 | 145 |
| 147 void DeviceRequestMessageFilter::OnChannelClosing() { | 146 void DeviceRequestMessageFilter::OnChannelClosing() { |
| 148 // Since the IPC channel is gone, cancel outstanding device requests. | 147 // Since the IPC channel is gone, cancel outstanding device requests. |
| 149 media_stream_manager_->CancelAllRequests(peer_pid()); | 148 media_stream_manager_->CancelAllRequests(peer_pid()); |
| 150 | 149 |
| 151 requests_.clear(); | 150 requests_.clear(); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void DeviceRequestMessageFilter::HmacDeviceIds( | |
| 155 const GURL& origin, | |
| 156 const StreamDeviceInfoArray& raw_devices, | |
| 157 StreamDeviceInfoArray* devices_with_guids) { | |
| 158 DCHECK(devices_with_guids); | |
| 159 | |
| 160 // Replace raw ids with hmac'd ids before returning to renderer process. | |
| 161 for (StreamDeviceInfoArray::const_iterator device_itr = raw_devices.begin(); | |
| 162 device_itr != raw_devices.end(); | |
| 163 ++device_itr) { | |
| 164 StreamDeviceInfo current_device_info = *device_itr; | |
| 165 current_device_info.device.id = | |
| 166 content::GetHMACForMediaDeviceID(origin, device_itr->device.id); | |
| 167 devices_with_guids->push_back(current_device_info); | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 void DeviceRequestMessageFilter::OnGetSources(int request_id, | 153 void DeviceRequestMessageFilter::OnGetSources(int request_id, |
| 172 const GURL& security_origin) { | 154 const GURL& security_origin) { |
| 173 // Make request to get audio devices. | 155 // Make request to get audio devices. |
| 174 const std::string& audio_label = media_stream_manager_->EnumerateDevices( | 156 const std::string& audio_label = media_stream_manager_->EnumerateDevices( |
| 175 this, -1, -1, -1, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin); | 157 this, -1, -1, -1, MEDIA_DEVICE_AUDIO_CAPTURE, security_origin); |
| 176 DCHECK(!audio_label.empty()); | 158 DCHECK(!audio_label.empty()); |
| 177 | 159 |
| 178 // Make request for video devices. | 160 // Make request for video devices. |
| 179 const std::string& video_label = media_stream_manager_->EnumerateDevices( | 161 const std::string& video_label = media_stream_manager_->EnumerateDevices( |
| 180 this, -1, -1, -1, MEDIA_DEVICE_VIDEO_CAPTURE, security_origin); | 162 this, -1, -1, -1, MEDIA_DEVICE_VIDEO_CAPTURE, security_origin); |
| 181 DCHECK(!video_label.empty()); | 163 DCHECK(!video_label.empty()); |
| 182 | 164 |
| 183 requests_.push_back(DeviceRequest( | 165 requests_.push_back(DeviceRequest( |
| 184 request_id, security_origin, audio_label, video_label)); | 166 request_id, security_origin, audio_label, video_label)); |
| 185 } | 167 } |
| 186 | 168 |
| 187 } // namespace content | 169 } // namespace content |
| OLD | NEW |