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

Side by Side Diff: net/websockets/websocket_channel.cc

Issue 2003253002: [Devtools] Allow User-Agent header override for Websockets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_channel.h" 5 #include "net/websockets/websocket_channel.h"
6 6
7 #include <limits.h> // for INT_MAX 7 #include <limits.h> // for INT_MAX
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // destroyed first. 330 // destroyed first.
331 stream_.reset(); 331 stream_.reset();
332 // The timer may have a callback pointing back to us, so stop it just in case 332 // The timer may have a callback pointing back to us, so stop it just in case
333 // someone decides to run the event loop from their destructor. 333 // someone decides to run the event loop from their destructor.
334 close_timer_.Stop(); 334 close_timer_.Stop();
335 } 335 }
336 336
337 void WebSocketChannel::SendAddChannelRequest( 337 void WebSocketChannel::SendAddChannelRequest(
338 const GURL& socket_url, 338 const GURL& socket_url,
339 const std::vector<std::string>& requested_subprotocols, 339 const std::vector<std::string>& requested_subprotocols,
340 const url::Origin& origin) { 340 const url::Origin& origin,
341 const std::string& additional_headers) {
341 // Delegate to the tested version. 342 // Delegate to the tested version.
342 SendAddChannelRequestWithSuppliedCreator( 343 SendAddChannelRequestWithSuppliedCreator(
343 socket_url, 344 socket_url,
344 requested_subprotocols, 345 requested_subprotocols,
345 origin, 346 origin,
347 additional_headers,
346 base::Bind(&WebSocketStream::CreateAndConnectStream)); 348 base::Bind(&WebSocketStream::CreateAndConnectStream));
347 } 349 }
348 350
349 void WebSocketChannel::SetState(State new_state) { 351 void WebSocketChannel::SetState(State new_state) {
350 DCHECK_NE(state_, new_state); 352 DCHECK_NE(state_, new_state);
351 353
352 if (new_state == CONNECTED) 354 if (new_state == CONNECTED)
353 established_on_ = base::TimeTicks::Now(); 355 established_on_ = base::TimeTicks::Now();
354 if (state_ == CONNECTED && !established_on_.is_null()) { 356 if (state_ == CONNECTED && !established_on_.is_null()) {
355 UMA_HISTOGRAM_LONG_TIMES( 357 UMA_HISTOGRAM_LONG_TIMES(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 return CHANNEL_DELETED; 540 return CHANNEL_DELETED;
539 DCHECK_EQ(CONNECTED, state_); 541 DCHECK_EQ(CONNECTED, state_);
540 SetState(SEND_CLOSED); 542 SetState(SEND_CLOSED);
541 return CHANNEL_ALIVE; 543 return CHANNEL_ALIVE;
542 } 544 }
543 545
544 void WebSocketChannel::SendAddChannelRequestForTesting( 546 void WebSocketChannel::SendAddChannelRequestForTesting(
545 const GURL& socket_url, 547 const GURL& socket_url,
546 const std::vector<std::string>& requested_subprotocols, 548 const std::vector<std::string>& requested_subprotocols,
547 const url::Origin& origin, 549 const url::Origin& origin,
550 const std::string& additional_headers,
548 const WebSocketStreamCreator& creator) { 551 const WebSocketStreamCreator& creator) {
549 SendAddChannelRequestWithSuppliedCreator( 552 SendAddChannelRequestWithSuppliedCreator(
550 socket_url, requested_subprotocols, origin, creator); 553 socket_url, requested_subprotocols, origin, additional_headers, creator);
551 } 554 }
552 555
553 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( 556 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting(
554 base::TimeDelta delay) { 557 base::TimeDelta delay) {
555 closing_handshake_timeout_ = delay; 558 closing_handshake_timeout_ = delay;
556 } 559 }
557 560
558 void WebSocketChannel::SetUnderlyingConnectionCloseTimeoutForTesting( 561 void WebSocketChannel::SetUnderlyingConnectionCloseTimeoutForTesting(
559 base::TimeDelta delay) { 562 base::TimeDelta delay) {
560 underlying_connection_close_timeout_ = delay; 563 underlying_connection_close_timeout_ = delay;
561 } 564 }
562 565
563 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( 566 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator(
564 const GURL& socket_url, 567 const GURL& socket_url,
565 const std::vector<std::string>& requested_subprotocols, 568 const std::vector<std::string>& requested_subprotocols,
566 const url::Origin& origin, 569 const url::Origin& origin,
570 const std::string& additional_headers,
567 const WebSocketStreamCreator& creator) { 571 const WebSocketStreamCreator& creator) {
568 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); 572 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_);
569 if (!socket_url.SchemeIsWSOrWSS()) { 573 if (!socket_url.SchemeIsWSOrWSS()) {
570 // TODO(ricea): Kill the renderer (this error should have been caught by 574 // TODO(ricea): Kill the renderer (this error should have been caught by
571 // Javascript). 575 // Javascript).
572 ignore_result(event_interface_->OnFailChannel("Invalid scheme")); 576 ignore_result(event_interface_->OnFailChannel("Invalid scheme"));
573 // |this| is deleted here. 577 // |this| is deleted here.
574 return; 578 return;
575 } 579 }
576 socket_url_ = socket_url; 580 socket_url_ = socket_url;
577 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate( 581 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate(
578 new ConnectDelegate(this)); 582 new ConnectDelegate(this));
579 stream_request_ = creator.Run(socket_url_, requested_subprotocols, origin, 583 stream_request_ = creator.Run(socket_url_, requested_subprotocols, origin,
580 url_request_context_, BoundNetLog(), 584 additional_headers, url_request_context_,
581 std::move(connect_delegate)); 585 BoundNetLog(), std::move(connect_delegate));
582 SetState(CONNECTING); 586 SetState(CONNECTING);
583 } 587 }
584 588
585 void WebSocketChannel::OnConnectSuccess( 589 void WebSocketChannel::OnConnectSuccess(
586 std::unique_ptr<WebSocketStream> stream) { 590 std::unique_ptr<WebSocketStream> stream) {
587 DCHECK(stream); 591 DCHECK(stream);
588 DCHECK_EQ(CONNECTING, state_); 592 DCHECK_EQ(CONNECTING, state_);
589 593
590 stream_ = std::move(stream); 594 stream_ = std::move(stream);
591 595
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 } 1176 }
1173 1177
1174 void WebSocketChannel::CloseTimeout() { 1178 void WebSocketChannel::CloseTimeout() {
1175 stream_->Close(); 1179 stream_->Close();
1176 SetState(CLOSED); 1180 SetState(CLOSED);
1177 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); 1181 DoDropChannel(false, kWebSocketErrorAbnormalClosure, "");
1178 // |this| has been deleted. 1182 // |this| has been deleted.
1179 } 1183 }
1180 1184
1181 } // namespace net 1185 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698