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