| Index: content/renderer/presentation/presentation_dispatcher.cc
|
| diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc
|
| index 15753c3e55239a1f3d9ce5844e6471601bd4064e..e92363f7900607ec153819e5f4dc4001a1b89b60 100644
|
| --- a/content/renderer/presentation/presentation_dispatcher.cc
|
| +++ b/content/renderer/presentation/presentation_dispatcher.cc
|
| @@ -226,12 +226,14 @@ void PresentationDispatcher::sendBlobData(
|
| }
|
|
|
| void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) {
|
| - ConnectToPresentationServiceIfNeeded();
|
| -
|
| - presentation_service_->SendConnectionMessage(
|
| - std::move(request->session_info), std::move(request->message),
|
| - base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
|
| - base::Unretained(this)));
|
| + DCHECK(request->connection_proxy);
|
| + // TODO(crbug.com/684116): Remove static_cast after moving message queue logic
|
| + // from PresentationDispatcher to PresentationConnectionProxy.
|
| + static_cast<const PresentationConnectionProxy*>(request->connection_proxy)
|
| + ->SendConnectionMessage(
|
| + std::move(request->message),
|
| + base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
|
| + base::Unretained(this)));
|
| }
|
|
|
| void PresentationDispatcher::HandleSendMessageRequests(bool success) {
|
| @@ -255,6 +257,20 @@ void PresentationDispatcher::HandleSendMessageRequests(bool success) {
|
| }
|
| }
|
|
|
| +void PresentationDispatcher::SetControllerConnection(
|
| + blink::mojom::PresentationSessionInfoPtr session_info,
|
| + blink::WebPresentationConnection* connection) {
|
| + DCHECK(connection);
|
| +
|
| + auto* controller_connection_proxy = new ControllerConnectionProxy(connection);
|
| + connection->bindProxy(base::WrapUnique(controller_connection_proxy));
|
| +
|
| + ConnectToPresentationServiceIfNeeded();
|
| + presentation_service_->SetPresentationConnection(
|
| + session_info.Clone(), controller_connection_proxy->Bind(),
|
| + controller_connection_proxy->MakeRemoteRequest());
|
| +}
|
| +
|
| void PresentationDispatcher::closeSession(
|
| const blink::WebURL& presentationUrl,
|
| const blink::WebString& presentationId) {
|
| @@ -487,11 +503,17 @@ void PresentationDispatcher::OnDefaultSessionStarted(
|
| return;
|
|
|
| if (!session_info.is_null()) {
|
| - presentation_service_->ListenForConnectionMessages(session_info.Clone());
|
| auto* connection = controller_->didStartDefaultSession(
|
| mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
|
| - connection->bindProxy(
|
| - base::MakeUnique<ControllerConnectionProxy>(connection));
|
| +
|
| + if (connection) {
|
| + SetControllerConnection(session_info.Clone(), connection);
|
| + // Change blink connection state to 'connected' before listening to
|
| + // connection message. Remove ListenForConnectionMessage() after
|
| + // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send
|
| + // message from route to blink connection.
|
| + presentation_service_->ListenForConnectionMessages(session_info.Clone());
|
| + }
|
| }
|
| }
|
|
|
| @@ -509,13 +531,14 @@ void PresentationDispatcher::OnSessionCreated(
|
| }
|
|
|
| DCHECK(!session_info.is_null());
|
| - presentation_service_->ListenForConnectionMessages(session_info.Clone());
|
| callback->onSuccess(
|
| mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
|
| -
|
| - auto* connection = callback->getConnection();
|
| - connection->bindProxy(
|
| - base::MakeUnique<ControllerConnectionProxy>(connection));
|
| + // Change blink connection state to 'connected' before listening to
|
| + // connection message. Remove ListenForConnectionMessage() after
|
| + // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send
|
| + // message from route to blink connection.
|
| + SetControllerConnection(session_info.Clone(), callback->getConnection());
|
| + presentation_service_->ListenForConnectionMessages(session_info.Clone());
|
| }
|
|
|
| void PresentationDispatcher::OnReceiverConnectionAvailable(
|
| @@ -523,6 +546,7 @@ void PresentationDispatcher::OnReceiverConnectionAvailable(
|
| blink::mojom::PresentationConnectionPtr controller_connection_ptr,
|
| blink::mojom::PresentationConnectionRequest receiver_connection_request) {
|
| DCHECK(receiver_);
|
| +
|
| // Bind receiver_connection_proxy with PresentationConnection in receiver
|
| // page.
|
| auto* connection = receiver_->onReceiverConnectionAvailable(
|
|
|