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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 namespace WebCore { | 68 namespace WebCore { |
69 | 69 |
70 const double TCPMaximumSegmentLifetime = 2 * 60.0; | 70 const double TCPMaximumSegmentLifetime = 2 * 60.0; |
71 | 71 |
72 WebSocketChannel::WebSocketChannel(Document* document, WebSocketChannelClient* c
lient) | 72 WebSocketChannel::WebSocketChannel(Document* document, WebSocketChannelClient* c
lient) |
73 : m_document(document) | 73 : m_document(document) |
74 , m_client(client) | 74 , m_client(client) |
75 , m_resumeTimer(this, &WebSocketChannel::resumeTimerFired) | 75 , m_resumeTimer(this, &WebSocketChannel::resumeTimerFired) |
76 , m_suspended(false) | 76 , m_suspended(false) |
77 , m_closing(false) | 77 , m_closing(false) |
| 78 , m_failed(false) |
78 , m_receivedClosingHandshake(false) | 79 , m_receivedClosingHandshake(false) |
79 , m_closingTimer(this, &WebSocketChannel::closingTimerFired) | 80 , m_closingTimer(this, &WebSocketChannel::closingTimerFired) |
80 , m_closed(false) | 81 , m_closed(false) |
81 , m_shouldDiscardReceivedData(false) | 82 , m_shouldDiscardReceivedData(false) |
82 , m_unhandledBufferedAmount(0) | 83 , m_unhandledBufferedAmount(0) |
83 , m_identifier(0) | 84 , m_identifier(0) |
84 , m_hasContinuousFrame(false) | 85 , m_hasContinuousFrame(false) |
85 , m_closeEventCode(CloseEventCodeAbnormalClosure) | 86 , m_closeEventCode(CloseEventCodeAbnormalClosure) |
86 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) | 87 , m_outgoingFrameQueueStatus(OutgoingFrameQueueOpen) |
87 , m_blobLoaderStatus(BlobLoaderNotStarted) | 88 , m_blobLoaderStatus(BlobLoaderNotStarted) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 201 |
201 // Hybi-10 specification explicitly states we must not continue to handle in
coming data | 202 // Hybi-10 specification explicitly states we must not continue to handle in
coming data |
202 // once the WebSocket connection is failed (section 7.1.7). | 203 // once the WebSocket connection is failed (section 7.1.7). |
203 RefPtr<WebSocketChannel> protect(this); // The client can close the channel,
potentially removing the last reference. | 204 RefPtr<WebSocketChannel> protect(this); // The client can close the channel,
potentially removing the last reference. |
204 m_shouldDiscardReceivedData = true; | 205 m_shouldDiscardReceivedData = true; |
205 if (!m_buffer.isEmpty()) | 206 if (!m_buffer.isEmpty()) |
206 skipBuffer(m_buffer.size()); // Save memory. | 207 skipBuffer(m_buffer.size()); // Save memory. |
207 m_deflateFramer.didFail(); | 208 m_deflateFramer.didFail(); |
208 m_hasContinuousFrame = false; | 209 m_hasContinuousFrame = false; |
209 m_continuousFrameData.clear(); | 210 m_continuousFrameData.clear(); |
210 m_client->didReceiveMessageError(); | 211 if (!m_failed) { |
| 212 m_failed = true; |
| 213 m_client->didReceiveMessageError(); |
| 214 } |
211 | 215 |
212 if (m_handle && !m_closed) | 216 if (m_handle && !m_closed) |
213 m_handle->disconnect(); // Will call didClose(). | 217 m_handle->disconnect(); // Will call didClose(). |
214 } | 218 } |
215 | 219 |
216 void WebSocketChannel::disconnect() | 220 void WebSocketChannel::disconnect() |
217 { | 221 { |
218 LOG(Network, "WebSocketChannel %p disconnect()", this); | 222 LOG(Network, "WebSocketChannel %p disconnect()", this); |
219 if (m_identifier && m_document) | 223 if (m_identifier && m_document) |
220 InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier); | 224 InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 319 |
316 void WebSocketChannel::didUpdateBufferedAmount(SocketStreamHandle*, size_t buffe
redAmount) | 320 void WebSocketChannel::didUpdateBufferedAmount(SocketStreamHandle*, size_t buffe
redAmount) |
317 { | 321 { |
318 if (m_client) | 322 if (m_client) |
319 m_client->didUpdateBufferedAmount(bufferedAmount); | 323 m_client->didUpdateBufferedAmount(bufferedAmount); |
320 } | 324 } |
321 | 325 |
322 void WebSocketChannel::didFailSocketStream(SocketStreamHandle* handle, const Soc
ketStreamError& error) | 326 void WebSocketChannel::didFailSocketStream(SocketStreamHandle* handle, const Soc
ketStreamError& error) |
323 { | 327 { |
324 LOG(Network, "WebSocketChannel %p didFailSocketStream()", this); | 328 LOG(Network, "WebSocketChannel %p didFailSocketStream()", this); |
325 ASSERT(handle == m_handle || !m_handle); | 329 ASSERT_UNUSED(handle, handle == m_handle || !m_handle); |
326 if (m_document) { | 330 m_shouldDiscardReceivedData = true; |
327 String message; | 331 String message; |
328 if (error.isNull()) | 332 if (error.isNull()) |
329 message = "WebSocket network error"; | 333 message = "WebSocket network error"; |
330 else if (error.localizedDescription().isNull()) | 334 else if (error.localizedDescription().isNull()) |
331 message = "WebSocket network error: error code " + String::number(er
ror.errorCode()); | 335 message = "WebSocket network error: error code " + String::number(error.
errorCode()); |
332 else | 336 else |
333 message = "WebSocket network error: " + error.localizedDescription()
; | 337 message = "WebSocket network error: error code " + String::number(error.
errorCode()) + ", " + error.localizedDescription(); |
334 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id
entifier, message); | 338 String failingURL = error.failingURL(); |
335 m_document->addConsoleMessage(NetworkMessageSource, ErrorMessageLevel, m
essage); | 339 ASSERT(failingURL.isNull() || m_handshake->url().string() == failingURL); |
| 340 if (failingURL.isNull()) |
| 341 failingURL = m_handshake->url().string(); |
| 342 LOG(Network, "Error Message: %s, FailURL: %s", message.utf8().data(), failin
gURL.utf8().data()); |
| 343 RefPtr<WebSocketChannel> protect(this); |
| 344 if (m_client && !m_closing && !m_failed) { |
| 345 m_failed = true; |
| 346 m_client->didReceiveMessageError(); |
336 } | 347 } |
337 m_shouldDiscardReceivedData = true; | 348 if (m_handle && !m_closed) |
338 handle->disconnect(); | 349 m_handle->disconnect(); |
339 } | 350 } |
340 | 351 |
341 void WebSocketChannel::didReceiveAuthenticationChallenge(SocketStreamHandle*, co
nst AuthenticationChallenge&) | 352 void WebSocketChannel::didReceiveAuthenticationChallenge(SocketStreamHandle*, co
nst AuthenticationChallenge&) |
342 { | 353 { |
343 } | 354 } |
344 | 355 |
345 void WebSocketChannel::didCancelAuthenticationChallenge(SocketStreamHandle*, con
st AuthenticationChallenge&) | 356 void WebSocketChannel::didCancelAuthenticationChallenge(SocketStreamHandle*, con
st AuthenticationChallenge&) |
346 { | 357 { |
347 } | 358 } |
348 | 359 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 return false; | 802 return false; |
792 } | 803 } |
793 | 804 |
794 Vector<char> frameData; | 805 Vector<char> frameData; |
795 frame.makeFrameData(frameData); | 806 frame.makeFrameData(frameData); |
796 | 807 |
797 return m_handle->send(frameData.data(), frameData.size()); | 808 return m_handle->send(frameData.data(), frameData.size()); |
798 } | 809 } |
799 | 810 |
800 } // namespace WebCore | 811 } // namespace WebCore |
OLD | NEW |