Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(967)

Unified Diff: content/browser/presentation/presentation_service_impl.cc

Issue 1037483003: [PresentationAPI] Implementing send() from WebPresentationClient to the PresentationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/presentation/presentation_service_impl.cc
diff --git a/content/browser/presentation/presentation_service_impl.cc b/content/browser/presentation/presentation_service_impl.cc
index 6b62c5f509bd50fe01cd5882fac0e8b715e68065..f1b85371799543820da88636ed0df2de0ea9e1a9 100644
--- a/content/browser/presentation/presentation_service_impl.cc
+++ b/content/browser/presentation/presentation_service_impl.cc
@@ -19,6 +19,8 @@
namespace {
+static const size_t kMaxPresentationSessionMessageSize = 64 * 1024; // 64 KB.
+
// The return value takes ownership of the contents of |input|.
presentation::SessionMessagePtr ToMojoSessionMessage(
content::PresentationSessionMessage* input) {
@@ -39,7 +41,38 @@ presentation::SessionMessagePtr ToMojoSessionMessage(
return output.Pass();
}
-} // namespace
+scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage(
+ presentation::SessionMessagePtr input) {
+ DCHECK(!input.is_null());
+ scoped_ptr<content::PresentationSessionMessage> output;
+ if (input->type == presentation::PresentationMessageType::
+ PRESENTATION_MESSAGE_TYPE_TEXT) {
+ DCHECK(!input->message.is_null());
+ DCHECK_LE(input->message.size(),
mark a. foltz 2015/05/07 01:34:30 Don't we want to validate this in all builds and r
USE s.singapati at gmail.com 2015/05/07 14:08:51 Done. Now it returns null PresentationSessionMessa
+ kMaxPresentationSessionMessageSize);
+ DCHECK(input->data.is_null()); // And size is 0.
+ output = content::PresentationSessionMessage::CreateStringMessage(
+ input->presentation_url,
+ input->presentation_id,
+ scoped_ptr<std::string>(new std::string(input->message)));
mark a. foltz 2015/05/07 01:34:30 Instead of allocating a new string, pass an empty
USE s.singapati at gmail.com 2015/05/07 14:08:51 swap() can not take input->message.get() which is
whywhat 2015/05/07 14:22:01 Swap is reflective so you can use input->message.S
+
+ } else if (input->type == presentation::PresentationMessageType::
+ PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) {
+ DCHECK(!input->data.is_null());
+ DCHECK_LE(input->data.size(),
+ kMaxPresentationSessionMessageSize);
+ DCHECK(input->message.is_null()); // And size is 0.
+ output = content::PresentationSessionMessage::CreateBinaryMessage(
+ input->presentation_url,
+ input->presentation_id,
+ scoped_ptr<std::vector<uint8_t>>(
+ new std::vector<uint8_t>(input->data)));
mark a. foltz 2015/05/07 01:34:30 Same comment as above.
USE s.singapati at gmail.com 2015/05/07 14:08:51 swap() can not take input->data.storage() which is
whywhat 2015/05/07 14:22:01 Ditto.
+ }
+
+ return output.Pass();
+}
+
+} // namespace
namespace content {
@@ -338,6 +371,37 @@ void PresentationServiceImpl::SetDefaultPresentationURL(
DoSetDefaultPresentationUrl(new_default_url, default_presentation_id);
}
+
+void PresentationServiceImpl::SendMessage(
+ presentation::SessionMessagePtr session_message,
+ const SendMessageMojoCallback& callback) {
+ DVLOG(2) << "SendMessage";
+ DCHECK(!session_message.is_null());
+ // send_message_cb_ptr_ should be null by now, otherwise resetting of
+ // send_message_cb_ptr_ with new callback will drop the old callback.
+ if (!delegate_ || send_message_cb_ptr_) {
+ callback.Run(false);
+ return;
+ }
+
+ send_message_cb_ptr_.reset(new SendMessageMojoCallback(callback));
+ delegate_->SendMessage(
+ render_process_id_,
+ render_frame_id_,
+ GetPresentationSessionMessage(session_message.Pass()),
+ base::Bind(&PresentationServiceImpl::OnSendMessageCallback,
+ weak_factory_.GetWeakPtr()));
+}
+
+void PresentationServiceImpl::OnSendMessageCallback() {
+ // It is possible that Reset() is invoked before receiving this callback.
+ // So, always check send_message_cb_ptr_ for non-null.
+ if (send_message_cb_ptr_) {
+ send_message_cb_ptr_->Run(true);
+ send_message_cb_ptr_.reset();
+ }
+}
+
void PresentationServiceImpl::CloseSession(
const mojo::String& presentation_url,
const mojo::String& presentation_id) {
@@ -448,6 +512,12 @@ void PresentationServiceImpl::Reset() {
mojo::Array<presentation::SessionMessagePtr>());
on_session_messages_callback_.reset();
}
+ if (send_message_cb_ptr_) {
+ // Run the callback with false, indicating the renderer to stop sending
+ // the requests and invalidate all pending requests.
+ send_message_cb_ptr_->Run(false);
+ send_message_cb_ptr_.reset();
+ }
}
// static

Powered by Google App Engine
This is Rietveld 408576698