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 12 matching lines...) Expand all Loading... |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "base/win/scoped_com_initializer.h" | 27 #include "base/win/scoped_com_initializer.h" |
28 #endif | 28 #endif |
29 | 29 |
30 using content::BrowserThread; | 30 using content::BrowserThread; |
31 using content::MediaStreamRequest; | 31 using content::MediaStreamRequest; |
32 | 32 |
33 namespace { | |
34 const char kExtensionScheme[] = "chrome-extension"; | |
35 } // namespace | |
36 | |
37 namespace media_stream { | 33 namespace media_stream { |
38 | 34 |
39 // Creates a random label used to identify requests. | 35 // Creates a random label used to identify requests. |
40 static std::string RandomLabel() { | 36 static std::string RandomLabel() { |
41 // An earlier PeerConnection spec, | 37 // An earlier PeerConnection spec, |
42 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the | 38 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the |
43 // MediaStream::label alphabet as containing 36 characters from | 39 // MediaStream::label alphabet as containing 36 characters from |
44 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, | 40 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, |
45 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. | 41 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. |
46 // Here we use a safe subset. | 42 // Here we use a safe subset. |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 237 |
242 // Get user confirmation to use the capture device. | 238 // Get user confirmation to use the capture device. |
243 device_settings_->RequestCaptureDeviceUsage(*label, | 239 device_settings_->RequestCaptureDeviceUsage(*label, |
244 render_process_id, | 240 render_process_id, |
245 render_view_id, | 241 render_view_id, |
246 options, | 242 options, |
247 security_origin); | 243 security_origin); |
248 | 244 |
249 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 245 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
250 switches::kEnableTabCapture) || | 246 switches::kEnableTabCapture) || |
251 !security_origin.SchemeIs(kExtensionScheme) || | |
252 (options.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE && | 247 (options.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE && |
253 options.audio_type != content::MEDIA_NO_SERVICE) || | 248 options.audio_type != content::MEDIA_NO_SERVICE) || |
254 (options.video_type != content::MEDIA_TAB_VIDEO_CAPTURE && | 249 (options.video_type != content::MEDIA_TAB_VIDEO_CAPTURE && |
255 options.video_type != content::MEDIA_NO_SERVICE)) { | 250 options.video_type != content::MEDIA_NO_SERVICE)) { |
256 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; | 251 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; |
257 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 252 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
258 base::Bind(&MediaStreamManager::CancelGenerateStream, | 253 base::Bind(&MediaStreamManager::CancelGenerateStream, |
259 base::Unretained(this), *label)); | 254 base::Unretained(this), *label)); |
260 return; | 255 return; |
261 } | 256 } |
262 | 257 |
263 // TODO(miu): We should ask the device manager whether a device with id | 258 // TODO(miu): We should ask the device manager whether a device with id |
264 // |device_id| actually exists. Note that no such MediaStreamProvider API for | 259 // |device_id| actually exists. Note that no such MediaStreamProvider API for |
265 // this currently exists. Also, we don't have a user-friendly device name for | 260 // this currently exists. Also, we don't have a user-friendly device name for |
266 // the infobar UI. | 261 // the infobar UI. |
267 StreamDeviceInfoArray devices; | |
268 if (content::IsAudioMediaType(options.audio_type)) { | 262 if (content::IsAudioMediaType(options.audio_type)) { |
269 // TODO(justinlin): Updating the state to requested and pending are no-ops | 263 // TODO(justinlin): Updating the state to requested and pending are no-ops |
270 // in terms of the media manager, but these are the state changes we want to | 264 // in terms of the media manager, but these are the state changes we want to |
271 // support in terms of extensions (which is registered as an observer). | 265 // support in terms of extensions (which is registered as an observer). |
272 request.setState(options.audio_type, | 266 request.setState(options.audio_type, |
273 content::MEDIA_REQUEST_STATE_REQUESTED); | 267 content::MEDIA_REQUEST_STATE_REQUESTED); |
274 request.setState(options.audio_type, | 268 request.setState(options.audio_type, |
275 content::MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 269 content::MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
276 devices.push_back( | 270 device_settings_->AvailableDevices( |
277 StreamDeviceInfo(options.audio_type, device_id, device_id, false)); | 271 *label, options.audio_type, StreamDeviceInfoArray( |
| 272 1, StreamDeviceInfo(options.audio_type, device_id, device_id, |
| 273 false))); |
278 } | 274 } |
279 if (content::IsVideoMediaType(options.video_type)) { | 275 if (content::IsVideoMediaType(options.video_type)) { |
280 request.setState(options.video_type, | 276 request.setState(options.video_type, |
281 content::MEDIA_REQUEST_STATE_REQUESTED); | 277 content::MEDIA_REQUEST_STATE_REQUESTED); |
282 request.setState(options.video_type, | 278 request.setState(options.video_type, |
283 content::MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 279 content::MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
284 devices.push_back( | 280 device_settings_->AvailableDevices( |
285 StreamDeviceInfo(options.video_type, device_id, device_id, false)); | 281 *label, options.video_type, StreamDeviceInfoArray( |
| 282 1, StreamDeviceInfo(options.video_type, device_id, device_id, |
| 283 false))); |
286 } | 284 } |
287 | |
288 // Bypass the user authorization dropdown for tab capture. | |
289 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
290 base::Bind(&MediaStreamManager::DevicesAccepted, | |
291 base::Unretained(this), *label, devices)); | |
292 } | 285 } |
293 | 286 |
294 void MediaStreamManager::CancelGenerateStream(const std::string& label) { | 287 void MediaStreamManager::CancelGenerateStream(const std::string& label) { |
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
296 | 289 |
297 DeviceRequests::iterator it = requests_.find(label); | 290 DeviceRequests::iterator it = requests_.find(label); |
298 if (it != requests_.end()) { | 291 if (it != requests_.end()) { |
299 // The request isn't complete. | 292 // The request isn't complete. |
300 if (!RequestDone(it->second)) { | 293 if (!RequestDone(it->second)) { |
301 DeviceRequest& request = it->second; | 294 DeviceRequest& request = it->second; |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 it != requests_.end(); ++it) { | 966 it != requests_.end(); ++it) { |
974 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && | 967 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && |
975 Requested(it->second.options, stream_type)) { | 968 Requested(it->second.options, stream_type)) { |
976 return true; | 969 return true; |
977 } | 970 } |
978 } | 971 } |
979 return false; | 972 return false; |
980 } | 973 } |
981 | 974 |
982 } // namespace media_stream | 975 } // namespace media_stream |
OLD | NEW |