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 39e5238b189b9fd7c3219337565554affc628c92..7406c2c6b34f1e8a3d9a92261ca4151dbcbfef0f 100644 |
| --- a/content/renderer/presentation/presentation_dispatcher.cc |
| +++ b/content/renderer/presentation/presentation_dispatcher.cc |
| @@ -132,6 +132,60 @@ void PresentationDispatcher::joinSession( |
| base::Owned(callback))); |
| } |
| +void PresentationDispatcher::sendString( |
| + const blink::WebString& presentationUrl, |
| + const blink::WebString& presentationId, |
| + const blink::WebString& message) { |
| + message_request_queue_.push(make_linked_ptr( |
| + new MessageRequest( |
| + presentationUrl.utf8(), |
| + presentationId.utf8(), |
| + message.utf8()))); |
| + // Start processing request if only one in the queue. |
| + if (message_request_queue_.size() == 1) { |
| + DoSendStringMessage(presentationUrl.utf8(), |
| + presentationId.utf8(), |
| + message.utf8()); |
| + } |
| +} |
| + |
| +void PresentationDispatcher::sendArrayBuffer( |
| + const blink::WebString& presentationUrl, |
| + const blink::WebString& presentationId, |
| + const char* data, |
| + size_t length) { |
| + // TODO(s.singapati): Handle ArrayBuffer data. |
| +} |
| + |
| +void PresentationDispatcher::DoSendStringMessage( |
| + const std::string& presentation_url, |
| + const std::string& presentation_id, |
| + const std::string& message) { |
| + ConnectToPresentationServiceIfNeeded(); |
| + presentation_service_->SendStringMessage( |
| + presentation_url, |
| + presentation_id, |
| + message, |
| + base::Bind(&PresentationDispatcher::HandleSendMessageRequests, |
| + base::Unretained(this))); |
| +} |
| + |
| +void PresentationDispatcher::HandleSendMessageRequests() { |
| + // In normal cases, message_request_queue_ should not be empty at this point |
| + // of time, but when FrameWillClose() is invoked before receiving the |
| + // callback for previous send mojo call, queue would have been emptied. |
| + if (message_request_queue_.empty()) |
| + return; |
| + |
| + message_request_queue_.pop(); |
| + if (!message_request_queue_.empty()) { |
| + const linked_ptr<MessageRequest>& request = message_request_queue_.front(); |
| + DoSendStringMessage(request->presentation_url, |
| + request->presentation_id, |
| + request->message); |
| + } |
| +} |
| + |
| void PresentationDispatcher::closeSession( |
| const blink::WebString& presentationUrl, |
| const blink::WebString& presentationId) { |
| @@ -150,6 +204,12 @@ void PresentationDispatcher::DidChangeDefaultPresentation() { |
| presentation_url.spec(), mojo::String()); |
| } |
| +void PresentationDispatcher::FrameWillClose() { |
|
imcheng
2015/04/14 21:29:13
How about overriding DidCommitProvisionalLoad to i
USE s.singapati at gmail.com
2015/04/15 16:09:08
I have tested that FrameWillClose() is always invo
|
| + // Remove all pending send message requests. |
| + MessageRequestQueue empty; |
| + std::swap(message_request_queue_, empty); |
| +} |
| + |
| void PresentationDispatcher::OnScreenAvailabilityChanged( |
| const std::string& presentation_url, bool available) { |
| if (!controller_) |
| @@ -228,4 +288,16 @@ void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| */ |
| } |
| +PresentationDispatcher::MessageRequest::MessageRequest( |
| + const std::string& presentation_url, |
| + const std::string& presentation_id, |
| + const std::string& message) |
| + : presentation_url(presentation_url), |
| + presentation_id(presentation_id), |
| + message(message) { |
| +} |
| + |
| +PresentationDispatcher::MessageRequest::~MessageRequest() { |
| +} |
| + |
| } // namespace content |