| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/presentation/PresentationConnection.h" | 5 #include "modules/presentation/PresentationConnection.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
| 9 #include "core/dom/DOMArrayBufferView.h" | 9 #include "core/dom/DOMArrayBufferView.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 std::unique_ptr<FileReaderLoader> m_loader; | 145 std::unique_ptr<FileReaderLoader> m_loader; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 PresentationConnection::PresentationConnection(LocalFrame* frame, | 148 PresentationConnection::PresentationConnection(LocalFrame* frame, |
| 149 const String& id, | 149 const String& id, |
| 150 const KURL& url) | 150 const KURL& url) |
| 151 : DOMWindowProperty(frame), | 151 : DOMWindowProperty(frame), |
| 152 m_id(id), | 152 m_id(id), |
| 153 m_url(url), | 153 m_url(url), |
| 154 m_state(WebPresentationConnectionState::Connecting), | 154 m_state(WebPresentationConnectionState::Connecting), |
| 155 m_binaryType(BinaryTypeBlob) {} | 155 m_binaryType(BinaryTypeBlob), |
| 156 m_proxy(nullptr) {} |
| 156 | 157 |
| 157 PresentationConnection::~PresentationConnection() { | 158 PresentationConnection::~PresentationConnection() { |
| 158 ASSERT(!m_blobLoader); | 159 ASSERT(!m_blobLoader); |
| 159 } | 160 } |
| 160 | 161 |
| 162 void PresentationConnection::SetPresentationConnectionProxy( |
| 163 std::unique_ptr<WebPresentationConnectionProxy> proxy) { |
| 164 if (!proxy) |
| 165 return; |
| 166 |
| 167 m_proxy = std::move(proxy); |
| 168 m_proxy->SetSourceConnection(this); |
| 169 } |
| 170 |
| 161 // static | 171 // static |
| 162 PresentationConnection* PresentationConnection::take( | 172 PresentationConnection* PresentationConnection::take( |
| 163 ScriptPromiseResolver* resolver, | 173 ScriptPromiseResolver* resolver, |
| 164 std::unique_ptr<WebPresentationConnectionClient> client, | 174 std::unique_ptr<WebPresentationConnectionClient> client, |
| 165 PresentationRequest* request) { | 175 PresentationRequest* request) { |
| 166 ASSERT(resolver); | 176 ASSERT(resolver); |
| 167 ASSERT(client); | 177 ASSERT(client); |
| 168 ASSERT(request); | 178 ASSERT(request); |
| 169 ASSERT(resolver->getExecutionContext()->isDocument()); | 179 ASSERT(resolver->getExecutionContext()->isDocument()); |
| 170 | 180 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 183 // static | 193 // static |
| 184 PresentationConnection* PresentationConnection::take( | 194 PresentationConnection* PresentationConnection::take( |
| 185 PresentationController* controller, | 195 PresentationController* controller, |
| 186 std::unique_ptr<WebPresentationConnectionClient> client, | 196 std::unique_ptr<WebPresentationConnectionClient> client, |
| 187 PresentationRequest* request) { | 197 PresentationRequest* request) { |
| 188 ASSERT(controller); | 198 ASSERT(controller); |
| 189 ASSERT(request); | 199 ASSERT(request); |
| 190 | 200 |
| 191 PresentationConnection* connection = new PresentationConnection( | 201 PresentationConnection* connection = new PresentationConnection( |
| 192 controller->frame(), client->getId(), client->getUrl()); | 202 controller->frame(), client->getId(), client->getUrl()); |
| 203 connection->SetPresentationConnectionProxy(client->takeProxy()); |
| 204 |
| 193 controller->registerConnection(connection); | 205 controller->registerConnection(connection); |
| 194 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | 206 request->dispatchEvent(PresentationConnectionAvailableEvent::create( |
| 195 EventTypeNames::connectionavailable, connection)); | 207 EventTypeNames::connectionavailable, connection)); |
| 196 | 208 |
| 197 return connection; | 209 return connection; |
| 198 } | 210 } |
| 199 | 211 |
| 200 // static | 212 // static |
| 201 PresentationConnection* PresentationConnection::take( | 213 PresentationConnection* PresentationConnection::take( |
| 202 PresentationReceiver* receiver, | 214 PresentationReceiver* receiver, |
| 203 std::unique_ptr<WebPresentationConnectionClient> client) { | 215 std::unique_ptr<WebPresentationConnectionClient> client) { |
| 204 DCHECK(receiver); | 216 DCHECK(receiver); |
| 205 DCHECK(client); | 217 DCHECK(client); |
| 206 | 218 |
| 207 PresentationConnection* connection = new PresentationConnection( | 219 PresentationConnection* connection = new PresentationConnection( |
| 208 receiver->frame(), client->getId(), client->getUrl()); | 220 receiver->frame(), client->getId(), client->getUrl()); |
| 221 connection->SetPresentationConnectionProxy(client->takeProxy()); |
| 222 |
| 209 receiver->registerConnection(connection); | 223 receiver->registerConnection(connection); |
| 210 | 224 |
| 211 return connection; | 225 return connection; |
| 212 } | 226 } |
| 213 | 227 |
| 214 const AtomicString& PresentationConnection::interfaceName() const { | 228 const AtomicString& PresentationConnection::interfaceName() const { |
| 215 return EventTargetNames::PresentationConnection; | 229 return EventTargetNames::PresentationConnection; |
| 216 } | 230 } |
| 217 | 231 |
| 218 ExecutionContext* PresentationConnection::getExecutionContext() const { | 232 ExecutionContext* PresentationConnection::getExecutionContext() const { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 314 |
| 301 void PresentationConnection::handleMessageQueue() { | 315 void PresentationConnection::handleMessageQueue() { |
| 302 WebPresentationClient* client = presentationClient(getExecutionContext()); | 316 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 303 if (!client) | 317 if (!client) |
| 304 return; | 318 return; |
| 305 | 319 |
| 306 while (!m_messages.isEmpty() && !m_blobLoader) { | 320 while (!m_messages.isEmpty() && !m_blobLoader) { |
| 307 Message* message = m_messages.first().get(); | 321 Message* message = m_messages.first().get(); |
| 308 switch (message->type) { | 322 switch (message->type) { |
| 309 case MessageTypeText: | 323 case MessageTypeText: |
| 310 client->sendString(m_url, m_id, message->text); | 324 if (m_proxy) |
| 325 m_proxy->SendString(message->text); |
| 326 else |
| 327 client->sendString(m_url, m_id, message->text); |
| 311 m_messages.removeFirst(); | 328 m_messages.removeFirst(); |
| 312 break; | 329 break; |
| 313 case MessageTypeArrayBuffer: | 330 case MessageTypeArrayBuffer: |
| 314 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 331 if (m_proxy) { |
| 315 message->arrayBuffer->data()), | 332 m_proxy->SendArrayBuffer( |
| 316 message->arrayBuffer->byteLength()); | 333 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 334 message->arrayBuffer->byteLength()); |
| 335 } else { |
| 336 client->sendArrayBuffer( |
| 337 m_url, m_id, |
| 338 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 339 message->arrayBuffer->byteLength()); |
| 340 } |
| 317 m_messages.removeFirst(); | 341 m_messages.removeFirst(); |
| 318 break; | 342 break; |
| 319 case MessageTypeBlob: | 343 case MessageTypeBlob: |
| 320 ASSERT(!m_blobLoader); | 344 ASSERT(!m_blobLoader); |
| 321 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 345 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 322 break; | 346 break; |
| 323 } | 347 } |
| 324 } | 348 } |
| 325 } | 349 } |
| 326 | 350 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 340 m_binaryType = BinaryTypeBlob; | 364 m_binaryType = BinaryTypeBlob; |
| 341 return; | 365 return; |
| 342 } | 366 } |
| 343 if (binaryType == "arraybuffer") { | 367 if (binaryType == "arraybuffer") { |
| 344 m_binaryType = BinaryTypeArrayBuffer; | 368 m_binaryType = BinaryTypeArrayBuffer; |
| 345 return; | 369 return; |
| 346 } | 370 } |
| 347 ASSERT_NOT_REACHED(); | 371 ASSERT_NOT_REACHED(); |
| 348 } | 372 } |
| 349 | 373 |
| 350 void PresentationConnection::didReceiveTextMessage(const String& message) { | 374 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
| 351 if (m_state != WebPresentationConnectionState::Connected) | 375 if (m_state != WebPresentationConnectionState::Connected) |
| 352 return; | 376 return; |
| 353 | 377 |
| 354 dispatchEvent(MessageEvent::create(message)); | 378 dispatchEvent(MessageEvent::create(message)); |
| 355 } | 379 } |
| 356 | 380 |
| 357 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 381 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
| 358 size_t length) { | 382 size_t length) { |
| 359 if (m_state != WebPresentationConnectionState::Connected) | 383 if (m_state != WebPresentationConnectionState::Connected) |
| 360 return; | 384 return; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 void PresentationConnection::tearDown() { | 491 void PresentationConnection::tearDown() { |
| 468 // Cancel current Blob loading if any. | 492 // Cancel current Blob loading if any. |
| 469 if (m_blobLoader) { | 493 if (m_blobLoader) { |
| 470 m_blobLoader->cancel(); | 494 m_blobLoader->cancel(); |
| 471 m_blobLoader.clear(); | 495 m_blobLoader.clear(); |
| 472 } | 496 } |
| 473 m_messages.clear(); | 497 m_messages.clear(); |
| 474 } | 498 } |
| 475 | 499 |
| 476 } // namespace blink | 500 } // namespace blink |
| OLD | NEW |