Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/presentation/presentation_connection_proxy.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "content/renderer/presentation/presentation_dispatcher.h" | |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | |
| 10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnection.h" | |
| 11 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" | |
| 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 PresentationConnectionProxy::PresentationConnectionProxy( | |
| 17 blink::WebPresentationConnection* source_connection) | |
| 18 : binding_(this), | |
| 19 target_connection_ptr_(nullptr), | |
| 20 source_connection_(source_connection) { | |
| 21 DCHECK(source_connection_); | |
| 22 } | |
| 23 | |
| 24 PresentationConnectionProxy::~PresentationConnectionProxy() = default; | |
| 25 | |
| 26 void PresentationConnectionProxy::SendConnectionMessage( | |
| 27 blink::mojom::ConnectionMessagePtr connection_message, | |
| 28 const OnMessageCallback& callback) const { | |
| 29 DCHECK(target_connection_ptr_); | |
| 30 target_connection_ptr_->OnMessage(std::move(connection_message), callback); | |
| 31 } | |
| 32 | |
| 33 void PresentationConnectionProxy::OnMessage( | |
| 34 blink::mojom::ConnectionMessagePtr message, | |
| 35 const OnMessageCallback& callback) { | |
| 36 DCHECK(!callback.is_null()); | |
| 37 | |
| 38 switch (message->type) { | |
| 39 case blink::mojom::PresentationMessageType::TEXT: { | |
| 40 DCHECK(message->message); | |
| 41 source_connection_->didReceiveTextMessage( | |
| 42 blink::WebString::fromUTF8(message->message.value())); | |
| 43 break; | |
| 44 } | |
| 45 case blink::mojom::PresentationMessageType::BINARY: { | |
| 46 DCHECK(message->data); | |
| 47 source_connection_->didReceiveBinaryMessage(&(message->data->front()), | |
| 48 message->data->size()); | |
| 49 break; | |
| 50 } | |
| 51 default: { | |
| 52 callback.Run(false); | |
| 53 NOTREACHED(); | |
| 54 break; | |
|
mlamouri (slow - plz ping)
2017/01/26 22:18:02
nit: it's a NOTREACHED() but you might want to ret
zhaobin
2017/01/26 22:48:14
Done.
| |
| 55 } | |
| 56 } | |
| 57 | |
| 58 callback.Run(true); | |
| 59 } | |
| 60 | |
| 61 // TODO(crbug.com/588874): Ensure legal PresentationConnection state transitions | |
| 62 // in a single place. | |
| 63 void PresentationConnectionProxy::DidChangeState( | |
| 64 blink::mojom::PresentationConnectionState state) { | |
| 65 if (state == blink::mojom::PresentationConnectionState::CONNECTED) { | |
|
mlamouri (slow - plz ping)
2017/01/26 22:18:02
nit:
```
if (state != blink::mojom:...::CONNECTED)
zhaobin
2017/01/26 22:48:14
Done.
| |
| 66 source_connection_->didChangeState( | |
| 67 blink::WebPresentationConnectionState::Connected); | |
| 68 } else { | |
| 69 // |DidChangeState| should only handle state transition from connecting -> | |
| 70 // connected. PresentationService and MRP handles other state transitions. | |
| 71 NOTREACHED(); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 ControllerConnectionProxy::ControllerConnectionProxy( | |
| 76 blink::WebPresentationConnection* controller_connection) | |
| 77 : PresentationConnectionProxy(controller_connection) {} | |
| 78 | |
| 79 ControllerConnectionProxy::~ControllerConnectionProxy() {} | |
|
mlamouri (slow - plz ping)
2017/01/26 22:18:02
= default;
zhaobin
2017/01/26 22:48:14
Done.
| |
| 80 | |
| 81 blink::mojom::PresentationConnectionPtr ControllerConnectionProxy::Bind() { | |
| 82 return binding_.CreateInterfacePtrAndBind(); | |
| 83 } | |
| 84 | |
| 85 blink::mojom::PresentationConnectionRequest | |
| 86 ControllerConnectionProxy::MakeRemoteRequest() { | |
| 87 DCHECK(!target_connection_ptr_) | |
| 88 << "target_connection_ptr_ should only be bound once."; | |
| 89 return mojo::MakeRequest(&target_connection_ptr_); | |
| 90 } | |
| 91 | |
| 92 ReceiverConnectionProxy::ReceiverConnectionProxy( | |
| 93 blink::WebPresentationConnection* receiver_connection) | |
| 94 : PresentationConnectionProxy(receiver_connection) {} | |
| 95 | |
| 96 ReceiverConnectionProxy::~ReceiverConnectionProxy() {} | |
|
mlamouri (slow - plz ping)
2017/01/26 22:18:02
ditto
zhaobin
2017/01/26 22:48:14
Done.
| |
| 97 | |
| 98 void ReceiverConnectionProxy::Bind( | |
| 99 blink::mojom::PresentationConnectionRequest receiver_connection_request) { | |
| 100 binding_.Bind(std::move(receiver_connection_request)); | |
| 101 } | |
| 102 | |
| 103 void ReceiverConnectionProxy::BindControllerConnection( | |
| 104 blink::mojom::PresentationConnectionPtr controller_connection_ptr) { | |
| 105 DCHECK(!target_connection_ptr_); | |
| 106 target_connection_ptr_ = std::move(controller_connection_ptr); | |
| 107 target_connection_ptr_->DidChangeState( | |
| 108 blink::mojom::PresentationConnectionState::CONNECTED); | |
| 109 | |
| 110 DidChangeState(blink::mojom::PresentationConnectionState::CONNECTED); | |
| 111 } | |
| 112 | |
| 113 } // namespace content | |
| OLD | NEW |