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 15 matching lines...) Expand all Loading... | |
| 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 "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/ExecutionContext.h" | 35 #include "core/dom/ExecutionContext.h" |
| 36 #include "core/dom/TaskRunnerHelper.h" | |
| 36 #include "core/fileapi/FileReaderLoader.h" | 37 #include "core/fileapi/FileReaderLoader.h" |
| 37 #include "core/fileapi/FileReaderLoaderClient.h" | 38 #include "core/fileapi/FileReaderLoaderClient.h" |
| 38 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/LocalFrameClient.h" | 40 #include "core/frame/LocalFrameClient.h" |
| 40 #include "core/inspector/ConsoleMessage.h" | 41 #include "core/inspector/ConsoleMessage.h" |
| 41 #include "core/inspector/InspectorInstrumentation.h" | 42 #include "core/inspector/InspectorInstrumentation.h" |
| 43 #include "core/loader/DocumentLoader.h" | |
| 42 #include "core/loader/FrameLoader.h" | 44 #include "core/loader/FrameLoader.h" |
| 43 #include "core/loader/MixedContentChecker.h" | 45 #include "core/loader/MixedContentChecker.h" |
| 46 #include "core/loader/SubresourceFilter.h" | |
| 44 #include "core/loader/ThreadableLoadingContext.h" | 47 #include "core/loader/ThreadableLoadingContext.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" |
| 53 #include "platform/weborigin/SecurityOrigin.h" | 56 #include "platform/weborigin/SecurityOrigin.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 m_url = url; | 180 m_url = url; |
| 178 Vector<String> protocols; | 181 Vector<String> protocols; |
| 179 // Avoid placing an empty token in the Vector when the protocol string is | 182 // Avoid placing an empty token in the Vector when the protocol string is |
| 180 // empty. | 183 // empty. |
| 181 if (!protocol.isEmpty()) { | 184 if (!protocol.isEmpty()) { |
| 182 // Since protocol is already verified and escaped, we can simply split | 185 // Since protocol is already verified and escaped, we can simply split |
| 183 // it. | 186 // it. |
| 184 protocol.split(", ", true, protocols); | 187 protocol.split(", ", true, protocols); |
| 185 } | 188 } |
| 186 | 189 |
| 190 // If the connection needs to be filtered, asynchronously fail. Synchronous | |
| 191 // failure blocks the worker thread which should be avoided. Note that | |
| 192 // returning "true" just indicates that this was not a mixed content error. | |
| 193 if (shouldDisallowConnection(url)) { | |
| 194 TaskRunnerHelper::get(TaskType::Networking, document()) | |
|
engedy
2017/03/06 16:31:01
nit: For this, do we need include a subset of {Web
Charlie Harrison
2017/03/06 19:22:12
Done.
| |
| 195 ->postTask( | |
| 196 BLINK_FROM_HERE, | |
| 197 WTF::bind( | |
| 198 &DocumentWebSocketChannel::fail, wrapPersistent(this), | |
| 199 String("Connection disallowed by the subresource filter"), | |
|
engedy
2017/03/06 16:31:01
Phrasing nit: WDYT about "... by subresource filte
engedy
2017/03/06 17:46:13
On second thought, let's hold off on printing the
Charlie Harrison
2017/03/06 19:22:12
Done.
| |
| 200 WarningMessageLevel, | |
|
engedy
2017/03/06 16:31:01
Do we print anything else to the console other tha
Charlie Harrison
2017/03/06 19:22:12
It does make more sense as an error level since we
| |
| 201 WTF::passed(SourceLocation::create(String(), 0, 0, nullptr)))); | |
| 202 return true; | |
| 203 } | |
| 204 | |
| 187 // TODO(kinuko): document() should return nullptr if we don't | 205 // TODO(kinuko): document() should return nullptr if we don't |
| 188 // have valid document/frame that returns non-empty interface provider. | 206 // have valid document/frame that returns non-empty interface provider. |
| 189 if (document() && document()->frame() && | 207 if (document() && document()->frame() && |
| 190 document()->frame()->interfaceProvider() != | 208 document()->frame()->interfaceProvider() != |
| 191 InterfaceProvider::getEmptyInterfaceProvider()) { | 209 InterfaceProvider::getEmptyInterfaceProvider()) { |
| 192 // Initialize the WebSocketHandle with the frame's InterfaceProvider to | 210 // Initialize the WebSocketHandle with the frame's InterfaceProvider to |
| 193 // provide the WebSocket implementation with context about this frame. | 211 // provide the WebSocket implementation with context about this frame. |
| 194 // This is important so that the browser can show UI associated with | 212 // This is important so that the browser can show UI associated with |
| 195 // the WebSocket (e.g., for certificate errors). | 213 // the WebSocket (e.g., for certificate errors). |
| 196 m_handle->initialize(document()->frame()->interfaceProvider()); | 214 m_handle->initialize(document()->frame()->interfaceProvider()); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 m_blobLoader.clear(); | 692 m_blobLoader.clear(); |
| 675 if (errorCode == FileError::kAbortErr) { | 693 if (errorCode == FileError::kAbortErr) { |
| 676 // The error is caused by cancel(). | 694 // The error is caused by cancel(). |
| 677 return; | 695 return; |
| 678 } | 696 } |
| 679 // FIXME: Generate human-friendly reason message. | 697 // FIXME: Generate human-friendly reason message. |
| 680 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); | 698 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); |
| 681 // |this| can be deleted here. | 699 // |this| can be deleted here. |
| 682 } | 700 } |
| 683 | 701 |
| 702 bool DocumentWebSocketChannel::shouldDisallowConnection(const KURL& url) { | |
| 703 DCHECK(m_handle); | |
| 704 DocumentLoader* loader = document()->loader(); | |
| 705 if (!loader) | |
| 706 return false; | |
| 707 SubresourceFilter* subresourceFilter = loader->subresourceFilter(); | |
| 708 if (!subresourceFilter) | |
| 709 return false; | |
| 710 return !subresourceFilter->allowWebSocketConnection(url); | |
| 711 } | |
| 712 | |
| 684 DEFINE_TRACE(DocumentWebSocketChannel) { | 713 DEFINE_TRACE(DocumentWebSocketChannel) { |
| 685 visitor->trace(m_blobLoader); | 714 visitor->trace(m_blobLoader); |
| 686 visitor->trace(m_messages); | 715 visitor->trace(m_messages); |
| 687 visitor->trace(m_client); | 716 visitor->trace(m_client); |
| 688 visitor->trace(m_loadingContext); | 717 visitor->trace(m_loadingContext); |
| 689 WebSocketChannel::trace(visitor); | 718 WebSocketChannel::trace(visitor); |
| 690 } | 719 } |
| 691 | 720 |
| 692 std::ostream& operator<<(std::ostream& ostream, | 721 std::ostream& operator<<(std::ostream& ostream, |
| 693 const DocumentWebSocketChannel* channel) { | 722 const DocumentWebSocketChannel* channel) { |
| 694 return ostream << "DocumentWebSocketChannel " | 723 return ostream << "DocumentWebSocketChannel " |
| 695 << static_cast<const void*>(channel); | 724 << static_cast<const void*>(channel); |
| 696 } | 725 } |
| 697 | 726 |
| 698 } // namespace blink | 727 } // namespace blink |
| OLD | NEW |