Chromium Code Reviews| Index: third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp |
| diff --git a/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp b/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp |
| index 089e79056e6db6d4035b8c01e96af14484c6d5a6..a61be9881a9afcd6a5b08205ce8536adbf213735 100644 |
| --- a/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp |
| +++ b/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp |
| @@ -33,26 +33,32 @@ |
| #include <memory> |
| #include "core/dom/DOMArrayBuffer.h" |
| #include "core/dom/ExecutionContext.h" |
| +#include "core/dom/TaskRunnerHelper.h" |
| #include "core/fileapi/FileReaderLoader.h" |
| #include "core/fileapi/FileReaderLoaderClient.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/LocalFrameClient.h" |
| #include "core/inspector/ConsoleMessage.h" |
| #include "core/inspector/InspectorInstrumentation.h" |
| +#include "core/loader/DocumentLoader.h" |
| #include "core/loader/FrameLoader.h" |
| #include "core/loader/MixedContentChecker.h" |
| +#include "core/loader/SubresourceFilter.h" |
| #include "core/loader/ThreadableLoadingContext.h" |
| #include "modules/websockets/InspectorWebSocketEvents.h" |
| #include "modules/websockets/WebSocketChannelClient.h" |
| #include "modules/websockets/WebSocketFrame.h" |
| #include "modules/websockets/WebSocketHandleImpl.h" |
| #include "platform/WebFrameScheduler.h" |
| +#include "platform/WebTaskRunner.h" |
| #include "platform/loader/fetch/UniqueIdentifier.h" |
| #include "platform/network/NetworkLog.h" |
| #include "platform/network/WebSocketHandshakeRequest.h" |
| #include "platform/weborigin/SecurityOrigin.h" |
| #include "public/platform/InterfaceProvider.h" |
| #include "public/platform/Platform.h" |
| +#include "public/platform/WebTraceLocation.h" |
| +#include "wtf/Functional.h" |
| #include "wtf/PtrUtil.h" |
| namespace blink { |
| @@ -184,6 +190,18 @@ bool DocumentWebSocketChannel::connect(const KURL& url, |
| protocol.split(", ", true, protocols); |
| } |
| + // If the connection needs to be filtered, asynchronously fail. Synchronous |
| + // failure blocks the worker thread which should be avoided. Note that |
| + // returning "true" just indicates that this was not a mixed content error. |
| + if (shouldDisallowConnection(url)) { |
| + TaskRunnerHelper::get(TaskType::Networking, document()) |
| + ->postTask( |
| + BLINK_FROM_HERE, |
| + WTF::bind(&DocumentWebSocketChannel::tearDownFailedConnection, |
| + wrapPersistent(this))); |
| + return true; |
| + } |
| + |
| // TODO(kinuko): document() should return nullptr if we don't |
| // have valid document/frame that returns non-empty interface provider. |
| if (document() && document()->frame() && |
| @@ -297,10 +315,6 @@ void DocumentWebSocketChannel::fail(const String& reason, |
| MessageLevel level, |
| std::unique_ptr<SourceLocation> location) { |
| NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; |
| - // m_handle and m_client can be null here. |
| - |
| - connection_handle_for_scheduler_.reset(); |
| - |
| if (document()) { |
| InspectorInstrumentation::didReceiveWebSocketFrameError( |
| document(), m_identifier, reason); |
| @@ -309,13 +323,7 @@ void DocumentWebSocketChannel::fail(const String& reason, |
| document()->addConsoleMessage(ConsoleMessage::create( |
| JSMessageSource, level, message, std::move(location))); |
| } |
| - |
| - if (m_client) |
| - m_client->didError(); |
| - // |reason| is only for logging and should not be provided for scripts, |
| - // hence close reason must be empty. |
| - handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
| - // handleDidClose may delete this object. |
| + tearDownFailedConnection(); |
| } |
| void DocumentWebSocketChannel::disconnect() { |
| @@ -681,6 +689,30 @@ void DocumentWebSocketChannel::didFailLoadingBlob( |
| // |this| can be deleted here. |
| } |
| +void DocumentWebSocketChannel::tearDownFailedConnection() { |
| + // m_handle and m_client can be null here. |
| + connection_handle_for_scheduler_.reset(); |
| + |
| + if (m_client) |
| + m_client->didError(); |
| + |
| + // |reason| is only for logging and should not be provided for scripts, |
|
yhirano
2017/03/06 20:39:01
This comment does not make sense any more. Moving
Charlie Harrison
2017/03/06 20:48:21
Done.
|
| + // hence close reason must be empty. |
| + handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
| + // handleDidClose may delete this object. |
| +} |
| + |
| +bool DocumentWebSocketChannel::shouldDisallowConnection(const KURL& url) { |
| + DCHECK(m_handle); |
| + DocumentLoader* loader = document()->loader(); |
| + if (!loader) |
| + return false; |
| + SubresourceFilter* subresourceFilter = loader->subresourceFilter(); |
| + if (!subresourceFilter) |
| + return false; |
| + return !subresourceFilter->allowWebSocketConnection(url); |
| +} |
| + |
| DEFINE_TRACE(DocumentWebSocketChannel) { |
| visitor->trace(m_blobLoader); |
| visitor->trace(m_messages); |