| 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); | 346 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); |
| 347 return false; | 347 return false; |
| 348 } | 348 } |
| 349 ASSERT(m_channel); | 349 ASSERT(m_channel); |
| 350 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); | 350 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); |
| 351 return m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBuf
ferView->byteLength()) == ThreadableWebSocketChannel::SendSuccess; | 351 return m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBuf
ferView->byteLength()) == ThreadableWebSocketChannel::SendSuccess; |
| 352 } | 352 } |
| 353 | 353 |
| 354 bool WebSocket::send(Blob* binaryData, ExceptionCode& ec) | 354 bool WebSocket::send(Blob* binaryData, ExceptionCode& ec) |
| 355 { | 355 { |
| 356 LOG(Network, "WebSocket %p send blob %s", this, binaryData->url().string().u
tf8().data()); | 356 LOG(Network, "WebSocket %p send blob %s", this, binaryData->uuid().utf8().da
ta()); |
| 357 ASSERT(binaryData); | 357 ASSERT(binaryData); |
| 358 if (m_state == CONNECTING) { | 358 if (m_state == CONNECTING) { |
| 359 ec = INVALID_STATE_ERR; | 359 ec = INVALID_STATE_ERR; |
| 360 return false; | 360 return false; |
| 361 } | 361 } |
| 362 if (m_state == CLOSING || m_state == CLOSED) { | 362 if (m_state == CLOSING || m_state == CLOSED) { |
| 363 unsigned long payloadSize = static_cast<unsigned long>(binaryData->size(
)); | 363 unsigned long payloadSize = static_cast<unsigned long>(binaryData->size(
)); |
| 364 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay
loadSize); | 364 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay
loadSize); |
| 365 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); | 365 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get
FramingOverhead(payloadSize)); |
| 366 return false; | 366 return false; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 if (m_state != OPEN && m_state != CLOSING) | 516 if (m_state != OPEN && m_state != CLOSING) |
| 517 return; | 517 return; |
| 518 ASSERT(scriptExecutionContext()); | 518 ASSERT(scriptExecutionContext()); |
| 519 dispatchEvent(MessageEvent::create(msg, SecurityOrigin::create(m_url)->toStr
ing())); | 519 dispatchEvent(MessageEvent::create(msg, SecurityOrigin::create(m_url)->toStr
ing())); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) | 522 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) |
| 523 { | 523 { |
| 524 switch (m_binaryType) { | 524 switch (m_binaryType) { |
| 525 case BinaryTypeBlob: { | 525 case BinaryTypeBlob: { |
| 526 // FIXME: What if this is a very large amount of data, too large to reas
onably fit |
| 527 // into a Vector<char>? As data is received, we should be spooling it ou
t incrementally |
| 528 // to construct the blob. |
| 526 size_t size = binaryData->size(); | 529 size_t size = binaryData->size(); |
| 527 RefPtr<RawData> rawData = RawData::create(); | 530 RefPtr<RawData> rawData = RawData::create(); |
| 528 binaryData->swap(*rawData->mutableData()); | 531 binaryData->swap(*rawData->mutableData()); |
| 529 OwnPtr<BlobData> blobData = BlobData::create(); | 532 OwnPtr<BlobData> blobData = BlobData::create(); |
| 530 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); | 533 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); |
| 531 RefPtr<Blob> blob = Blob::create(blobData.release(), size); | 534 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release
(), size)); |
| 532 dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::creat
e(m_url)->toString())); | 535 dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::creat
e(m_url)->toString())); |
| 533 break; | 536 break; |
| 534 } | 537 } |
| 535 | 538 |
| 536 case BinaryTypeArrayBuffer: | 539 case BinaryTypeArrayBuffer: |
| 537 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->data(
), binaryData->size()), SecurityOrigin::create(m_url)->toString())); | 540 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->data(
), binaryData->size()), SecurityOrigin::create(m_url)->toString())); |
| 538 break; | 541 break; |
| 539 } | 542 } |
| 540 } | 543 } |
| 541 | 544 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) | 602 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) |
| 600 overhead += 8; | 603 overhead += 8; |
| 601 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) | 604 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) |
| 602 overhead += 2; | 605 overhead += 2; |
| 603 return overhead; | 606 return overhead; |
| 604 } | 607 } |
| 605 | 608 |
| 606 } // namespace WebCore | 609 } // namespace WebCore |
| 607 | 610 |
| 608 #endif | 611 #endif |
| OLD | NEW |