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> |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 137 |
| 138 render_process_id_ = render_frame_host->GetProcess()->GetID(); | 138 render_process_id_ = render_frame_host->GetProcess()->GetID(); |
| 139 render_frame_id_ = render_frame_host->GetRoutingID(); | 139 render_frame_id_ = render_frame_host->GetRoutingID(); |
| 140 DVLOG(2) << "PresentationServiceImpl: " | 140 DVLOG(2) << "PresentationServiceImpl: " |
| 141 << render_process_id_ << ", " << render_frame_id_; | 141 << render_process_id_ << ", " << render_frame_id_; |
| 142 if (delegate_) | 142 if (delegate_) |
| 143 delegate_->AddObserver(render_process_id_, render_frame_id_, this); | 143 delegate_->AddObserver(render_process_id_, render_frame_id_, this); |
| 144 } | 144 } |
| 145 | 145 |
| 146 PresentationServiceImpl::~PresentationServiceImpl() { | 146 PresentationServiceImpl::~PresentationServiceImpl() { |
| 147 DVLOG(2) << "~PresentationServiceImpl: " << render_process_id_ << ", " | |
| 148 << render_frame_id_; | |
| 147 if (delegate_) | 149 if (delegate_) |
| 148 delegate_->RemoveObserver(render_process_id_, render_frame_id_); | 150 delegate_->RemoveObserver(render_process_id_, render_frame_id_); |
| 149 } | 151 } |
| 150 | 152 |
| 151 // static | 153 // static |
| 152 void PresentationServiceImpl::CreateMojoService( | 154 void PresentationServiceImpl::CreateMojoService( |
| 153 RenderFrameHost* render_frame_host, | 155 RenderFrameHost* render_frame_host, |
| 154 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { | 156 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { |
| 155 DVLOG(2) << "CreateMojoService"; | 157 DVLOG(2) << "CreateMojoService"; |
| 156 WebContents* web_contents = | 158 WebContents* web_contents = |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 171 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { | 173 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { |
| 172 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( | 174 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( |
| 173 this, std::move(request))); | 175 this, std::move(request))); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void PresentationServiceImpl::SetClient( | 178 void PresentationServiceImpl::SetClient( |
| 177 blink::mojom::PresentationServiceClientPtr client) { | 179 blink::mojom::PresentationServiceClientPtr client) { |
| 178 DCHECK(!client_.get()); | 180 DCHECK(!client_.get()); |
| 179 // TODO(imcheng): Set ErrorHandler to listen for errors. | 181 // TODO(imcheng): Set ErrorHandler to listen for errors. |
| 180 client_ = std::move(client); | 182 client_ = std::move(client); |
| 183 | |
| 184 if (delegate_) { | |
|
imcheng
2016/09/28 07:28:37
1) We might as well call these in the PSImpl const
zhaobin
2016/09/29 17:20:44
1) RegisterReceiverAvailableCallback() invokes dis
| |
| 185 delegate_->RegisterReceiverAvailableCallback( | |
| 186 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable, | |
| 187 weak_factory_.GetWeakPtr())); | |
| 188 delegate_->RegisterOffscreenPresentationClient(render_process_id_, | |
| 189 render_frame_id_, this); | |
| 190 } | |
| 181 } | 191 } |
| 182 | 192 |
| 183 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { | 193 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { |
| 184 DVLOG(2) << "ListenForScreenAvailability " << url; | 194 DVLOG(2) << "ListenForScreenAvailability " << url; |
| 185 if (!delegate_) { | 195 if (!delegate_) { |
| 186 client_->OnScreenAvailabilityUpdated(url, false); | 196 client_->OnScreenAvailabilityUpdated(url, false); |
| 187 return; | 197 return; |
| 188 } | 198 } |
| 189 | 199 |
| 190 if (screen_availability_listeners_.count(url.spec())) | 200 if (screen_availability_listeners_.count(url.spec())) |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 430 } |
| 421 } | 431 } |
| 422 | 432 |
| 423 void PresentationServiceImpl::CloseConnection( | 433 void PresentationServiceImpl::CloseConnection( |
| 424 const GURL& presentation_url, | 434 const GURL& presentation_url, |
| 425 const std::string& presentation_id) { | 435 const std::string& presentation_id) { |
| 426 DVLOG(2) << "CloseConnection " << presentation_id; | 436 DVLOG(2) << "CloseConnection " << presentation_id; |
| 427 if (delegate_) | 437 if (delegate_) |
| 428 delegate_->CloseConnection(render_process_id_, render_frame_id_, | 438 delegate_->CloseConnection(render_process_id_, render_frame_id_, |
| 429 presentation_id); | 439 presentation_id); |
| 440 | |
| 441 for (const auto& iter : offscreen_presentation_observers_) | |
|
imcheng
2016/09/28 07:28:37
This probably doesn't make sense until we have ext
zhaobin
2016/09/29 17:20:44
code removed in new patch
| |
| 442 iter->RemoveOffscreenPresentationClient(this); | |
| 443 offscreen_presentation_observers_.clear(); | |
| 430 } | 444 } |
| 431 | 445 |
| 432 void PresentationServiceImpl::Terminate(const GURL& presentation_url, | 446 void PresentationServiceImpl::Terminate(const GURL& presentation_url, |
| 433 const std::string& presentation_id) { | 447 const std::string& presentation_id) { |
| 434 DVLOG(2) << "Terminate " << presentation_id; | 448 DVLOG(2) << "Terminate " << presentation_id; |
| 435 if (delegate_) | 449 if (delegate_) |
| 436 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); | 450 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); |
| 437 } | 451 } |
| 438 | 452 |
| 439 void PresentationServiceImpl::OnConnectionStateChanged( | 453 void PresentationServiceImpl::OnConnectionStateChanged( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 std::transform(messages.begin(), messages.end(), mojo_messages.begin(), | 499 std::transform(messages.begin(), messages.end(), mojo_messages.begin(), |
| 486 [pass_ownership](PresentationSessionMessage* message) { | 500 [pass_ownership](PresentationSessionMessage* message) { |
| 487 return ToMojoSessionMessage(message, pass_ownership); | 501 return ToMojoSessionMessage(message, pass_ownership); |
| 488 }); | 502 }); |
| 489 | 503 |
| 490 client_->OnSessionMessagesReceived( | 504 client_->OnSessionMessagesReceived( |
| 491 blink::mojom::PresentationSessionInfo::From(session), | 505 blink::mojom::PresentationSessionInfo::From(session), |
| 492 std::move(mojo_messages)); | 506 std::move(mojo_messages)); |
| 493 } | 507 } |
| 494 | 508 |
| 509 void PresentationServiceImpl::OnReceiverConnectionAvailable( | |
| 510 const content::PresentationSessionInfo& session_info, | |
| 511 OffscreenPresentationClient* controller) { | |
| 512 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; | |
| 513 client_->OnReceiverConnectionAvailable( | |
| 514 blink::mojom::PresentationSessionInfo::From(session_info)); | |
| 515 | |
| 516 controller->SetOffscreenPresentationClient(this); | |
| 517 this->SetOffscreenPresentationClient(controller); | |
| 518 } | |
| 519 | |
| 520 void PresentationServiceImpl::SetOffscreenPresentationClient( | |
| 521 OffscreenPresentationClient* client) { | |
| 522 offscreen_presentation_observers_.insert(client); | |
| 523 } | |
| 524 | |
| 525 void PresentationServiceImpl::RemoveOffscreenPresentationClient( | |
| 526 OffscreenPresentationClient* client) { | |
| 527 offscreen_presentation_observers_.erase(client); | |
| 528 } | |
| 529 | |
| 495 void PresentationServiceImpl::DidNavigateAnyFrame( | 530 void PresentationServiceImpl::DidNavigateAnyFrame( |
| 496 content::RenderFrameHost* render_frame_host, | 531 content::RenderFrameHost* render_frame_host, |
| 497 const content::LoadCommittedDetails& details, | 532 const content::LoadCommittedDetails& details, |
| 498 const content::FrameNavigateParams& params) { | 533 const content::FrameNavigateParams& params) { |
| 499 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 534 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
| 500 if (!FrameMatches(render_frame_host)) | 535 if (!FrameMatches(render_frame_host)) |
| 501 return; | 536 return; |
| 502 | 537 |
| 503 std::string prev_url_host = details.previous_url.host(); | 538 std::string prev_url_host = details.previous_url.host(); |
| 504 std::string curr_url_host = params.url.host(); | 539 std::string curr_url_host = params.url.host(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 mojo::Array<blink::mojom::SessionMessagePtr>()); | 589 mojo::Array<blink::mojom::SessionMessagePtr>()); |
| 555 on_session_messages_callback_.reset(); | 590 on_session_messages_callback_.reset(); |
| 556 } | 591 } |
| 557 | 592 |
| 558 if (send_message_callback_) { | 593 if (send_message_callback_) { |
| 559 // Run the callback with false, indicating the renderer to stop sending | 594 // Run the callback with false, indicating the renderer to stop sending |
| 560 // the requests and invalidate all pending requests. | 595 // the requests and invalidate all pending requests. |
| 561 send_message_callback_->Run(false); | 596 send_message_callback_->Run(false); |
| 562 send_message_callback_.reset(); | 597 send_message_callback_.reset(); |
| 563 } | 598 } |
| 599 | |
| 600 for (const auto& iter : offscreen_presentation_observers_) | |
| 601 iter->RemoveOffscreenPresentationClient(this); | |
| 602 | |
| 603 offscreen_presentation_observers_.clear(); | |
| 564 } | 604 } |
| 565 | 605 |
| 566 void PresentationServiceImpl::OnDelegateDestroyed() { | 606 void PresentationServiceImpl::OnDelegateDestroyed() { |
| 567 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 607 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
| 568 delegate_ = nullptr; | 608 delegate_ = nullptr; |
| 569 Reset(); | 609 Reset(); |
| 570 } | 610 } |
| 571 | 611 |
| 572 void PresentationServiceImpl::OnDefaultPresentationStarted( | 612 void PresentationServiceImpl::OnDefaultPresentationStarted( |
| 573 const PresentationSessionInfo& connection) { | 613 const PresentationSessionInfo& connection) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 | 660 |
| 621 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( | 661 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( |
| 622 blink::mojom::PresentationSessionInfoPtr session, | 662 blink::mojom::PresentationSessionInfoPtr session, |
| 623 blink::mojom::PresentationErrorPtr error) { | 663 blink::mojom::PresentationErrorPtr error) { |
| 624 DCHECK(!callback_.is_null()); | 664 DCHECK(!callback_.is_null()); |
| 625 callback_.Run(std::move(session), std::move(error)); | 665 callback_.Run(std::move(session), std::move(error)); |
| 626 callback_.Reset(); | 666 callback_.Reset(); |
| 627 } | 667 } |
| 628 | 668 |
| 629 } // namespace content | 669 } // namespace content |
| OLD | NEW |