OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 | 241 |
242 return label; | 242 return label; |
243 } | 243 } |
244 | 244 |
245 std::string MediaStreamManager::GenerateStreamForDevice( | 245 std::string MediaStreamManager::GenerateStreamForDevice( |
246 MediaStreamRequester* requester, int render_process_id, int render_view_id, | 246 MediaStreamRequester* requester, int render_process_id, int render_view_id, |
247 const StreamOptions& options, const std::string& device_id, | 247 const StreamOptions& options, const std::string& device_id, |
248 const GURL& security_origin) { | 248 const GURL& security_origin) { |
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
250 | 250 |
251 int target_render_process_id = -1; | |
252 int target_render_view_id = -1; | |
253 // We will post the request to the target render view, not the source (i.e. | |
254 // source is an extension, and target is the tab we want to capture). | |
255 bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
no longer working on chromium
2012/12/07 15:56:39
How about doing an early return with a std::string
justinlin
2012/12/07 15:59:53
I considered that, but is that safe to do? If we d
no longer working on chromium
2012/12/07 16:06:07
It sounds wrong since the requests can fail on cre
justinlin
2012/12/07 17:06:39
OK, changed it to match the CL you just sent. This
| |
256 device_id, &target_render_process_id, &target_render_view_id); | |
257 | |
251 // Create a new request based on options. | 258 // Create a new request based on options. |
252 DeviceRequest* request = new DeviceRequest(requester, options, | 259 DeviceRequest* request = new DeviceRequest(requester, options, |
253 DeviceRequest::GENERATE_STREAM, | 260 DeviceRequest::GENERATE_STREAM, |
254 render_process_id, | 261 target_render_process_id, |
255 render_view_id, | 262 target_render_view_id, |
256 security_origin); | 263 security_origin); |
257 const std::string& label = AddRequest(request); | 264 const std::string& label = AddRequest(request); |
258 request->requested_device_id = device_id; | 265 request->requested_device_id = device_id; |
259 | 266 |
260 // Get user confirmation to use the capture device. | 267 // Get user confirmation to use the capture device. |
261 PostRequestToUI(label); | 268 PostRequestToUI(label); |
262 | 269 |
263 if (!security_origin.SchemeIs(kExtensionScheme) || | 270 if (!has_valid_device_id || |
271 !security_origin.SchemeIs(kExtensionScheme) || | |
264 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | 272 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && |
265 options.audio_type != MEDIA_NO_SERVICE) || | 273 options.audio_type != MEDIA_NO_SERVICE) || |
266 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && | 274 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && |
267 options.video_type != MEDIA_NO_SERVICE)) { | 275 options.video_type != MEDIA_NO_SERVICE)) { |
268 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; | 276 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; |
269 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 277 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
270 base::Bind(&MediaStreamManager::CancelRequest, | 278 base::Bind(&MediaStreamManager::CancelRequest, |
271 base::Unretained(this), label)); | 279 base::Unretained(this), label)); |
272 return label; | 280 return label; |
273 } | 281 } |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 return; | 860 return; |
853 } | 861 } |
854 | 862 |
855 // Process all newly-accepted devices for this request. | 863 // Process all newly-accepted devices for this request. |
856 DeviceRequest* request = request_it->second; | 864 DeviceRequest* request = request_it->second; |
857 bool found_audio = false, found_video = false; | 865 bool found_audio = false, found_video = false; |
858 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); | 866 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); |
859 device_it != devices.end(); ++device_it) { | 867 device_it != devices.end(); ++device_it) { |
860 StreamDeviceInfo device_info = *device_it; // Make a copy. | 868 StreamDeviceInfo device_info = *device_it; // Make a copy. |
861 | 869 |
870 // TODO(justinlin): Nicer way to do this? | |
871 // Re-append the device_id since we lost it when posting request to UI. | |
872 if (device_info.stream_type == content::MEDIA_TAB_VIDEO_CAPTURE || | |
873 device_info.stream_type == content::MEDIA_TAB_AUDIO_CAPTURE) | |
874 device_info.device_id = request->requested_device_id; | |
875 | |
862 // Set in_use to false to be able to track if this device has been | 876 // Set in_use to false to be able to track if this device has been |
863 // opened. in_use might be true if the device type can be used in more | 877 // opened. in_use might be true if the device type can be used in more |
864 // than one session. | 878 // than one session. |
865 DCHECK_EQ(request->getState(device_it->stream_type), | 879 DCHECK_EQ(request->getState(device_it->stream_type), |
866 MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 880 MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
867 device_info.in_use = false; | 881 device_info.in_use = false; |
868 | 882 |
869 device_info.session_id = | 883 device_info.session_id = |
870 GetDeviceManager(device_info.stream_type)->Open(device_info); | 884 GetDeviceManager(device_info.stream_type)->Open(device_info); |
871 request->setState(device_it->stream_type, MEDIA_REQUEST_STATE_OPENING); | 885 request->setState(device_it->stream_type, MEDIA_REQUEST_STATE_OPENING); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 ui_controller_.reset(); | 944 ui_controller_.reset(); |
931 } | 945 } |
932 | 946 |
933 void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { | 947 void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { |
934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
935 MediaStreamDevices opened_devices; | 949 MediaStreamDevices opened_devices; |
936 DevicesFromRequest(request, &opened_devices); | 950 DevicesFromRequest(request, &opened_devices); |
937 if (opened_devices.empty()) | 951 if (opened_devices.empty()) |
938 return; | 952 return; |
939 | 953 |
940 int target_render_process_id = request.render_process_id; | 954 NotifyUIDevicesOpened(request.render_process_id, |
941 int target_render_view_id = request.render_view_id; | 955 request.render_view_id, |
942 | |
943 // For tab capture requests, we should notify the UI to update the renderer | |
944 // that is the target of the capture instead of the requester. | |
945 if (request.options.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || | |
946 request.options.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { | |
947 if (!WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
948 request.requested_device_id, | |
949 &target_render_process_id, | |
950 &target_render_view_id)) | |
951 return; | |
952 } | |
953 | |
954 NotifyUIDevicesOpened(target_render_process_id, | |
955 target_render_view_id, | |
956 opened_devices); | 956 opened_devices); |
957 } | 957 } |
958 | 958 |
959 void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { | 959 void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { |
960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
961 MediaStreamDevices closed_devices; | 961 MediaStreamDevices closed_devices; |
962 DevicesFromRequest(request, &closed_devices); | 962 DevicesFromRequest(request, &closed_devices); |
963 if (closed_devices.empty()) | 963 if (closed_devices.empty()) |
964 return; | 964 return; |
965 | 965 |
966 int target_render_process_id = request.render_process_id; | 966 NotifyUIDevicesClosed(request.render_process_id, |
967 int target_render_view_id = request.render_view_id; | 967 request.render_view_id, |
968 | |
969 // For tab capture requests, we should notify the UI to update the renderer | |
970 // that is the target of the capture instead of the requester. | |
971 if (request.options.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || | |
972 request.options.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { | |
973 if (!WebContentsCaptureUtil::ExtractTabCaptureTarget( | |
974 request.requested_device_id, | |
975 &target_render_process_id, | |
976 &target_render_view_id)) | |
977 return; | |
978 } | |
979 | |
980 NotifyUIDevicesClosed(target_render_process_id, | |
981 target_render_view_id, | |
982 closed_devices); | 968 closed_devices); |
983 } | 969 } |
984 | 970 |
985 void MediaStreamManager::DevicesFromRequest( | 971 void MediaStreamManager::DevicesFromRequest( |
986 const DeviceRequest& request, MediaStreamDevices* devices) { | 972 const DeviceRequest& request, MediaStreamDevices* devices) { |
987 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); | 973 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); |
988 it != request.devices.end(); ++it) { | 974 it != request.devices.end(); ++it) { |
989 devices->push_back(MediaStreamDevice( | 975 devices->push_back(MediaStreamDevice( |
990 it->stream_type, it->device_id, it->name)); | 976 it->stream_type, it->device_id, it->name)); |
991 } | 977 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 } | 1067 } |
1082 | 1068 |
1083 // Always do enumeration even though some enumeration is in progress, | 1069 // Always do enumeration even though some enumeration is in progress, |
1084 // because those enumeration commands could be sent before these devices | 1070 // because those enumeration commands could be sent before these devices |
1085 // change. | 1071 // change. |
1086 ++active_enumeration_ref_count_[stream_type]; | 1072 ++active_enumeration_ref_count_[stream_type]; |
1087 GetDeviceManager(stream_type)->EnumerateDevices(); | 1073 GetDeviceManager(stream_type)->EnumerateDevices(); |
1088 } | 1074 } |
1089 | 1075 |
1090 } // namespace content | 1076 } // namespace content |
OLD | NEW |