OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "third_party/WebKit/public/platform/WebString.h" |
| 9 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" |
| 10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnectionClient.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 PresentationConnectionProxy::PresentationConnectionProxy() |
| 15 : binding_(this), |
| 16 target_connection_(nullptr), |
| 17 source_connection_(nullptr) {} |
| 18 |
| 19 PresentationConnectionProxy::~PresentationConnectionProxy() = default; |
| 20 |
| 21 blink::mojom::PresentationConnectionPtr PresentationConnectionProxy::Bind() { |
| 22 return binding_.CreateInterfacePtrAndBind(); |
| 23 } |
| 24 |
| 25 void PresentationConnectionProxy::SendSessionMessage( |
| 26 blink::mojom::PresentationSessionInfoPtr session, |
| 27 blink::mojom::SessionMessagePtr session_message) const { |
| 28 DCHECK(target_connection_); |
| 29 target_connection_->OnMessage(std::move(session_message), |
| 30 on_message_callback_); |
| 31 } |
| 32 |
| 33 void PresentationConnectionProxy::SetSourceConnection( |
| 34 blink::WebPresentationConnection* connection) { |
| 35 DCHECK(!source_connection_); |
| 36 source_connection_ = connection; |
| 37 } |
| 38 |
| 39 void PresentationConnectionProxy::SetTargetConnection( |
| 40 blink::mojom::PresentationConnectionPtr connection) { |
| 41 DCHECK(!target_connection_); |
| 42 target_connection_ = std::move(connection); |
| 43 target_connection_->DidChangeState( |
| 44 blink::mojom::PresentationConnectionState::CONNECTED); |
| 45 } |
| 46 |
| 47 void PresentationConnectionProxy::OnMessage( |
| 48 blink::mojom::SessionMessagePtr session_message, |
| 49 const OnMessageCallback& callback) { |
| 50 DCHECK(source_connection_); |
| 51 DCHECK(!callback.is_null()); |
| 52 |
| 53 switch (session_message->type) { |
| 54 case blink::mojom::PresentationMessageType::TEXT: { |
| 55 DCHECK(session_message->message); |
| 56 source_connection_->didReceiveTextMessage( |
| 57 blink::WebString::fromUTF8(session_message->message.value())); |
| 58 break; |
| 59 } |
| 60 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: |
| 61 case blink::mojom::PresentationMessageType::BLOB: { |
| 62 DCHECK(session_message->data); |
| 63 source_connection_->didReceiveBinaryMessage( |
| 64 &(session_message->data->front()), session_message->data->size()); |
| 65 break; |
| 66 } |
| 67 default: { |
| 68 NOTREACHED(); |
| 69 break; |
| 70 } |
| 71 } |
| 72 |
| 73 callback.Run(true); |
| 74 } |
| 75 |
| 76 void PresentationConnectionProxy::DidChangeState( |
| 77 blink::mojom::PresentationConnectionState state) { |
| 78 DCHECK(source_connection_); |
| 79 if (state == blink::mojom::PresentationConnectionState::CONNECTED) { |
| 80 source_connection_->didChangeState( |
| 81 blink::WebPresentationConnectionState::Connected); |
| 82 } else { |
| 83 // |DidChangeState| should only handles state transition from connecting -> |
| 84 // connected. PresentationService and MRP handles other state transitions. |
| 85 NOTREACHED(); |
| 86 } |
| 87 } |
| 88 |
| 89 void PresentationConnectionProxy::RegisterOnMessageCallback( |
| 90 const OnMessageCallback& callback) { |
| 91 on_message_callback_ = callback; |
| 92 } |
| 93 |
| 94 } // namespace content |
OLD | NEW |