| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 WebSocket::WebSocket(ExecutionContext* context) | 134 WebSocket::WebSocket(ExecutionContext* context) |
| 135 : ActiveDOMObject(context) | 135 : ActiveDOMObject(context) |
| 136 , m_state(CONNECTING) | 136 , m_state(CONNECTING) |
| 137 , m_bufferedAmount(0) | 137 , m_bufferedAmount(0) |
| 138 , m_bufferedAmountAfterClose(0) | 138 , m_bufferedAmountAfterClose(0) |
| 139 , m_binaryType(BinaryTypeBlob) | 139 , m_binaryType(BinaryTypeBlob) |
| 140 , m_subprotocol("") | 140 , m_subprotocol("") |
| 141 , m_extensions("") | 141 , m_extensions("") |
| 142 , m_stopped(false) | 142 , m_stopped(false) |
| 143 , m_timerForDeferredDropProtection(this, &WebSocket::dropProtection) | 143 , m_dropProtectionRunner(this, &WebSocket::dropProtection) |
| 144 { | 144 { |
| 145 ScriptWrappable::init(this); | 145 ScriptWrappable::init(this); |
| 146 } | 146 } |
| 147 | 147 |
| 148 WebSocket::~WebSocket() | 148 WebSocket::~WebSocket() |
| 149 { | 149 { |
| 150 if (m_channel) | 150 if (m_channel) |
| 151 m_channel->disconnect(); | 151 m_channel->disconnect(); |
| 152 } | 152 } |
| 153 | 153 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 if (m_channel) | 471 if (m_channel) |
| 472 m_channel->suspend(); | 472 m_channel->suspend(); |
| 473 } | 473 } |
| 474 | 474 |
| 475 void WebSocket::resume() | 475 void WebSocket::resume() |
| 476 { | 476 { |
| 477 if (m_channel) | 477 if (m_channel) |
| 478 m_channel->resume(); | 478 m_channel->resume(); |
| 479 } | 479 } |
| 480 | 480 |
| 481 void WebSocket::dropProtection(Timer<WebSocket>*) | 481 void WebSocket::dropProtection() |
| 482 { | 482 { |
| 483 unsetPendingActivity(this); | 483 unsetPendingActivity(this); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void WebSocket::stop() | 486 void WebSocket::stop() |
| 487 { | 487 { |
| 488 m_stopped = true; | 488 m_stopped = true; |
| 489 | 489 |
| 490 if (!hasPendingActivity()) { | 490 if (!hasPendingActivity()) { |
| 491 ASSERT(!m_channel); | 491 ASSERT(!m_channel); |
| 492 ASSERT(m_state == CLOSED); | 492 ASSERT(m_state == CLOSED); |
| 493 return; | 493 return; |
| 494 } | 494 } |
| 495 if (m_channel) { | 495 if (m_channel) { |
| 496 m_channel->close(WebSocketChannel::CloseEventCodeGoingAway, String()); | 496 m_channel->close(WebSocketChannel::CloseEventCodeGoingAway, String()); |
| 497 m_channel->disconnect(); | 497 m_channel->disconnect(); |
| 498 m_channel = 0; | 498 m_channel = 0; |
| 499 } | 499 } |
| 500 m_state = CLOSED; | 500 m_state = CLOSED; |
| 501 | 501 |
| 502 ActiveDOMObject::stop(); | 502 ActiveDOMObject::stop(); |
| 503 | 503 |
| 504 // ContextLifecycleNotifier is iterating over the set of ActiveDOMObject | 504 // ContextLifecycleNotifier is iterating over the set of ActiveDOMObject |
| 505 // instances. Deleting this WebSocket instance synchronously leads to | 505 // instances. Deleting this WebSocket instance synchronously leads to |
| 506 // ContextLifecycleNotifier::removeObserver() call which is prohibited | 506 // ContextLifecycleNotifier::removeObserver() call which is prohibited |
| 507 // to be called during iteration. Defer it. | 507 // to be called during iteration. Defer it. |
| 508 if (m_timerForDeferredDropProtection.isActive()) | 508 m_dropProtectionRunner.runAsync(); |
| 509 return; | |
| 510 m_timerForDeferredDropProtection.startOneShot(0); | |
| 511 } | 509 } |
| 512 | 510 |
| 513 void WebSocket::didConnect() | 511 void WebSocket::didConnect() |
| 514 { | 512 { |
| 515 LOG(Network, "WebSocket %p didConnect()", this); | 513 LOG(Network, "WebSocket %p didConnect()", this); |
| 516 if (m_state != CONNECTING) | 514 if (m_state != CONNECTING) |
| 517 return; | 515 return; |
| 518 m_state = OPEN; | 516 m_state = OPEN; |
| 519 m_subprotocol = m_channel->subprotocol(); | 517 m_subprotocol = m_channel->subprotocol(); |
| 520 m_extensions = m_channel->extensions(); | 518 m_extensions = m_channel->extensions(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0
x10000; | 616 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0
x10000; |
| 619 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; | 617 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; |
| 620 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) | 618 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) |
| 621 overhead += 8; | 619 overhead += 8; |
| 622 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) | 620 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) |
| 623 overhead += 2; | 621 overhead += 2; |
| 624 return overhead; | 622 return overhead; |
| 625 } | 623 } |
| 626 | 624 |
| 627 } // namespace WebCore | 625 } // namespace WebCore |
| OLD | NEW |