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

Unified Diff: third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp

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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
diff --git a/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp b/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
index 3d2fcd2d12e39e475e5d5df9fd449a97fef2f81a..0e2f120d17ea405ddfb75ae0569ef453ab91c9c4 100644
--- a/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
+++ b/third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp
@@ -153,12 +153,22 @@ PresentationConnection::PresentationConnection(LocalFrame* frame,
m_url(url),
// TODO(zhaobin): change initial state to Connecting. (crbug/659423)
m_state(WebPresentationConnectionState::Connected),
- m_binaryType(BinaryTypeBlob) {}
+ m_binaryType(BinaryTypeBlob),
+ m_proxy(nullptr) {}
PresentationConnection::~PresentationConnection() {
ASSERT(!m_blobLoader);
}
+void PresentationConnection::SetPresentationConnectionProxy(
+ std::unique_ptr<WebPresentationConnectionProxy> proxy) {
+ if (!proxy)
+ return;
+
+ m_proxy = std::move(proxy);
+ m_proxy->SetSourceConnection(this);
+}
+
// static
PresentationConnection* PresentationConnection::take(
ScriptPromiseResolver* resolver,
@@ -191,6 +201,8 @@ PresentationConnection* PresentationConnection::take(
PresentationConnection* connection = new PresentationConnection(
controller->frame(), client->getId(), client->getUrl());
+ connection->SetPresentationConnectionProxy(client->takeProxy());
+
controller->registerConnection(connection);
request->dispatchEvent(PresentationConnectionAvailableEvent::create(
EventTypeNames::connectionavailable, connection));
@@ -207,6 +219,8 @@ PresentationConnection* PresentationConnection::take(
PresentationConnection* connection = new PresentationConnection(
receiver->frame(), client->getId(), client->getUrl());
+ connection->SetPresentationConnectionProxy(client->takeProxy());
+
receiver->registerConnection(connection);
return connection;
@@ -308,13 +322,23 @@ void PresentationConnection::handleMessageQueue() {
Message* message = m_messages.first().get();
switch (message->type) {
case MessageTypeText:
- client->sendString(m_url, m_id, message->text);
+ if (m_proxy)
+ m_proxy->SendString(message->text);
+ else
+ client->sendString(m_url, m_id, message->text);
m_messages.removeFirst();
break;
case MessageTypeArrayBuffer:
- client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>(
- message->arrayBuffer->data()),
- message->arrayBuffer->byteLength());
+ if (m_proxy) {
+ m_proxy->SendArrayBuffer(
+ static_cast<const uint8_t*>(message->arrayBuffer->data()),
+ message->arrayBuffer->byteLength());
+ } else {
+ client->sendArrayBuffer(
+ m_url, m_id,
+ static_cast<const uint8_t*>(message->arrayBuffer->data()),
+ message->arrayBuffer->byteLength());
+ }
m_messages.removeFirst();
break;
case MessageTypeBlob:
@@ -348,7 +372,7 @@ void PresentationConnection::setBinaryType(const String& binaryType) {
ASSERT_NOT_REACHED();
}
-void PresentationConnection::didReceiveTextMessage(const String& message) {
+void PresentationConnection::didReceiveTextMessage(const WebString& message) {
if (m_state != WebPresentationConnectionState::Connected)
return;

Powered by Google App Engine
This is Rietveld 408576698