OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 m_handle = SocketStreamHandle::create(this); | 117 m_handle = SocketStreamHandle::create(this); |
118 ASSERT(m_handle); | 118 ASSERT(m_handle); |
119 if (m_document->frame()) { | 119 if (m_document->frame()) { |
120 m_document->frame()->loader().client()->dispatchWillOpenSocketStream(m_h
andle.get()); | 120 m_document->frame()->loader().client()->dispatchWillOpenSocketStream(m_h
andle.get()); |
121 } | 121 } |
122 m_handle->connect(m_handshake->url()); | 122 m_handle->connect(m_handshake->url()); |
123 | 123 |
124 return true; | 124 return true; |
125 } | 125 } |
126 | 126 |
127 String MainThreadWebSocketChannel::subprotocol() | |
128 { | |
129 WTF_LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this); | |
130 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected) | |
131 return ""; | |
132 String serverProtocol = m_handshake->serverWebSocketProtocol(); | |
133 if (serverProtocol.isNull()) | |
134 return ""; | |
135 return serverProtocol; | |
136 } | |
137 | |
138 String MainThreadWebSocketChannel::extensions() | |
139 { | |
140 WTF_LOG(Network, "MainThreadWebSocketChannel %p extensions()", this); | |
141 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected) | |
142 return ""; | |
143 String extensions = m_handshake->acceptedExtensions(); | |
144 if (extensions.isNull()) | |
145 return ""; | |
146 return extensions; | |
147 } | |
148 | |
149 WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const String& mess
age) | 127 WebSocketChannel::SendResult MainThreadWebSocketChannel::send(const String& mess
age) |
150 { | 128 { |
151 WTF_LOG(Network, "MainThreadWebSocketChannel %p send() Sending String '%s'",
this, message.utf8().data()); | 129 WTF_LOG(Network, "MainThreadWebSocketChannel %p send() Sending String '%s'",
this, message.utf8().data()); |
152 CString utf8 = message.utf8(StrictUTF8ConversionReplacingUnpairedSurrogatesW
ithFFFD); | 130 CString utf8 = message.utf8(StrictUTF8ConversionReplacingUnpairedSurrogatesW
ithFFFD); |
153 enqueueTextFrame(utf8); | 131 enqueueTextFrame(utf8); |
154 processOutgoingFrameQueue(); | 132 processOutgoingFrameQueue(); |
155 // m_channel->send() may happen later, thus it's not always possible to know
whether | 133 // m_channel->send() may happen later, thus it's not always possible to know
whether |
156 // the message has been sent to the socket successfully. In this case, we ha
ve no choice | 134 // the message has been sent to the socket successfully. In this case, we ha
ve no choice |
157 // but to return SendSuccess. | 135 // but to return SendSuccess. |
158 return WebSocketChannel::SendSuccess; | 136 return WebSocketChannel::SendSuccess; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m
_document, m_identifier, 0, &m_handshake->serverHandshakeResponse()); | 455 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m
_document, m_identifier, 0, &m_handshake->serverHandshakeResponse()); |
478 } | 456 } |
479 | 457 |
480 if (m_deflateFramer.enabled() && m_document) { | 458 if (m_deflateFramer.enabled() && m_document) { |
481 const String message = "WebSocket extension \"x-webkit-deflate-f
rame\" is deprecated"; | 459 const String message = "WebSocket extension \"x-webkit-deflate-f
rame\" is deprecated"; |
482 m_document->addConsoleMessage(JSMessageSource, WarningMessageLev
el, message, m_sourceURLAtConstruction, m_lineNumberAtConstruction); | 460 m_document->addConsoleMessage(JSMessageSource, WarningMessageLev
el, message, m_sourceURLAtConstruction, m_lineNumberAtConstruction); |
483 } | 461 } |
484 | 462 |
485 WTF_LOG(Network, "MainThreadWebSocketChannel %p Connected", this); | 463 WTF_LOG(Network, "MainThreadWebSocketChannel %p Connected", this); |
486 skipBuffer(headerLength); | 464 skipBuffer(headerLength); |
487 m_client->didConnect(); | 465 String subprotocol = m_handshake->serverWebSocketProtocol(); |
| 466 String extensions = m_handshake->acceptedExtensions(); |
| 467 m_client->didConnect(subprotocol.isNull() ? "" : subprotocol, extens
ions.isNull() ? "" : extensions); |
488 WTF_LOG(Network, "MainThreadWebSocketChannel %p %lu bytes remaining
in m_buffer", this, static_cast<unsigned long>(m_buffer.size())); | 468 WTF_LOG(Network, "MainThreadWebSocketChannel %p %lu bytes remaining
in m_buffer", this, static_cast<unsigned long>(m_buffer.size())); |
489 return !m_buffer.isEmpty(); | 469 return !m_buffer.isEmpty(); |
490 } | 470 } |
491 ASSERT(m_handshake->mode() == WebSocketHandshake::Failed); | 471 ASSERT(m_handshake->mode() == WebSocketHandshake::Failed); |
492 WTF_LOG(Network, "MainThreadWebSocketChannel %p Connection failed", this
); | 472 WTF_LOG(Network, "MainThreadWebSocketChannel %p Connection failed", this
); |
493 skipBuffer(headerLength); | 473 skipBuffer(headerLength); |
494 m_shouldDiscardReceivedData = true; | 474 m_shouldDiscardReceivedData = true; |
495 failAsError(m_handshake->failureReason()); | 475 failAsError(m_handshake->failureReason()); |
496 return false; | 476 return false; |
497 } | 477 } |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 } | 844 } |
865 | 845 |
866 Vector<char> frameData; | 846 Vector<char> frameData; |
867 frame.makeFrameData(frameData); | 847 frame.makeFrameData(frameData); |
868 | 848 |
869 m_perMessageDeflate.resetDeflateBuffer(); | 849 m_perMessageDeflate.resetDeflateBuffer(); |
870 return m_handle->send(frameData.data(), frameData.size()); | 850 return m_handle->send(frameData.data(), frameData.size()); |
871 } | 851 } |
872 | 852 |
873 } // namespace WebCore | 853 } // namespace WebCore |
OLD | NEW |