| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/presentation/presentation_connection_proxy.h" | 5 #include "content/renderer/presentation/presentation_connection_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/public/common/presentation_session.h" | 8 #include "content/public/common/presentation_session.h" |
| 9 #include "content/renderer/presentation/presentation_dispatcher.h" | 9 #include "content/renderer/presentation/presentation_dispatcher.h" |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
| 11 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" | 11 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" |
| 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" | 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
| 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" | 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 PresentationConnectionProxy::PresentationConnectionProxy( | 17 PresentationConnectionProxy::PresentationConnectionProxy( |
| 18 blink::WebPresentationConnection* source_connection) | 18 blink::WebPresentationConnection* source_connection) |
| 19 : binding_(this), | 19 : binding_(this), |
| 20 target_connection_ptr_(nullptr), | 20 target_connection_ptr_(nullptr), |
| 21 source_connection_(source_connection) { | 21 source_connection_(source_connection) { |
| 22 DCHECK(source_connection_); | 22 DCHECK(source_connection_); |
| 23 } | 23 } |
| 24 | 24 |
| 25 PresentationConnectionProxy::~PresentationConnectionProxy() = default; | 25 PresentationConnectionProxy::~PresentationConnectionProxy() = default; |
| 26 | 26 |
| 27 void PresentationConnectionProxy::SendConnectionMessage( | 27 void PresentationConnectionProxy::SendConnectionMessage( |
| 28 blink::mojom::ConnectionMessagePtr connection_message, | 28 PresentationConnectionMessage message, |
| 29 const OnMessageCallback& callback) const { | 29 const OnMessageCallback& callback) const { |
| 30 DCHECK(target_connection_ptr_); | 30 DCHECK(target_connection_ptr_); |
| 31 target_connection_ptr_->OnMessage(std::move(connection_message), callback); | 31 target_connection_ptr_->OnMessage(std::move(message), callback); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void PresentationConnectionProxy::OnMessage( | 34 void PresentationConnectionProxy::OnMessage( |
| 35 blink::mojom::ConnectionMessagePtr message, | 35 PresentationConnectionMessage message, |
| 36 const OnMessageCallback& callback) { | 36 const OnMessageCallback& callback) { |
| 37 DCHECK(!callback.is_null()); | 37 DCHECK(!callback.is_null()); |
| 38 | 38 |
| 39 switch (message->type) { | 39 if (message.is_binary()) { |
| 40 case blink::mojom::PresentationMessageType::TEXT: { | 40 source_connection_->didReceiveBinaryMessage(&(message.data->front()), |
| 41 DCHECK(message->message); | 41 message.data->size()); |
| 42 source_connection_->didReceiveTextMessage( | 42 } else { |
| 43 blink::WebString::fromUTF8(message->message.value())); | 43 source_connection_->didReceiveTextMessage( |
| 44 break; | 44 blink::WebString::fromUTF8(*(message.message))); |
| 45 } | |
| 46 case blink::mojom::PresentationMessageType::BINARY: { | |
| 47 DCHECK(message->data); | |
| 48 source_connection_->didReceiveBinaryMessage(&(message->data->front()), | |
| 49 message->data->size()); | |
| 50 break; | |
| 51 } | |
| 52 default: { | |
| 53 callback.Run(false); | |
| 54 NOTREACHED(); | |
| 55 return; | |
| 56 } | |
| 57 } | 45 } |
| 58 | 46 |
| 59 callback.Run(true); | 47 callback.Run(true); |
| 60 } | 48 } |
| 61 | 49 |
| 62 // TODO(crbug.com/588874): Ensure legal PresentationConnection state transitions | 50 // TODO(crbug.com/588874): Ensure legal PresentationConnection state transitions |
| 63 // in a single place. | 51 // in a single place. |
| 64 void PresentationConnectionProxy::DidChangeState( | 52 void PresentationConnectionProxy::DidChangeState( |
| 65 content::PresentationConnectionState state) { | 53 content::PresentationConnectionState state) { |
| 66 if (state == content::PRESENTATION_CONNECTION_STATE_CONNECTED) { | 54 if (state == content::PRESENTATION_CONNECTION_STATE_CONNECTED) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 blink::mojom::PresentationConnectionPtr controller_connection_ptr) { | 107 blink::mojom::PresentationConnectionPtr controller_connection_ptr) { |
| 120 DCHECK(!target_connection_ptr_); | 108 DCHECK(!target_connection_ptr_); |
| 121 target_connection_ptr_ = std::move(controller_connection_ptr); | 109 target_connection_ptr_ = std::move(controller_connection_ptr); |
| 122 target_connection_ptr_->DidChangeState( | 110 target_connection_ptr_->DidChangeState( |
| 123 content::PRESENTATION_CONNECTION_STATE_CONNECTED); | 111 content::PRESENTATION_CONNECTION_STATE_CONNECTED); |
| 124 | 112 |
| 125 DidChangeState(content::PRESENTATION_CONNECTION_STATE_CONNECTED); | 113 DidChangeState(content::PRESENTATION_CONNECTION_STATE_CONNECTED); |
| 126 } | 114 } |
| 127 | 115 |
| 128 } // namespace content | 116 } // namespace content |
| OLD | NEW |