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 | |
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(BLINK_FROM_HERE, | |
205 WTF::bind(&DocumentWebSocketChannel::handleDidClose, | |
yhirano
2017/03/01 03:40:42
Thank you!
I found we need some more operations s
Charlie Harrison
2017/03/01 03:58:51
Done, how does this look to you?
| |
206 wrapPersistent(this), false, | |
207 CloseEventCodePolicyViolation, String(""))); | |
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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 m_blobLoader.clear(); | 671 m_blobLoader.clear(); |
656 if (errorCode == FileError::kAbortErr) { | 672 if (errorCode == FileError::kAbortErr) { |
657 // The error is caused by cancel(). | 673 // The error is caused by cancel(). |
658 return; | 674 return; |
659 } | 675 } |
660 // FIXME: Generate human-friendly reason message. | 676 // FIXME: Generate human-friendly reason message. |
661 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); | 677 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); |
662 // |this| can be deleted here. | 678 // |this| can be deleted here. |
663 } | 679 } |
664 | 680 |
681 bool DocumentWebSocketChannel::shouldFilterConnection(const KURL& url) { | |
682 if (!m_handle) | |
683 return false; | |
684 DocumentLoader* loader = document()->loader(); | |
685 if (!loader) | |
686 return false; | |
687 DocumentSubresourceFilterClient* subresourceFilter = | |
688 loader->subresourceFilter(); | |
689 if (!subresourceFilter) | |
690 return false; | |
691 return !subresourceFilter->allowWebSocketConnection(url); | |
692 } | |
693 | |
665 DEFINE_TRACE(DocumentWebSocketChannel) { | 694 DEFINE_TRACE(DocumentWebSocketChannel) { |
666 visitor->trace(m_blobLoader); | 695 visitor->trace(m_blobLoader); |
667 visitor->trace(m_messages); | 696 visitor->trace(m_messages); |
668 visitor->trace(m_client); | 697 visitor->trace(m_client); |
669 visitor->trace(m_document); | 698 visitor->trace(m_document); |
670 WebSocketChannel::trace(visitor); | 699 WebSocketChannel::trace(visitor); |
671 } | 700 } |
672 | 701 |
673 std::ostream& operator<<(std::ostream& ostream, | 702 std::ostream& operator<<(std::ostream& ostream, |
674 const DocumentWebSocketChannel* channel) { | 703 const DocumentWebSocketChannel* channel) { |
675 return ostream << "DocumentWebSocketChannel " | 704 return ostream << "DocumentWebSocketChannel " |
676 << static_cast<const void*>(channel); | 705 << static_cast<const void*>(channel); |
677 } | 706 } |
678 | 707 |
679 } // namespace blink | 708 } // namespace blink |
OLD | NEW |