| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 Member<DocumentWebSocketChannel> m_channel; | 82 Member<DocumentWebSocketChannel> m_channel; |
| 83 FileReaderLoader m_loader; | 83 FileReaderLoader m_loader; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob
DataHandle, DocumentWebSocketChannel* channel) | 86 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob
DataHandle, DocumentWebSocketChannel* channel) |
| 87 : m_channel(channel) | 87 : m_channel(channel) |
| 88 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) | 88 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) |
| 89 { | 89 { |
| 90 m_loader.start(channel->executionContext(), blobDataHandle); | 90 m_loader.start(channel->getExecutionContext(), blobDataHandle); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void DocumentWebSocketChannel::BlobLoader::cancel() | 93 void DocumentWebSocketChannel::BlobLoader::cancel() |
| 94 { | 94 { |
| 95 m_loader.cancel(); | 95 m_loader.cancel(); |
| 96 // didFail will be called immediately. | 96 // didFail will be called immediately. |
| 97 // |this| is deleted here. | 97 // |this| is deleted here. |
| 98 } | 98 } |
| 99 | 99 |
| 100 void DocumentWebSocketChannel::BlobLoader::didFinishLoading() | 100 void DocumentWebSocketChannel::BlobLoader::didFinishLoading() |
| (...skipping 29 matching lines...) Expand all Loading... |
| 130 bool DocumentWebSocketChannel::connect(const KURL& url, const String& protocol) | 130 bool DocumentWebSocketChannel::connect(const KURL& url, const String& protocol) |
| 131 { | 131 { |
| 132 WTF_LOG(Network, "DocumentWebSocketChannel %p connect()", this); | 132 WTF_LOG(Network, "DocumentWebSocketChannel %p connect()", this); |
| 133 if (!m_handle) | 133 if (!m_handle) |
| 134 return false; | 134 return false; |
| 135 | 135 |
| 136 if (document()->frame()) { | 136 if (document()->frame()) { |
| 137 if (MixedContentChecker::shouldBlockWebSocket(document()->frame(), url)) | 137 if (MixedContentChecker::shouldBlockWebSocket(document()->frame(), url)) |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 if (MixedContentChecker::isMixedContent(document()->securityOrigin(), url))
{ | 140 if (MixedContentChecker::isMixedContent(document()->getSecurityOrigin(), url
)) { |
| 141 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; | 141 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; |
| 142 document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); | 142 document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Wa
rningMessageLevel, message)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 m_url = url; | 145 m_url = url; |
| 146 Vector<String> protocols; | 146 Vector<String> protocols; |
| 147 // Avoid placing an empty token in the Vector when the protocol string is | 147 // Avoid placing an empty token in the Vector when the protocol string is |
| 148 // empty. | 148 // empty. |
| 149 if (!protocol.isEmpty()) { | 149 if (!protocol.isEmpty()) { |
| 150 // Since protocol is already verified and escaped, we can simply split | 150 // Since protocol is already verified and escaped, we can simply split |
| 151 // it. | 151 // it. |
| 152 protocol.split(", ", true, protocols); | 152 protocol.split(", ", true, protocols); |
| 153 } | 153 } |
| 154 WebVector<WebString> webProtocols(protocols.size()); | 154 WebVector<WebString> webProtocols(protocols.size()); |
| 155 for (size_t i = 0; i < protocols.size(); ++i) { | 155 for (size_t i = 0; i < protocols.size(); ++i) { |
| 156 webProtocols[i] = protocols[i]; | 156 webProtocols[i] = protocols[i]; |
| 157 } | 157 } |
| 158 | 158 |
| 159 if (document()->frame()) | 159 if (document()->frame()) |
| 160 document()->frame()->loader().client()->dispatchWillOpenWebSocket(m_hand
le.get()); | 160 document()->frame()->loader().client()->dispatchWillOpenWebSocket(m_hand
le.get()); |
| 161 m_handle->connect(url, webProtocols, WebSecurityOrigin(executionContext()->s
ecurityOrigin()), this); | 161 m_handle->connect(url, webProtocols, WebSecurityOrigin(getExecutionContext()
->getSecurityOrigin()), this); |
| 162 | 162 |
| 163 flowControlIfNecessary(); | 163 flowControlIfNecessary(); |
| 164 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", TRACE_EVENT_SCO
PE_THREAD, "data", InspectorWebSocketCreateEvent::data(document(), m_identifier,
url, protocol)); | 164 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", TRACE_EVENT_SCO
PE_THREAD, "data", InspectorWebSocketCreateEvent::data(document(), m_identifier,
url, protocol)); |
| 165 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url,
protocol); | 165 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url,
protocol); |
| 166 return true; | 166 return true; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void DocumentWebSocketChannel::send(const CString& message) | 169 void DocumentWebSocketChannel::send(const CString& message) |
| 170 { | 170 { |
| 171 WTF_LOG(Network, "DocumentWebSocketChannel %p sendText(%s)", this, message.d
ata()); | 171 WTF_LOG(Network, "DocumentWebSocketChannel %p sendText(%s)", this, message.d
ata()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 processSendQueue(); | 231 processSendQueue(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, co
nst String& sourceURL, unsigned lineNumber) | 234 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, co
nst String& sourceURL, unsigned lineNumber) |
| 235 { | 235 { |
| 236 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8()
.data()); | 236 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8()
.data()); |
| 237 // m_handle and m_client can be null here. | 237 // m_handle and m_client can be null here. |
| 238 | 238 |
| 239 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi
fier, reason); | 239 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi
fier, reason); |
| 240 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; | 240 const String message = "WebSocket connection to '" + m_url.elidedString() +
"' failed: " + reason; |
| 241 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, level, message, sourceURL, lineNumber)); | 241 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSou
rce, level, message, sourceURL, lineNumber)); |
| 242 | 242 |
| 243 if (m_client) | 243 if (m_client) |
| 244 m_client->didError(); | 244 m_client->didError(); |
| 245 // |reason| is only for logging and should not be provided for scripts, | 245 // |reason| is only for logging and should not be provided for scripts, |
| 246 // hence close reason must be empty. | 246 // hence close reason must be empty. |
| 247 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); | 247 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
| 248 // handleDidClose may delete this object. | 248 // handleDidClose may delete this object. |
| 249 } | 249 } |
| 250 | 250 |
| 251 void DocumentWebSocketChannel::disconnect() | 251 void DocumentWebSocketChannel::disconnect() |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 m_client = nullptr; | 375 m_client = nullptr; |
| 376 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = | 376 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = |
| 377 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC
hannelClient::ClosingHandshakeIncomplete; | 377 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete : WebSocketC
hannelClient::ClosingHandshakeIncomplete; |
| 378 client->didClose(status, code, reason); | 378 client->didClose(status, code, reason); |
| 379 // client->didClose may delete this object. | 379 // client->didClose may delete this object. |
| 380 } | 380 } |
| 381 | 381 |
| 382 Document* DocumentWebSocketChannel::document() | 382 Document* DocumentWebSocketChannel::document() |
| 383 { | 383 { |
| 384 // This context is always a Document. See the constructor. | 384 // This context is always a Document. See the constructor. |
| 385 ExecutionContext* context = executionContext(); | 385 ExecutionContext* context = getExecutionContext(); |
| 386 ASSERT(context->isDocument()); | 386 ASSERT(context->isDocument()); |
| 387 return toDocument(context); | 387 return toDocument(context); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, const WebStri
ng& selectedProtocol, const WebString& extensions) | 390 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, const WebStri
ng& selectedProtocol, const WebString& extensions) |
| 391 { | 391 { |
| 392 WTF_LOG(Network, "DocumentWebSocketChannel %p didConnect(%p, %s, %s)", this,
handle, selectedProtocol.utf8().c_str(), extensions.utf8().c_str()); | 392 WTF_LOG(Network, "DocumentWebSocketChannel %p didConnect(%p, %s, %s)", this,
handle, selectedProtocol.utf8().c_str(), extensions.utf8().c_str()); |
| 393 | 393 |
| 394 ASSERT(m_handle); | 394 ASSERT(m_handle); |
| 395 ASSERT(handle == m_handle); | 395 ASSERT(handle == m_handle); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 554 |
| 555 DEFINE_TRACE(DocumentWebSocketChannel) | 555 DEFINE_TRACE(DocumentWebSocketChannel) |
| 556 { | 556 { |
| 557 visitor->trace(m_blobLoader); | 557 visitor->trace(m_blobLoader); |
| 558 visitor->trace(m_client); | 558 visitor->trace(m_client); |
| 559 WebSocketChannel::trace(visitor); | 559 WebSocketChannel::trace(visitor); |
| 560 ContextLifecycleObserver::trace(visitor); | 560 ContextLifecycleObserver::trace(visitor); |
| 561 } | 561 } |
| 562 | 562 |
| 563 } // namespace blink | 563 } // namespace blink |
| OLD | NEW |