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..234f8b7f3d621117fe1de6b3f4afc5c252ba3fe0 |
| --- /dev/null |
| +++ b/content/renderer/presentation/presentation_connection_proxy.cc |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2017 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 "content/renderer/presentation/presentation_dispatcher.h" |
| +#include "third_party/WebKit/public/platform/WebString.h" |
| +#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationConnection.h" |
| +#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationController.h" |
| +#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationSessionInfo.h" |
| + |
| +namespace content { |
| + |
| +PresentationConnectionProxy::PresentationConnectionProxy( |
| + blink::WebPresentationConnection* connection) |
| + : binding_(this), |
| + target_connection_(nullptr), |
| + source_connection_(connection) { |
| + DCHECK(source_connection_); |
| +} |
| + |
| +PresentationConnectionProxy::~PresentationConnectionProxy() = default; |
| + |
| +void PresentationConnectionProxy::SendConnectionMessage( |
| + blink::mojom::ConnectionMessagePtr session_message, |
| + const OnMessageCallback& callback) const { |
| + DCHECK(target_connection_); |
|
imcheng
2017/01/20 20:15:43
What prevents this method from being called before
zhaobin
2017/01/23 19:38:49
Yes.
|
| + target_connection_->OnMessage(std::move(session_message), callback); |
| +} |
| + |
| +void PresentationConnectionProxy::OnMessage( |
| + blink::mojom::ConnectionMessagePtr message, |
| + const OnMessageCallback& callback) { |
| + DCHECK(source_connection_); |
|
imcheng
2017/01/20 20:15:43
This DCHECK already exists in the constructor. Not
zhaobin
2017/01/23 19:38:48
Done.
|
| + DCHECK(!callback.is_null()); |
| + |
| + switch (message->type) { |
| + case blink::mojom::PresentationMessageType::TEXT: { |
| + DCHECK(message->message); |
| + source_connection_->didReceiveTextMessage( |
| + blink::WebString::fromUTF8(message->message.value())); |
| + break; |
| + } |
| + case blink::mojom::PresentationMessageType::BINARY: { |
| + DCHECK(message->data); |
| + source_connection_->didReceiveBinaryMessage(&(message->data->front()), |
| + message->data->size()); |
| + break; |
| + } |
| + default: { |
| + callback.Run(false); |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| + |
| + callback.Run(true); |
| +} |
| + |
| +void PresentationConnectionProxy::DidChangeState( |
|
imcheng
2017/01/20 20:15:43
If I were to close() one side of a 1-UA presentati
zhaobin
2017/01/23 19:38:48
Yes.
|
| + blink::mojom::PresentationConnectionState state) { |
| + DCHECK(source_connection_); |
|
imcheng
2017/01/20 20:15:43
ditto on DCHECK
zhaobin
2017/01/23 19:38:48
Done.
|
| + if (state == blink::mojom::PresentationConnectionState::CONNECTED) { |
| + source_connection_->didChangeState( |
| + blink::WebPresentationConnectionState::Connected); |
| + } else { |
| + // |DidChangeState| should only handles state transition from connecting -> |
|
imcheng
2017/01/20 20:15:43
s/handles/handle
zhaobin
2017/01/23 19:38:49
Done.
|
| + // connected. PresentationService and MRP handles other state transitions. |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +ControllerConnectionProxy::ControllerConnectionProxy( |
| + blink::WebPresentationConnection* connection) |
| + : PresentationConnectionProxy(connection) {} |
| + |
| +ControllerConnectionProxy::~ControllerConnectionProxy() {} |
| + |
| +blink::mojom::PresentationConnectionPtr ControllerConnectionProxy::Bind() { |
| + return binding_.CreateInterfacePtrAndBind(); |
| +} |
| + |
| +blink::mojom::PresentationConnectionRequest |
| +ControllerConnectionProxy::MakeRemoteRequest() { |
| + DCHECK(!target_connection_) |
| + << "target_connection_ should only be bound once."; |
| + return mojo::MakeRequest(&target_connection_); |
| +} |
| + |
| +ReceiverConnectionProxy::ReceiverConnectionProxy( |
| + blink::WebPresentationConnection* connection) |
| + : PresentationConnectionProxy(connection) {} |
| + |
| +ReceiverConnectionProxy::~ReceiverConnectionProxy() {} |
| + |
| +void ReceiverConnectionProxy::Bind( |
| + blink::mojom::PresentationConnectionRequest target_connection_request) { |
| + binding_.Bind(std::move(target_connection_request)); |
| +} |
| + |
| +void ReceiverConnectionProxy::BindTargetConnection( |
| + blink::mojom::PresentationConnectionPtr connection) { |
| + DCHECK(!target_connection_); |
| + target_connection_ = std::move(connection); |
| + target_connection_->DidChangeState( |
| + blink::mojom::PresentationConnectionState::CONNECTED); |
| + |
| + DidChangeState(blink::mojom::PresentationConnectionState::CONNECTED); |
| +} |
| + |
| +} // namespace content |