| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/websockets/MainThreadWebSocketChannel.h" | 32 #include "modules/websockets/MainThreadWebSocketChannel.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 34 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
| 37 #include "core/fileapi/Blob.h" | 37 #include "core/fileapi/Blob.h" |
| 38 #include "core/fileapi/FileReaderLoader.h" | 38 #include "core/fileapi/FileReaderLoader.h" |
| 39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.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" |
| 44 #include "core/loader/MixedContentChecker.h" | 45 #include "core/loader/MixedContentChecker.h" |
| 45 #include "core/loader/UniqueIdentifier.h" | 46 #include "core/loader/UniqueIdentifier.h" |
| 46 #include "core/page/Page.h" | 47 #include "core/page/Page.h" |
| 47 #include "modules/websockets/WebSocketChannelClient.h" | 48 #include "modules/websockets/WebSocketChannelClient.h" |
| 48 #include "platform/Logging.h" | 49 #include "platform/Logging.h" |
| 49 #include "platform/network/SocketStreamError.h" | 50 #include "platform/network/SocketStreamError.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 bool MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol
) | 91 bool MainThreadWebSocketChannel::connect(const KURL& url, const String& protocol
) |
| 91 { | 92 { |
| 92 WTF_LOG(Network, "MainThreadWebSocketChannel %p connect()", this); | 93 WTF_LOG(Network, "MainThreadWebSocketChannel %p connect()", this); |
| 93 ASSERT(!m_handle); | 94 ASSERT(!m_handle); |
| 94 ASSERT(!m_suspended); | 95 ASSERT(!m_suspended); |
| 95 | 96 |
| 96 if (m_document->frame() && !m_document->frame()->loader().mixedContentChecke
r()->canConnectInsecureWebSocket(m_document->securityOrigin(), url)) | 97 if (m_document->frame() && !m_document->frame()->loader().mixedContentChecke
r()->canConnectInsecureWebSocket(m_document->securityOrigin(), url)) |
| 97 return false; | 98 return false; |
| 98 if (MixedContentChecker::isMixedContent(m_document->securityOrigin(), url))
{ | 99 if (MixedContentChecker::isMixedContent(m_document->securityOrigin(), url))
{ |
| 99 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; | 100 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; |
| 100 m_document->addConsoleMessage(JSMessageSource, WarningMessageLevel, mess
age); | 101 m_document->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); |
| 101 } | 102 } |
| 102 | 103 |
| 103 m_handshake = adoptPtrWillBeNoop(new WebSocketHandshake(url, protocol, m_doc
ument)); | 104 m_handshake = adoptPtrWillBeNoop(new WebSocketHandshake(url, protocol, m_doc
ument)); |
| 104 m_handshake->reset(); | 105 m_handshake->reset(); |
| 105 m_handshake->addExtensionProcessor(m_perMessageDeflate.createExtensionProces
sor()); | 106 m_handshake->addExtensionProcessor(m_perMessageDeflate.createExtensionProces
sor()); |
| 106 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor(
)); | 107 m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor(
)); |
| 107 if (m_identifier) { | 108 if (m_identifier) { |
| 108 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketCreate", "data", InspectorWebSocketCreateEvent::data(m_document, m_identi
fier, url, protocol)); | 109 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketCreate", "data", InspectorWebSocketCreateEvent::data(m_document, m_identi
fier, url, protocol)); |
| 109 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 110 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
| 110 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 111 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 m_didFailOfClientAlreadyRun = true; | 192 m_didFailOfClientAlreadyRun = true; |
| 192 m_client->didReceiveMessageError(); | 193 m_client->didReceiveMessageError(); |
| 193 } | 194 } |
| 194 | 195 |
| 195 void MainThreadWebSocketChannel::fail(const String& reason, MessageLevel level,
const String& sourceURL, unsigned lineNumber) | 196 void MainThreadWebSocketChannel::fail(const String& reason, MessageLevel level,
const String& sourceURL, unsigned lineNumber) |
| 196 { | 197 { |
| 197 WTF_LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, r
eason.utf8().data()); | 198 WTF_LOG(Network, "MainThreadWebSocketChannel %p fail() reason='%s'", this, r
eason.utf8().data()); |
| 198 if (m_document) { | 199 if (m_document) { |
| 199 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id
entifier, reason); | 200 InspectorInstrumentation::didReceiveWebSocketFrameError(m_document, m_id
entifier, reason); |
| 200 const String message = "WebSocket connection to '" + m_handshake->url().
elidedString() + "' failed: " + reason; | 201 const String message = "WebSocket connection to '" + m_handshake->url().
elidedString() + "' failed: " + reason; |
| 201 m_document->addConsoleMessage(JSMessageSource, level, message, sourceURL
, lineNumber); | 202 m_document->addConsoleMessage(ConsoleMessage::create(JSMessageSource, le
vel, message, sourceURL, lineNumber, 0, nullptr, nullptr, 0, NotSharableCrossOri
gin)); |
| 202 } | 203 } |
| 203 // Hybi-10 specification explicitly states we must not continue to handle in
coming data | 204 // Hybi-10 specification explicitly states we must not continue to handle in
coming data |
| 204 // once the WebSocket connection is failed (section 7.1.7). | 205 // once the WebSocket connection is failed (section 7.1.7). |
| 205 RefPtrWillBeRawPtr<MainThreadWebSocketChannel> protect(this); // The client
can close the channel, potentially removing the last reference. | 206 RefPtrWillBeRawPtr<MainThreadWebSocketChannel> protect(this); // The client
can close the channel, potentially removing the last reference. |
| 206 m_shouldDiscardReceivedData = true; | 207 m_shouldDiscardReceivedData = true; |
| 207 if (!m_buffer.isEmpty()) | 208 if (!m_buffer.isEmpty()) |
| 208 skipBuffer(m_buffer.size()); // Save memory. | 209 skipBuffer(m_buffer.size()); // Save memory. |
| 209 m_deflateFramer.didFail(); | 210 m_deflateFramer.didFail(); |
| 210 m_perMessageDeflate.didFail(); | 211 m_perMessageDeflate.didFail(); |
| 211 m_hasContinuousFrame = false; | 212 m_hasContinuousFrame = false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 271 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
| 271 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 272 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
| 272 InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier); | 273 InspectorInstrumentation::didCloseWebSocket(m_document, m_identifier); |
| 273 } | 274 } |
| 274 ASSERT_UNUSED(handle, handle == m_handle || !m_handle); | 275 ASSERT_UNUSED(handle, handle == m_handle || !m_handle); |
| 275 | 276 |
| 276 // Show error message on JS console if this is unexpected connection close | 277 // Show error message on JS console if this is unexpected connection close |
| 277 // during opening handshake. | 278 // during opening handshake. |
| 278 if (!m_hasCalledDisconnectOnHandle && m_handshake->mode() == WebSocketHandsh
ake::Incomplete && m_document) { | 279 if (!m_hasCalledDisconnectOnHandle && m_handshake->mode() == WebSocketHandsh
ake::Incomplete && m_document) { |
| 279 const String message = "WebSocket connection to '" + m_handshake->url().
elidedString() + "' failed: Connection closed before receiving a handshake respo
nse"; | 280 const String message = "WebSocket connection to '" + m_handshake->url().
elidedString() + "' failed: Connection closed before receiving a handshake respo
nse"; |
| 280 m_document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, messag
e, m_sourceURLAtConstruction, m_lineNumberAtConstruction); | 281 m_document->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Er
rorMessageLevel, message, m_sourceURLAtConstruction, m_lineNumberAtConstruction,
0, nullptr, nullptr, 0, NotSharableCrossOrigin)); |
| 281 } | 282 } |
| 282 | 283 |
| 283 m_state = ChannelClosed; | 284 m_state = ChannelClosed; |
| 284 if (m_closingTimer.isActive()) | 285 if (m_closingTimer.isActive()) |
| 285 m_closingTimer.stop(); | 286 m_closingTimer.stop(); |
| 286 if (m_outgoingFrameQueueStatus != OutgoingFrameQueueClosed) | 287 if (m_outgoingFrameQueueStatus != OutgoingFrameQueueClosed) |
| 287 abortOutgoingFrameQueue(); | 288 abortOutgoingFrameQueue(); |
| 288 if (m_handle) { | 289 if (m_handle) { |
| 289 WebSocketChannelClient* client = m_client; | 290 WebSocketChannelClient* client = m_client; |
| 290 m_client = nullptr; | 291 m_client = nullptr; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return false; | 465 return false; |
| 465 if (m_handshake->mode() == WebSocketHandshake::Connected) { | 466 if (m_handshake->mode() == WebSocketHandshake::Connected) { |
| 466 if (m_identifier) { | 467 if (m_identifier) { |
| 467 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timelin
e"), "WebSocketReceiveHandshakeResponse", "data", InspectorWebSocketEvent::data(
m_document, m_identifier)); | 468 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timelin
e"), "WebSocketReceiveHandshakeResponse", "data", InspectorWebSocketEvent::data(
m_document, m_identifier)); |
| 468 // FIXME(361045): remove InspectorInstrumentation calls once Dev
Tools Timeline migrates to tracing. | 469 // FIXME(361045): remove InspectorInstrumentation calls once Dev
Tools Timeline migrates to tracing. |
| 469 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m
_document, m_identifier, 0, &m_handshake->serverHandshakeResponse()); | 470 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m
_document, m_identifier, 0, &m_handshake->serverHandshakeResponse()); |
| 470 } | 471 } |
| 471 | 472 |
| 472 if (m_deflateFramer.enabled() && m_document) { | 473 if (m_deflateFramer.enabled() && m_document) { |
| 473 const String message = "WebSocket extension \"x-webkit-deflate-f
rame\" is deprecated"; | 474 const String message = "WebSocket extension \"x-webkit-deflate-f
rame\" is deprecated"; |
| 474 m_document->addConsoleMessage(JSMessageSource, WarningMessageLev
el, message, m_sourceURLAtConstruction, m_lineNumberAtConstruction); | 475 m_document->addConsoleMessage(ConsoleMessage::create(JSMessageSo
urce, WarningMessageLevel, message, m_sourceURLAtConstruction, m_lineNumberAtCon
struction, 0, nullptr, nullptr, 0, NotSharableCrossOrigin)); |
| 475 } | 476 } |
| 476 | 477 |
| 477 WTF_LOG(Network, "MainThreadWebSocketChannel %p Connected", this); | 478 WTF_LOG(Network, "MainThreadWebSocketChannel %p Connected", this); |
| 478 skipBuffer(headerLength); | 479 skipBuffer(headerLength); |
| 479 String subprotocol = m_handshake->serverWebSocketProtocol(); | 480 String subprotocol = m_handshake->serverWebSocketProtocol(); |
| 480 String extensions = m_handshake->acceptedExtensions(); | 481 String extensions = m_handshake->acceptedExtensions(); |
| 481 m_client->didConnect(subprotocol.isNull() ? "" : subprotocol, extens
ions.isNull() ? "" : extensions); | 482 m_client->didConnect(subprotocol.isNull() ? "" : subprotocol, extens
ions.isNull() ? "" : extensions); |
| 482 WTF_LOG(Network, "MainThreadWebSocketChannel %p %lu bytes remaining
in m_buffer", this, static_cast<unsigned long>(m_buffer.size())); | 483 WTF_LOG(Network, "MainThreadWebSocketChannel %p %lu bytes remaining
in m_buffer", this, static_cast<unsigned long>(m_buffer.size())); |
| 483 return !m_buffer.isEmpty(); | 484 return !m_buffer.isEmpty(); |
| 484 } | 485 } |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 { | 870 { |
| 870 visitor->trace(m_document); | 871 visitor->trace(m_document); |
| 871 visitor->trace(m_client); | 872 visitor->trace(m_client); |
| 872 visitor->trace(m_handshake); | 873 visitor->trace(m_handshake); |
| 873 visitor->trace(m_handle); | 874 visitor->trace(m_handle); |
| 874 WebSocketChannel::trace(visitor); | 875 WebSocketChannel::trace(visitor); |
| 875 SocketStreamHandleClient::trace(visitor); | 876 SocketStreamHandleClient::trace(visitor); |
| 876 } | 877 } |
| 877 | 878 |
| 878 } // namespace WebCore | 879 } // namespace WebCore |
| OLD | NEW |