| 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 14 matching lines...) Expand all Loading... |
| 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 | 32 |
| 33 #include "modules/websockets/MainThreadWebSocketChannel.h" | 33 #include "modules/websockets/MainThreadWebSocketChannel.h" |
| 34 | 34 |
| 35 #include "bindings/v8/ScriptCallStackFactory.h" |
| 35 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExceptionCodePlaceholder.h" | 37 #include "core/dom/ExceptionCodePlaceholder.h" |
| 37 #include "core/dom/ScriptExecutionContext.h" | 38 #include "core/dom/ScriptExecutionContext.h" |
| 38 #include "core/fileapi/Blob.h" | 39 #include "core/fileapi/Blob.h" |
| 39 #include "core/fileapi/FileError.h" | 40 #include "core/fileapi/FileError.h" |
| 40 #include "core/fileapi/FileReaderLoader.h" | 41 #include "core/fileapi/FileReaderLoader.h" |
| 41 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
| 42 #include "core/inspector/ScriptCallStack.h" | 43 #include "core/inspector/ScriptCallStack.h" |
| 43 #include "core/loader/CookieJar.h" | 44 #include "core/loader/CookieJar.h" |
| 44 #include "core/loader/FrameLoader.h" | 45 #include "core/loader/FrameLoader.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 , m_receivedClosingHandshake(false) | 81 , m_receivedClosingHandshake(false) |
| 81 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired) | 82 , m_closingTimer(this, &MainThreadWebSocketChannel::closingTimerFired) |
| 82 , m_closed(false) | 83 , m_closed(false) |
| 83 , m_shouldDiscardReceivedData(false) | 84 , m_shouldDiscardReceivedData(false) |
| 84 , m_unhandledBufferedAmount(0) | 85 , m_unhandledBufferedAmount(0) |
| 85 , m_identifier(0) | 86 , m_identifier(0) |
| 86 , m_hasContinuousFrame(false) | 87 , m_hasContinuousFrame(false) |
| 87 , m_closeEventCode(CloseEventCodeAbnormalClosure) | 88 , m_closeEventCode(CloseEventCodeAbnormalClosure) |
| 88 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) | 89 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) |
| 89 , m_blobLoaderStatus(BlobLoaderNotStarted) | 90 , m_blobLoaderStatus(BlobLoaderNotStarted) |
| 91 , m_callFrameAtConnection("", "", 0) |
| 90 { | 92 { |
| 91 if (Page* page = m_document->page()) | 93 if (Page* page = m_document->page()) |
| 92 m_identifier = createUniqueIdentifier(); | 94 m_identifier = createUniqueIdentifier(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 MainThreadWebSocketChannel::~MainThreadWebSocketChannel() | 97 MainThreadWebSocketChannel::~MainThreadWebSocketChannel() |
| 96 { | 98 { |
| 97 } | 99 } |
| 98 | 100 |
| 99 void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol
) | 101 void MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol
) |
| 100 { | 102 { |
| 101 LOG(Network, "MainThreadWebSocketChannel %p connect()", this); | 103 LOG(Network, "MainThreadWebSocketChannel %p connect()", this); |
| 102 ASSERT(!m_handle); | 104 ASSERT(!m_handle); |
| 103 ASSERT(!m_suspended); | 105 ASSERT(!m_suspended); |
| 104 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document)); | 106 m_handshake = adoptPtr(new WebSocketHandshake(url, protocol, m_document)); |
| 105 m_handshake->reset(); | 107 m_handshake->reset(); |
| 106 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor(
)); | 108 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor(
)); |
| 107 if (m_identifier) | 109 if (m_identifier) |
| 108 InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, u
rl, m_document->url(), protocol); | 110 InspectorInstrumentation::didCreateWebSocket(m_document, m_identifier, u
rl, m_document->url(), protocol); |
| 109 ref(); | 111 ref(); |
| 110 m_handle = SocketStreamHandle::create(m_handshake->url(), this); | 112 m_handle = SocketStreamHandle::create(m_handshake->url(), this); |
| 113 RefPtr<ScriptCallStack> callstack = createScriptCallStack(1, true); |
| 114 m_callFrameAtConnection = callstack && callstack->size() > 0 ? callstack->at
(0) : ScriptCallFrame("", "", 0); |
| 111 } | 115 } |
| 112 | 116 |
| 113 String MainThreadWebSocketChannel::subprotocol() | 117 String MainThreadWebSocketChannel::subprotocol() |
| 114 { | 118 { |
| 115 LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this); | 119 LOG(Network, "MainThreadWebSocketChannel %p subprotocol()", this); |
| 116 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected) | 120 if (!m_handshake || m_handshake->mode() != WebSocketHandshake::Connected) |
| 117 return ""; | 121 return ""; |
| 118 String serverProtocol = m_handshake->serverWebSocketProtocol(); | 122 String serverProtocol = m_handshake->serverWebSocketProtocol(); |
| 119 if (serverProtocol.isNull()) | 123 if (serverProtocol.isNull()) |
| 120 return ""; | 124 return ""; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (m_closing && !m_closingTimer.isActive()) | 193 if (m_closing && !m_closingTimer.isActive()) |
| 190 m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime); | 194 m_closingTimer.startOneShot(2 * TCPMaximumSegmentLifetime); |
| 191 } | 195 } |
| 192 | 196 |
| 193 void MainThreadWebSocketChannel::fail(const String& reason) | 197 void MainThreadWebSocketChannel::fail(const String& reason) |
| 194 { | 198 { |
| 195 LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reaso
n.utf8().data()); | 199 LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, reaso
n.utf8().data()); |
| 196 ASSERT(!m_suspended); | 200 ASSERT(!m_suspended); |
| 197 if (m_document) { | 201 if (m_document) { |
| 198 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id
entifier, reason); | 202 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id
entifier, reason); |
| 199 m_document->addConsoleMessage(NetworkMessageSource, ErrorMessageLevel, "
WebSocket connection to '" + m_handshake->url().elidedString() + "' failed: " +
reason); | 203 const String message = "WebSocket connection to '" + m_handshake->url().
elidedString() + "' failed: " + reason; |
| 204 RefPtr<ScriptCallStack> callstack = createScriptCallStack(1, true); |
| 205 if (callstack && callstack->size() > 0) { |
| 206 // We are in a JS callstack. |
| 207 // So, the addConsoleMessage method will show the stack appropriatel
y. |
| 208 m_document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, me
ssage); |
| 209 } else { |
| 210 // We are not in a JS callstack. |
| 211 // Then show the source file and the line number at the connection i
nitiation. |
| 212 const String& url = m_callFrameAtConnection.sourceURL(); |
| 213 unsigned lineNumber = m_callFrameAtConnection.lineNumber(); |
| 214 static_cast<ScriptExecutionContext*>(m_document)->addConsoleMessage(
JSMessageSource, ErrorMessageLevel, message, url, lineNumber, 0, 0); |
| 215 } |
| 200 } | 216 } |
| 201 | 217 |
| 202 // Hybi-10 specification explicitly states we must not continue to handle in
coming data | 218 // Hybi-10 specification explicitly states we must not continue to handle in
coming data |
| 203 // once the WebSocket connection is failed (section 7.1.7). | 219 // once the WebSocket connection is failed (section 7.1.7). |
| 204 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th
e channel, potentially removing the last reference. | 220 RefPtr<MainThreadWebSocketChannel> protect(this); // The client can close th
e channel, potentially removing the last reference. |
| 205 m_shouldDiscardReceivedData = true; | 221 m_shouldDiscardReceivedData = true; |
| 206 if (!m_buffer.isEmpty()) | 222 if (!m_buffer.isEmpty()) |
| 207 skipBuffer(m_buffer.size()); // Save memory. | 223 skipBuffer(m_buffer.size()); // Save memory. |
| 208 m_deflateFramer.didFail(); | 224 m_deflateFramer.didFail(); |
| 209 m_hasContinuousFrame = false; | 225 m_hasContinuousFrame = false; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 return false; | 809 return false; |
| 794 } | 810 } |
| 795 | 811 |
| 796 Vector<char> frameData; | 812 Vector<char> frameData; |
| 797 frame.makeFrameData(frameData); | 813 frame.makeFrameData(frameData); |
| 798 | 814 |
| 799 return m_handle->send(frameData.data(), frameData.size()); | 815 return m_handle->send(frameData.data(), frameData.size()); |
| 800 } | 816 } |
| 801 | 817 |
| 802 } // namespace WebCore | 818 } // namespace WebCore |
| OLD | NEW |