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..b0b6c9a4ca4b378f9451b64fe8aecbba4ec18b7a 100644 |
| --- a/content/renderer/presentation/presentation_dispatcher.cc |
| +++ b/content/renderer/presentation/presentation_dispatcher.cc |
| @@ -132,6 +132,76 @@ 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) { |
| + const linked_ptr<MessageRequest>& request = message_request_queue_.front(); |
| + DoSendMessage(*request); |
| + } |
| +} |
| + |
| +void PresentationDispatcher::sendArrayBuffer( |
| + const blink::WebString& presentationUrl, |
| + const blink::WebString& presentationId, |
| + const uint8* data, |
| + size_t length) { |
| + DCHECK(data); |
| + const std::vector<uint8> vector(data, data + length); |
|
mark a. foltz
2015/04/22 19:34:23
Are you sure this is efficient (as good as or bett
USE s.singapati at gmail.com
2015/04/27 19:28:56
well, std::copy might be faster, since the vector
|
| + message_request_queue_.push(make_linked_ptr( |
| + new MessageRequest( |
| + presentationUrl.utf8(), |
| + presentationId.utf8(), |
| + vector))); |
| + |
| + // Start processing request if only one in the queue. |
| + if (message_request_queue_.size() == 1) { |
| + const linked_ptr<MessageRequest>& request = message_request_queue_.front(); |
| + DoSendMessage(*request); |
| + } |
| +} |
| + |
| +void PresentationDispatcher::DoSendMessage( |
| + const MessageRequest& request) { |
| + ConnectToPresentationServiceIfNeeded(); |
| + |
| + presentation::MessageRequestPtr message_request( |
| + presentation::MessageRequest::New()); |
| + message_request->presentation_url = request.presentation_url; |
| + message_request->presentation_id = request.presentation_id; |
| + message_request->type = |
| + static_cast<presentation::PresentationMessageType>(request.type); |
| + message_request->message = request.message; |
| + message_request->data = mojo::Array<uint8>::From(request.data); |
| + |
| + presentation_service_->SendMessage( |
| + message_request.Pass(), |
| + 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(); |
| + DoSendMessage(*request); |
| + } |
| +} |
| + |
| void PresentationDispatcher::closeSession( |
| const blink::WebString& presentationUrl, |
| const blink::WebString& presentationId) { |
| @@ -150,6 +220,25 @@ void PresentationDispatcher::DidChangeDefaultPresentation() { |
| presentation_url.spec(), mojo::String()); |
| } |
| +void PresentationDispatcher::DidCommitProvisionalLoad( |
| + bool is_new_navigation, |
| + bool is_same_page_navigation) { |
| + blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| + // If not top-level navigation. |
| + if (frame->parent() || is_same_page_navigation) |
| + return; |
| + |
| + // Remove all pending send message requests. |
| + MessageRequestQueue empty; |
| + std::swap(message_request_queue_, empty); |
| +} |
| + |
| +void PresentationDispatcher::FrameWillClose() { |
| + // 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_) |