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

Unified Diff: content/renderer/presentation/renderer_presentation_connection.cc

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: resolve code review comments from Mark Created 4 years, 2 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/renderer/presentation/renderer_presentation_connection.cc
diff --git a/content/renderer/presentation/renderer_presentation_connection.cc b/content/renderer/presentation/renderer_presentation_connection.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9f83b88ad746ce7b9fa8afeae41fe1d52316920f
--- /dev/null
+++ b/content/renderer/presentation/renderer_presentation_connection.cc
@@ -0,0 +1,83 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/presentation/renderer_presentation_connection.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationConnection.h"
+
+namespace content {
+
+RendererPresentationConnection::RendererPresentationConnection()
+ : binding_(this) {}
+
+RendererPresentationConnection::~RendererPresentationConnection() = default;
+
+blink::mojom::PresentationConnectionPtr RendererPresentationConnection::Bind() {
+ return binding_.CreateInterfacePtrAndBind();
+}
+
+void RendererPresentationConnection::SendString(
+ const blink::WebString& message) {
+ if (!target_connection_)
+ return;
+
+ blink::mojom::SessionMessagePtr session_message =
+ blink::mojom::SessionMessage::New();
+ session_message->type = blink::mojom::PresentationMessageType::TEXT;
+ session_message->message = message.utf8();
+
+ target_connection_->OnSessionMessageReceived(std::move(session_message));
+}
+
+void RendererPresentationConnection::SendArrayBuffer(const uint8_t* data,
+ size_t length) {
+ if (!target_connection_)
+ return;
+
+ blink::mojom::SessionMessagePtr session_message =
+ blink::mojom::SessionMessage::New();
+ session_message->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
+ session_message->data = std::vector<uint8_t>(data, data + length);
+
+ target_connection_->OnSessionMessageReceived(std::move(session_message));
+}
+
+void RendererPresentationConnection::SetConnection(
+ blink::WebPresentationConnection* connection) {
+ connection_ = connection;
+}
+
+void RendererPresentationConnection::SetTargetConnection(
+ blink::mojom::PresentationConnectionPtr connection) {
+ target_connection_ = std::move(connection);
+}
+
+void RendererPresentationConnection::OnSessionMessageReceived(
+ blink::mojom::SessionMessagePtr session_message) {
+ DCHECK(connection_);
+
+ switch (session_message->type) {
+ case blink::mojom::PresentationMessageType::TEXT: {
+ // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)?
mark a. foltz 2016/10/10 18:28:52 I'm not sure this TODO makes sense here; we could
zhaobin 2016/10/12 02:27:33 Done.
+ connection_->didReceiveTextMessage(
+ blink::WebString::fromUTF8(session_message->message.value()));
+ break;
+ }
+ case blink::mojom::PresentationMessageType::ARRAY_BUFFER:
+ case blink::mojom::PresentationMessageType::BLOB: {
+ // TODO(mfoltz): Do we need to DCHECK(messages[i]->data)?
mark a. foltz 2016/10/10 18:28:52 See comment above.
zhaobin 2016/10/12 02:27:34 Done.
+ connection_->didReceiveBinaryMessage(&(session_message->data->front()),
+ session_message->data->size());
+ break;
+ }
+ default: {
+ NOTREACHED();
+ break;
+ }
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698