Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/presentation/presentation_service_impl.h" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "content/browser/frame_host/frame_tree_node.h" | |
| 15 #include "content/browser/frame_host/render_frame_host_impl.h" | |
| 14 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/browser/navigation_handle.h" | 17 #include "content/public/browser/navigation_handle.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 17 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/common/content_client.h" | 21 #include "content/public/common/content_client.h" |
| 20 #include "content/public/common/frame_navigate_params.h" | 22 #include "content/public/common/frame_navigate_params.h" |
| 21 #include "content/public/common/presentation_connection_message.h" | 23 #include "content/public/common/presentation_connection_message.h" |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 52 controller_delegate_(controller_delegate), | 54 controller_delegate_(controller_delegate), |
| 53 receiver_delegate_(receiver_delegate), | 55 receiver_delegate_(receiver_delegate), |
| 54 start_presentation_request_id_(kInvalidRequestId), | 56 start_presentation_request_id_(kInvalidRequestId), |
| 55 weak_factory_(this) { | 57 weak_factory_(this) { |
| 56 DCHECK(render_frame_host); | 58 DCHECK(render_frame_host); |
| 57 DCHECK(web_contents); | 59 DCHECK(web_contents); |
| 58 CHECK(render_frame_host->IsRenderFrameLive()); | 60 CHECK(render_frame_host->IsRenderFrameLive()); |
| 59 | 61 |
| 60 render_process_id_ = render_frame_host->GetProcess()->GetID(); | 62 render_process_id_ = render_frame_host->GetProcess()->GetID(); |
| 61 render_frame_id_ = render_frame_host->GetRoutingID(); | 63 render_frame_id_ = render_frame_host->GetRoutingID(); |
| 62 DVLOG(2) << "PresentationServiceImpl: " | 64 auto* rfh_impl = static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 63 << render_process_id_ << ", " << render_frame_id_; | 65 is_main_frame_ = rfh_impl->frame_tree_node()->IsMainFrame(); |
|
ncarter (slow)
2017/06/23 19:49:01
I forgot -- you can do this without the cast by ju
ncarter (slow)
2017/06/23 19:49:33
(no parent means yes main frame)
zhaobin
2017/06/23 21:34:12
Done.
| |
| 66 | |
| 67 DVLOG(2) << "PresentationServiceImpl: " << render_process_id_ << ", " | |
| 68 << render_frame_id_ << " is main frame: " << is_main_frame_; | |
| 64 | 69 |
| 65 if (auto* delegate = GetPresentationServiceDelegate()) | 70 if (auto* delegate = GetPresentationServiceDelegate()) |
| 66 delegate->AddObserver(render_process_id_, render_frame_id_, this); | 71 delegate->AddObserver(render_process_id_, render_frame_id_, this); |
| 67 } | 72 } |
| 68 | 73 |
| 69 PresentationServiceImpl::~PresentationServiceImpl() { | 74 PresentationServiceImpl::~PresentationServiceImpl() { |
| 70 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", " | 75 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", " |
| 71 << render_frame_id_; | 76 << render_frame_id_; |
| 72 | 77 |
| 73 if (auto* delegate = GetPresentationServiceDelegate()) | 78 if (auto* delegate = GetPresentationServiceDelegate()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( | 112 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( |
| 108 this, std::move(request))); | 113 this, std::move(request))); |
| 109 } | 114 } |
| 110 | 115 |
| 111 void PresentationServiceImpl::SetClient( | 116 void PresentationServiceImpl::SetClient( |
| 112 blink::mojom::PresentationServiceClientPtr client) { | 117 blink::mojom::PresentationServiceClientPtr client) { |
| 113 DCHECK(!client_.get()); | 118 DCHECK(!client_.get()); |
| 114 // TODO(imcheng): Set ErrorHandler to listen for errors. | 119 // TODO(imcheng): Set ErrorHandler to listen for errors. |
| 115 client_ = std::move(client); | 120 client_ = std::move(client); |
| 116 | 121 |
| 117 if (receiver_delegate_) { | 122 if (receiver_delegate_ && is_main_frame_) { |
| 118 receiver_delegate_->RegisterReceiverConnectionAvailableCallback( | 123 receiver_delegate_->RegisterReceiverConnectionAvailableCallback( |
| 119 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable, | 124 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable, |
| 120 weak_factory_.GetWeakPtr())); | 125 weak_factory_.GetWeakPtr())); |
| 121 } | 126 } |
| 122 } | 127 } |
| 123 | 128 |
| 124 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { | 129 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { |
| 125 DVLOG(2) << "ListenForScreenAvailability " << url.spec(); | 130 DVLOG(2) << "ListenForScreenAvailability " << url.spec(); |
| 126 if (!controller_delegate_) { | 131 if (!controller_delegate_) { |
| 127 client_->OnScreenAvailabilityUpdated( | 132 client_->OnScreenAvailabilityUpdated( |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 LOG(ERROR) << "PresentationServiceImpl is being deleted in " | 426 LOG(ERROR) << "PresentationServiceImpl is being deleted in " |
| 422 << "WebContentsDestroyed()! This shouldn't happen since it " | 427 << "WebContentsDestroyed()! This shouldn't happen since it " |
| 423 << "should've been deleted during RenderFrameDeleted()."; | 428 << "should've been deleted during RenderFrameDeleted()."; |
| 424 Reset(); | 429 Reset(); |
| 425 delete this; | 430 delete this; |
| 426 } | 431 } |
| 427 | 432 |
| 428 void PresentationServiceImpl::Reset() { | 433 void PresentationServiceImpl::Reset() { |
| 429 DVLOG(2) << "PresentationServiceImpl::Reset"; | 434 DVLOG(2) << "PresentationServiceImpl::Reset"; |
| 430 | 435 |
| 431 if (auto* delegate = GetPresentationServiceDelegate()) | 436 if (controller_delegate_) |
| 432 delegate->Reset(render_process_id_, render_frame_id_); | 437 controller_delegate_->Reset(render_process_id_, render_frame_id_); |
| 438 | |
| 439 if (receiver_delegate_ && is_main_frame_) | |
| 440 receiver_delegate_->Reset(render_process_id_, render_frame_id_); | |
| 433 | 441 |
| 434 default_presentation_urls_.clear(); | 442 default_presentation_urls_.clear(); |
| 435 | 443 |
| 436 screen_availability_listeners_.clear(); | 444 screen_availability_listeners_.clear(); |
| 437 | 445 |
| 438 start_presentation_request_id_ = kInvalidRequestId; | 446 start_presentation_request_id_ = kInvalidRequestId; |
| 439 pending_start_presentation_cb_.reset(); | 447 pending_start_presentation_cb_.reset(); |
| 440 | 448 |
| 441 pending_reconnect_presentation_cbs_.clear(); | 449 pending_reconnect_presentation_cbs_.clear(); |
| 442 } | 450 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 } | 497 } |
| 490 | 498 |
| 491 void PresentationServiceImpl::NewPresentationCallbackWrapper::Run( | 499 void PresentationServiceImpl::NewPresentationCallbackWrapper::Run( |
| 492 const base::Optional<PresentationInfo>& presentation_info, | 500 const base::Optional<PresentationInfo>& presentation_info, |
| 493 const base::Optional<PresentationError>& error) { | 501 const base::Optional<PresentationError>& error) { |
| 494 DCHECK(!callback_.is_null()); | 502 DCHECK(!callback_.is_null()); |
| 495 std::move(callback_).Run(presentation_info, error); | 503 std::move(callback_).Run(presentation_info, error); |
| 496 } | 504 } |
| 497 | 505 |
| 498 } // namespace content | 506 } // namespace content |
| OLD | NEW |