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/renderer/presentation/presentation_dispatcher.h" | 5 #include "content/renderer/presentation/presentation_dispatcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 namespace content { | 79 namespace content { |
| 80 | 80 |
| 81 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 81 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| 82 : RenderFrameObserver(render_frame), | 82 : RenderFrameObserver(render_frame), |
| 83 controller_(nullptr), | 83 controller_(nullptr), |
| 84 binding_(this), | 84 binding_(this), |
| 85 listening_state_(ListeningState::Inactive), | 85 listening_state_(ListeningState::Inactive), |
| 86 last_known_availability_(false) { | 86 last_known_availability_(false), |
| 87 listening_for_messages_(false) { | |
| 87 } | 88 } |
| 88 | 89 |
| 89 PresentationDispatcher::~PresentationDispatcher() { | 90 PresentationDispatcher::~PresentationDispatcher() { |
| 90 // Controller should be destroyed before the dispatcher when frame is | 91 // Controller should be destroyed before the dispatcher when frame is |
| 91 // destroyed. | 92 // destroyed. |
| 92 DCHECK(!controller_); | 93 DCHECK(!controller_); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void PresentationDispatcher::setController( | 96 void PresentationDispatcher::setController( |
| 96 blink::WebPresentationController* controller) { | 97 blink::WebPresentationController* controller) { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 bool is_new_navigation, | 331 bool is_new_navigation, |
| 331 bool is_same_page_navigation) { | 332 bool is_same_page_navigation) { |
| 332 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 333 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 333 // If not top-level navigation. | 334 // If not top-level navigation. |
| 334 if (frame->parent() || is_same_page_navigation) | 335 if (frame->parent() || is_same_page_navigation) |
| 335 return; | 336 return; |
| 336 | 337 |
| 337 // Remove all pending send message requests. | 338 // Remove all pending send message requests. |
| 338 MessageRequestQueue empty; | 339 MessageRequestQueue empty; |
| 339 std::swap(message_request_queue_, empty); | 340 std::swap(message_request_queue_, empty); |
| 341 | |
| 342 listening_for_messages_ = false; | |
| 340 } | 343 } |
| 341 | 344 |
| 342 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { | 345 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
| 343 last_known_availability_ = available; | 346 last_known_availability_ = available; |
| 344 | 347 |
| 345 if (listening_state_ == ListeningState::Waiting) | 348 if (listening_state_ == ListeningState::Waiting) |
| 346 listening_state_ = ListeningState::Active; | 349 listening_state_ = ListeningState::Active; |
| 347 | 350 |
| 348 for (auto observer : availability_observers_) | 351 for (auto observer : availability_observers_) |
| 349 observer->availabilityChanged(available); | 352 observer->availabilityChanged(available); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 if (!error.is_null()) { | 384 if (!error.is_null()) { |
| 382 DCHECK(session_info.is_null()); | 385 DCHECK(session_info.is_null()); |
| 383 callback->onError(new blink::WebPresentationError( | 386 callback->onError(new blink::WebPresentationError( |
| 384 GetWebPresentationErrorTypeFromMojo(error->error_type), | 387 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 385 blink::WebString::fromUTF8(error->message))); | 388 blink::WebString::fromUTF8(error->message))); |
| 386 return; | 389 return; |
| 387 } | 390 } |
| 388 | 391 |
| 389 DCHECK(!session_info.is_null()); | 392 DCHECK(!session_info.is_null()); |
| 390 callback->onSuccess(new PresentationSessionClient(session_info.Pass())); | 393 callback->onSuccess(new PresentationSessionClient(session_info.Pass())); |
| 391 presentation_service_->ListenForSessionMessages( | 394 if (!listening_for_messages_) { |
| 392 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 395 listening_for_messages_ = true; |
| 393 base::Unretained(this))); | 396 presentation_service_->ListenForSessionMessages( |
| 397 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | |
| 398 base::Unretained(this))); | |
| 399 } | |
| 394 } | 400 } |
| 395 | 401 |
| 396 void PresentationDispatcher::OnSessionStateChange( | 402 void PresentationDispatcher::OnSessionStateChange( |
| 397 presentation::PresentationSessionInfoPtr session_info, | 403 presentation::PresentationSessionInfoPtr session_info, |
| 398 presentation::PresentationSessionState session_state) { | 404 presentation::PresentationSessionState session_state) { |
| 399 if (!controller_) | 405 if (!controller_) |
| 400 return; | 406 return; |
| 401 | 407 |
| 402 presentation_service_->ListenForSessionStateChange(base::Bind( | 408 presentation_service_->ListenForSessionStateChange(base::Bind( |
| 403 &PresentationDispatcher::OnSessionStateChange, | 409 &PresentationDispatcher::OnSessionStateChange, |
| 404 base::Unretained(this))); | 410 base::Unretained(this))); |
| 405 | 411 |
| 406 DCHECK(!session_info.is_null()); | 412 DCHECK(!session_info.is_null()); |
| 407 controller_->didChangeSessionState( | 413 controller_->didChangeSessionState( |
| 408 new PresentationSessionClient(session_info.Pass()), | 414 new PresentationSessionClient(session_info.Pass()), |
| 409 GetWebPresentationSessionStateFromMojo(session_state)); | 415 GetWebPresentationSessionStateFromMojo(session_state)); |
| 410 } | 416 } |
| 411 | 417 |
| 412 void PresentationDispatcher::OnSessionMessagesReceived( | 418 void PresentationDispatcher::OnSessionMessagesReceived( |
| 413 mojo::Array<presentation::SessionMessagePtr> messages) { | 419 mojo::Array<presentation::SessionMessagePtr> messages) { |
| 420 DCHECK(listening_for_messages_); | |
|
imcheng (use chromium acct)
2015/07/07 22:24:38
Is it possible for DidCommitProvisionalLoad() to b
haibinlu
2015/07/07 22:37:24
good point. updated.
| |
| 421 | |
| 414 // When messages is null, there is an error at presentation service side. | 422 // When messages is null, there is an error at presentation service side. |
| 415 if (!controller_ || messages.is_null()) | 423 if (!controller_ || messages.is_null()) { |
|
imcheng (use chromium acct)
2015/07/07 22:24:39
So, we don't use an empty list for |messages| to d
haibinlu
2015/07/07 22:37:24
right. no empty list. presentation_service_impl co
| |
| 424 listening_for_messages_ = false; | |
| 416 return; | 425 return; |
| 426 } | |
| 417 | 427 |
| 418 for (size_t i = 0; i < messages.size(); ++i) { | 428 for (size_t i = 0; i < messages.size(); ++i) { |
| 419 if (messages[i]->type == | 429 if (messages[i]->type == |
| 420 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT) { | 430 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT) { |
| 421 controller_->didReceiveSessionTextMessage( | 431 controller_->didReceiveSessionTextMessage( |
| 422 new PresentationSessionClient(messages[i]->presentation_url, | 432 new PresentationSessionClient(messages[i]->presentation_url, |
| 423 messages[i]->presentation_id), | 433 messages[i]->presentation_id), |
| 424 blink::WebString::fromUTF8(messages[i]->message)); | 434 blink::WebString::fromUTF8(messages[i]->message)); |
| 425 } else { | 435 } else { |
| 426 // TODO(haibinlu): handle binary message | 436 // TODO(haibinlu): handle binary message |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 if (should_listen) { | 475 if (should_listen) { |
| 466 listening_state_ = ListeningState::Waiting; | 476 listening_state_ = ListeningState::Waiting; |
| 467 presentation_service_->ListenForScreenAvailability(); | 477 presentation_service_->ListenForScreenAvailability(); |
| 468 } else { | 478 } else { |
| 469 listening_state_ = ListeningState::Inactive; | 479 listening_state_ = ListeningState::Inactive; |
| 470 presentation_service_->StopListeningForScreenAvailability(); | 480 presentation_service_->StopListeningForScreenAvailability(); |
| 471 } | 481 } |
| 472 } | 482 } |
| 473 | 483 |
| 474 } // namespace content | 484 } // namespace content |
| OLD | NEW |