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/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/FrameLoaderClient.h" | 45 #include "core/loader/FrameLoaderClient.h" |
44 #include "core/loader/MixedContentChecker.h" | 46 #include "core/loader/MixedContentChecker.h" |
45 #include "modules/websockets/InspectorWebSocketEvents.h" | 47 #include "modules/websockets/InspectorWebSocketEvents.h" |
46 #include "modules/websockets/WebSocketChannelClient.h" | 48 #include "modules/websockets/WebSocketChannelClient.h" |
47 #include "modules/websockets/WebSocketFrame.h" | 49 #include "modules/websockets/WebSocketFrame.h" |
48 #include "modules/websockets/WebSocketHandleImpl.h" | 50 #include "modules/websockets/WebSocketHandleImpl.h" |
49 #include "platform/WebFrameScheduler.h" | 51 #include "platform/WebFrameScheduler.h" |
50 #include "platform/loader/fetch/UniqueIdentifier.h" | 52 #include "platform/loader/fetch/UniqueIdentifier.h" |
51 #include "platform/network/NetworkLog.h" | 53 #include "platform/network/NetworkLog.h" |
52 #include "platform/network/WebSocketHandshakeRequest.h" | 54 #include "platform/network/WebSocketHandshakeRequest.h" |
53 #include "platform/weborigin/SecurityOrigin.h" | 55 #include "platform/weborigin/SecurityOrigin.h" |
54 #include "public/platform/InterfaceProvider.h" | 56 #include "public/platform/InterfaceProvider.h" |
55 #include "public/platform/Platform.h" | 57 #include "public/platform/Platform.h" |
58 #include "public/platform/WebDocumentSubresourceFilter.h" | |
56 #include "wtf/PtrUtil.h" | 59 #include "wtf/PtrUtil.h" |
57 | 60 |
58 namespace blink { | 61 namespace blink { |
59 | 62 |
60 class DocumentWebSocketChannel::BlobLoader final | 63 class DocumentWebSocketChannel::BlobLoader final |
61 : public GarbageCollectedFinalized<DocumentWebSocketChannel::BlobLoader>, | 64 : public GarbageCollectedFinalized<DocumentWebSocketChannel::BlobLoader>, |
62 public FileReaderLoaderClient { | 65 public FileReaderLoaderClient { |
63 public: | 66 public: |
64 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); | 67 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); |
65 ~BlobLoader() override {} | 68 ~BlobLoader() override {} |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 document()->firstPartyForCookies(), document()->userAgent(), | 199 document()->firstPartyForCookies(), document()->userAgent(), |
197 this); | 200 this); |
198 | 201 |
199 flowControlIfNecessary(); | 202 flowControlIfNecessary(); |
200 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", | 203 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", |
201 TRACE_EVENT_SCOPE_THREAD, "data", | 204 TRACE_EVENT_SCOPE_THREAD, "data", |
202 InspectorWebSocketCreateEvent::data( | 205 InspectorWebSocketCreateEvent::data( |
203 document(), m_identifier, url, protocol)); | 206 document(), m_identifier, url, protocol)); |
204 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, | 207 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, |
205 protocol); | 208 protocol); |
209 TaskRunnerHelper::get(TaskType::Networking, document()) | |
210 ->postTask(BLINK_FROM_HERE, | |
211 WTF::bind(&DocumentWebSocketChannel::maybeFilterConnection, | |
212 wrapPersistent(this))); | |
206 return true; | 213 return true; |
207 } | 214 } |
208 | 215 |
209 void DocumentWebSocketChannel::send(const CString& message) { | 216 void DocumentWebSocketChannel::send(const CString& message) { |
210 NETWORK_DVLOG(1) << this << " sendText(" << message << ")"; | 217 NETWORK_DVLOG(1) << this << " sendText(" << message << ")"; |
211 // FIXME: Change the inspector API to show the entire message instead | 218 // FIXME: Change the inspector API to show the entire message instead |
212 // of individual frames. | 219 // of individual frames. |
213 InspectorInstrumentation::didSendWebSocketFrame( | 220 InspectorInstrumentation::didSendWebSocketFrame( |
214 document(), m_identifier, WebSocketFrame::OpCodeText, true, | 221 document(), m_identifier, WebSocketFrame::OpCodeText, true, |
215 message.data(), message.length()); | 222 message.data(), message.length()); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 m_blobLoader.clear(); | 662 m_blobLoader.clear(); |
656 if (errorCode == FileError::kAbortErr) { | 663 if (errorCode == FileError::kAbortErr) { |
657 // The error is caused by cancel(). | 664 // The error is caused by cancel(). |
658 return; | 665 return; |
659 } | 666 } |
660 // FIXME: Generate human-friendly reason message. | 667 // FIXME: Generate human-friendly reason message. |
661 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); | 668 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); |
662 // |this| can be deleted here. | 669 // |this| can be deleted here. |
663 } | 670 } |
664 | 671 |
672 void DocumentWebSocketChannel::maybeFilterConnection() { | |
673 if (!m_handle) | |
674 return; | |
675 DocumentLoader* loader = document()->loader(); | |
676 if (!loader) | |
677 return; | |
678 WebDocumentSubresourceFilter* subresourceFilter = loader->subresourceFilter(); | |
679 if (!subresourceFilter) | |
680 return; | |
681 | |
682 WebDocumentSubresourceFilter::LoadPolicy loadPolicy = | |
683 subresourceFilter->getLoadPolicy(m_url); | |
684 if (loadPolicy == WebDocumentSubresourceFilter::Disallow) | |
685 subresourceFilter->reportDisallowedLoad(); | |
686 if (loadPolicy != WebDocumentSubresourceFilter::Allow) | |
687 loader->didObserveLoadingBehavior(WebLoadingBehaviorSubresourceFilterMatch); | |
688 // TODO(csharrison): Figure out the ideal event code / reason to send here. | |
689 close(CloseEventCodeNotSpecified, ""); | |
yhirano
2017/02/24 03:55:29
if (loadPolicy == Allow)
return;
?
yhirano
2017/02/24 03:55:30
Is 1008 good for this case?
Charlie Harrison
2017/02/24 21:13:02
Done. Oops :P
Charlie Harrison
2017/02/24 21:13:02
Done.
| |
690 } | |
691 | |
665 DEFINE_TRACE(DocumentWebSocketChannel) { | 692 DEFINE_TRACE(DocumentWebSocketChannel) { |
666 visitor->trace(m_blobLoader); | 693 visitor->trace(m_blobLoader); |
667 visitor->trace(m_messages); | 694 visitor->trace(m_messages); |
668 visitor->trace(m_client); | 695 visitor->trace(m_client); |
669 visitor->trace(m_document); | 696 visitor->trace(m_document); |
670 WebSocketChannel::trace(visitor); | 697 WebSocketChannel::trace(visitor); |
671 } | 698 } |
672 | 699 |
673 std::ostream& operator<<(std::ostream& ostream, | 700 std::ostream& operator<<(std::ostream& ostream, |
674 const DocumentWebSocketChannel* channel) { | 701 const DocumentWebSocketChannel* channel) { |
675 return ostream << "DocumentWebSocketChannel " | 702 return ostream << "DocumentWebSocketChannel " |
676 << static_cast<const void*>(channel); | 703 << static_cast<const void*>(channel); |
677 } | 704 } |
678 | 705 |
679 } // namespace blink | 706 } // namespace blink |
OLD | NEW |