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/renderer_presentation_connection.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 | |
11 namespace content { | |
12 | |
13 RendererPresentationConnection::RendererPresentationConnection() | |
14 : binding_(this) {} | |
15 | |
16 RendererPresentationConnection::~RendererPresentationConnection() = default; | |
17 | |
18 blink::mojom::PresentationConnectionPtr RendererPresentationConnection::Bind() { | |
19 return binding_.CreateInterfacePtrAndBind(); | |
20 } | |
21 | |
22 void RendererPresentationConnection::SendString( | |
23 const blink::WebString& message) { | |
24 if (!target_connection_) | |
25 return; | |
26 | |
27 blink::mojom::SessionMessagePtr session_message = | |
28 blink::mojom::SessionMessage::New(); | |
29 session_message->type = blink::mojom::PresentationMessageType::TEXT; | |
30 session_message->message = message.utf8(); | |
31 | |
32 target_connection_->OnSessionMessageReceived(std::move(session_message)); | |
33 } | |
34 | |
35 void RendererPresentationConnection::SendArrayBuffer(const uint8_t* data, | |
36 size_t length) { | |
37 if (!target_connection_) | |
38 return; | |
39 | |
40 blink::mojom::SessionMessagePtr session_message = | |
41 blink::mojom::SessionMessage::New(); | |
42 session_message->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER; | |
43 session_message->data = std::vector<uint8_t>(data, data + length); | |
44 | |
45 target_connection_->OnSessionMessageReceived(std::move(session_message)); | |
46 } | |
47 | |
48 void RendererPresentationConnection::SetConnection( | |
49 blink::WebPresentationConnection* connection) { | |
50 connection_ = connection; | |
51 } | |
52 | |
53 void RendererPresentationConnection::SetTargetConnection( | |
54 blink::mojom::PresentationConnectionPtr connection) { | |
55 target_connection_ = std::move(connection); | |
56 } | |
57 | |
58 void RendererPresentationConnection::OnSessionMessageReceived( | |
59 blink::mojom::SessionMessagePtr session_message) { | |
60 DCHECK(connection_); | |
61 | |
62 switch (session_message->type) { | |
63 case blink::mojom::PresentationMessageType::TEXT: { | |
64 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)? | |
mark a. foltz
2016/10/10 18:28:52
I'm not sure this TODO makes sense here; we could
zhaobin
2016/10/12 02:27:33
Done.
| |
65 connection_->didReceiveTextMessage( | |
66 blink::WebString::fromUTF8(session_message->message.value())); | |
67 break; | |
68 } | |
69 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: | |
70 case blink::mojom::PresentationMessageType::BLOB: { | |
71 // TODO(mfoltz): Do we need to DCHECK(messages[i]->data)? | |
mark a. foltz
2016/10/10 18:28:52
See comment above.
zhaobin
2016/10/12 02:27:34
Done.
| |
72 connection_->didReceiveBinaryMessage(&(session_message->data->front()), | |
73 session_message->data->size()); | |
74 break; | |
75 } | |
76 default: { | |
77 NOTREACHED(); | |
78 break; | |
79 } | |
80 } | |
81 } | |
82 | |
83 } // namespace content | |
OLD | NEW |