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 // It will invoke onReceiverConnectionAvailable callback | |
| 185 // on receiver frame (associated with ReceiverPSDImpl); | |
| 186 // It does nothing on controller frame. | |
| 187 if (delegate_) | |
| 188 delegate_->RegisterOffscreenPresentationReceiver(this); | |
|
imcheng
2016/09/19 23:01:17
I have a few concerns with this approach:
1) We a
zhaobin
2016/09/23 17:18:18
Acknowledged.
| |
| 181 } | 189 } |
| 182 | 190 |
| 183 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { | 191 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { |
| 184 DVLOG(2) << "ListenForScreenAvailability " << url; | 192 DVLOG(2) << "ListenForScreenAvailability " << url; |
| 185 if (!delegate_) { | 193 if (!delegate_) { |
| 186 client_->OnScreenAvailabilityUpdated(url, false); | 194 client_->OnScreenAvailabilityUpdated(url, false); |
| 187 return; | 195 return; |
| 188 } | 196 } |
| 189 | 197 |
| 190 if (screen_availability_listeners_.count(url.spec())) | 198 if (screen_availability_listeners_.count(url.spec())) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 if (request_session_id != start_session_request_id_) | 320 if (request_session_id != start_session_request_id_) |
| 313 return; | 321 return; |
| 314 | 322 |
| 315 CHECK(pending_start_session_cb_.get()); | 323 CHECK(pending_start_session_cb_.get()); |
| 316 pending_start_session_cb_->Run( | 324 pending_start_session_cb_->Run( |
| 317 blink::mojom::PresentationSessionInfo::From(session_info), | 325 blink::mojom::PresentationSessionInfo::From(session_info), |
| 318 blink::mojom::PresentationErrorPtr()); | 326 blink::mojom::PresentationErrorPtr()); |
| 319 ListenForConnectionStateChange(session_info); | 327 ListenForConnectionStateChange(session_info); |
| 320 pending_start_session_cb_.reset(); | 328 pending_start_session_cb_.reset(); |
| 321 start_session_request_id_ = kInvalidRequestSessionId; | 329 start_session_request_id_ = kInvalidRequestSessionId; |
| 330 | |
| 331 if (delegate_) | |
| 332 delegate_->RegisterOffscreenPresentationController( | |
| 333 session_info.presentation_id, this); | |
| 322 } | 334 } |
| 323 | 335 |
| 324 void PresentationServiceImpl::OnStartSessionError( | 336 void PresentationServiceImpl::OnStartSessionError( |
| 325 int request_session_id, | 337 int request_session_id, |
| 326 const PresentationError& error) { | 338 const PresentationError& error) { |
| 327 if (request_session_id != start_session_request_id_) | 339 if (request_session_id != start_session_request_id_) |
| 328 return; | 340 return; |
| 329 | 341 |
| 330 CHECK(pending_start_session_cb_.get()); | 342 CHECK(pending_start_session_cb_.get()); |
| 331 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), | 343 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 if (send_message_callback_) { | 429 if (send_message_callback_) { |
| 418 send_message_callback_->Run(sent); | 430 send_message_callback_->Run(sent); |
| 419 send_message_callback_.reset(); | 431 send_message_callback_.reset(); |
| 420 } | 432 } |
| 421 } | 433 } |
| 422 | 434 |
| 423 void PresentationServiceImpl::CloseConnection( | 435 void PresentationServiceImpl::CloseConnection( |
| 424 const GURL& presentation_url, | 436 const GURL& presentation_url, |
| 425 const std::string& presentation_id) { | 437 const std::string& presentation_id) { |
| 426 DVLOG(2) << "CloseConnection " << presentation_id; | 438 DVLOG(2) << "CloseConnection " << presentation_id; |
| 427 if (delegate_) | 439 if (delegate_) { |
| 428 delegate_->CloseConnection(render_process_id_, render_frame_id_, | 440 delegate_->CloseConnection(render_process_id_, render_frame_id_, |
| 429 presentation_id); | 441 presentation_id); |
| 442 delegate_->UnregisterOffscreenPresentationController(presentation_id, this); | |
| 443 } | |
| 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 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; | |
| 512 client_->OnReceiverConnectionAvailable( | |
| 513 blink::mojom::PresentationSessionInfo::From(session_info)); | |
| 514 } | |
| 515 | |
| 516 void PresentationServiceImpl::AddOffscreenPresentationObserver( | |
| 517 OffscreenPresentationClient* client) { | |
| 518 offscreen_presentation_observers_.insert(client); | |
| 519 } | |
| 520 | |
| 521 void PresentationServiceImpl::RemoveOffscreenPresentationObserver( | |
| 522 OffscreenPresentationClient* client) { | |
| 523 offscreen_presentation_observers_.erase(client); | |
| 524 } | |
| 525 | |
| 495 void PresentationServiceImpl::DidNavigateAnyFrame( | 526 void PresentationServiceImpl::DidNavigateAnyFrame( |
| 496 content::RenderFrameHost* render_frame_host, | 527 content::RenderFrameHost* render_frame_host, |
| 497 const content::LoadCommittedDetails& details, | 528 const content::LoadCommittedDetails& details, |
| 498 const content::FrameNavigateParams& params) { | 529 const content::FrameNavigateParams& params) { |
| 499 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 530 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
| 500 if (!FrameMatches(render_frame_host)) | 531 if (!FrameMatches(render_frame_host)) |
| 501 return; | 532 return; |
| 502 | 533 |
| 503 std::string prev_url_host = details.previous_url.host(); | 534 std::string prev_url_host = details.previous_url.host(); |
| 504 std::string curr_url_host = params.url.host(); | 535 std::string curr_url_host = params.url.host(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 530 void PresentationServiceImpl::WebContentsDestroyed() { | 561 void PresentationServiceImpl::WebContentsDestroyed() { |
| 531 LOG(ERROR) << "PresentationServiceImpl is being deleted in " | 562 LOG(ERROR) << "PresentationServiceImpl is being deleted in " |
| 532 << "WebContentsDestroyed()! This shouldn't happen since it " | 563 << "WebContentsDestroyed()! This shouldn't happen since it " |
| 533 << "should've been deleted during RenderFrameDeleted()."; | 564 << "should've been deleted during RenderFrameDeleted()."; |
| 534 Reset(); | 565 Reset(); |
| 535 delete this; | 566 delete this; |
| 536 } | 567 } |
| 537 | 568 |
| 538 void PresentationServiceImpl::Reset() { | 569 void PresentationServiceImpl::Reset() { |
| 539 DVLOG(2) << "PresentationServiceImpl::Reset"; | 570 DVLOG(2) << "PresentationServiceImpl::Reset"; |
| 540 if (delegate_) | 571 if (delegate_) { |
| 541 delegate_->Reset(render_process_id_, render_frame_id_); | 572 delegate_->Reset(render_process_id_, render_frame_id_); |
| 573 delegate_->UnregisterOffscreenPresentationReceiver(this); | |
| 574 } | |
| 542 | 575 |
| 543 default_presentation_urls_.clear(); | 576 default_presentation_urls_.clear(); |
| 544 | 577 |
| 545 screen_availability_listeners_.clear(); | 578 screen_availability_listeners_.clear(); |
| 546 | 579 |
| 547 start_session_request_id_ = kInvalidRequestSessionId; | 580 start_session_request_id_ = kInvalidRequestSessionId; |
| 548 pending_start_session_cb_.reset(); | 581 pending_start_session_cb_.reset(); |
| 549 | 582 |
| 550 pending_join_session_cbs_.clear(); | 583 pending_join_session_cbs_.clear(); |
| 551 | 584 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 | 653 |
| 621 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( | 654 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( |
| 622 blink::mojom::PresentationSessionInfoPtr session, | 655 blink::mojom::PresentationSessionInfoPtr session, |
| 623 blink::mojom::PresentationErrorPtr error) { | 656 blink::mojom::PresentationErrorPtr error) { |
| 624 DCHECK(!callback_.is_null()); | 657 DCHECK(!callback_.is_null()); |
| 625 callback_.Run(std::move(session), std::move(error)); | 658 callback_.Run(std::move(session), std::move(error)); |
| 626 callback_.Reset(); | 659 callback_.Reset(); |
| 627 } | 660 } |
| 628 | 661 |
| 629 } // namespace content | 662 } // namespace content |
| OLD | NEW |