Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannel.cpp

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

Powered by Google App Engine
This is Rietveld 408576698