Chromium Code Reviews| Index: content/renderer/presentation/presentation_dispatcher.cc |
| diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc |
| index 6691be68207d752afcfe8c499db8a2098a000cab..ac4dbb768fbd963e2b6c3d4152e0cdd84a9387ee 100644 |
| --- a/content/renderer/presentation/presentation_dispatcher.cc |
| +++ b/content/renderer/presentation/presentation_dispatcher.cc |
| @@ -83,7 +83,8 @@ PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| controller_(nullptr), |
| binding_(this), |
| listening_state_(ListeningState::Inactive), |
| - last_known_availability_(false) { |
| + last_known_availability_(false), |
| + listening_for_messages_(false) { |
| } |
| PresentationDispatcher::~PresentationDispatcher() { |
| @@ -337,6 +338,8 @@ void PresentationDispatcher::DidCommitProvisionalLoad( |
| // Remove all pending send message requests. |
| MessageRequestQueue empty; |
| std::swap(message_request_queue_, empty); |
| + |
| + listening_for_messages_ = false; |
| } |
| void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
| @@ -370,6 +373,7 @@ void PresentationDispatcher::OnDefaultSessionStarted( |
| if (!session_info.is_null()) { |
| controller_->didStartDefaultSession( |
| new PresentationSessionClient(session_info.Pass())); |
| + StartListenForMessages(); |
| } |
| } |
| @@ -388,6 +392,14 @@ void PresentationDispatcher::OnSessionCreated( |
| DCHECK(!session_info.is_null()); |
| callback->onSuccess(new PresentationSessionClient(session_info.Pass())); |
| + StartListenForMessages(); |
| +} |
| + |
| +void PresentationDispatcher::StartListenForMessages() { |
| + if (listening_for_messages_) |
| + return; |
| + |
| + listening_for_messages_ = true; |
| presentation_service_->ListenForSessionMessages( |
| base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
| base::Unretained(this))); |
| @@ -411,9 +423,14 @@ void PresentationDispatcher::OnSessionStateChange( |
| void PresentationDispatcher::OnSessionMessagesReceived( |
| mojo::Array<presentation::SessionMessagePtr> messages) { |
| + if (!listening_for_messages_) |
|
Kevin M
2015/07/08 20:16:08
Add a LOG/DLOG here to call our attention to stran
haibinlu
2015/07/08 20:47:41
added comments.
this may happen. frame navigated,
|
| + return; |
| + |
| // When messages is null, there is an error at presentation service side. |
| - if (!controller_ || messages.is_null()) |
| + if (!controller_ || messages.is_null()) { |
| + listening_for_messages_ = false; |
|
Kevin M
2015/07/08 20:16:07
LOG?
haibinlu
2015/07/08 20:47:41
null message is expected to indicate messaging err
|
| return; |
| + } |
| for (size_t i = 0; i < messages.size(); ++i) { |
| if (messages[i]->type == |