| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 void cancel() { m_loader->cancel(); } | 136 void cancel() { m_loader->cancel(); } |
| 137 | 137 |
| 138 DEFINE_INLINE_TRACE() { visitor->trace(m_PresentationConnection); } | 138 DEFINE_INLINE_TRACE() { visitor->trace(m_PresentationConnection); } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 Member<PresentationConnection> m_PresentationConnection; | 141 Member<PresentationConnection> m_PresentationConnection; |
| 142 std::unique_ptr<FileReaderLoader> m_loader; | 142 std::unique_ptr<FileReaderLoader> m_loader; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 PresentationConnection::PresentationConnection(LocalFrame* frame, | 145 PresentationConnection::PresentationConnection( |
| 146 const String& id, | 146 LocalFrame* frame, |
| 147 const KURL& url) | 147 const String& id, |
| 148 const KURL& url, |
| 149 WebPresentationConnectionProxy* proxy) |
| 148 : DOMWindowProperty(frame), | 150 : DOMWindowProperty(frame), |
| 149 m_id(id), | 151 m_id(id), |
| 150 m_url(url), | 152 m_url(url), |
| 151 m_state(WebPresentationConnectionState::Connected), | 153 m_state(WebPresentationConnectionState::Connected), |
| 152 m_binaryType(BinaryTypeBlob) {} | 154 m_binaryType(BinaryTypeBlob), |
| 155 m_proxy(proxy) { |
| 156 DCHECK(m_proxy); |
| 157 m_proxy->SetConnection(this); |
| 158 } |
| 153 | 159 |
| 154 PresentationConnection::~PresentationConnection() { | 160 PresentationConnection::~PresentationConnection() { |
| 155 ASSERT(!m_blobLoader); | 161 ASSERT(!m_blobLoader); |
| 156 } | 162 } |
| 157 | 163 |
| 158 // static | 164 // static |
| 159 PresentationConnection* PresentationConnection::take( | 165 PresentationConnection* PresentationConnection::take( |
| 160 ScriptPromiseResolver* resolver, | 166 ScriptPromiseResolver* resolver, |
| 161 std::unique_ptr<WebPresentationConnectionClient> client, | 167 std::unique_ptr<WebPresentationConnectionClient> client, |
| 162 PresentationRequest* request) { | 168 PresentationRequest* request) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 178 } | 184 } |
| 179 | 185 |
| 180 // static | 186 // static |
| 181 PresentationConnection* PresentationConnection::take( | 187 PresentationConnection* PresentationConnection::take( |
| 182 PresentationController* controller, | 188 PresentationController* controller, |
| 183 std::unique_ptr<WebPresentationConnectionClient> client, | 189 std::unique_ptr<WebPresentationConnectionClient> client, |
| 184 PresentationRequest* request) { | 190 PresentationRequest* request) { |
| 185 ASSERT(controller); | 191 ASSERT(controller); |
| 186 ASSERT(request); | 192 ASSERT(request); |
| 187 | 193 |
| 188 PresentationConnection* connection = new PresentationConnection( | 194 PresentationConnection* connection = |
| 189 controller->frame(), client->getId(), client->getUrl()); | 195 new PresentationConnection(controller->frame(), client->getId(), |
| 196 client->getUrl(), client->getOrCreateProxy()); |
| 190 controller->registerConnection(connection); | 197 controller->registerConnection(connection); |
| 191 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | 198 request->dispatchEvent(PresentationConnectionAvailableEvent::create( |
| 192 EventTypeNames::connectionavailable, connection)); | 199 EventTypeNames::connectionavailable, connection)); |
| 193 | 200 |
| 194 return connection; | 201 return connection; |
| 195 } | 202 } |
| 196 | 203 |
| 197 // static | 204 // static |
| 198 PresentationConnection* PresentationConnection::take( | 205 PresentationConnection* PresentationConnection::take( |
| 199 PresentationReceiver* receiver, | 206 PresentationReceiver* receiver, |
| 200 std::unique_ptr<WebPresentationConnectionClient> client) { | 207 std::unique_ptr<WebPresentationConnectionClient> client) { |
| 201 DCHECK(receiver); | 208 DCHECK(receiver); |
| 202 DCHECK(client); | 209 DCHECK(client); |
| 203 | 210 |
| 204 PresentationConnection* connection = new PresentationConnection( | 211 PresentationConnection* connection = |
| 205 receiver->frame(), client->getId(), client->getUrl()); | 212 new PresentationConnection(receiver->frame(), client->getId(), |
| 213 client->getUrl(), client->getOrCreateProxy()); |
| 206 receiver->registerConnection(connection); | 214 receiver->registerConnection(connection); |
| 207 | 215 |
| 208 return connection; | 216 return connection; |
| 209 } | 217 } |
| 210 | 218 |
| 211 const AtomicString& PresentationConnection::interfaceName() const { | 219 const AtomicString& PresentationConnection::interfaceName() const { |
| 212 return EventTargetNames::PresentationConnection; | 220 return EventTargetNames::PresentationConnection; |
| 213 } | 221 } |
| 214 | 222 |
| 215 ExecutionContext* PresentationConnection::getExecutionContext() const { | 223 ExecutionContext* PresentationConnection::getExecutionContext() const { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 305 |
| 298 void PresentationConnection::handleMessageQueue() { | 306 void PresentationConnection::handleMessageQueue() { |
| 299 WebPresentationClient* client = presentationClient(getExecutionContext()); | 307 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 300 if (!client) | 308 if (!client) |
| 301 return; | 309 return; |
| 302 | 310 |
| 303 while (!m_messages.isEmpty() && !m_blobLoader) { | 311 while (!m_messages.isEmpty() && !m_blobLoader) { |
| 304 Message* message = m_messages.first().get(); | 312 Message* message = m_messages.first().get(); |
| 305 switch (message->type) { | 313 switch (message->type) { |
| 306 case MessageTypeText: | 314 case MessageTypeText: |
| 315 m_proxy->SendString(message->text); |
| 307 client->sendString(m_url, m_id, message->text); | 316 client->sendString(m_url, m_id, message->text); |
| 308 m_messages.removeFirst(); | 317 m_messages.removeFirst(); |
| 309 break; | 318 break; |
| 310 case MessageTypeArrayBuffer: | 319 case MessageTypeArrayBuffer: |
| 320 m_proxy->SendArrayBuffer( |
| 321 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 322 message->arrayBuffer->byteLength()); |
| 311 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 323 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( |
| 312 message->arrayBuffer->data()), | 324 message->arrayBuffer->data()), |
| 313 message->arrayBuffer->byteLength()); | 325 message->arrayBuffer->byteLength()); |
| 314 m_messages.removeFirst(); | 326 m_messages.removeFirst(); |
| 315 break; | 327 break; |
| 316 case MessageTypeBlob: | 328 case MessageTypeBlob: |
| 317 ASSERT(!m_blobLoader); | 329 ASSERT(!m_blobLoader); |
| 318 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 330 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 319 break; | 331 break; |
| 320 } | 332 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 337 m_binaryType = BinaryTypeBlob; | 349 m_binaryType = BinaryTypeBlob; |
| 338 return; | 350 return; |
| 339 } | 351 } |
| 340 if (binaryType == "arraybuffer") { | 352 if (binaryType == "arraybuffer") { |
| 341 m_binaryType = BinaryTypeArrayBuffer; | 353 m_binaryType = BinaryTypeArrayBuffer; |
| 342 return; | 354 return; |
| 343 } | 355 } |
| 344 ASSERT_NOT_REACHED(); | 356 ASSERT_NOT_REACHED(); |
| 345 } | 357 } |
| 346 | 358 |
| 347 void PresentationConnection::didReceiveTextMessage(const String& message) { | 359 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
| 348 if (m_state != WebPresentationConnectionState::Connected) | 360 if (m_state != WebPresentationConnectionState::Connected) |
| 349 return; | 361 return; |
| 350 | 362 |
| 351 dispatchEvent(MessageEvent::create(message)); | 363 dispatchEvent(MessageEvent::create(message)); |
| 352 } | 364 } |
| 353 | 365 |
| 354 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 366 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
| 355 size_t length) { | 367 size_t length) { |
| 356 if (m_state != WebPresentationConnectionState::Connected) | 368 if (m_state != WebPresentationConnectionState::Connected) |
| 357 return; | 369 return; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 void PresentationConnection::tearDown() { | 470 void PresentationConnection::tearDown() { |
| 459 // Cancel current Blob loading if any. | 471 // Cancel current Blob loading if any. |
| 460 if (m_blobLoader) { | 472 if (m_blobLoader) { |
| 461 m_blobLoader->cancel(); | 473 m_blobLoader->cancel(); |
| 462 m_blobLoader.clear(); | 474 m_blobLoader.clear(); |
| 463 } | 475 } |
| 464 m_messages.clear(); | 476 m_messages.clear(); |
| 465 } | 477 } |
| 466 | 478 |
| 467 } // namespace blink | 479 } // namespace blink |
| OLD | NEW |