Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: Source/modules/websockets/WebSocket.cpp

Issue 23992003: blob hacking webcore style (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 updateBufferedAmountAfterClose(arrayBufferView->byteLength()); 333 updateBufferedAmountAfterClose(arrayBufferView->byteLength());
334 return; 334 return;
335 } 335 }
336 ASSERT(m_channel); 336 ASSERT(m_channel);
337 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); 337 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer());
338 handleSendResult(m_channel->send(*arrayBuffer, arrayBufferView->byteOffset() , arrayBufferView->byteLength()), es); 338 handleSendResult(m_channel->send(*arrayBuffer, arrayBufferView->byteOffset() , arrayBufferView->byteLength()), es);
339 } 339 }
340 340
341 void WebSocket::send(Blob* binaryData, ExceptionState& es) 341 void WebSocket::send(Blob* binaryData, ExceptionState& es)
342 { 342 {
343 LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData->url( ).elidedString().utf8().data()); 343 LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData->uuid ().utf8().data());
344 ASSERT(binaryData); 344 ASSERT(binaryData);
345 if (m_state == CONNECTING) { 345 if (m_state == CONNECTING) {
346 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("send", "WebSocket", "already in CONNECTING state.")); 346 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("send", "WebSocket", "already in CONNECTING state."));
347 return; 347 return;
348 } 348 }
349 if (m_state == CLOSING || m_state == CLOSED) { 349 if (m_state == CLOSING || m_state == CLOSED) {
350 updateBufferedAmountAfterClose(static_cast<unsigned long>(binaryData->si ze())); 350 updateBufferedAmountAfterClose(static_cast<unsigned long>(binaryData->si ze()));
351 return; 351 return;
352 } 352 }
353 ASSERT(m_channel); 353 ASSERT(m_channel);
354 handleSendResult(m_channel->send(*binaryData), es); 354 handleSendResult(m_channel->send(binaryData->blobDataHandle()), es);
355 } 355 }
356 356
357 void WebSocket::close(unsigned short code, const String& reason, ExceptionState& es) 357 void WebSocket::close(unsigned short code, const String& reason, ExceptionState& es)
358 { 358 {
359 closeInternal(code, reason, es); 359 closeInternal(code, reason, es);
360 } 360 }
361 361
362 void WebSocket::close(ExceptionState& es) 362 void WebSocket::close(ExceptionState& es)
363 { 363 {
364 closeInternal(WebSocketChannel::CloseEventCodeNotSpecified, String(), es); 364 closeInternal(WebSocketChannel::CloseEventCodeNotSpecified, String(), es);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) 547 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData)
548 { 548 {
549 LOG(Network, "WebSocket %p didReceiveBinaryData() %lu byte binary message", this, static_cast<unsigned long>(binaryData->size())); 549 LOG(Network, "WebSocket %p didReceiveBinaryData() %lu byte binary message", this, static_cast<unsigned long>(binaryData->size()));
550 switch (m_binaryType) { 550 switch (m_binaryType) {
551 case BinaryTypeBlob: { 551 case BinaryTypeBlob: {
552 size_t size = binaryData->size(); 552 size_t size = binaryData->size();
553 RefPtr<RawData> rawData = RawData::create(); 553 RefPtr<RawData> rawData = RawData::create();
554 binaryData->swap(*rawData->mutableData()); 554 binaryData->swap(*rawData->mutableData());
555 OwnPtr<BlobData> blobData = BlobData::create(); 555 OwnPtr<BlobData> blobData = BlobData::create();
556 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); 556 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile);
557 RefPtr<Blob> blob = Blob::create(blobData.release(), size); 557 RefPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release (), size));
558
559 if (!m_stopped) 558 if (!m_stopped)
560 dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::c reate(m_url)->toString())); 559 dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::c reate(m_url)->toString()));
561
562 break; 560 break;
563 } 561 }
564 562
565 case BinaryTypeArrayBuffer: 563 case BinaryTypeArrayBuffer:
566 if (!m_stopped) 564 if (!m_stopped)
567 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->d ata(), binaryData->size()), SecurityOrigin::create(m_url)->toString())); 565 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->d ata(), binaryData->size()), SecurityOrigin::create(m_url)->toString()));
568 566
569 break; 567 break;
570 } 568 }
571 } 569 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0 x10000; 633 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0 x10000;
636 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; 634 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength;
637 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) 635 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength)
638 overhead += 8; 636 overhead += 8;
639 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) 637 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength)
640 overhead += 2; 638 overhead += 2;
641 return overhead; 639 return overhead;
642 } 640 }
643 641
644 } // namespace WebCore 642 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698