| 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 client->sendString(m_url, m_id, message->text, m_proxy.get()); |
| 311 m_messages.removeFirst(); | 325 m_messages.removeFirst(); |
| 312 break; | 326 break; |
| 313 case MessageTypeArrayBuffer: | 327 case MessageTypeArrayBuffer: |
| 314 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 328 client->sendArrayBuffer( |
| 315 message->arrayBuffer->data()), | 329 m_url, m_id, |
| 316 message->arrayBuffer->byteLength()); | 330 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 331 message->arrayBuffer->byteLength(), m_proxy.get()); |
| 317 m_messages.removeFirst(); | 332 m_messages.removeFirst(); |
| 318 break; | 333 break; |
| 319 case MessageTypeBlob: | 334 case MessageTypeBlob: |
| 320 ASSERT(!m_blobLoader); | 335 ASSERT(!m_blobLoader); |
| 321 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 336 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 322 break; | 337 break; |
| 323 } | 338 } |
| 324 } | 339 } |
| 325 } | 340 } |
| 326 | 341 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 340 m_binaryType = BinaryTypeBlob; | 355 m_binaryType = BinaryTypeBlob; |
| 341 return; | 356 return; |
| 342 } | 357 } |
| 343 if (binaryType == "arraybuffer") { | 358 if (binaryType == "arraybuffer") { |
| 344 m_binaryType = BinaryTypeArrayBuffer; | 359 m_binaryType = BinaryTypeArrayBuffer; |
| 345 return; | 360 return; |
| 346 } | 361 } |
| 347 ASSERT_NOT_REACHED(); | 362 ASSERT_NOT_REACHED(); |
| 348 } | 363 } |
| 349 | 364 |
| 350 void PresentationConnection::didReceiveTextMessage(const String& message) { | 365 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
| 351 if (m_state != WebPresentationConnectionState::Connected) | 366 if (m_state != WebPresentationConnectionState::Connected) |
| 352 return; | 367 return; |
| 353 | 368 |
| 354 dispatchEvent(MessageEvent::create(message)); | 369 dispatchEvent(MessageEvent::create(message)); |
| 355 } | 370 } |
| 356 | 371 |
| 357 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 372 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
| 358 size_t length) { | 373 size_t length) { |
| 359 if (m_state != WebPresentationConnectionState::Connected) | 374 if (m_state != WebPresentationConnectionState::Connected) |
| 360 return; | 375 return; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 m_state = WebPresentationConnectionState::Closed; | 452 m_state = WebPresentationConnectionState::Closed; |
| 438 dispatchEvent(PresentationConnectionCloseEvent::create( | 453 dispatchEvent(PresentationConnectionCloseEvent::create( |
| 439 EventTypeNames::close, connectionCloseReasonToString(reason), message)); | 454 EventTypeNames::close, connectionCloseReasonToString(reason), message)); |
| 440 } | 455 } |
| 441 | 456 |
| 442 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { | 457 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { |
| 443 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 458 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
| 444 ASSERT(buffer && buffer->buffer()); | 459 ASSERT(buffer && buffer->buffer()); |
| 445 // Send the loaded blob immediately here and continue processing the queue. | 460 // Send the loaded blob immediately here and continue processing the queue. |
| 446 WebPresentationClient* client = presentationClient(getExecutionContext()); | 461 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 447 if (client) | 462 if (client) { |
| 448 client->sendBlobData(m_url, m_id, | 463 client->sendBlobData(m_url, m_id, |
| 449 static_cast<const uint8_t*>(buffer->data()), | 464 static_cast<const uint8_t*>(buffer->data()), |
| 450 buffer->byteLength()); | 465 buffer->byteLength(), m_proxy.get()); |
| 466 } |
| 451 | 467 |
| 452 m_messages.removeFirst(); | 468 m_messages.removeFirst(); |
| 453 m_blobLoader.clear(); | 469 m_blobLoader.clear(); |
| 454 handleMessageQueue(); | 470 handleMessageQueue(); |
| 455 } | 471 } |
| 456 | 472 |
| 457 void PresentationConnection::didFailLoadingBlob( | 473 void PresentationConnection::didFailLoadingBlob( |
| 458 FileError::ErrorCode errorCode) { | 474 FileError::ErrorCode errorCode) { |
| 459 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); | 475 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); |
| 460 // FIXME: generate error message? | 476 // FIXME: generate error message? |
| 461 // Ignore the current failed blob item and continue with next items. | 477 // Ignore the current failed blob item and continue with next items. |
| 462 m_messages.removeFirst(); | 478 m_messages.removeFirst(); |
| 463 m_blobLoader.clear(); | 479 m_blobLoader.clear(); |
| 464 handleMessageQueue(); | 480 handleMessageQueue(); |
| 465 } | 481 } |
| 466 | 482 |
| 467 void PresentationConnection::tearDown() { | 483 void PresentationConnection::tearDown() { |
| 468 // Cancel current Blob loading if any. | 484 // Cancel current Blob loading if any. |
| 469 if (m_blobLoader) { | 485 if (m_blobLoader) { |
| 470 m_blobLoader->cancel(); | 486 m_blobLoader->cancel(); |
| 471 m_blobLoader.clear(); | 487 m_blobLoader.clear(); |
| 472 } | 488 } |
| 473 m_messages.clear(); | 489 m_messages.clear(); |
| 474 } | 490 } |
| 475 | 491 |
| 476 } // namespace blink | 492 } // namespace blink |
| OLD | NEW |