Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: content/renderer/presentation/presentation_connection_proxy.cc

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: rebase with master and resolve merge conflicts Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
11 namespace content {
12
13 PresentationConnectionProxy::PresentationConnectionProxy() : binding_(this) {}
14
15 PresentationConnectionProxy::~PresentationConnectionProxy() = default;
16
17 blink::mojom::PresentationConnectionPtr PresentationConnectionProxy::Bind() {
18 return binding_.CreateInterfacePtrAndBind();
19 }
20
21 void PresentationConnectionProxy::SendString(const blink::WebString& message) {
22 if (!target_connection_)
23 return;
mark a. foltz 2016/10/21 00:53:03 This feels like a bug; the connection should not b
zhaobin 2016/10/22 02:44:13 Done.
24
25 blink::mojom::SessionMessagePtr session_message =
mark a. foltz 2016/10/21 00:53:03 Can you use the existing type converter for this?
zhaobin 2016/10/22 02:44:13 Done.
26 blink::mojom::SessionMessage::New();
27 session_message->type = blink::mojom::PresentationMessageType::TEXT;
28 session_message->message = message.utf8();
29
30 target_connection_->OnConnectionMessageReceived(std::move(session_message));
31 }
32
33 void PresentationConnectionProxy::SendArrayBuffer(const uint8_t* data,
34 size_t length) {
35 if (!target_connection_)
36 return;
37
38 blink::mojom::SessionMessagePtr session_message =
39 blink::mojom::SessionMessage::New();
40 session_message->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
41 session_message->data = std::vector<uint8_t>(data, data + length);
42
43 target_connection_->OnConnectionMessageReceived(std::move(session_message));
44 }
45
46 void PresentationConnectionProxy::SetSourceConnection(
47 blink::WebPresentationConnection* connection) {
48 source_connection_ = connection;
mark a. foltz 2016/10/21 00:53:02 DCHECK(!source_connection_) before setting.
zhaobin 2016/10/22 02:44:13 Done.
49 }
50
51 void PresentationConnectionProxy::SetTargetConnection(
52 blink::mojom::PresentationConnectionPtr connection) {
53 target_connection_ = std::move(connection);
mark a. foltz 2016/10/21 00:53:02 DCHECK(!target_connection_) before setting.
zhaobin 2016/10/22 02:44:13 Done.
54 }
55
56 void PresentationConnectionProxy::OnConnectionMessageReceived(
57 blink::mojom::SessionMessagePtr session_message) {
58 DCHECK(source_connection_);
59
60 switch (session_message->type) {
61 case blink::mojom::PresentationMessageType::TEXT: {
62 DCHECK(session_message->message);
63 source_connection_->didReceiveTextMessage(
64 blink::WebString::fromUTF8(session_message->message.value()));
65 break;
66 }
67 case blink::mojom::PresentationMessageType::ARRAY_BUFFER:
68 case blink::mojom::PresentationMessageType::BLOB: {
69 DCHECK(session_message->data);
70 source_connection_->didReceiveBinaryMessage(
71 &(session_message->data->front()), session_message->data->size());
72 break;
73 }
74 default: {
75 NOTREACHED();
76 break;
77 }
78 }
79 }
80
81 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698