| 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/presentation/presentation_type_converters.h" | |
| 15 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
| 21 #include "content/public/common/frame_navigate_params.h" | 20 #include "content/public/common/frame_navigate_params.h" |
| 22 #include "content/public/common/presentation_connection_message.h" | 21 #include "content/public/common/presentation_connection_message.h" |
| 23 #include "content/public/common/presentation_constants.h" | 22 #include "content/public/common/presentation_constants.h" |
| 24 | 23 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return output; | 99 return output; |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 | 102 |
| 104 NOTREACHED() << "Invalid presentation message type " << input->type; | 103 NOTREACHED() << "Invalid presentation message type " << input->type; |
| 105 return output; | 104 return output; |
| 106 } | 105 } |
| 107 | 106 |
| 108 void InvokeNewSessionCallbackWithError( | 107 void InvokeNewSessionCallbackWithError( |
| 109 const PresentationServiceImpl::NewSessionCallback& callback) { | 108 const PresentationServiceImpl::NewSessionCallback& callback) { |
| 110 callback.Run(blink::mojom::PresentationSessionInfoPtr(), | 109 callback.Run(base::nullopt, |
| 111 blink::mojom::PresentationError::From(PresentationError( | 110 PresentationError( |
| 112 PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS, | 111 PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS, |
| 113 "There is already an unsettled Promise from a previous call " | 112 "There is already an unsettled Promise from a previous call " |
| 114 "to start."))); | 113 "to start.")); |
| 115 } | 114 } |
| 116 | 115 |
| 117 } // namespace | 116 } // namespace |
| 118 | 117 |
| 119 PresentationServiceImpl::PresentationServiceImpl( | 118 PresentationServiceImpl::PresentationServiceImpl( |
| 120 RenderFrameHost* render_frame_host, | 119 RenderFrameHost* render_frame_host, |
| 121 WebContents* web_contents, | 120 WebContents* web_contents, |
| 122 ControllerPresentationServiceDelegate* controller_delegate, | 121 ControllerPresentationServiceDelegate* controller_delegate, |
| 123 ReceiverPresentationServiceDelegate* receiver_delegate) | 122 ReceiverPresentationServiceDelegate* receiver_delegate) |
| 124 : WebContentsObserver(web_contents), | 123 : WebContentsObserver(web_contents), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 controller_delegate_->RemoveScreenAvailabilityListener( | 225 controller_delegate_->RemoveScreenAvailabilityListener( |
| 227 render_process_id_, render_frame_id_, listener_it->second.get()); | 226 render_process_id_, render_frame_id_, listener_it->second.get()); |
| 228 screen_availability_listeners_.erase(listener_it); | 227 screen_availability_listeners_.erase(listener_it); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void PresentationServiceImpl::StartSession( | 230 void PresentationServiceImpl::StartSession( |
| 232 const std::vector<GURL>& presentation_urls, | 231 const std::vector<GURL>& presentation_urls, |
| 233 const NewSessionCallback& callback) { | 232 const NewSessionCallback& callback) { |
| 234 DVLOG(2) << "StartSession"; | 233 DVLOG(2) << "StartSession"; |
| 235 if (!controller_delegate_) { | 234 if (!controller_delegate_) { |
| 236 callback.Run( | 235 callback.Run(base::nullopt, |
| 237 blink::mojom::PresentationSessionInfoPtr(), | 236 PresentationError(PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |
| 238 blink::mojom::PresentationError::From(PresentationError( | 237 "No screens found.")); |
| 239 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); | |
| 240 return; | 238 return; |
| 241 } | 239 } |
| 242 | 240 |
| 243 // There is a StartSession request in progress. To avoid queueing up | 241 // There is a StartSession request in progress. To avoid queueing up |
| 244 // requests, the incoming request is rejected. | 242 // requests, the incoming request is rejected. |
| 245 if (start_session_request_id_ != kInvalidRequestSessionId) { | 243 if (start_session_request_id_ != kInvalidRequestSessionId) { |
| 246 InvokeNewSessionCallbackWithError(callback); | 244 InvokeNewSessionCallbackWithError(callback); |
| 247 return; | 245 return; |
| 248 } | 246 } |
| 249 | 247 |
| 250 start_session_request_id_ = GetNextRequestSessionId(); | 248 start_session_request_id_ = GetNextRequestSessionId(); |
| 251 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); | 249 pending_start_session_cb_.reset(new NewSessionCallbackWrapper(callback)); |
| 252 controller_delegate_->StartSession( | 250 controller_delegate_->StartSession( |
| 253 render_process_id_, render_frame_id_, presentation_urls, | 251 render_process_id_, render_frame_id_, presentation_urls, |
| 254 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, | 252 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, |
| 255 weak_factory_.GetWeakPtr(), start_session_request_id_), | 253 weak_factory_.GetWeakPtr(), start_session_request_id_), |
| 256 base::Bind(&PresentationServiceImpl::OnStartSessionError, | 254 base::Bind(&PresentationServiceImpl::OnStartSessionError, |
| 257 weak_factory_.GetWeakPtr(), start_session_request_id_)); | 255 weak_factory_.GetWeakPtr(), start_session_request_id_)); |
| 258 } | 256 } |
| 259 | 257 |
| 260 void PresentationServiceImpl::JoinSession( | 258 void PresentationServiceImpl::JoinSession( |
| 261 const std::vector<GURL>& presentation_urls, | 259 const std::vector<GURL>& presentation_urls, |
| 262 const base::Optional<std::string>& presentation_id, | 260 const base::Optional<std::string>& presentation_id, |
| 263 const NewSessionCallback& callback) { | 261 const NewSessionCallback& callback) { |
| 264 DVLOG(2) << "JoinSession"; | 262 DVLOG(2) << "JoinSession"; |
| 265 if (!controller_delegate_) { | 263 if (!controller_delegate_) { |
| 266 callback.Run(blink::mojom::PresentationSessionInfoPtr(), | 264 callback.Run(base::nullopt, |
| 267 blink::mojom::PresentationError::From(PresentationError( | 265 PresentationError(PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
| 268 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, | 266 "Error joining route: No matching route")); |
| 269 "Error joining route: No matching route"))); | |
| 270 return; | 267 return; |
| 271 } | 268 } |
| 272 | 269 |
| 273 int request_session_id = RegisterJoinSessionCallback(callback); | 270 int request_session_id = RegisterJoinSessionCallback(callback); |
| 274 if (request_session_id == kInvalidRequestSessionId) { | 271 if (request_session_id == kInvalidRequestSessionId) { |
| 275 InvokeNewSessionCallbackWithError(callback); | 272 InvokeNewSessionCallbackWithError(callback); |
| 276 return; | 273 return; |
| 277 } | 274 } |
| 278 controller_delegate_->JoinSession( | 275 controller_delegate_->JoinSession( |
| 279 render_process_id_, render_frame_id_, presentation_urls, | 276 render_process_id_, render_frame_id_, presentation_urls, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 307 } | 304 } |
| 308 } | 305 } |
| 309 | 306 |
| 310 void PresentationServiceImpl::OnStartSessionSucceeded( | 307 void PresentationServiceImpl::OnStartSessionSucceeded( |
| 311 int request_session_id, | 308 int request_session_id, |
| 312 const PresentationSessionInfo& session_info) { | 309 const PresentationSessionInfo& session_info) { |
| 313 if (request_session_id != start_session_request_id_) | 310 if (request_session_id != start_session_request_id_) |
| 314 return; | 311 return; |
| 315 | 312 |
| 316 CHECK(pending_start_session_cb_.get()); | 313 CHECK(pending_start_session_cb_.get()); |
| 317 pending_start_session_cb_->Run( | 314 pending_start_session_cb_->Run(session_info, base::nullopt); |
| 318 blink::mojom::PresentationSessionInfo::From(session_info), | |
| 319 blink::mojom::PresentationErrorPtr()); | |
| 320 ListenForConnectionStateChange(session_info); | 315 ListenForConnectionStateChange(session_info); |
| 321 pending_start_session_cb_.reset(); | 316 pending_start_session_cb_.reset(); |
| 322 start_session_request_id_ = kInvalidRequestSessionId; | 317 start_session_request_id_ = kInvalidRequestSessionId; |
| 323 } | 318 } |
| 324 | 319 |
| 325 void PresentationServiceImpl::OnStartSessionError( | 320 void PresentationServiceImpl::OnStartSessionError( |
| 326 int request_session_id, | 321 int request_session_id, |
| 327 const PresentationError& error) { | 322 const PresentationError& error) { |
| 328 if (request_session_id != start_session_request_id_) | 323 if (request_session_id != start_session_request_id_) |
| 329 return; | 324 return; |
| 330 | 325 |
| 331 CHECK(pending_start_session_cb_.get()); | 326 CHECK(pending_start_session_cb_.get()); |
| 332 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(), | 327 pending_start_session_cb_->Run(base::nullopt, error); |
| 333 blink::mojom::PresentationError::From(error)); | |
| 334 pending_start_session_cb_.reset(); | 328 pending_start_session_cb_.reset(); |
| 335 start_session_request_id_ = kInvalidRequestSessionId; | 329 start_session_request_id_ = kInvalidRequestSessionId; |
| 336 } | 330 } |
| 337 | 331 |
| 338 void PresentationServiceImpl::OnJoinSessionSucceeded( | 332 void PresentationServiceImpl::OnJoinSessionSucceeded( |
| 339 int request_session_id, | 333 int request_session_id, |
| 340 const PresentationSessionInfo& session_info) { | 334 const PresentationSessionInfo& session_info) { |
| 341 if (RunAndEraseJoinSessionMojoCallback( | 335 if (RunAndEraseJoinSessionMojoCallback(request_session_id, session_info, |
| 342 request_session_id, | 336 base::nullopt)) { |
| 343 blink::mojom::PresentationSessionInfo::From(session_info), | |
| 344 blink::mojom::PresentationErrorPtr())) { | |
| 345 ListenForConnectionStateChange(session_info); | 337 ListenForConnectionStateChange(session_info); |
| 346 } | 338 } |
| 347 } | 339 } |
| 348 | 340 |
| 349 void PresentationServiceImpl::OnJoinSessionError( | 341 void PresentationServiceImpl::OnJoinSessionError( |
| 350 int request_session_id, | 342 int request_session_id, |
| 351 const PresentationError& error) { | 343 const PresentationError& error) { |
| 352 RunAndEraseJoinSessionMojoCallback( | 344 RunAndEraseJoinSessionMojoCallback(request_session_id, base::nullopt, error); |
| 353 request_session_id, blink::mojom::PresentationSessionInfoPtr(), | |
| 354 blink::mojom::PresentationError::From(error)); | |
| 355 } | 345 } |
| 356 | 346 |
| 357 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( | 347 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( |
| 358 int request_session_id, | 348 int request_session_id, |
| 359 blink::mojom::PresentationSessionInfoPtr session, | 349 const base::Optional<PresentationSessionInfo>& session_info, |
| 360 blink::mojom::PresentationErrorPtr error) { | 350 const base::Optional<PresentationError>& error) { |
| 361 auto it = pending_join_session_cbs_.find(request_session_id); | 351 auto it = pending_join_session_cbs_.find(request_session_id); |
| 362 if (it == pending_join_session_cbs_.end()) | 352 if (it == pending_join_session_cbs_.end()) |
| 363 return false; | 353 return false; |
| 364 | 354 |
| 365 DCHECK(it->second.get()); | 355 DCHECK(it->second.get()); |
| 366 it->second->Run(std::move(session), std::move(error)); | 356 it->second->Run(session_info, error); |
| 367 pending_join_session_cbs_.erase(it); | 357 pending_join_session_cbs_.erase(it); |
| 368 return true; | 358 return true; |
| 369 } | 359 } |
| 370 | 360 |
| 371 void PresentationServiceImpl::SetDefaultPresentationUrls( | 361 void PresentationServiceImpl::SetDefaultPresentationUrls( |
| 372 const std::vector<GURL>& presentation_urls) { | 362 const std::vector<GURL>& presentation_urls) { |
| 373 DVLOG(2) << "SetDefaultPresentationUrls"; | 363 DVLOG(2) << "SetDefaultPresentationUrls"; |
| 374 if (!controller_delegate_) | 364 if (!controller_delegate_) |
| 375 return; | 365 return; |
| 376 | 366 |
| 377 if (default_presentation_urls_ == presentation_urls) | 367 if (default_presentation_urls_ == presentation_urls) |
| 378 return; | 368 return; |
| 379 | 369 |
| 380 default_presentation_urls_ = presentation_urls; | 370 default_presentation_urls_ = presentation_urls; |
| 381 controller_delegate_->SetDefaultPresentationUrls( | 371 controller_delegate_->SetDefaultPresentationUrls( |
| 382 render_process_id_, render_frame_id_, presentation_urls, | 372 render_process_id_, render_frame_id_, presentation_urls, |
| 383 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, | 373 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, |
| 384 weak_factory_.GetWeakPtr())); | 374 weak_factory_.GetWeakPtr())); |
| 385 } | 375 } |
| 386 | 376 |
| 387 void PresentationServiceImpl::SendConnectionMessage( | 377 void PresentationServiceImpl::SendConnectionMessage( |
| 388 blink::mojom::PresentationSessionInfoPtr session, | 378 const PresentationSessionInfo& session_info, |
| 389 blink::mojom::ConnectionMessagePtr connection_message, | 379 blink::mojom::ConnectionMessagePtr connection_message, |
| 390 const SendConnectionMessageCallback& callback) { | 380 const SendConnectionMessageCallback& callback) { |
| 391 DVLOG(2) << "SendConnectionMessage" | 381 DVLOG(2) << "SendConnectionMessage [id]: " << session_info.presentation_id; |
| 392 << " [id]: " << session->id; | |
| 393 DCHECK(!connection_message.is_null()); | 382 DCHECK(!connection_message.is_null()); |
| 394 // send_message_callback_ should be null by now, otherwise resetting of | 383 // send_message_callback_ should be null by now, otherwise resetting of |
| 395 // send_message_callback_ with new callback will drop the old callback. | 384 // send_message_callback_ with new callback will drop the old callback. |
| 396 if (!controller_delegate_ || send_message_callback_) { | 385 if (!controller_delegate_ || send_message_callback_) { |
| 397 callback.Run(false); | 386 callback.Run(false); |
| 398 return; | 387 return; |
| 399 } | 388 } |
| 400 | 389 |
| 401 send_message_callback_.reset(new SendConnectionMessageCallback(callback)); | 390 send_message_callback_.reset(new SendConnectionMessageCallback(callback)); |
| 402 controller_delegate_->SendMessage( | 391 controller_delegate_->SendMessage( |
| 403 render_process_id_, render_frame_id_, | 392 render_process_id_, render_frame_id_, session_info, |
| 404 session.To<PresentationSessionInfo>(), | |
| 405 GetPresentationConnectionMessage(std::move(connection_message)), | 393 GetPresentationConnectionMessage(std::move(connection_message)), |
| 406 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, | 394 base::Bind(&PresentationServiceImpl::OnSendMessageCallback, |
| 407 weak_factory_.GetWeakPtr())); | 395 weak_factory_.GetWeakPtr())); |
| 408 } | 396 } |
| 409 | 397 |
| 410 void PresentationServiceImpl::OnSendMessageCallback(bool sent) { | 398 void PresentationServiceImpl::OnSendMessageCallback(bool sent) { |
| 411 // It is possible that Reset() is invoked before receiving this callback. | 399 // It is possible that Reset() is invoked before receiving this callback. |
| 412 // So, always check send_message_callback_ for non-null. | 400 // So, always check send_message_callback_ for non-null. |
| 413 if (send_message_callback_) { | 401 if (send_message_callback_) { |
| 414 send_message_callback_->Run(sent); | 402 send_message_callback_->Run(sent); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 434 } | 422 } |
| 435 | 423 |
| 436 void PresentationServiceImpl::OnConnectionStateChanged( | 424 void PresentationServiceImpl::OnConnectionStateChanged( |
| 437 const PresentationSessionInfo& connection, | 425 const PresentationSessionInfo& connection, |
| 438 const PresentationConnectionStateChangeInfo& info) { | 426 const PresentationConnectionStateChangeInfo& info) { |
| 439 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " | 427 DVLOG(2) << "PresentationServiceImpl::OnConnectionStateChanged " |
| 440 << "[presentation_id]: " << connection.presentation_id | 428 << "[presentation_id]: " << connection.presentation_id |
| 441 << " [state]: " << info.state; | 429 << " [state]: " << info.state; |
| 442 DCHECK(client_.get()); | 430 DCHECK(client_.get()); |
| 443 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { | 431 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { |
| 444 client_->OnConnectionClosed( | 432 client_->OnConnectionClosed(connection, info.close_reason, info.message); |
| 445 blink::mojom::PresentationSessionInfo::From(connection), | |
| 446 content::PresentationConnectionCloseReasonToMojo(info.close_reason), | |
| 447 info.message); | |
| 448 } else { | 433 } else { |
| 449 client_->OnConnectionStateChanged( | 434 client_->OnConnectionStateChanged(connection, info.state); |
| 450 blink::mojom::PresentationSessionInfo::From(connection), | |
| 451 PresentationConnectionStateToMojo(info.state)); | |
| 452 } | 435 } |
| 453 } | 436 } |
| 454 | 437 |
| 455 bool PresentationServiceImpl::FrameMatches( | 438 bool PresentationServiceImpl::FrameMatches( |
| 456 content::RenderFrameHost* render_frame_host) const { | 439 content::RenderFrameHost* render_frame_host) const { |
| 457 if (!render_frame_host) | 440 if (!render_frame_host) |
| 458 return false; | 441 return false; |
| 459 | 442 |
| 460 return render_frame_host->GetProcess()->GetID() == render_process_id_ && | 443 return render_frame_host->GetProcess()->GetID() == render_process_id_ && |
| 461 render_frame_host->GetRoutingID() == render_frame_id_; | 444 render_frame_host->GetRoutingID() == render_frame_id_; |
| 462 } | 445 } |
| 463 | 446 |
| 464 PresentationServiceDelegate* | 447 PresentationServiceDelegate* |
| 465 PresentationServiceImpl::GetPresentationServiceDelegate() { | 448 PresentationServiceImpl::GetPresentationServiceDelegate() { |
| 466 return receiver_delegate_ | 449 return receiver_delegate_ |
| 467 ? static_cast<PresentationServiceDelegate*>(receiver_delegate_) | 450 ? static_cast<PresentationServiceDelegate*>(receiver_delegate_) |
| 468 : static_cast<PresentationServiceDelegate*>(controller_delegate_); | 451 : static_cast<PresentationServiceDelegate*>(controller_delegate_); |
| 469 } | 452 } |
| 470 | 453 |
| 471 void PresentationServiceImpl::ListenForConnectionMessages( | 454 void PresentationServiceImpl::ListenForConnectionMessages( |
| 472 blink::mojom::PresentationSessionInfoPtr session) { | 455 const PresentationSessionInfo& session_info) { |
| 473 DVLOG(2) << "ListenForConnectionMessages"; | 456 DVLOG(2) << "ListenForConnectionMessages"; |
| 474 if (!controller_delegate_) | 457 if (!controller_delegate_) |
| 475 return; | 458 return; |
| 476 | 459 |
| 477 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); | |
| 478 controller_delegate_->ListenForConnectionMessages( | 460 controller_delegate_->ListenForConnectionMessages( |
| 479 render_process_id_, render_frame_id_, session_info, | 461 render_process_id_, render_frame_id_, session_info, |
| 480 base::Bind(&PresentationServiceImpl::OnConnectionMessages, | 462 base::Bind(&PresentationServiceImpl::OnConnectionMessages, |
| 481 weak_factory_.GetWeakPtr(), session_info)); | 463 weak_factory_.GetWeakPtr(), session_info)); |
| 482 } | 464 } |
| 483 | 465 |
| 484 void PresentationServiceImpl::SetPresentationConnection( | 466 void PresentationServiceImpl::SetPresentationConnection( |
| 485 blink::mojom::PresentationSessionInfoPtr session, | 467 const PresentationSessionInfo& session_info, |
| 486 blink::mojom::PresentationConnectionPtr controller_connection_ptr, | 468 blink::mojom::PresentationConnectionPtr controller_connection_ptr, |
| 487 blink::mojom::PresentationConnectionRequest receiver_connection_request) { | 469 blink::mojom::PresentationConnectionRequest receiver_connection_request) { |
| 488 DVLOG(2) << "SetPresentationConnection"; | 470 DVLOG(2) << "SetPresentationConnection"; |
| 489 | 471 |
| 490 if (!controller_delegate_) | 472 if (!controller_delegate_) |
| 491 return; | 473 return; |
| 492 | 474 |
| 493 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); | |
| 494 controller_delegate_->ConnectToOffscreenPresentation( | 475 controller_delegate_->ConnectToOffscreenPresentation( |
| 495 render_process_id_, render_frame_id_, session_info, | 476 render_process_id_, render_frame_id_, session_info, |
| 496 std::move(controller_connection_ptr), | 477 std::move(controller_connection_ptr), |
| 497 std::move(receiver_connection_request)); | 478 std::move(receiver_connection_request)); |
| 498 } | 479 } |
| 499 | 480 |
| 500 void PresentationServiceImpl::OnConnectionMessages( | 481 void PresentationServiceImpl::OnConnectionMessages( |
| 501 const PresentationSessionInfo& session, | 482 const PresentationSessionInfo& session_info, |
| 502 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages, | 483 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& messages, |
| 503 bool pass_ownership) { | 484 bool pass_ownership) { |
| 504 DCHECK(client_); | 485 DCHECK(client_); |
| 505 | 486 |
| 506 DVLOG(2) << "OnConnectionMessages" | 487 DVLOG(2) << "OnConnectionMessages [id]: " << session_info.presentation_id; |
| 507 << " [id]: " << session.presentation_id; | |
| 508 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages( | 488 std::vector<blink::mojom::ConnectionMessagePtr> mojo_messages( |
| 509 messages.size()); | 489 messages.size()); |
| 510 std::transform( | 490 std::transform( |
| 511 messages.begin(), messages.end(), mojo_messages.begin(), | 491 messages.begin(), messages.end(), mojo_messages.begin(), |
| 512 [pass_ownership]( | 492 [pass_ownership]( |
| 513 const std::unique_ptr<PresentationConnectionMessage>& message) { | 493 const std::unique_ptr<PresentationConnectionMessage>& message) { |
| 514 return ToMojoConnectionMessage(message.get(), pass_ownership); | 494 return ToMojoConnectionMessage(message.get(), pass_ownership); |
| 515 }); | 495 }); |
| 516 | 496 |
| 517 client_->OnConnectionMessagesReceived( | 497 client_->OnConnectionMessagesReceived(session_info, std::move(mojo_messages)); |
| 518 blink::mojom::PresentationSessionInfo::From(session), | |
| 519 std::move(mojo_messages)); | |
| 520 } | 498 } |
| 521 | 499 |
| 522 void PresentationServiceImpl::OnReceiverConnectionAvailable( | 500 void PresentationServiceImpl::OnReceiverConnectionAvailable( |
| 523 const content::PresentationSessionInfo& session_info, | 501 const content::PresentationSessionInfo& session_info, |
| 524 PresentationConnectionPtr controller_connection_ptr, | 502 PresentationConnectionPtr controller_connection_ptr, |
| 525 PresentationConnectionRequest receiver_connection_request) { | 503 PresentationConnectionRequest receiver_connection_request) { |
| 526 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; | 504 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable"; |
| 527 | 505 |
| 528 client_->OnReceiverConnectionAvailable( | 506 client_->OnReceiverConnectionAvailable( |
| 529 blink::mojom::PresentationSessionInfo::From(session_info), | 507 session_info, std::move(controller_connection_ptr), |
| 530 std::move(controller_connection_ptr), | |
| 531 std::move(receiver_connection_request)); | 508 std::move(receiver_connection_request)); |
| 532 } | 509 } |
| 533 | 510 |
| 534 void PresentationServiceImpl::DidNavigateAnyFrame( | 511 void PresentationServiceImpl::DidNavigateAnyFrame( |
| 535 content::RenderFrameHost* render_frame_host, | 512 content::RenderFrameHost* render_frame_host, |
| 536 const content::LoadCommittedDetails& details, | 513 const content::LoadCommittedDetails& details, |
| 537 const content::FrameNavigateParams& params) { | 514 const content::FrameNavigateParams& params) { |
| 538 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 515 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
| 539 if (!FrameMatches(render_frame_host)) | 516 if (!FrameMatches(render_frame_host)) |
| 540 return; | 517 return; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 void PresentationServiceImpl::OnDelegateDestroyed() { | 583 void PresentationServiceImpl::OnDelegateDestroyed() { |
| 607 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; | 584 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; |
| 608 controller_delegate_ = nullptr; | 585 controller_delegate_ = nullptr; |
| 609 receiver_delegate_ = nullptr; | 586 receiver_delegate_ = nullptr; |
| 610 Reset(); | 587 Reset(); |
| 611 } | 588 } |
| 612 | 589 |
| 613 void PresentationServiceImpl::OnDefaultPresentationStarted( | 590 void PresentationServiceImpl::OnDefaultPresentationStarted( |
| 614 const PresentationSessionInfo& connection) { | 591 const PresentationSessionInfo& connection) { |
| 615 DCHECK(client_.get()); | 592 DCHECK(client_.get()); |
| 616 client_->OnDefaultSessionStarted( | 593 client_->OnDefaultSessionStarted(connection); |
| 617 blink::mojom::PresentationSessionInfo::From(connection)); | |
| 618 ListenForConnectionStateChange(connection); | 594 ListenForConnectionStateChange(connection); |
| 619 } | 595 } |
| 620 | 596 |
| 621 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: | 597 PresentationServiceImpl::ScreenAvailabilityListenerImpl:: |
| 622 ScreenAvailabilityListenerImpl(const GURL& availability_url, | 598 ScreenAvailabilityListenerImpl(const GURL& availability_url, |
| 623 PresentationServiceImpl* service) | 599 PresentationServiceImpl* service) |
| 624 : availability_url_(availability_url), service_(service) { | 600 : availability_url_(availability_url), service_(service) { |
| 625 DCHECK(service_); | 601 DCHECK(service_); |
| 626 DCHECK(service_->client_.get()); | 602 DCHECK(service_->client_.get()); |
| 627 } | 603 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 650 : callback_(callback) { | 626 : callback_(callback) { |
| 651 } | 627 } |
| 652 | 628 |
| 653 PresentationServiceImpl::NewSessionCallbackWrapper | 629 PresentationServiceImpl::NewSessionCallbackWrapper |
| 654 ::~NewSessionCallbackWrapper() { | 630 ::~NewSessionCallbackWrapper() { |
| 655 if (!callback_.is_null()) | 631 if (!callback_.is_null()) |
| 656 InvokeNewSessionCallbackWithError(callback_); | 632 InvokeNewSessionCallbackWithError(callback_); |
| 657 } | 633 } |
| 658 | 634 |
| 659 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( | 635 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( |
| 660 blink::mojom::PresentationSessionInfoPtr session, | 636 const base::Optional<PresentationSessionInfo>& session_info, |
| 661 blink::mojom::PresentationErrorPtr error) { | 637 const base::Optional<PresentationError>& error) { |
| 662 DCHECK(!callback_.is_null()); | 638 DCHECK(!callback_.is_null()); |
| 663 callback_.Run(std::move(session), std::move(error)); | 639 callback_.Run(session_info, error); |
| 664 callback_.Reset(); | 640 callback_.Reset(); |
| 665 } | 641 } |
| 666 | 642 |
| 667 } // namespace content | 643 } // namespace content |
| OLD | NEW |