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 11 matching lines...) Expand all Loading... | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | |
33 #include "modules/websockets/DOMWebSocket.h" | 32 #include "modules/websockets/DOMWebSocket.h" |
34 | 33 |
35 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
36 #include "bindings/core/v8/ScriptController.h" | 35 #include "bindings/core/v8/ScriptController.h" |
36 #include "core/dom/DOMArrayBuffer.h" | |
37 #include "core/dom/DOMArrayBufferView.h" | |
37 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
38 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
39 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
40 #include "core/events/MessageEvent.h" | 41 #include "core/events/MessageEvent.h" |
41 #include "core/fileapi/Blob.h" | 42 #include "core/fileapi/Blob.h" |
42 #include "core/frame/ConsoleTypes.h" | 43 #include "core/frame/ConsoleTypes.h" |
43 #include "core/frame/LocalDOMWindow.h" | 44 #include "core/frame/LocalDOMWindow.h" |
44 #include "core/frame/LocalFrame.h" | 45 #include "core/frame/LocalFrame.h" |
45 #include "core/frame/csp/ContentSecurityPolicy.h" | 46 #include "core/frame/csp/ContentSecurityPolicy.h" |
46 #include "core/inspector/ConsoleMessage.h" | 47 #include "core/inspector/ConsoleMessage.h" |
47 #include "core/inspector/ScriptCallStack.h" | 48 #include "core/inspector/ScriptCallStack.h" |
48 #include "modules/websockets/CloseEvent.h" | 49 #include "modules/websockets/CloseEvent.h" |
49 #include "platform/Logging.h" | 50 #include "platform/Logging.h" |
50 #include "platform/blob/BlobData.h" | 51 #include "platform/blob/BlobData.h" |
51 #include "platform/heap/Handle.h" | 52 #include "platform/heap/Handle.h" |
52 #include "platform/weborigin/KnownPorts.h" | 53 #include "platform/weborigin/KnownPorts.h" |
53 #include "platform/weborigin/SecurityOrigin.h" | 54 #include "platform/weborigin/SecurityOrigin.h" |
54 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
55 #include "wtf/ArrayBuffer.h" | |
56 #include "wtf/ArrayBufferView.h" | |
57 #include "wtf/Assertions.h" | 56 #include "wtf/Assertions.h" |
58 #include "wtf/HashSet.h" | 57 #include "wtf/HashSet.h" |
59 #include "wtf/PassOwnPtr.h" | 58 #include "wtf/PassOwnPtr.h" |
60 #include "wtf/StdLibExtras.h" | 59 #include "wtf/StdLibExtras.h" |
61 #include "wtf/text/CString.h" | 60 #include "wtf/text/CString.h" |
62 #include "wtf/text/StringBuilder.h" | 61 #include "wtf/text/StringBuilder.h" |
63 #include "wtf/text/WTFString.h" | 62 #include "wtf/text/WTFString.h" |
64 | 63 |
65 namespace blink { | 64 namespace blink { |
66 | 65 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 if (m_state == CLOSING || m_state == CLOSED) { | 384 if (m_state == CLOSING || m_state == CLOSED) { |
386 updateBufferedAmountAfterClose(message.utf8().length()); | 385 updateBufferedAmountAfterClose(message.utf8().length()); |
387 return; | 386 return; |
388 } | 387 } |
389 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeString, WebSocketSendTypeMax); | 388 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeString, WebSocketSendTypeMax); |
390 ASSERT(m_channel); | 389 ASSERT(m_channel); |
391 m_bufferedAmount += message.utf8().length(); | 390 m_bufferedAmount += message.utf8().length(); |
392 m_channel->send(message); | 391 m_channel->send(message); |
393 } | 392 } |
394 | 393 |
395 void DOMWebSocket::send(ArrayBuffer* binaryData, ExceptionState& exceptionState) | 394 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta te) |
396 { | 395 { |
397 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD ata); | 396 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBuffer %p", this, binaryD ata); |
398 ASSERT(binaryData); | 397 ASSERT(binaryData && binaryData->buffer()); |
399 if (m_state == CONNECTING) { | 398 if (m_state == CONNECTING) { |
400 setInvalidStateErrorForSendMethod(exceptionState); | 399 setInvalidStateErrorForSendMethod(exceptionState); |
401 return; | 400 return; |
402 } | 401 } |
403 if (m_state == CLOSING || m_state == CLOSED) { | 402 if (m_state == CLOSING || m_state == CLOSED) { |
404 updateBufferedAmountAfterClose(binaryData->byteLength()); | 403 updateBufferedAmountAfterClose(binaryData->byteLength()); |
405 return; | 404 return; |
406 } | 405 } |
407 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeArrayBuffer, WebSocketSendTypeMax); | 406 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeArrayBuffer, WebSocketSendTypeMax); |
408 ASSERT(m_channel); | 407 ASSERT(m_channel); |
409 m_bufferedAmount += binaryData->byteLength(); | 408 m_bufferedAmount += binaryData->byteLength(); |
410 m_channel->send(*binaryData, 0, binaryData->byteLength()); | 409 m_channel->send(*binaryData->buffer(), 0, binaryData->byteLength()); |
411 } | 410 } |
412 | 411 |
413 void DOMWebSocket::send(ArrayBufferView* arrayBufferView, ExceptionState& except ionState) | 412 void DOMWebSocket::send(DOMArrayBufferView* arrayBufferView, ExceptionState& exc eptionState) |
414 { | 413 { |
415 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, arr ayBufferView); | 414 WTF_LOG(Network, "WebSocket %p send() Sending ArrayBufferView %p", this, arr ayBufferView); |
416 ASSERT(arrayBufferView); | 415 ASSERT(arrayBufferView); |
haraken
2014/10/14 15:11:20
This check should be:
ASSERT(arrayBufferView &&
Yuki
2014/10/15 09:35:24
I agree that we'll need cleaner policy for this po
| |
417 if (m_state == CONNECTING) { | 416 if (m_state == CONNECTING) { |
418 setInvalidStateErrorForSendMethod(exceptionState); | 417 setInvalidStateErrorForSendMethod(exceptionState); |
419 return; | 418 return; |
420 } | 419 } |
421 if (m_state == CLOSING || m_state == CLOSED) { | 420 if (m_state == CLOSING || m_state == CLOSED) { |
422 updateBufferedAmountAfterClose(arrayBufferView->byteLength()); | 421 updateBufferedAmountAfterClose(arrayBufferView->byteLength()); |
423 return; | 422 return; |
424 } | 423 } |
425 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeArrayBufferView, WebSocketSendTypeMax); | 424 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeArrayBufferView, WebSocketSendTypeMax); |
426 ASSERT(m_channel); | 425 ASSERT(m_channel); |
427 m_bufferedAmount += arrayBufferView->byteLength(); | 426 m_bufferedAmount += arrayBufferView->byteLength(); |
428 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); | 427 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->view()->buffer()); |
429 m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBufferView ->byteLength()); | 428 m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBufferView ->byteLength()); |
430 } | 429 } |
431 | 430 |
432 void DOMWebSocket::send(Blob* binaryData, ExceptionState& exceptionState) | 431 void DOMWebSocket::send(Blob* binaryData, ExceptionState& exceptionState) |
433 { | 432 { |
434 WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData-> uuid().utf8().data()); | 433 WTF_LOG(Network, "WebSocket %p send() Sending Blob '%s'", this, binaryData-> uuid().utf8().data()); |
435 ASSERT(binaryData); | 434 ASSERT(binaryData); |
436 if (m_state == CONNECTING) { | 435 if (m_state == CONNECTING) { |
437 setInvalidStateErrorForSendMethod(exceptionState); | 436 setInvalidStateErrorForSendMethod(exceptionState); |
438 return; | 437 return; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 RefPtr<RawData> rawData = RawData::create(); | 615 RefPtr<RawData> rawData = RawData::create(); |
617 binaryData->swap(*rawData->mutableData()); | 616 binaryData->swap(*rawData->mutableData()); |
618 OwnPtr<BlobData> blobData = BlobData::create(); | 617 OwnPtr<BlobData> blobData = BlobData::create(); |
619 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); | 618 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); |
620 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), siz e)); | 619 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), siz e)); |
621 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString())); | 620 m_eventQueue->dispatch(MessageEvent::create(blob, SecurityOrigin::create (m_url)->toString())); |
622 break; | 621 break; |
623 } | 622 } |
624 | 623 |
625 case BinaryTypeArrayBuffer: | 624 case BinaryTypeArrayBuffer: |
626 RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::create(binaryData->data() , binaryData->size()); | 625 RefPtr<DOMArrayBuffer> arrayBuffer = DOMArrayBuffer::create(binaryData-> data(), binaryData->size()); |
627 if (!arrayBuffer) { | 626 if (!arrayBuffer) { |
628 // Failed to allocate an ArrayBuffer. We need to crash the renderer | 627 // Failed to allocate an ArrayBuffer. We need to crash the renderer |
629 // since there's no way defined in the spec to tell this to the | 628 // since there's no way defined in the spec to tell this to the |
630 // user. | 629 // user. |
631 CRASH(); | 630 CRASH(); |
632 } | 631 } |
633 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString())); | 632 m_eventQueue->dispatch(MessageEvent::create(arrayBuffer.release(), Secur ityOrigin::create(m_url)->toString())); |
634 break; | 633 break; |
635 } | 634 } |
636 } | 635 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 | 687 |
689 void DOMWebSocket::trace(Visitor* visitor) | 688 void DOMWebSocket::trace(Visitor* visitor) |
690 { | 689 { |
691 visitor->trace(m_channel); | 690 visitor->trace(m_channel); |
692 visitor->trace(m_eventQueue); | 691 visitor->trace(m_eventQueue); |
693 WebSocketChannelClient::trace(visitor); | 692 WebSocketChannelClient::trace(visitor); |
694 EventTargetWithInlineData::trace(visitor); | 693 EventTargetWithInlineData::trace(visitor); |
695 } | 694 } |
696 | 695 |
697 } // namespace blink | 696 } // namespace blink |
OLD | NEW |