OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/renderer/media/webrtc/peer_connection_dependency_factory.h" | 5 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 // Copy the flag from Preference associated with this WebFrame. | 390 // Copy the flag from Preference associated with this WebFrame. |
391 P2PPortAllocator::Config port_config; | 391 P2PPortAllocator::Config port_config; |
392 | 392 |
393 // |media_permission| will be called to check mic/camera permission. If at | 393 // |media_permission| will be called to check mic/camera permission. If at |
394 // least one of them is granted, P2PPortAllocator is allowed to gather local | 394 // least one of them is granted, P2PPortAllocator is allowed to gather local |
395 // host IP addresses as ICE candidates. |media_permission| could be nullptr, | 395 // host IP addresses as ICE candidates. |media_permission| could be nullptr, |
396 // which means the permission will be granted automatically. This could be the | 396 // which means the permission will be granted automatically. This could be the |
397 // case when either the experiment is not enabled or the preference is not | 397 // case when either the experiment is not enabled or the preference is not |
398 // enforced. | 398 // enforced. |
399 scoped_ptr<media::MediaPermission> media_permission; | 399 // |
| 400 // Note on |media_permission| lifetime: |media_permission| is owned by a frame |
| 401 // (RenderFrameImpl). It is also stored as an indirect member of |
| 402 // RTCPeerConnectionHandler (through PeerConnection/PeerConnectionInterface -> |
| 403 // P2PPortAllocator -> FilteringNetworkManager -> |media_permission|). |
| 404 // The RTCPeerConnectionHandler is owned as RTCPeerConnection::m_peerHandler |
| 405 // in Blink, which will be reset in RTCPeerConnection::stop(). Since |
| 406 // ActiveDOMObject::stop() is guaranteed to be called before a frame is |
| 407 // detached, it is impossible for RTCPeerConnectionHandler to outlive the |
| 408 // frame. Therefore using a raw pointer of |media_permission| is safe here. |
| 409 media::MediaPermission* media_permission = nullptr; |
400 if (!GetContentClient() | 410 if (!GetContentClient() |
401 ->renderer() | 411 ->renderer() |
402 ->ShouldEnforceWebRTCRoutingPreferences()) { | 412 ->ShouldEnforceWebRTCRoutingPreferences()) { |
403 port_config.enable_multiple_routes = true; | 413 port_config.enable_multiple_routes = true; |
404 port_config.enable_nonproxied_udp = true; | 414 port_config.enable_nonproxied_udp = true; |
405 VLOG(3) << "WebRTC routing preferences will not be enforced"; | 415 VLOG(3) << "WebRTC routing preferences will not be enforced"; |
406 } else { | 416 } else { |
407 if (web_frame && web_frame->view()) { | 417 if (web_frame && web_frame->view()) { |
408 RenderViewImpl* renderer_view_impl = | 418 RenderViewImpl* renderer_view_impl = |
409 RenderViewImpl::FromWebView(web_frame->view()); | 419 RenderViewImpl::FromWebView(web_frame->view()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 base::CommandLine::ForCurrentProcess()->HasSwitch( | 456 base::CommandLine::ForCurrentProcess()->HasSwitch( |
447 switches::kEnforceWebRtcIPPermissionCheck); | 457 switches::kEnforceWebRtcIPPermissionCheck); |
448 create_media_permission = | 458 create_media_permission = |
449 create_media_permission || | 459 create_media_permission || |
450 StartsWith(base::FieldTrialList::FindFullName( | 460 StartsWith(base::FieldTrialList::FindFullName( |
451 "WebRTC-LocalIPPermissionCheck"), | 461 "WebRTC-LocalIPPermissionCheck"), |
452 "Enabled", base::CompareCase::SENSITIVE); | 462 "Enabled", base::CompareCase::SENSITIVE); |
453 if (create_media_permission) { | 463 if (create_media_permission) { |
454 content::RenderFrameImpl* render_frame = | 464 content::RenderFrameImpl* render_frame = |
455 content::RenderFrameImpl::FromWebFrame(web_frame); | 465 content::RenderFrameImpl::FromWebFrame(web_frame); |
456 if (render_frame) { | 466 if (render_frame) |
457 media_permission = render_frame->CreateMediaPermissionProxy( | 467 media_permission = render_frame->GetMediaPermission(); |
458 chrome_worker_thread_.task_runner()); | |
459 } | |
460 DCHECK(media_permission); | 468 DCHECK(media_permission); |
461 } | 469 } |
462 } | 470 } |
463 } | 471 } |
464 | 472 |
465 const GURL& requesting_origin = | 473 const GURL& requesting_origin = |
466 GURL(web_frame->document().url()).GetOrigin(); | 474 GURL(web_frame->document().url()).GetOrigin(); |
467 | 475 |
468 scoped_ptr<rtc::NetworkManager> network_manager; | 476 scoped_ptr<rtc::NetworkManager> network_manager; |
469 if (port_config.enable_multiple_routes) { | 477 if (port_config.enable_multiple_routes) { |
470 media::MediaPermission* media_permission_ptr = media_permission.get(); | |
471 FilteringNetworkManager* filtering_network_manager = | 478 FilteringNetworkManager* filtering_network_manager = |
472 new FilteringNetworkManager(network_manager_, requesting_origin, | 479 new FilteringNetworkManager(network_manager_, requesting_origin, |
473 std::move(media_permission)); | 480 media_permission); |
474 if (media_permission_ptr) { | 481 if (media_permission) { |
475 // Start permission check earlier to reduce any impact to call set up | 482 // Start permission check earlier to reduce any impact to call set up |
476 // time. It's safe to use Unretained here since both destructor and | 483 // time. It's safe to use Unretained here since both destructor and |
477 // Initialize can only be called on the worker thread. | 484 // Initialize can only be called on the worker thread. |
478 chrome_worker_thread_.task_runner()->PostTask( | 485 chrome_worker_thread_.task_runner()->PostTask( |
479 FROM_HERE, base::Bind(&FilteringNetworkManager::Initialize, | 486 FROM_HERE, base::Bind(&FilteringNetworkManager::Initialize, |
480 base::Unretained(filtering_network_manager))); | 487 base::Unretained(filtering_network_manager))); |
481 } | 488 } |
482 network_manager.reset(filtering_network_manager); | 489 network_manager.reset(filtering_network_manager); |
483 } else { | 490 } else { |
484 network_manager.reset(new EmptyNetworkManager(network_manager_)); | 491 network_manager.reset(new EmptyNetworkManager(network_manager_)); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 } | 781 } |
775 | 782 |
776 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { | 783 void PeerConnectionDependencyFactory::EnsureWebRtcAudioDeviceImpl() { |
777 if (audio_device_.get()) | 784 if (audio_device_.get()) |
778 return; | 785 return; |
779 | 786 |
780 audio_device_ = new WebRtcAudioDeviceImpl(); | 787 audio_device_ = new WebRtcAudioDeviceImpl(); |
781 } | 788 } |
782 | 789 |
783 } // namespace content | 790 } // namespace content |
OLD | NEW |