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/renderer/presentation/presentation_dispatcher.h" | 5 #include "content/renderer/presentation/presentation_dispatcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "content/public/common/presentation_constants.h" | 15 #include "content/public/common/presentation_constants.h" |
16 #include "content/public/renderer/render_frame.h" | 16 #include "content/public/renderer/render_frame.h" |
17 #include "content/renderer/presentation/presentation_connection_proxy.h" | |
17 #include "mojo/public/cpp/bindings/type_converter.h" | 18 #include "mojo/public/cpp/bindings/type_converter.h" |
18 #include "services/service_manager/public/cpp/interface_provider.h" | 19 #include "services/service_manager/public/cpp/interface_provider.h" |
19 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
20 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
21 #include "third_party/WebKit/public/platform/WebVector.h" | 22 #include "third_party/WebKit/public/platform/WebVector.h" |
22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" | 23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" |
24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnection.h" | |
23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionCallbacks.h" | 25 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionCallbacks.h" |
24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" | 26 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" |
25 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" | 27 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" |
26 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" | 28 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" |
27 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" | 29 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" |
28 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" | 30 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" |
29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
30 #include "url/gurl.h" | 32 #include "url/gurl.h" |
31 | 33 |
32 namespace mojo { | 34 namespace mojo { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( | 218 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( |
217 presentationUrl, presentationId, | 219 presentationUrl, presentationId, |
218 blink::mojom::PresentationMessageType::BINARY, data, length, | 220 blink::mojom::PresentationMessageType::BINARY, data, length, |
219 connection_proxy))); | 221 connection_proxy))); |
220 // Start processing request if only one in the queue. | 222 // Start processing request if only one in the queue. |
221 if (message_request_queue_.size() == 1) | 223 if (message_request_queue_.size() == 1) |
222 DoSendMessage(message_request_queue_.front().get()); | 224 DoSendMessage(message_request_queue_.front().get()); |
223 } | 225 } |
224 | 226 |
225 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { | 227 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { |
226 ConnectToPresentationServiceIfNeeded(); | 228 DCHECK(request->connection_proxy); |
227 | 229 static_cast<const PresentationConnectionProxy*>(request->connection_proxy) |
mark a. foltz
2017/01/23 22:29:34
Is the static_cast necessary? I don't see where r
zhaobin
2017/01/24 19:28:46
It is declared in 4th patch as WebPresentationConn
| |
228 presentation_service_->SendConnectionMessage( | 230 ->SendConnectionMessage( |
229 std::move(request->session_info), std::move(request->message), | 231 std::move(request->message), |
230 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, | 232 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, |
231 base::Unretained(this))); | 233 base::Unretained(this))); |
232 } | 234 } |
233 | 235 |
234 void PresentationDispatcher::HandleSendMessageRequests(bool success) { | 236 void PresentationDispatcher::HandleSendMessageRequests(bool success) { |
235 // In normal cases, message_request_queue_ should not be empty at this point | 237 // In normal cases, message_request_queue_ should not be empty at this point |
236 // of time, but when DidCommitProvisionalLoad() is invoked before receiving | 238 // of time, but when DidCommitProvisionalLoad() is invoked before receiving |
237 // the callback for previous send mojo call, queue would have been emptied. | 239 // the callback for previous send mojo call, queue would have been emptied. |
238 if (message_request_queue_.empty()) | 240 if (message_request_queue_.empty()) |
239 return; | 241 return; |
240 | 242 |
241 if (!success) { | 243 if (!success) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 UpdateListeningState(status); | 397 UpdateListeningState(status); |
396 } | 398 } |
397 | 399 |
398 void PresentationDispatcher::OnDefaultSessionStarted( | 400 void PresentationDispatcher::OnDefaultSessionStarted( |
399 blink::mojom::PresentationSessionInfoPtr session_info) { | 401 blink::mojom::PresentationSessionInfoPtr session_info) { |
400 if (!controller_) | 402 if (!controller_) |
401 return; | 403 return; |
402 | 404 |
403 if (!session_info.is_null()) { | 405 if (!session_info.is_null()) { |
404 presentation_service_->ListenForConnectionMessages(session_info.Clone()); | 406 presentation_service_->ListenForConnectionMessages(session_info.Clone()); |
405 controller_->didStartDefaultSession( | 407 auto* connection = controller_->didStartDefaultSession( |
406 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); | 408 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); |
409 | |
410 auto* controller_connection_proxy = | |
mark a. foltz
2017/01/23 22:29:34
This block of code is duplicated with L437-442. P
zhaobin
2017/01/24 19:28:46
Done.
| |
411 new ControllerConnectionProxy(connection); | |
412 connection->setProxy(base::WrapUnique(controller_connection_proxy)); | |
413 presentation_service_->SetPresentationConnection( | |
414 session_info.Clone(), controller_connection_proxy->Bind(), | |
415 controller_connection_proxy->MakeRemoteRequest()); | |
407 } | 416 } |
408 } | 417 } |
409 | 418 |
410 void PresentationDispatcher::OnSessionCreated( | 419 void PresentationDispatcher::OnSessionCreated( |
411 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, | 420 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, |
412 blink::mojom::PresentationSessionInfoPtr session_info, | 421 blink::mojom::PresentationSessionInfoPtr session_info, |
413 blink::mojom::PresentationErrorPtr error) { | 422 blink::mojom::PresentationErrorPtr error) { |
414 DCHECK(callback); | 423 DCHECK(callback); |
415 if (!error.is_null()) { | 424 if (!error.is_null()) { |
416 DCHECK(session_info.is_null()); | 425 DCHECK(session_info.is_null()); |
417 callback->onError(blink::WebPresentationError( | 426 callback->onError(blink::WebPresentationError( |
418 GetWebPresentationErrorTypeFromMojo(error->error_type), | 427 GetWebPresentationErrorTypeFromMojo(error->error_type), |
419 blink::WebString::fromUTF8(error->message))); | 428 blink::WebString::fromUTF8(error->message))); |
420 return; | 429 return; |
421 } | 430 } |
422 | 431 |
423 DCHECK(!session_info.is_null()); | 432 DCHECK(!session_info.is_null()); |
424 presentation_service_->ListenForConnectionMessages(session_info.Clone()); | 433 presentation_service_->ListenForConnectionMessages(session_info.Clone()); |
425 callback->onSuccess( | 434 callback->onSuccess( |
426 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); | 435 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); |
436 | |
437 auto* connection = callback->getConnection(); | |
438 auto* controller_connection_proxy = new ControllerConnectionProxy(connection); | |
439 connection->setProxy(base::WrapUnique(controller_connection_proxy)); | |
440 presentation_service_->SetPresentationConnection( | |
441 session_info.Clone(), controller_connection_proxy->Bind(), | |
442 controller_connection_proxy->MakeRemoteRequest()); | |
427 } | 443 } |
428 | 444 |
429 void PresentationDispatcher::OnReceiverConnectionAvailable( | 445 void PresentationDispatcher::OnReceiverConnectionAvailable( |
430 blink::mojom::PresentationSessionInfoPtr session_info, | 446 blink::mojom::PresentationSessionInfoPtr session_info, |
431 blink::mojom::PresentationConnectionPtr, | 447 blink::mojom::PresentationConnectionPtr controller_connection_ptr, |
432 blink::mojom::PresentationConnectionRequest) { | 448 blink::mojom::PresentationConnectionRequest receiver_connection_request) { |
433 if (!receiver_) { | 449 DCHECK(receiver_); |
434 receiver_->onReceiverConnectionAvailable( | 450 |
435 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); | 451 // Bind receiver_connection_proxy with PresentationConnection |
436 } | 452 // in receiver page. |
453 auto* connection = receiver_->onReceiverConnectionAvailable( | |
454 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); | |
455 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection); | |
456 connection->setProxy(base::WrapUnique(receiver_connection_proxy)); | |
457 | |
458 receiver_connection_proxy->Bind(std::move(receiver_connection_request)); | |
459 receiver_connection_proxy->SetTargetConnection( | |
460 std::move(controller_connection_ptr)); | |
437 } | 461 } |
438 | 462 |
439 void PresentationDispatcher::OnConnectionStateChanged( | 463 void PresentationDispatcher::OnConnectionStateChanged( |
440 blink::mojom::PresentationSessionInfoPtr session_info, | 464 blink::mojom::PresentationSessionInfoPtr session_info, |
441 blink::mojom::PresentationConnectionState state) { | 465 blink::mojom::PresentationConnectionState state) { |
442 if (!controller_) | 466 if (!controller_) |
443 return; | 467 return; |
444 | 468 |
445 controller_->didChangeSessionState( | 469 controller_->didChangeSessionState( |
446 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info), | 470 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info), |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 599 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
576 const GURL& availability_url) | 600 const GURL& availability_url) |
577 : url(availability_url), | 601 : url(availability_url), |
578 last_known_availability(false), | 602 last_known_availability(false), |
579 listening_state(ListeningState::INACTIVE) {} | 603 listening_state(ListeningState::INACTIVE) {} |
580 | 604 |
581 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 605 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
582 } | 606 } |
583 | 607 |
584 } // namespace content | 608 } // namespace content |
OLD | NEW |