Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 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 "modules/websockets/DocumentWebSocketChannel.h" | 31 #include "modules/websockets/DocumentWebSocketChannel.h" |
| 32 | 32 |
| 33 #include <memory> | 33 #include <memory> |
| 34 #include "core/dom/DOMArrayBuffer.h" | 34 #include "core/dom/DOMArrayBuffer.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/dom/TaskRunnerHelper.h" | |
| 37 #include "core/fileapi/FileReaderLoader.h" | 38 #include "core/fileapi/FileReaderLoader.h" |
| 38 #include "core/fileapi/FileReaderLoaderClient.h" | 39 #include "core/fileapi/FileReaderLoaderClient.h" |
| 39 #include "core/frame/LocalFrame.h" | 40 #include "core/frame/LocalFrame.h" |
| 40 #include "core/frame/LocalFrameClient.h" | 41 #include "core/frame/LocalFrameClient.h" |
| 41 #include "core/inspector/ConsoleMessage.h" | 42 #include "core/inspector/ConsoleMessage.h" |
| 42 #include "core/inspector/InspectorInstrumentation.h" | 43 #include "core/inspector/InspectorInstrumentation.h" |
| 44 #include "core/loader/DocumentLoader.h" | |
| 45 #include "core/loader/DocumentSubresourceFilterClient.h" | |
| 43 #include "core/loader/FrameLoader.h" | 46 #include "core/loader/FrameLoader.h" |
| 44 #include "core/loader/MixedContentChecker.h" | 47 #include "core/loader/MixedContentChecker.h" |
| 45 #include "modules/websockets/InspectorWebSocketEvents.h" | 48 #include "modules/websockets/InspectorWebSocketEvents.h" |
| 46 #include "modules/websockets/WebSocketChannelClient.h" | 49 #include "modules/websockets/WebSocketChannelClient.h" |
| 47 #include "modules/websockets/WebSocketFrame.h" | 50 #include "modules/websockets/WebSocketFrame.h" |
| 48 #include "modules/websockets/WebSocketHandleImpl.h" | 51 #include "modules/websockets/WebSocketHandleImpl.h" |
| 49 #include "platform/WebFrameScheduler.h" | 52 #include "platform/WebFrameScheduler.h" |
| 50 #include "platform/loader/fetch/UniqueIdentifier.h" | 53 #include "platform/loader/fetch/UniqueIdentifier.h" |
| 51 #include "platform/network/NetworkLog.h" | 54 #include "platform/network/NetworkLog.h" |
| 52 #include "platform/network/WebSocketHandshakeRequest.h" | 55 #include "platform/network/WebSocketHandshakeRequest.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 document()->frame()->interfaceProvider() != | 188 document()->frame()->interfaceProvider() != |
| 186 InterfaceProvider::getEmptyInterfaceProvider()) { | 189 InterfaceProvider::getEmptyInterfaceProvider()) { |
| 187 // Initialize the WebSocketHandle with the frame's InterfaceProvider to | 190 // Initialize the WebSocketHandle with the frame's InterfaceProvider to |
| 188 // provide the WebSocket implementation with context about this frame. | 191 // provide the WebSocket implementation with context about this frame. |
| 189 // This is important so that the browser can show UI associated with | 192 // This is important so that the browser can show UI associated with |
| 190 // the WebSocket (e.g., for certificate errors). | 193 // the WebSocket (e.g., for certificate errors). |
| 191 m_handle->initialize(document()->frame()->interfaceProvider()); | 194 m_handle->initialize(document()->frame()->interfaceProvider()); |
| 192 } else { | 195 } else { |
| 193 m_handle->initialize(Platform::current()->interfaceProvider()); | 196 m_handle->initialize(Platform::current()->interfaceProvider()); |
| 194 } | 197 } |
| 198 | |
| 199 // If the connection needs to be filtered, asynchronously fail. Note that | |
|
yhirano
2017/03/01 06:40:58
Please move this section before L187.
Charlie Harrison
2017/03/01 18:55:57
Done.
| |
| 200 // returning "true" just indicates that this was not synchronous security | |
| 201 // error. | |
| 202 if (shouldFilterConnection(url)) { | |
| 203 TaskRunnerHelper::get(TaskType::Networking, document()) | |
| 204 ->postTask( | |
| 205 BLINK_FROM_HERE, | |
| 206 WTF::bind(&DocumentWebSocketChannel::failWithClosureCode, | |
| 207 wrapPersistent(this), CloseEventCodePolicyViolation)); | |
| 208 return true; | |
| 209 } | |
| 210 | |
| 195 m_handle->connect(url, protocols, document()->getSecurityOrigin(), | 211 m_handle->connect(url, protocols, document()->getSecurityOrigin(), |
| 196 document()->firstPartyForCookies(), document()->userAgent(), | 212 document()->firstPartyForCookies(), document()->userAgent(), |
| 197 this); | 213 this); |
| 198 | 214 |
| 199 flowControlIfNecessary(); | 215 flowControlIfNecessary(); |
| 200 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", | 216 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", |
| 201 TRACE_EVENT_SCOPE_THREAD, "data", | 217 TRACE_EVENT_SCOPE_THREAD, "data", |
| 202 InspectorWebSocketCreateEvent::data( | 218 InspectorWebSocketCreateEvent::data( |
| 203 document(), m_identifier, url, protocol)); | 219 document(), m_identifier, url, protocol)); |
| 204 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, | 220 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 m_messages.append(new Message(codeToSend, reason)); | 303 m_messages.append(new Message(codeToSend, reason)); |
| 288 processSendQueue(); | 304 processSendQueue(); |
| 289 } | 305 } |
| 290 | 306 |
| 291 void DocumentWebSocketChannel::fail(const String& reason, | 307 void DocumentWebSocketChannel::fail(const String& reason, |
| 292 MessageLevel level, | 308 MessageLevel level, |
| 293 std::unique_ptr<SourceLocation> location) { | 309 std::unique_ptr<SourceLocation> location) { |
| 294 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; | 310 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; |
| 295 // m_handle and m_client can be null here. | 311 // m_handle and m_client can be null here. |
| 296 | 312 |
| 297 connection_handle_for_scheduler_.reset(); | |
| 298 | |
| 299 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), | 313 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), |
| 300 m_identifier, reason); | 314 m_identifier, reason); |
| 301 const String message = "WebSocket connection to '" + m_url.elidedString() + | 315 const String message = "WebSocket connection to '" + m_url.elidedString() + |
| 302 "' failed: " + reason; | 316 "' failed: " + reason; |
| 303 document()->addConsoleMessage(ConsoleMessage::create( | 317 document()->addConsoleMessage(ConsoleMessage::create( |
|
yhirano
2017/03/01 06:40:58
Is showing a console message useful for developers
Charlie Harrison
2017/03/01 18:55:57
It is useful. Eventually we will move the notifica
| |
| 304 JSMessageSource, level, message, std::move(location))); | 318 JSMessageSource, level, message, std::move(location))); |
| 305 | 319 failWithClosureCode(CloseEventCodeAbnormalClosure); |
| 306 if (m_client) | |
| 307 m_client->didError(); | |
| 308 // |reason| is only for logging and should not be provided for scripts, | |
| 309 // hence close reason must be empty. | |
| 310 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); | |
| 311 // handleDidClose may delete this object. | |
| 312 } | 320 } |
| 313 | 321 |
| 314 void DocumentWebSocketChannel::disconnect() { | 322 void DocumentWebSocketChannel::disconnect() { |
| 315 NETWORK_DVLOG(1) << this << " disconnect()"; | 323 NETWORK_DVLOG(1) << this << " disconnect()"; |
| 316 if (m_identifier) { | 324 if (m_identifier) { |
| 317 TRACE_EVENT_INSTANT1( | 325 TRACE_EVENT_INSTANT1( |
| 318 "devtools.timeline", "WebSocketDestroy", TRACE_EVENT_SCOPE_THREAD, | 326 "devtools.timeline", "WebSocketDestroy", TRACE_EVENT_SCOPE_THREAD, |
| 319 "data", InspectorWebSocketEvent::data(document(), m_identifier)); | 327 "data", InspectorWebSocketEvent::data(document(), m_identifier)); |
| 320 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 328 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
| 321 } | 329 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 m_blobLoader.clear(); | 663 m_blobLoader.clear(); |
| 656 if (errorCode == FileError::kAbortErr) { | 664 if (errorCode == FileError::kAbortErr) { |
| 657 // The error is caused by cancel(). | 665 // The error is caused by cancel(). |
| 658 return; | 666 return; |
| 659 } | 667 } |
| 660 // FIXME: Generate human-friendly reason message. | 668 // FIXME: Generate human-friendly reason message. |
| 661 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); | 669 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); |
| 662 // |this| can be deleted here. | 670 // |this| can be deleted here. |
| 663 } | 671 } |
| 664 | 672 |
| 673 void DocumentWebSocketChannel::failWithClosureCode(unsigned short code) { | |
| 674 connection_handle_for_scheduler_.reset(); | |
| 675 | |
| 676 if (m_client) | |
| 677 m_client->didError(); | |
| 678 // |reason| is only for logging and should not be provided for scripts, | |
| 679 // hence close reason must be empty. | |
| 680 handleDidClose(false, code, String()); | |
| 681 // handleDidClose may delete this object. | |
| 682 } | |
| 683 | |
| 684 bool DocumentWebSocketChannel::shouldFilterConnection(const KURL& url) { | |
| 685 if (!m_handle) | |
| 686 return false; | |
| 687 DocumentLoader* loader = document()->loader(); | |
| 688 if (!loader) | |
| 689 return false; | |
| 690 DocumentSubresourceFilterClient* subresourceFilter = | |
| 691 loader->subresourceFilter(); | |
| 692 if (!subresourceFilter) | |
| 693 return false; | |
| 694 return !subresourceFilter->allowWebSocketConnection(url); | |
| 695 } | |
| 696 | |
| 665 DEFINE_TRACE(DocumentWebSocketChannel) { | 697 DEFINE_TRACE(DocumentWebSocketChannel) { |
| 666 visitor->trace(m_blobLoader); | 698 visitor->trace(m_blobLoader); |
| 667 visitor->trace(m_messages); | 699 visitor->trace(m_messages); |
| 668 visitor->trace(m_client); | 700 visitor->trace(m_client); |
| 669 visitor->trace(m_document); | 701 visitor->trace(m_document); |
| 670 WebSocketChannel::trace(visitor); | 702 WebSocketChannel::trace(visitor); |
| 671 } | 703 } |
| 672 | 704 |
| 673 std::ostream& operator<<(std::ostream& ostream, | 705 std::ostream& operator<<(std::ostream& ostream, |
| 674 const DocumentWebSocketChannel* channel) { | 706 const DocumentWebSocketChannel* channel) { |
| 675 return ostream << "DocumentWebSocketChannel " | 707 return ostream << "DocumentWebSocketChannel " |
| 676 << static_cast<const void*>(channel); | 708 << static_cast<const void*>(channel); |
| 677 } | 709 } |
| 678 | 710 |
| 679 } // namespace blink | 711 } // namespace blink |
| OLD | NEW |