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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 unsigned short code; | 99 unsigned short code; |
100 String reason; | 100 String reason; |
101 }; | 101 }; |
102 | 102 |
103 DocumentWebSocketChannel::BlobLoader::BlobLoader( | 103 DocumentWebSocketChannel::BlobLoader::BlobLoader( |
104 PassRefPtr<BlobDataHandle> blobDataHandle, | 104 PassRefPtr<BlobDataHandle> blobDataHandle, |
105 DocumentWebSocketChannel* channel) | 105 DocumentWebSocketChannel* channel) |
106 : m_channel(channel), | 106 : m_channel(channel), |
107 m_loader( | 107 m_loader( |
108 FileReaderLoader::create(FileReaderLoader::ReadAsArrayBuffer, this)) { | 108 FileReaderLoader::create(FileReaderLoader::ReadAsArrayBuffer, this)) { |
109 m_loader->start(channel->getExecutionContext(), std::move(blobDataHandle)); | 109 m_loader->start(channel->document(), std::move(blobDataHandle)); |
110 } | 110 } |
111 | 111 |
112 void DocumentWebSocketChannel::BlobLoader::cancel() { | 112 void DocumentWebSocketChannel::BlobLoader::cancel() { |
113 m_loader->cancel(); | 113 m_loader->cancel(); |
114 // didFail will be called immediately. | 114 // didFail will be called immediately. |
115 // |this| is deleted here. | 115 // |this| is deleted here. |
116 } | 116 } |
117 | 117 |
118 void DocumentWebSocketChannel::BlobLoader::didFinishLoading() { | 118 void DocumentWebSocketChannel::BlobLoader::didFinishLoading() { |
119 m_channel->didFinishLoadingBlob(m_loader->arrayBufferResult()); | 119 m_channel->didFinishLoadingBlob(m_loader->arrayBufferResult()); |
120 // |this| is deleted here. | 120 // |this| is deleted here. |
121 } | 121 } |
122 | 122 |
123 void DocumentWebSocketChannel::BlobLoader::didFail( | 123 void DocumentWebSocketChannel::BlobLoader::didFail( |
124 FileError::ErrorCode errorCode) { | 124 FileError::ErrorCode errorCode) { |
125 m_channel->didFailLoadingBlob(errorCode); | 125 m_channel->didFailLoadingBlob(errorCode); |
126 // |this| is deleted here. | 126 // |this| is deleted here. |
127 } | 127 } |
128 | 128 |
129 DocumentWebSocketChannel::DocumentWebSocketChannel( | 129 DocumentWebSocketChannel::DocumentWebSocketChannel( |
130 Document* document, | 130 Document* document, |
131 WebSocketChannelClient* client, | 131 WebSocketChannelClient* client, |
132 std::unique_ptr<SourceLocation> location, | 132 std::unique_ptr<SourceLocation> location, |
133 WebSocketHandle* handle) | 133 WebSocketHandle* handle) |
134 : ContextLifecycleObserver(document), | 134 : m_handle(wrapUnique(handle ? handle : new WebSocketHandleImpl())), |
135 m_handle(wrapUnique(handle ? handle : new WebSocketHandleImpl())), | |
136 m_client(client), | 135 m_client(client), |
137 m_identifier(createUniqueIdentifier()), | 136 m_identifier(createUniqueIdentifier()), |
| 137 m_document(document), |
138 m_sendingQuota(0), | 138 m_sendingQuota(0), |
139 m_receivedDataSizeForFlowControl( | 139 m_receivedDataSizeForFlowControl( |
140 receivedDataSizeForFlowControlHighWaterMark * 2) // initial quota | 140 receivedDataSizeForFlowControlHighWaterMark * 2) // initial quota |
141 , | 141 , |
142 m_sentSizeOfTopMessage(0), | 142 m_sentSizeOfTopMessage(0), |
143 m_locationAtConstruction(std::move(location)) {} | 143 m_locationAtConstruction(std::move(location)) {} |
144 | 144 |
145 DocumentWebSocketChannel::~DocumentWebSocketChannel() { | 145 DocumentWebSocketChannel::~DocumentWebSocketChannel() { |
146 DCHECK(!m_blobLoader); | 146 DCHECK(!m_blobLoader); |
147 } | 147 } |
(...skipping 29 matching lines...) Expand all Loading... |
177 | 177 |
178 if (document()->frame()) { | 178 if (document()->frame()) { |
179 // Initialize the WebSocketHandle with the frame's InterfaceProvider to | 179 // Initialize the WebSocketHandle with the frame's InterfaceProvider to |
180 // provide the WebSocket implementation with context about this frame. | 180 // provide the WebSocket implementation with context about this frame. |
181 // This is important so that the browser can show UI associated with | 181 // This is important so that the browser can show UI associated with |
182 // the WebSocket (e.g., for certificate errors). | 182 // the WebSocket (e.g., for certificate errors). |
183 m_handle->initialize(document()->frame()->interfaceProvider()); | 183 m_handle->initialize(document()->frame()->interfaceProvider()); |
184 } else { | 184 } else { |
185 m_handle->initialize(Platform::current()->interfaceProvider()); | 185 m_handle->initialize(Platform::current()->interfaceProvider()); |
186 } | 186 } |
187 m_handle->connect(url, protocols, getExecutionContext()->getSecurityOrigin(), | 187 m_handle->connect(url, protocols, document()->getSecurityOrigin(), |
188 document()->firstPartyForCookies(), document()->userAgent(), | 188 document()->firstPartyForCookies(), document()->userAgent(), |
189 this); | 189 this); |
190 | 190 |
191 flowControlIfNecessary(); | 191 flowControlIfNecessary(); |
192 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", | 192 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", |
193 TRACE_EVENT_SCOPE_THREAD, "data", | 193 TRACE_EVENT_SCOPE_THREAD, "data", |
194 InspectorWebSocketCreateEvent::data( | 194 InspectorWebSocketCreateEvent::data( |
195 document(), m_identifier, url, protocol)); | 195 document(), m_identifier, url, protocol)); |
196 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, | 196 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, |
197 protocol); | 197 protocol); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 void DocumentWebSocketChannel::fail(const String& reason, | 283 void DocumentWebSocketChannel::fail(const String& reason, |
284 MessageLevel level, | 284 MessageLevel level, |
285 std::unique_ptr<SourceLocation> location) { | 285 std::unique_ptr<SourceLocation> location) { |
286 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; | 286 NETWORK_DVLOG(1) << this << " fail(" << reason << ")"; |
287 // m_handle and m_client can be null here. | 287 // m_handle and m_client can be null here. |
288 | 288 |
289 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), | 289 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), |
290 m_identifier, reason); | 290 m_identifier, reason); |
291 const String message = "WebSocket connection to '" + m_url.elidedString() + | 291 const String message = "WebSocket connection to '" + m_url.elidedString() + |
292 "' failed: " + reason; | 292 "' failed: " + reason; |
293 getExecutionContext()->addConsoleMessage(ConsoleMessage::create( | 293 document()->addConsoleMessage(ConsoleMessage::create( |
294 JSMessageSource, level, message, std::move(location))); | 294 JSMessageSource, level, message, std::move(location))); |
295 | 295 |
296 if (m_client) | 296 if (m_client) |
297 m_client->didError(); | 297 m_client->didError(); |
298 // |reason| is only for logging and should not be provided for scripts, | 298 // |reason| is only for logging and should not be provided for scripts, |
299 // hence close reason must be empty. | 299 // hence close reason must be empty. |
300 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); | 300 handleDidClose(false, CloseEventCodeAbnormalClosure, String()); |
301 // handleDidClose may delete this object. | 301 // handleDidClose may delete this object. |
302 } | 302 } |
303 | 303 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 WebSocketChannelClient* client = m_client; | 440 WebSocketChannelClient* client = m_client; |
441 m_client = nullptr; | 441 m_client = nullptr; |
442 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = | 442 WebSocketChannelClient::ClosingHandshakeCompletionStatus status = |
443 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete | 443 wasClean ? WebSocketChannelClient::ClosingHandshakeComplete |
444 : WebSocketChannelClient::ClosingHandshakeIncomplete; | 444 : WebSocketChannelClient::ClosingHandshakeIncomplete; |
445 client->didClose(status, code, reason); | 445 client->didClose(status, code, reason); |
446 // client->didClose may delete this object. | 446 // client->didClose may delete this object. |
447 } | 447 } |
448 | 448 |
449 Document* DocumentWebSocketChannel::document() { | 449 Document* DocumentWebSocketChannel::document() { |
450 // This context is always a Document. See the constructor. | 450 return m_document; |
451 ExecutionContext* context = getExecutionContext(); | |
452 DCHECK(context->isDocument()); | |
453 return toDocument(context); | |
454 } | 451 } |
455 | 452 |
456 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, | 453 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, |
457 const String& selectedProtocol, | 454 const String& selectedProtocol, |
458 const String& extensions) { | 455 const String& extensions) { |
459 NETWORK_DVLOG(1) << this << " didConnect(" << handle << ", " | 456 NETWORK_DVLOG(1) << this << " didConnect(" << handle << ", " |
460 << String(selectedProtocol) << ", " << String(extensions) | 457 << String(selectedProtocol) << ", " << String(extensions) |
461 << ")"; | 458 << ")"; |
462 | 459 |
463 DCHECK(m_handle); | 460 DCHECK(m_handle); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 643 } |
647 // FIXME: Generate human-friendly reason message. | 644 // FIXME: Generate human-friendly reason message. |
648 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); | 645 failAsError("Failed to load Blob: error code = " + String::number(errorCode)); |
649 // |this| can be deleted here. | 646 // |this| can be deleted here. |
650 } | 647 } |
651 | 648 |
652 DEFINE_TRACE(DocumentWebSocketChannel) { | 649 DEFINE_TRACE(DocumentWebSocketChannel) { |
653 visitor->trace(m_blobLoader); | 650 visitor->trace(m_blobLoader); |
654 visitor->trace(m_messages); | 651 visitor->trace(m_messages); |
655 visitor->trace(m_client); | 652 visitor->trace(m_client); |
| 653 visitor->trace(m_document); |
656 WebSocketChannel::trace(visitor); | 654 WebSocketChannel::trace(visitor); |
657 ContextLifecycleObserver::trace(visitor); | |
658 } | 655 } |
659 | 656 |
660 std::ostream& operator<<(std::ostream& ostream, | 657 std::ostream& operator<<(std::ostream& ostream, |
661 const DocumentWebSocketChannel* channel) { | 658 const DocumentWebSocketChannel* channel) { |
662 return ostream << "DocumentWebSocketChannel " | 659 return ostream << "DocumentWebSocketChannel " |
663 << static_cast<const void*>(channel); | 660 << static_cast<const void*>(channel); |
664 } | 661 } |
665 | 662 |
666 } // namespace blink | 663 } // namespace blink |
OLD | NEW |