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* connection) | |
18 : binding_(this), | |
19 target_connection_(nullptr), | |
20 source_connection_(connection) { | |
21 DCHECK(source_connection_); | |
22 } | |
23 | |
24 PresentationConnectionProxy::~PresentationConnectionProxy() = default; | |
25 | |
26 void PresentationConnectionProxy::SendConnectionMessage( | |
27 blink::mojom::ConnectionMessagePtr session_message, | |
28 const OnMessageCallback& callback) const { | |
29 DCHECK(target_connection_); | |
mark a. foltz
2017/01/23 20:18:41
It seems like the following three things have to b
zhaobin
2017/01/24 01:23:23
For (1), we will call into PresentationConnectionP
| |
30 target_connection_->OnMessage(std::move(session_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; | |
55 } | |
56 } | |
57 | |
58 callback.Run(true); | |
59 } | |
60 | |
61 void PresentationConnectionProxy::DidChangeState( | |
62 blink::mojom::PresentationConnectionState state) { | |
63 if (state == blink::mojom::PresentationConnectionState::CONNECTED) { | |
64 source_connection_->didChangeState( | |
65 blink::WebPresentationConnectionState::Connected); | |
66 } else { | |
67 // |DidChangeState| should only handle state transition from connecting -> | |
mark a. foltz
2017/01/23 20:18:41
Long term, I'd rather have one code path to handle
zhaobin
2017/01/24 01:23:23
crbug.com/588874 tracks this. Added a TODO. Curren
| |
68 // connected. PresentationService and MRP handles other state transitions. | |
69 NOTREACHED(); | |
70 } | |
71 } | |
72 | |
73 ControllerConnectionProxy::ControllerConnectionProxy( | |
74 blink::WebPresentationConnection* connection) | |
75 : PresentationConnectionProxy(connection) {} | |
76 | |
77 ControllerConnectionProxy::~ControllerConnectionProxy() {} | |
78 | |
79 blink::mojom::PresentationConnectionPtr ControllerConnectionProxy::Bind() { | |
80 return binding_.CreateInterfacePtrAndBind(); | |
81 } | |
82 | |
83 blink::mojom::PresentationConnectionRequest | |
84 ControllerConnectionProxy::MakeRemoteRequest() { | |
85 DCHECK(!target_connection_) | |
86 << "target_connection_ should only be bound once."; | |
87 return mojo::MakeRequest(&target_connection_); | |
88 } | |
89 | |
90 ReceiverConnectionProxy::ReceiverConnectionProxy( | |
91 blink::WebPresentationConnection* connection) | |
92 : PresentationConnectionProxy(connection) {} | |
93 | |
94 ReceiverConnectionProxy::~ReceiverConnectionProxy() {} | |
95 | |
96 void ReceiverConnectionProxy::Bind( | |
97 blink::mojom::PresentationConnectionRequest target_connection_request) { | |
98 binding_.Bind(std::move(target_connection_request)); | |
99 } | |
100 | |
101 void ReceiverConnectionProxy::BindTargetConnection( | |
102 blink::mojom::PresentationConnectionPtr connection) { | |
103 DCHECK(!target_connection_); | |
104 target_connection_ = std::move(connection); | |
105 target_connection_->DidChangeState( | |
106 blink::mojom::PresentationConnectionState::CONNECTED); | |
107 | |
108 DidChangeState(blink::mojom::PresentationConnectionState::CONNECTED); | |
109 } | |
110 | |
111 } // namespace content | |
OLD | NEW |