| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // TODO(zhaobin): change initial state to Connecting. (crbug/659423) | 154 // TODO(zhaobin): change initial state to Connecting. (crbug/659423) |
| 155 m_state(WebPresentationConnectionState::Connected), | 155 m_state(WebPresentationConnectionState::Connected), |
| 156 m_binaryType(BinaryTypeBlob) {} | 156 m_binaryType(BinaryTypeBlob), |
| 157 m_proxy(nullptr) {} |
| 157 | 158 |
| 158 PresentationConnection::~PresentationConnection() { | 159 PresentationConnection::~PresentationConnection() { |
| 159 ASSERT(!m_blobLoader); | 160 ASSERT(!m_blobLoader); |
| 160 } | 161 } |
| 161 | 162 |
| 163 void PresentationConnection::SetPresentationConnectionProxy( |
| 164 std::unique_ptr<WebPresentationConnectionProxy> proxy) { |
| 165 if (!proxy) |
| 166 return; |
| 167 |
| 168 m_proxy = std::move(proxy); |
| 169 m_proxy->SetSourceConnection(this); |
| 170 } |
| 171 |
| 162 // static | 172 // static |
| 163 PresentationConnection* PresentationConnection::take( | 173 PresentationConnection* PresentationConnection::take( |
| 164 ScriptPromiseResolver* resolver, | 174 ScriptPromiseResolver* resolver, |
| 165 std::unique_ptr<WebPresentationConnectionClient> client, | 175 std::unique_ptr<WebPresentationConnectionClient> client, |
| 166 PresentationRequest* request) { | 176 PresentationRequest* request) { |
| 167 ASSERT(resolver); | 177 ASSERT(resolver); |
| 168 ASSERT(client); | 178 ASSERT(client); |
| 169 ASSERT(request); | 179 ASSERT(request); |
| 170 ASSERT(resolver->getExecutionContext()->isDocument()); | 180 ASSERT(resolver->getExecutionContext()->isDocument()); |
| 171 | 181 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 184 // static | 194 // static |
| 185 PresentationConnection* PresentationConnection::take( | 195 PresentationConnection* PresentationConnection::take( |
| 186 PresentationController* controller, | 196 PresentationController* controller, |
| 187 std::unique_ptr<WebPresentationConnectionClient> client, | 197 std::unique_ptr<WebPresentationConnectionClient> client, |
| 188 PresentationRequest* request) { | 198 PresentationRequest* request) { |
| 189 ASSERT(controller); | 199 ASSERT(controller); |
| 190 ASSERT(request); | 200 ASSERT(request); |
| 191 | 201 |
| 192 PresentationConnection* connection = new PresentationConnection( | 202 PresentationConnection* connection = new PresentationConnection( |
| 193 controller->frame(), client->getId(), client->getUrl()); | 203 controller->frame(), client->getId(), client->getUrl()); |
| 204 connection->SetPresentationConnectionProxy(client->takeProxy()); |
| 205 |
| 194 controller->registerConnection(connection); | 206 controller->registerConnection(connection); |
| 195 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | 207 request->dispatchEvent(PresentationConnectionAvailableEvent::create( |
| 196 EventTypeNames::connectionavailable, connection)); | 208 EventTypeNames::connectionavailable, connection)); |
| 197 | 209 |
| 198 return connection; | 210 return connection; |
| 199 } | 211 } |
| 200 | 212 |
| 201 // static | 213 // static |
| 202 PresentationConnection* PresentationConnection::take( | 214 PresentationConnection* PresentationConnection::take( |
| 203 PresentationReceiver* receiver, | 215 PresentationReceiver* receiver, |
| 204 std::unique_ptr<WebPresentationConnectionClient> client) { | 216 std::unique_ptr<WebPresentationConnectionClient> client) { |
| 205 DCHECK(receiver); | 217 DCHECK(receiver); |
| 206 DCHECK(client); | 218 DCHECK(client); |
| 207 | 219 |
| 208 PresentationConnection* connection = new PresentationConnection( | 220 PresentationConnection* connection = new PresentationConnection( |
| 209 receiver->frame(), client->getId(), client->getUrl()); | 221 receiver->frame(), client->getId(), client->getUrl()); |
| 222 connection->SetPresentationConnectionProxy(client->takeProxy()); |
| 223 |
| 210 receiver->registerConnection(connection); | 224 receiver->registerConnection(connection); |
| 211 | 225 |
| 212 return connection; | 226 return connection; |
| 213 } | 227 } |
| 214 | 228 |
| 215 const AtomicString& PresentationConnection::interfaceName() const { | 229 const AtomicString& PresentationConnection::interfaceName() const { |
| 216 return EventTargetNames::PresentationConnection; | 230 return EventTargetNames::PresentationConnection; |
| 217 } | 231 } |
| 218 | 232 |
| 219 ExecutionContext* PresentationConnection::getExecutionContext() const { | 233 ExecutionContext* PresentationConnection::getExecutionContext() const { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 315 |
| 302 void PresentationConnection::handleMessageQueue() { | 316 void PresentationConnection::handleMessageQueue() { |
| 303 WebPresentationClient* client = presentationClient(getExecutionContext()); | 317 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 304 if (!client) | 318 if (!client) |
| 305 return; | 319 return; |
| 306 | 320 |
| 307 while (!m_messages.isEmpty() && !m_blobLoader) { | 321 while (!m_messages.isEmpty() && !m_blobLoader) { |
| 308 Message* message = m_messages.first().get(); | 322 Message* message = m_messages.first().get(); |
| 309 switch (message->type) { | 323 switch (message->type) { |
| 310 case MessageTypeText: | 324 case MessageTypeText: |
| 311 client->sendString(m_url, m_id, message->text); | 325 if (m_proxy) |
| 326 m_proxy->SendString(message->text); |
| 327 else |
| 328 client->sendString(m_url, m_id, message->text); |
| 312 m_messages.removeFirst(); | 329 m_messages.removeFirst(); |
| 313 break; | 330 break; |
| 314 case MessageTypeArrayBuffer: | 331 case MessageTypeArrayBuffer: |
| 315 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 332 if (m_proxy) { |
| 316 message->arrayBuffer->data()), | 333 m_proxy->SendArrayBuffer( |
| 317 message->arrayBuffer->byteLength()); | 334 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 335 message->arrayBuffer->byteLength()); |
| 336 } else { |
| 337 client->sendArrayBuffer( |
| 338 m_url, m_id, |
| 339 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
| 340 message->arrayBuffer->byteLength()); |
| 341 } |
| 318 m_messages.removeFirst(); | 342 m_messages.removeFirst(); |
| 319 break; | 343 break; |
| 320 case MessageTypeBlob: | 344 case MessageTypeBlob: |
| 321 ASSERT(!m_blobLoader); | 345 ASSERT(!m_blobLoader); |
| 322 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 346 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 323 break; | 347 break; |
| 324 } | 348 } |
| 325 } | 349 } |
| 326 } | 350 } |
| 327 | 351 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 341 m_binaryType = BinaryTypeBlob; | 365 m_binaryType = BinaryTypeBlob; |
| 342 return; | 366 return; |
| 343 } | 367 } |
| 344 if (binaryType == "arraybuffer") { | 368 if (binaryType == "arraybuffer") { |
| 345 m_binaryType = BinaryTypeArrayBuffer; | 369 m_binaryType = BinaryTypeArrayBuffer; |
| 346 return; | 370 return; |
| 347 } | 371 } |
| 348 ASSERT_NOT_REACHED(); | 372 ASSERT_NOT_REACHED(); |
| 349 } | 373 } |
| 350 | 374 |
| 351 void PresentationConnection::didReceiveTextMessage(const String& message) { | 375 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
| 352 if (m_state != WebPresentationConnectionState::Connected) | 376 if (m_state != WebPresentationConnectionState::Connected) |
| 353 return; | 377 return; |
| 354 | 378 |
| 355 dispatchEvent(MessageEvent::create(message)); | 379 dispatchEvent(MessageEvent::create(message)); |
| 356 } | 380 } |
| 357 | 381 |
| 358 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 382 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
| 359 size_t length) { | 383 size_t length) { |
| 360 if (m_state != WebPresentationConnectionState::Connected) | 384 if (m_state != WebPresentationConnectionState::Connected) |
| 361 return; | 385 return; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 void PresentationConnection::tearDown() { | 492 void PresentationConnection::tearDown() { |
| 469 // Cancel current Blob loading if any. | 493 // Cancel current Blob loading if any. |
| 470 if (m_blobLoader) { | 494 if (m_blobLoader) { |
| 471 m_blobLoader->cancel(); | 495 m_blobLoader->cancel(); |
| 472 m_blobLoader.clear(); | 496 m_blobLoader.clear(); |
| 473 } | 497 } |
| 474 m_messages.clear(); | 498 m_messages.clear(); |
| 475 } | 499 } |
| 476 | 500 |
| 477 } // namespace blink | 501 } // namespace blink |
| OLD | NEW |