| 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)?
|
| + 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)?
|
| + connection_->didReceiveBinaryMessage(&(session_message->data->front()),
|
| + session_message->data->size());
|
| + break;
|
| + }
|
| + default: {
|
| + NOTREACHED();
|
| + break;
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace content
|
|
|