OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 13 matching lines...) Expand all Loading... |
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 #include "modules/websockets/DocumentWebSocketChannel.h" | 32 #include "modules/websockets/DocumentWebSocketChannel.h" |
33 | 33 |
| 34 #include "core/dom/DOMArrayBuffer.h" |
34 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
35 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
36 #include "core/fileapi/FileReaderLoader.h" | 37 #include "core/fileapi/FileReaderLoader.h" |
37 #include "core/fileapi/FileReaderLoaderClient.h" | 38 #include "core/fileapi/FileReaderLoaderClient.h" |
38 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
39 #include "core/inspector/ConsoleMessage.h" | 40 #include "core/inspector/ConsoleMessage.h" |
40 #include "core/inspector/InspectorInstrumentation.h" | 41 #include "core/inspector/InspectorInstrumentation.h" |
41 #include "core/inspector/InspectorTraceEvents.h" | 42 #include "core/inspector/InspectorTraceEvents.h" |
42 #include "core/loader/FrameLoader.h" | 43 #include "core/loader/FrameLoader.h" |
43 #include "core/loader/FrameLoaderClient.h" | 44 #include "core/loader/FrameLoaderClient.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // of individual frames. | 194 // of individual frames. |
194 // FIXME: We can't access the data here. | 195 // FIXME: We can't access the data here. |
195 // Since Binary data are not displayed in Inspector, this does not | 196 // Since Binary data are not displayed in Inspector, this does not |
196 // affect actual behavior. | 197 // affect actual behavior. |
197 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, "", 0); | 198 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, "", 0); |
198 } | 199 } |
199 m_messages.append(adoptPtr(new Message(blobDataHandle))); | 200 m_messages.append(adoptPtr(new Message(blobDataHandle))); |
200 sendInternal(); | 201 sendInternal(); |
201 } | 202 } |
202 | 203 |
203 void DocumentWebSocketChannel::send(const ArrayBuffer& buffer, unsigned byteOffs
et, unsigned byteLength) | 204 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, unsigned byteO
ffset, unsigned byteLength) |
204 { | 205 { |
205 WTF_LOG(Network, "DocumentWebSocketChannel %p sendArrayBuffer(%p, %u, %u)",
this, buffer.data(), byteOffset, byteLength); | 206 WTF_LOG(Network, "DocumentWebSocketChannel %p sendArrayBuffer(%p, %u, %u)",
this, buffer.data(), byteOffset, byteLength); |
206 if (m_identifier) { | 207 if (m_identifier) { |
207 // FIXME: Change the inspector API to show the entire message instead | 208 // FIXME: Change the inspector API to show the entire message instead |
208 // of individual frames. | 209 // of individual frames. |
209 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) +
byteOffset, byteLength); | 210 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier
, WebSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) +
byteOffset, byteLength); |
210 } | 211 } |
211 // buffer.slice copies its contents. | 212 // buffer.slice copies its contents. |
212 // FIXME: Reduce copy by sending the data immediately when we don't need to | 213 // FIXME: Reduce copy by sending the data immediately when we don't need to |
213 // queue the data. | 214 // queue the data. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 281 } |
281 | 282 |
282 DocumentWebSocketChannel::Message::Message(const String& text) | 283 DocumentWebSocketChannel::Message::Message(const String& text) |
283 : type(MessageTypeText) | 284 : type(MessageTypeText) |
284 , text(text.utf8(StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD)) {
} | 285 , text(text.utf8(StrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD)) {
} |
285 | 286 |
286 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa
ndle) | 287 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa
ndle) |
287 : type(MessageTypeBlob) | 288 : type(MessageTypeBlob) |
288 , blobDataHandle(blobDataHandle) { } | 289 , blobDataHandle(blobDataHandle) { } |
289 | 290 |
290 DocumentWebSocketChannel::Message::Message(PassRefPtr<ArrayBuffer> arrayBuffer) | 291 DocumentWebSocketChannel::Message::Message(PassRefPtr<DOMArrayBuffer> arrayBuffe
r) |
291 : type(MessageTypeArrayBuffer) | 292 : type(MessageTypeArrayBuffer) |
292 , arrayBuffer(arrayBuffer) { } | 293 , arrayBuffer(arrayBuffer) { } |
293 | 294 |
294 DocumentWebSocketChannel::Message::Message(PassOwnPtr<Vector<char> > vectorData) | 295 DocumentWebSocketChannel::Message::Message(PassOwnPtr<Vector<char> > vectorData) |
295 : type(MessageTypeVector) | 296 : type(MessageTypeVector) |
296 , vectorData(vectorData) { } | 297 , vectorData(vectorData) { } |
297 | 298 |
298 DocumentWebSocketChannel::Message::Message(unsigned short code, const String& re
ason) | 299 DocumentWebSocketChannel::Message::Message(unsigned short code, const String& re
ason) |
299 : type(MessageTypeClose) | 300 : type(MessageTypeClose) |
300 , code(code) | 301 , code(code) |
(...skipping 20 matching lines...) Expand all Loading... |
321 consumedBufferedAmount += size; | 322 consumedBufferedAmount += size; |
322 break; | 323 break; |
323 } | 324 } |
324 case MessageTypeBlob: | 325 case MessageTypeBlob: |
325 ASSERT(!m_blobLoader); | 326 ASSERT(!m_blobLoader); |
326 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 327 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
327 break; | 328 break; |
328 case MessageTypeArrayBuffer: { | 329 case MessageTypeArrayBuffer: { |
329 WebSocketHandle::MessageType type = | 330 WebSocketHandle::MessageType type = |
330 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio
n : WebSocketHandle::MessageTypeBinary; | 331 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio
n : WebSocketHandle::MessageTypeBinary; |
331 size_t size = std::min(static_cast<size_t>(m_sendingQuota), message-
>arrayBuffer->byteLength() - m_sentSizeOfTopMessage); | 332 size_t size = std::min(static_cast<size_t>(m_sendingQuota), static_c
ast<size_t>(message->arrayBuffer->byteLength() - m_sentSizeOfTopMessage)); |
332 final = (m_sentSizeOfTopMessage + size == message->arrayBuffer->byte
Length()); | 333 final = (m_sentSizeOfTopMessage + size == message->arrayBuffer->byte
Length()); |
333 m_handle->send(final, type, static_cast<const char*>(message->arrayB
uffer->data()) + m_sentSizeOfTopMessage, size); | 334 m_handle->send(final, type, static_cast<const char*>(message->arrayB
uffer->data()) + m_sentSizeOfTopMessage, size); |
334 m_sentSizeOfTopMessage += size; | 335 m_sentSizeOfTopMessage += size; |
335 m_sendingQuota -= size; | 336 m_sendingQuota -= size; |
336 consumedBufferedAmount += size; | 337 consumedBufferedAmount += size; |
337 break; | 338 break; |
338 } | 339 } |
339 case MessageTypeVector: { | 340 case MessageTypeVector: { |
340 WebSocketHandle::MessageType type = | 341 WebSocketHandle::MessageType type = |
341 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio
n : WebSocketHandle::MessageTypeBinary; | 342 m_sentSizeOfTopMessage ? WebSocketHandle::MessageTypeContinuatio
n : WebSocketHandle::MessageTypeBinary; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 { | 555 { |
555 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)",
this, handle); | 556 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)",
this, handle); |
556 | 557 |
557 ASSERT(m_handle); | 558 ASSERT(m_handle); |
558 ASSERT(handle == m_handle); | 559 ASSERT(handle == m_handle); |
559 | 560 |
560 if (m_client) | 561 if (m_client) |
561 m_client->didStartClosingHandshake(); | 562 m_client->didStartClosingHandshake(); |
562 } | 563 } |
563 | 564 |
564 void DocumentWebSocketChannel::didFinishLoadingBlob(PassRefPtr<ArrayBuffer> buff
er) | 565 void DocumentWebSocketChannel::didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer> b
uffer) |
565 { | 566 { |
566 m_blobLoader.clear(); | 567 m_blobLoader.clear(); |
567 ASSERT(m_handle); | 568 ASSERT(m_handle); |
568 // The loaded blob is always placed on m_messages[0]. | 569 // The loaded blob is always placed on m_messages[0]. |
569 ASSERT(m_messages.size() > 0 && m_messages.first()->type == MessageTypeBlob)
; | 570 ASSERT(m_messages.size() > 0 && m_messages.first()->type == MessageTypeBlob)
; |
570 // We replace it with the loaded blob. | 571 // We replace it with the loaded blob. |
571 m_messages.first() = adoptPtr(new Message(buffer)); | 572 m_messages.first() = adoptPtr(new Message(buffer)); |
572 sendInternal(); | 573 sendInternal(); |
573 } | 574 } |
574 | 575 |
(...skipping 10 matching lines...) Expand all Loading... |
585 } | 586 } |
586 | 587 |
587 void DocumentWebSocketChannel::trace(Visitor* visitor) | 588 void DocumentWebSocketChannel::trace(Visitor* visitor) |
588 { | 589 { |
589 visitor->trace(m_blobLoader); | 590 visitor->trace(m_blobLoader); |
590 visitor->trace(m_client); | 591 visitor->trace(m_client); |
591 WebSocketChannel::trace(visitor); | 592 WebSocketChannel::trace(visitor); |
592 } | 593 } |
593 | 594 |
594 } // namespace blink | 595 } // namespace blink |
OLD | NEW |