| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); | 308 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); |
| 309 return false; | 309 return false; |
| 310 } | 310 } |
| 311 ASSERT(m_channel); | 311 ASSERT(m_channel); |
| 312 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); | 312 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); |
| 313 return m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBuf
ferView->byteLength()) == ThreadableWebSocketChannel::SendSuccess; | 313 return m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBuf
ferView->byteLength()) == ThreadableWebSocketChannel::SendSuccess; |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool WebSocket::send(Blob* binaryData, ExceptionCode& ec) | 316 bool WebSocket::send(Blob* binaryData, ExceptionCode& ec) |
| 317 { | 317 { |
| 318 LOG(Network, "WebSocket %p send blob %s", this, binaryData->url().string().u
tf8().data()); | 318 LOG(Network, "WebSocket %p send blob %s", this, binaryData->uuid().utf8().da
ta()); |
| 319 ASSERT(binaryData); | 319 ASSERT(binaryData); |
| 320 if (m_state == CONNECTING) { | 320 if (m_state == CONNECTING) { |
| 321 ec = INVALID_STATE_ERR; | 321 ec = INVALID_STATE_ERR; |
| 322 return false; | 322 return false; |
| 323 } | 323 } |
| 324 if (m_state == CLOSING || m_state == CLOSED) { | 324 if (m_state == CLOSING || m_state == CLOSED) { |
| 325 unsigned long payloadSize = static_cast<unsigned long>(binaryData->size(
)); | 325 unsigned long payloadSize = static_cast<unsigned long>(binaryData->size(
)); |
| 326 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay
loadSize); | 326 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay
loadSize); |
| 327 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); | 327 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); |
| 328 return false; | 328 return false; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 if (m_state != OPEN && m_state != CLOSING) | 484 if (m_state != OPEN && m_state != CLOSING) |
| 485 return; | 485 return; |
| 486 ASSERT(scriptExecutionContext()); | 486 ASSERT(scriptExecutionContext()); |
| 487 dispatchEvent(MessageEvent::create(msg)); | 487 dispatchEvent(MessageEvent::create(msg)); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) | 490 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) |
| 491 { | 491 { |
| 492 switch (m_binaryType) { | 492 switch (m_binaryType) { |
| 493 case BinaryTypeBlob: { | 493 case BinaryTypeBlob: { |
| 494 // FIXME: What if this is a very large amount of data, too large to reas
onably fit |
| 495 // into a Vector<char>? |
| 494 size_t size = binaryData->size(); | 496 size_t size = binaryData->size(); |
| 495 RefPtr<RawData> rawData = RawData::create(); | 497 RefPtr<RawData> rawData = RawData::create(); |
| 496 binaryData->swap(*rawData->mutableData()); | 498 binaryData->swap(*rawData->mutableData()); |
| 497 OwnPtr<BlobData> blobData = BlobData::create(); | 499 OwnPtr<BlobData> blobData = BlobData::create(); |
| 498 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); | 500 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); |
| 499 RefPtr<Blob> blob = Blob::create(blobData.release(), size); | 501 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release
(), size)); |
| 500 dispatchEvent(MessageEvent::create(blob.release())); | 502 dispatchEvent(MessageEvent::create(blob.release())); |
| 501 break; | 503 break; |
| 502 } | 504 } |
| 503 | 505 |
| 504 case BinaryTypeArrayBuffer: | 506 case BinaryTypeArrayBuffer: |
| 505 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->data(
), binaryData->size()))); | 507 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->data(
), binaryData->size()))); |
| 506 break; | 508 break; |
| 507 } | 509 } |
| 508 } | 510 } |
| 509 | 511 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) | 569 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) |
| 568 overhead += 8; | 570 overhead += 8; |
| 569 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) | 571 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) |
| 570 overhead += 2; | 572 overhead += 2; |
| 571 return overhead; | 573 return overhead; |
| 572 } | 574 } |
| 573 | 575 |
| 574 } // namespace WebCore | 576 } // namespace WebCore |
| 575 | 577 |
| 576 #endif | 578 #endif |
| OLD | NEW |