Chromium Code Reviews| Index: content/renderer/presentation/presentation_connection_proxy.cc |
| diff --git a/content/renderer/presentation/presentation_connection_proxy.cc b/content/renderer/presentation/presentation_connection_proxy.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e7fdbeec3be4a4174c5593d1f43e388d5a0b69d3 |
| --- /dev/null |
| +++ b/content/renderer/presentation/presentation_connection_proxy.cc |
| @@ -0,0 +1,81 @@ |
| +// 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/presentation_connection_proxy.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 { |
| + |
| +PresentationConnectionProxy::PresentationConnectionProxy() : binding_(this) {} |
| + |
| +PresentationConnectionProxy::~PresentationConnectionProxy() = default; |
| + |
| +blink::mojom::PresentationConnectionPtr PresentationConnectionProxy::Bind() { |
| + return binding_.CreateInterfacePtrAndBind(); |
| +} |
| + |
| +void PresentationConnectionProxy::SendString(const blink::WebString& message) { |
| + if (!target_connection_) |
| + return; |
|
mark a. foltz
2016/10/21 00:53:03
This feels like a bug; the connection should not b
zhaobin
2016/10/22 02:44:13
Done.
|
| + |
| + blink::mojom::SessionMessagePtr session_message = |
|
mark a. foltz
2016/10/21 00:53:03
Can you use the existing type converter for this?
zhaobin
2016/10/22 02:44:13
Done.
|
| + blink::mojom::SessionMessage::New(); |
| + session_message->type = blink::mojom::PresentationMessageType::TEXT; |
| + session_message->message = message.utf8(); |
| + |
| + target_connection_->OnConnectionMessageReceived(std::move(session_message)); |
| +} |
| + |
| +void PresentationConnectionProxy::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_->OnConnectionMessageReceived(std::move(session_message)); |
| +} |
| + |
| +void PresentationConnectionProxy::SetSourceConnection( |
| + blink::WebPresentationConnection* connection) { |
| + source_connection_ = connection; |
|
mark a. foltz
2016/10/21 00:53:02
DCHECK(!source_connection_) before setting.
zhaobin
2016/10/22 02:44:13
Done.
|
| +} |
| + |
| +void PresentationConnectionProxy::SetTargetConnection( |
| + blink::mojom::PresentationConnectionPtr connection) { |
| + target_connection_ = std::move(connection); |
|
mark a. foltz
2016/10/21 00:53:02
DCHECK(!target_connection_) before setting.
zhaobin
2016/10/22 02:44:13
Done.
|
| +} |
| + |
| +void PresentationConnectionProxy::OnConnectionMessageReceived( |
| + blink::mojom::SessionMessagePtr session_message) { |
| + DCHECK(source_connection_); |
| + |
| + switch (session_message->type) { |
| + case blink::mojom::PresentationMessageType::TEXT: { |
| + DCHECK(session_message->message); |
| + source_connection_->didReceiveTextMessage( |
| + blink::WebString::fromUTF8(session_message->message.value())); |
| + break; |
| + } |
| + case blink::mojom::PresentationMessageType::ARRAY_BUFFER: |
| + case blink::mojom::PresentationMessageType::BLOB: { |
| + DCHECK(session_message->data); |
| + source_connection_->didReceiveBinaryMessage( |
| + &(session_message->data->front()), session_message->data->size()); |
| + break; |
| + } |
| + default: { |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| +} |
| + |
| +} // namespace content |