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 27 matching lines...) Expand all Loading... |
38 #include "core/fileapi/FileReaderLoaderClient.h" | 38 #include "core/fileapi/FileReaderLoaderClient.h" |
39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
40 #include "core/inspector/ConsoleMessage.h" | 40 #include "core/inspector/ConsoleMessage.h" |
41 #include "core/inspector/InspectorInstrumentation.h" | 41 #include "core/inspector/InspectorInstrumentation.h" |
42 #include "core/loader/FrameLoader.h" | 42 #include "core/loader/FrameLoader.h" |
43 #include "core/loader/FrameLoaderClient.h" | 43 #include "core/loader/FrameLoaderClient.h" |
44 #include "core/loader/MixedContentChecker.h" | 44 #include "core/loader/MixedContentChecker.h" |
45 #include "modules/websockets/InspectorWebSocketEvents.h" | 45 #include "modules/websockets/InspectorWebSocketEvents.h" |
46 #include "modules/websockets/WebSocketChannelClient.h" | 46 #include "modules/websockets/WebSocketChannelClient.h" |
47 #include "modules/websockets/WebSocketFrame.h" | 47 #include "modules/websockets/WebSocketFrame.h" |
48 #include "modules/websockets/WebSocketHandle.h" | |
49 #include "platform/network/NetworkLog.h" | 48 #include "platform/network/NetworkLog.h" |
50 #include "platform/network/WebSocketHandshakeRequest.h" | 49 #include "platform/network/WebSocketHandshakeRequest.h" |
51 #include "platform/weborigin/SecurityOrigin.h" | 50 #include "platform/weborigin/SecurityOrigin.h" |
52 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 52 #include "public/platform/WebSecurityOrigin.h" |
| 53 #include "public/platform/WebString.h" |
| 54 #include "public/platform/WebURL.h" |
| 55 #include "public/platform/WebVector.h" |
| 56 #include "public/platform/modules/websockets/WebSocketHandshakeRequestInfo.h" |
| 57 #include "public/platform/modules/websockets/WebSocketHandshakeResponseInfo.h" |
53 #include "wtf/PtrUtil.h" | 58 #include "wtf/PtrUtil.h" |
54 #include <memory> | 59 #include <memory> |
55 | 60 |
56 namespace blink { | 61 namespace blink { |
57 | 62 |
58 class DocumentWebSocketChannel::BlobLoader final : public GarbageCollectedFinali
zed<DocumentWebSocketChannel::BlobLoader>, public FileReaderLoaderClient { | 63 class DocumentWebSocketChannel::BlobLoader final : public GarbageCollectedFinali
zed<DocumentWebSocketChannel::BlobLoader>, public FileReaderLoaderClient { |
59 public: | 64 public: |
60 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); | 65 BlobLoader(PassRefPtr<BlobDataHandle>, DocumentWebSocketChannel*); |
61 ~BlobLoader() override { } | 66 ~BlobLoader() override { } |
62 | 67 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 129 } |
125 | 130 |
126 void DocumentWebSocketChannel::BlobLoader::didFail(FileError::ErrorCode errorCod
e) | 131 void DocumentWebSocketChannel::BlobLoader::didFail(FileError::ErrorCode errorCod
e) |
127 { | 132 { |
128 m_channel->didFailLoadingBlob(errorCode); | 133 m_channel->didFailLoadingBlob(errorCode); |
129 // |this| is deleted here. | 134 // |this| is deleted here. |
130 } | 135 } |
131 | 136 |
132 DocumentWebSocketChannel::DocumentWebSocketChannel(Document* document, WebSocket
ChannelClient* client, std::unique_ptr<SourceLocation> location, WebSocketHandle
*handle) | 137 DocumentWebSocketChannel::DocumentWebSocketChannel(Document* document, WebSocket
ChannelClient* client, std::unique_ptr<SourceLocation> location, WebSocketHandle
*handle) |
133 : ContextLifecycleObserver(document) | 138 : ContextLifecycleObserver(document) |
134 , m_handle(wrapUnique(handle ? handle : new WebSocketHandle())) | 139 , m_handle(wrapUnique(handle ? handle : Platform::current()->createWebSocket
Handle())) |
135 , m_client(client) | 140 , m_client(client) |
136 , m_identifier(createUniqueIdentifier()) | 141 , m_identifier(createUniqueIdentifier()) |
137 , m_sendingQuota(0) | 142 , m_sendingQuota(0) |
138 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota | 143 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota |
139 , m_sentSizeOfTopMessage(0) | 144 , m_sentSizeOfTopMessage(0) |
140 , m_locationAtConstruction(std::move(location)) | 145 , m_locationAtConstruction(std::move(location)) |
141 { | 146 { |
142 } | 147 } |
143 | 148 |
144 DocumentWebSocketChannel::~DocumentWebSocketChannel() | 149 DocumentWebSocketChannel::~DocumentWebSocketChannel() |
(...skipping 18 matching lines...) Expand all Loading... |
163 | 168 |
164 m_url = url; | 169 m_url = url; |
165 Vector<String> protocols; | 170 Vector<String> protocols; |
166 // Avoid placing an empty token in the Vector when the protocol string is | 171 // Avoid placing an empty token in the Vector when the protocol string is |
167 // empty. | 172 // empty. |
168 if (!protocol.isEmpty()) { | 173 if (!protocol.isEmpty()) { |
169 // Since protocol is already verified and escaped, we can simply split | 174 // Since protocol is already verified and escaped, we can simply split |
170 // it. | 175 // it. |
171 protocol.split(", ", true, protocols); | 176 protocol.split(", ", true, protocols); |
172 } | 177 } |
| 178 WebVector<WebString> webProtocols(protocols.size()); |
| 179 for (size_t i = 0; i < protocols.size(); ++i) { |
| 180 webProtocols[i] = protocols[i]; |
| 181 } |
173 | 182 |
174 if (document()->frame()) { | 183 if (document()->frame()) |
175 // Initialize the WebSocketHandle with the frame's InterfaceProvider to | 184 document()->frame()->loader().client()->dispatchWillOpenWebSocket(m_hand
le.get()); |
176 // provide the WebSocket implementation with context about this frame. | 185 m_handle->connect(url, webProtocols, WebSecurityOrigin(getExecutionContext()
->getSecurityOrigin()), document()->firstPartyForCookies(), document()->userAgen
t(), this); |
177 // This is important so that the browser can show UI associated with | |
178 // the WebSocket (e.g., for certificate errors). | |
179 m_handle->initialize(document()->frame()->interfaceProvider()); | |
180 } else { | |
181 m_handle->initialize(Platform::current()->interfaceProvider()); | |
182 } | |
183 m_handle->connect(url, protocols, getExecutionContext()->getSecurityOrigin()
, document()->firstPartyForCookies(), document()->userAgent(), this); | |
184 | 186 |
185 flowControlIfNecessary(); | 187 flowControlIfNecessary(); |
186 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", TRACE_EVENT_SCO
PE_THREAD, "data", InspectorWebSocketCreateEvent::data(document(), m_identifier,
url, protocol)); | 188 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketCreate", TRACE_EVENT_SCO
PE_THREAD, "data", InspectorWebSocketCreateEvent::data(document(), m_identifier,
url, protocol)); |
187 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url,
protocol); | 189 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url,
protocol); |
188 return true; | 190 return true; |
189 } | 191 } |
190 | 192 |
191 void DocumentWebSocketChannel::send(const CString& message) | 193 void DocumentWebSocketChannel::send(const CString& message) |
192 { | 194 { |
193 NETWORK_DVLOG(1) << this << " sendText(" << message << ")"; | 195 NETWORK_DVLOG(1) << this << " sendText(" << message << ")"; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 404 } |
403 | 405 |
404 Document* DocumentWebSocketChannel::document() | 406 Document* DocumentWebSocketChannel::document() |
405 { | 407 { |
406 // This context is always a Document. See the constructor. | 408 // This context is always a Document. See the constructor. |
407 ExecutionContext* context = getExecutionContext(); | 409 ExecutionContext* context = getExecutionContext(); |
408 ASSERT(context->isDocument()); | 410 ASSERT(context->isDocument()); |
409 return toDocument(context); | 411 return toDocument(context); |
410 } | 412 } |
411 | 413 |
412 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, const String&
selectedProtocol, const String& extensions) | 414 void DocumentWebSocketChannel::didConnect(WebSocketHandle* handle, const WebStri
ng& selectedProtocol, const WebString& extensions) |
413 { | 415 { |
414 NETWORK_DVLOG(1) << this << " didConnect(" << handle << ", " << String(selec
tedProtocol) << ", " << String(extensions) << ")"; | 416 NETWORK_DVLOG(1) << this << " didConnect(" << handle << ", " << String(selec
tedProtocol) << ", " << String(extensions) << ")"; |
415 | 417 |
416 ASSERT(m_handle); | 418 ASSERT(m_handle); |
417 ASSERT(handle == m_handle.get()); | 419 ASSERT(handle == m_handle.get()); |
418 ASSERT(m_client); | 420 ASSERT(m_client); |
419 | 421 |
420 m_client->didConnect(selectedProtocol, extensions); | 422 m_client->didConnect(selectedProtocol, extensions); |
421 } | 423 } |
422 | 424 |
423 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
PassRefPtr<WebSocketHandshakeRequest> request) | 425 void DocumentWebSocketChannel::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) |
424 { | 426 { |
425 NETWORK_DVLOG(1) << this << " didStartOpeningHandshake(" << handle << ")"; | 427 NETWORK_DVLOG(1) << this << " didStartOpeningHandshake(" << handle << ")"; |
426 | 428 |
427 ASSERT(m_handle); | 429 ASSERT(m_handle); |
428 ASSERT(handle == m_handle.get()); | 430 ASSERT(handle == m_handle.get()); |
429 | 431 |
430 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketSendHandshakeRequest", T
RACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_ide
ntifier)); | 432 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketSendHandshakeRequest", T
RACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_ide
ntifier)); |
431 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(), m_id
entifier, request.get()); | 433 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(), m_id
entifier, &request.toCoreRequest()); |
432 m_handshakeRequest = request; | 434 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreRequest
()); |
433 } | 435 } |
434 | 436 |
435 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponse* response) | 437 void DocumentWebSocketChannel::didFinishOpeningHandshake(WebSocketHandle* handle
, const WebSocketHandshakeResponseInfo& response) |
436 { | 438 { |
437 NETWORK_DVLOG(1) << this << " didFinishOpeningHandshake(" << handle << ")"; | 439 NETWORK_DVLOG(1) << this << " didFinishOpeningHandshake(" << handle << ")"; |
438 | 440 |
439 ASSERT(m_handle); | 441 ASSERT(m_handle); |
440 ASSERT(handle == m_handle.get()); | 442 ASSERT(handle == m_handle.get()); |
441 | 443 |
442 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketReceiveHandshakeResponse
", TRACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m
_identifier)); | 444 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketReceiveHandshakeResponse
", TRACE_EVENT_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m
_identifier)); |
443 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(), m
_identifier, m_handshakeRequest.get(), response); | 445 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(), m
_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); |
444 m_handshakeRequest.clear(); | 446 m_handshakeRequest.clear(); |
445 } | 447 } |
446 | 448 |
447 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const String& me
ssage) | 449 void DocumentWebSocketChannel::didFail(WebSocketHandle* handle, const WebString&
message) |
448 { | 450 { |
449 NETWORK_DVLOG(1) << this << " didFail(" << handle << ", " << String(message)
<< ")"; | 451 NETWORK_DVLOG(1) << this << " didFail(" << handle << ", " << String(message)
<< ")"; |
450 | 452 |
451 ASSERT(m_handle); | 453 ASSERT(m_handle); |
452 ASSERT(handle == m_handle.get()); | 454 ASSERT(handle == m_handle.get()); |
453 | 455 |
454 // This function is called when the browser is required to fail the | 456 // This function is called when the browser is required to fail the |
455 // WebSocketConnection. Hence we fail this channel by calling | 457 // WebSocketConnection. Hence we fail this channel by calling |
456 // |this->failAsError| function. | 458 // |this->failAsError| function. |
457 failAsError(message); | 459 failAsError(message); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 } else { | 504 } else { |
503 m_client->didReceiveTextMessage(message); | 505 m_client->didReceiveTextMessage(message); |
504 } | 506 } |
505 } else { | 507 } else { |
506 std::unique_ptr<Vector<char>> binaryData = wrapUnique(new Vector<char>); | 508 std::unique_ptr<Vector<char>> binaryData = wrapUnique(new Vector<char>); |
507 binaryData->swap(m_receivingMessageData); | 509 binaryData->swap(m_receivingMessageData); |
508 m_client->didReceiveBinaryMessage(std::move(binaryData)); | 510 m_client->didReceiveBinaryMessage(std::move(binaryData)); |
509 } | 511 } |
510 } | 512 } |
511 | 513 |
512 void DocumentWebSocketChannel::didClose(WebSocketHandle* handle, bool wasClean,
unsigned short code, const String& reason) | 514 void DocumentWebSocketChannel::didClose(WebSocketHandle* handle, bool wasClean,
unsigned short code, const WebString& reason) |
513 { | 515 { |
514 NETWORK_DVLOG(1) << this << " didClose(" << handle << ", " << wasClean << ",
" << code << ", " << String(reason) << ")"; | 516 NETWORK_DVLOG(1) << this << " didClose(" << handle << ", " << wasClean << ",
" << code << ", " << String(reason) << ")"; |
515 | 517 |
516 ASSERT(m_handle); | 518 ASSERT(m_handle); |
517 ASSERT(handle == m_handle.get()); | 519 ASSERT(handle == m_handle.get()); |
518 | 520 |
519 m_handle.reset(); | 521 m_handle.reset(); |
520 | 522 |
521 if (m_identifier) { | 523 if (m_identifier) { |
522 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketDestroy", TRACE_EVEN
T_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_identifier))
; | 524 TRACE_EVENT_INSTANT1("devtools.timeline", "WebSocketDestroy", TRACE_EVEN
T_SCOPE_THREAD, "data", InspectorWebSocketEvent::data(document(), m_identifier))
; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 WebSocketChannel::trace(visitor); | 584 WebSocketChannel::trace(visitor); |
583 ContextLifecycleObserver::trace(visitor); | 585 ContextLifecycleObserver::trace(visitor); |
584 } | 586 } |
585 | 587 |
586 std::ostream& operator<<(std::ostream& ostream, const DocumentWebSocketChannel*
channel) | 588 std::ostream& operator<<(std::ostream& ostream, const DocumentWebSocketChannel*
channel) |
587 { | 589 { |
588 return ostream << "DocumentWebSocketChannel " << static_cast<const void*>(ch
annel); | 590 return ostream << "DocumentWebSocketChannel " << static_cast<const void*>(ch
annel); |
589 } | 591 } |
590 | 592 |
591 } // namespace blink | 593 } // namespace blink |
OLD | NEW |