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 "config.h" | 5 #include "config.h" |
6 #include "modules/presentation/PresentationConnection.h" | 6 #include "modules/presentation/PresentationConnection.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/DOMArrayBufferView.h" | 10 #include "core/dom/DOMArrayBufferView.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 return; | 307 return; |
308 } | 308 } |
309 case BinaryTypeArrayBuffer: | 309 case BinaryTypeArrayBuffer: |
310 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); | 310 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, length); |
311 dispatchEvent(MessageEvent::create(buffer.release())); | 311 dispatchEvent(MessageEvent::create(buffer.release())); |
312 return; | 312 return; |
313 } | 313 } |
314 ASSERT_NOT_REACHED(); | 314 ASSERT_NOT_REACHED(); |
315 } | 315 } |
316 | 316 |
| 317 void PresentationConnection::close() |
| 318 { |
| 319 if (m_state != WebPresentationConnectionState::Connected) |
| 320 return; |
| 321 WebPresentationClient* client = presentationClient(executionContext()); |
| 322 if (client) |
| 323 client->closeSession(m_url, m_id); |
| 324 |
| 325 tearDown(); |
| 326 } |
| 327 |
317 void PresentationConnection::terminate() | 328 void PresentationConnection::terminate() |
318 { | 329 { |
319 if (m_state != WebPresentationConnectionState::Connected) | 330 if (m_state != WebPresentationConnectionState::Connected) |
320 return; | 331 return; |
321 WebPresentationClient* client = presentationClient(executionContext()); | 332 WebPresentationClient* client = presentationClient(executionContext()); |
322 if (client) | 333 if (client) |
323 client->terminateSession(m_url, m_id); | 334 client->terminateSession(m_url, m_id); |
324 | 335 |
325 // Cancel current Blob loading if any. | 336 tearDown(); |
326 if (m_blobLoader) { | |
327 m_blobLoader->cancel(); | |
328 m_blobLoader.clear(); | |
329 } | |
330 | |
331 // Clear message queue. | |
332 Deque<OwnPtr<Message>> empty; | |
333 m_messages.swap(empty); | |
334 } | 337 } |
335 | 338 |
336 bool PresentationConnection::matches(WebPresentationConnectionClient* client) co
nst | 339 bool PresentationConnection::matches(WebPresentationConnectionClient* client) co
nst |
337 { | 340 { |
338 return client && m_url == static_cast<String>(client->getUrl()) && m_id == s
tatic_cast<String>(client->getId()); | 341 return client && m_url == static_cast<String>(client->getUrl()) && m_id == s
tatic_cast<String>(client->getId()); |
339 } | 342 } |
340 | 343 |
341 void PresentationConnection::didChangeState(WebPresentationConnectionState state
) | 344 void PresentationConnection::didChangeState(WebPresentationConnectionState state
) |
342 { | 345 { |
343 if (m_state == state) | 346 if (m_state == state) |
(...skipping 20 matching lines...) Expand all Loading... |
364 void PresentationConnection::didFailLoadingBlob(FileError::ErrorCode errorCode) | 367 void PresentationConnection::didFailLoadingBlob(FileError::ErrorCode errorCode) |
365 { | 368 { |
366 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; | 369 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; |
367 // FIXME: generate error message? | 370 // FIXME: generate error message? |
368 // Ignore the current failed blob item and continue with next items. | 371 // Ignore the current failed blob item and continue with next items. |
369 m_messages.removeFirst(); | 372 m_messages.removeFirst(); |
370 m_blobLoader.clear(); | 373 m_blobLoader.clear(); |
371 handleMessageQueue(); | 374 handleMessageQueue(); |
372 } | 375 } |
373 | 376 |
374 bool PresentationConnection::isDisconnected() const | 377 void PresentationConnection::tearDown() |
375 { | 378 { |
376 return m_state == WebPresentationConnectionState::Closed || m_state == WebPr
esentationConnectionState::Terminated; | 379 // Cancel current Blob loading if any. |
| 380 if (m_blobLoader) { |
| 381 m_blobLoader->cancel(); |
| 382 m_blobLoader.clear(); |
| 383 } |
| 384 |
| 385 // Clear message queue. |
| 386 Deque<OwnPtr<Message>> empty; |
| 387 m_messages.swap(empty); |
377 } | 388 } |
378 | 389 |
379 } // namespace blink | 390 } // namespace blink |
OLD | NEW |