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

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: merge with master Created 4 years, 1 month 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()
14 : binding_(this),
15 target_connection_(nullptr),
16 source_connection_(nullptr) {}
17
18 PresentationConnectionProxy::~PresentationConnectionProxy() = default;
19
20 blink::mojom::PresentationConnectionPtr PresentationConnectionProxy::Bind() {
21 return binding_.CreateInterfacePtrAndBind();
22 }
23
24 void PresentationConnectionProxy::SendString(const blink::WebString& message) {
25 DCHECK(target_connection_);
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_->OnMessage(std::move(session_message));
33 }
34
35 void PresentationConnectionProxy::SendArrayBuffer(const uint8_t* data,
36 size_t length) {
37 DCHECK(target_connection_);
38
39 blink::mojom::SessionMessagePtr session_message =
40 blink::mojom::SessionMessage::New();
41 session_message->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
42 session_message->data = std::vector<uint8_t>(data, data + length);
43
44 target_connection_->OnMessage(std::move(session_message));
45 }
46
47 void PresentationConnectionProxy::SetSourceConnection(
48 blink::WebPresentationConnection* connection) {
49 DCHECK(!source_connection_);
50 source_connection_ = connection;
51 }
52
53 void PresentationConnectionProxy::SetTargetConnection(
54 blink::mojom::PresentationConnectionPtr connection) {
55 DCHECK(!target_connection_);
56 target_connection_ = std::move(connection);
57 }
58
59 void PresentationConnectionProxy::OnMessage(
60 blink::mojom::SessionMessagePtr session_message) {
61 DCHECK(source_connection_);
62
63 switch (session_message->type) {
64 case blink::mojom::PresentationMessageType::TEXT: {
65 DCHECK(session_message->message);
66 source_connection_->didReceiveTextMessage(
67 blink::WebString::fromUTF8(session_message->message.value()));
68 break;
69 }
70 case blink::mojom::PresentationMessageType::ARRAY_BUFFER:
71 case blink::mojom::PresentationMessageType::BLOB: {
72 DCHECK(session_message->data);
73 source_connection_->didReceiveBinaryMessage(
74 &(session_message->data->front()), session_message->data->size());
75 break;
76 }
77 default: {
78 NOTREACHED();
79 break;
80 }
81 }
82 }
83
84 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_connection_proxy.h ('k') | content/renderer/presentation/presentation_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698