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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // several subclasses of DeviceRequest and move some of the responsibility of | 166 // several subclasses of DeviceRequest and move some of the responsibility of |
167 // the MediaStreamManager to the subclasses to get rid of the way too many if | 167 // the MediaStreamManager to the subclasses to get rid of the way too many if |
168 // statements in MediaStreamManager. | 168 // statements in MediaStreamManager. |
169 class MediaStreamManager::DeviceRequest { | 169 class MediaStreamManager::DeviceRequest { |
170 public: | 170 public: |
171 DeviceRequest(MediaStreamRequester* requester, | 171 DeviceRequest(MediaStreamRequester* requester, |
172 int requesting_process_id, | 172 int requesting_process_id, |
173 int requesting_view_id, | 173 int requesting_view_id, |
174 int page_request_id, | 174 int page_request_id, |
175 const GURL& security_origin, | 175 const GURL& security_origin, |
| 176 bool user_gesture, |
176 MediaStreamRequestType request_type, | 177 MediaStreamRequestType request_type, |
177 const StreamOptions& options, | 178 const StreamOptions& options, |
178 const ResourceContext::SaltCallback& salt_callback) | 179 const ResourceContext::SaltCallback& salt_callback) |
179 : requester(requester), | 180 : requester(requester), |
180 requesting_process_id(requesting_process_id), | 181 requesting_process_id(requesting_process_id), |
181 requesting_view_id(requesting_view_id), | 182 requesting_view_id(requesting_view_id), |
182 page_request_id(page_request_id), | 183 page_request_id(page_request_id), |
183 security_origin(security_origin), | 184 security_origin(security_origin), |
| 185 user_gesture(user_gesture), |
184 request_type(request_type), | 186 request_type(request_type), |
185 options(options), | 187 options(options), |
186 salt_callback(salt_callback), | 188 salt_callback(salt_callback), |
187 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), | 189 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), |
188 audio_type_(MEDIA_NO_SERVICE), | 190 audio_type_(MEDIA_NO_SERVICE), |
189 video_type_(MEDIA_NO_SERVICE) { | 191 video_type_(MEDIA_NO_SERVICE) { |
190 } | 192 } |
191 | 193 |
192 ~DeviceRequest() {} | 194 ~DeviceRequest() {} |
193 | 195 |
(...skipping 13 matching lines...) Expand all Loading... |
207 | 209 |
208 // Creates a MediaStreamRequest object that is used by this request when UI | 210 // Creates a MediaStreamRequest object that is used by this request when UI |
209 // is asked for permission and device selection. | 211 // is asked for permission and device selection. |
210 void CreateUIRequest(const std::string& requested_audio_device_id, | 212 void CreateUIRequest(const std::string& requested_audio_device_id, |
211 const std::string& requested_video_device_id) { | 213 const std::string& requested_video_device_id) { |
212 DCHECK(!ui_request_); | 214 DCHECK(!ui_request_); |
213 ui_request_.reset(new MediaStreamRequest(requesting_process_id, | 215 ui_request_.reset(new MediaStreamRequest(requesting_process_id, |
214 requesting_view_id, | 216 requesting_view_id, |
215 page_request_id, | 217 page_request_id, |
216 security_origin, | 218 security_origin, |
| 219 user_gesture, |
217 request_type, | 220 request_type, |
218 requested_audio_device_id, | 221 requested_audio_device_id, |
219 requested_video_device_id, | 222 requested_video_device_id, |
220 audio_type_, | 223 audio_type_, |
221 video_type_)); | 224 video_type_)); |
222 } | 225 } |
223 | 226 |
224 // Creates a tab capture specific MediaStreamRequest object that is used by | 227 // Creates a tab capture specific MediaStreamRequest object that is used by |
225 // this request when UI is asked for permission and device selection. | 228 // this request when UI is asked for permission and device selection. |
226 void CreateTabCatureUIRequest(int target_render_process_id, | 229 void CreateTabCatureUIRequest(int target_render_process_id, |
227 int target_render_view_id, | 230 int target_render_view_id, |
228 const std::string& tab_capture_id) { | 231 const std::string& tab_capture_id) { |
229 DCHECK(!ui_request_); | 232 DCHECK(!ui_request_); |
230 ui_request_.reset(new MediaStreamRequest(target_render_process_id, | 233 ui_request_.reset(new MediaStreamRequest(target_render_process_id, |
231 target_render_view_id, | 234 target_render_view_id, |
232 page_request_id, | 235 page_request_id, |
233 security_origin, | 236 security_origin, |
| 237 user_gesture, |
234 request_type, | 238 request_type, |
235 "", | 239 "", |
236 "", | 240 "", |
237 audio_type_, | 241 audio_type_, |
238 video_type_)); | 242 video_type_)); |
239 ui_request_->tab_capture_device_id = tab_capture_id; | 243 ui_request_->tab_capture_device_id = tab_capture_id; |
240 } | 244 } |
241 | 245 |
242 const MediaStreamRequest* UIRequest() const { return ui_request_.get(); } | 246 const MediaStreamRequest* UIRequest() const { return ui_request_.get(); } |
243 | 247 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // will receive a handle to the MediaStream. This may be different from | 296 // will receive a handle to the MediaStream. This may be different from |
293 // MediaStreamRequest::render_view_id which in the tab capture case | 297 // MediaStreamRequest::render_view_id which in the tab capture case |
294 // specifies the target renderer from which audio and video is captured. | 298 // specifies the target renderer from which audio and video is captured. |
295 const int requesting_view_id; | 299 const int requesting_view_id; |
296 | 300 |
297 // An ID the render view provided to identify this request. | 301 // An ID the render view provided to identify this request. |
298 const int page_request_id; | 302 const int page_request_id; |
299 | 303 |
300 const GURL security_origin; | 304 const GURL security_origin; |
301 | 305 |
| 306 const bool user_gesture; |
| 307 |
302 const MediaStreamRequestType request_type; | 308 const MediaStreamRequestType request_type; |
303 | 309 |
304 const StreamOptions options; | 310 const StreamOptions options; |
305 | 311 |
306 ResourceContext::SaltCallback salt_callback; | 312 ResourceContext::SaltCallback salt_callback; |
307 | 313 |
308 StreamDeviceInfoArray devices; | 314 StreamDeviceInfoArray devices; |
309 | 315 |
310 // Callback to the requester which audio/video devices have been selected. | 316 // Callback to the requester which audio/video devices have been selected. |
311 // It can be null if the requester has no interest to know the result. | 317 // It can be null if the requester has no interest to know the result. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 const MediaRequestResponseCallback& callback) { | 388 const MediaRequestResponseCallback& callback) { |
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
384 | 390 |
385 // TODO(perkj): The argument list with NULL parameters to DeviceRequest | 391 // TODO(perkj): The argument list with NULL parameters to DeviceRequest |
386 // suggests that this is the wrong design. Can this be refactored? | 392 // suggests that this is the wrong design. Can this be refactored? |
387 DeviceRequest* request = new DeviceRequest(NULL, | 393 DeviceRequest* request = new DeviceRequest(NULL, |
388 render_process_id, | 394 render_process_id, |
389 render_view_id, | 395 render_view_id, |
390 page_request_id, | 396 page_request_id, |
391 security_origin, | 397 security_origin, |
| 398 false, // user gesture |
392 MEDIA_DEVICE_ACCESS, | 399 MEDIA_DEVICE_ACCESS, |
393 options, | 400 options, |
394 base::Bind(&ReturnEmptySalt)); | 401 base::Bind(&ReturnEmptySalt)); |
395 | 402 |
396 const std::string& label = AddRequest(request); | 403 const std::string& label = AddRequest(request); |
397 | 404 |
398 request->callback = callback; | 405 request->callback = callback; |
399 // Post a task and handle the request asynchronously. The reason is that the | 406 // Post a task and handle the request asynchronously. The reason is that the |
400 // requester won't have a label for the request until this function returns | 407 // requester won't have a label for the request until this function returns |
401 // and thus can not handle a response. Using base::Unretained is safe since | 408 // and thus can not handle a response. Using base::Unretained is safe since |
402 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 409 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
403 // been stopped. | 410 // been stopped. |
404 BrowserThread::PostTask( | 411 BrowserThread::PostTask( |
405 BrowserThread::IO, FROM_HERE, | 412 BrowserThread::IO, FROM_HERE, |
406 base::Bind(&MediaStreamManager::SetupRequest, | 413 base::Bind(&MediaStreamManager::SetupRequest, |
407 base::Unretained(this), label)); | 414 base::Unretained(this), label)); |
408 return label; | 415 return label; |
409 } | 416 } |
410 | 417 |
411 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, | 418 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, |
412 int render_process_id, | 419 int render_process_id, |
413 int render_view_id, | 420 int render_view_id, |
414 const ResourceContext::SaltCallback& sc, | 421 const ResourceContext::SaltCallback& sc, |
415 int page_request_id, | 422 int page_request_id, |
416 const StreamOptions& options, | 423 const StreamOptions& options, |
417 const GURL& security_origin) { | 424 const GURL& security_origin, |
| 425 bool user_gesture) { |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
419 DVLOG(1) << "GenerateStream()"; | 427 DVLOG(1) << "GenerateStream()"; |
420 if (CommandLine::ForCurrentProcess()->HasSwitch( | 428 if (CommandLine::ForCurrentProcess()->HasSwitch( |
421 switches::kUseFakeUIForMediaStream)) { | 429 switches::kUseFakeUIForMediaStream)) { |
422 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 430 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
423 } | 431 } |
424 | 432 |
425 DeviceRequest* request = new DeviceRequest(requester, | 433 DeviceRequest* request = new DeviceRequest(requester, |
426 render_process_id, | 434 render_process_id, |
427 render_view_id, | 435 render_view_id, |
428 page_request_id, | 436 page_request_id, |
429 security_origin, | 437 security_origin, |
| 438 user_gesture, |
430 MEDIA_GENERATE_STREAM, | 439 MEDIA_GENERATE_STREAM, |
431 options, | 440 options, |
432 sc); | 441 sc); |
433 | 442 |
434 const std::string& label = AddRequest(request); | 443 const std::string& label = AddRequest(request); |
435 | 444 |
436 // Post a task and handle the request asynchronously. The reason is that the | 445 // Post a task and handle the request asynchronously. The reason is that the |
437 // requester won't have a label for the request until this function returns | 446 // requester won't have a label for the request until this function returns |
438 // and thus can not handle a response. Using base::Unretained is safe since | 447 // and thus can not handle a response. Using base::Unretained is safe since |
439 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 448 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
613 DCHECK(requester); | 622 DCHECK(requester); |
614 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 623 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
615 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 624 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
616 | 625 |
617 DeviceRequest* request = new DeviceRequest(requester, | 626 DeviceRequest* request = new DeviceRequest(requester, |
618 render_process_id, | 627 render_process_id, |
619 render_view_id, | 628 render_view_id, |
620 page_request_id, | 629 page_request_id, |
621 security_origin, | 630 security_origin, |
| 631 false, // user gesture |
622 MEDIA_ENUMERATE_DEVICES, | 632 MEDIA_ENUMERATE_DEVICES, |
623 StreamOptions(), | 633 StreamOptions(), |
624 sc); | 634 sc); |
625 if (IsAudioMediaType(type)) | 635 if (IsAudioMediaType(type)) |
626 request->SetAudioType(type); | 636 request->SetAudioType(type); |
627 else if (IsVideoMediaType(type)) | 637 else if (IsVideoMediaType(type)) |
628 request->SetVideoType(type); | 638 request->SetVideoType(type); |
629 | 639 |
630 const std::string& label = AddRequest(request); | 640 const std::string& label = AddRequest(request); |
631 // Post a task and handle the request asynchronously. The reason is that the | 641 // Post a task and handle the request asynchronously. The reason is that the |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 options.mandatory_video.push_back( | 701 options.mandatory_video.push_back( |
692 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 702 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
693 } else { | 703 } else { |
694 NOTREACHED(); | 704 NOTREACHED(); |
695 } | 705 } |
696 DeviceRequest* request = new DeviceRequest(requester, | 706 DeviceRequest* request = new DeviceRequest(requester, |
697 render_process_id, | 707 render_process_id, |
698 render_view_id, | 708 render_view_id, |
699 page_request_id, | 709 page_request_id, |
700 security_origin, | 710 security_origin, |
| 711 false, // user gesture |
701 MEDIA_OPEN_DEVICE, | 712 MEDIA_OPEN_DEVICE, |
702 options, | 713 options, |
703 sc); | 714 sc); |
704 | 715 |
705 const std::string& label = AddRequest(request); | 716 const std::string& label = AddRequest(request); |
706 // Post a task and handle the request asynchronously. The reason is that the | 717 // Post a task and handle the request asynchronously. The reason is that the |
707 // requester won't have a label for the request until this function returns | 718 // requester won't have a label for the request until this function returns |
708 // and thus can not handle a response. Using base::Unretained is safe since | 719 // and thus can not handle a response. Using base::Unretained is safe since |
709 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 720 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
710 // been stopped. | 721 // been stopped. |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 1892 if (it->device.type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
1882 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, | 1893 video_capture_manager_->SetDesktopCaptureWindowId(it->session_id, |
1883 window_id); | 1894 window_id); |
1884 break; | 1895 break; |
1885 } | 1896 } |
1886 } | 1897 } |
1887 } | 1898 } |
1888 } | 1899 } |
1889 | 1900 |
1890 } // namespace content | 1901 } // namespace content |
OLD | NEW |