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

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

Issue 2102993002: Fix WebSocket to set first party for cookies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update testRunner calls to setBlockThirdPartyCookies() Created 4 years, 5 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
« no previous file with comments | « net/websockets/websocket_channel.h ('k') | net/websockets/websocket_channel_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 GURL& first_party_for_cookies,
341 const std::string& additional_headers) { 342 const std::string& additional_headers) {
342 // Delegate to the tested version. 343 // Delegate to the tested version.
343 SendAddChannelRequestWithSuppliedCreator( 344 SendAddChannelRequestWithSuppliedCreator(
344 socket_url, requested_subprotocols, origin, additional_headers, 345 socket_url, requested_subprotocols, origin, first_party_for_cookies,
345 base::Bind(&WebSocketStream::CreateAndConnectStream)); 346 additional_headers, base::Bind(&WebSocketStream::CreateAndConnectStream));
346 } 347 }
347 348
348 void WebSocketChannel::SetState(State new_state) { 349 void WebSocketChannel::SetState(State new_state) {
349 DCHECK_NE(state_, new_state); 350 DCHECK_NE(state_, new_state);
350 351
351 if (new_state == CONNECTED) 352 if (new_state == CONNECTED)
352 established_on_ = base::TimeTicks::Now(); 353 established_on_ = base::TimeTicks::Now();
353 if (state_ == CONNECTED && !established_on_.is_null()) { 354 if (state_ == CONNECTED && !established_on_.is_null()) {
354 UMA_HISTOGRAM_LONG_TIMES( 355 UMA_HISTOGRAM_LONG_TIMES(
355 "Net.WebSocket.Duration", base::TimeTicks::Now() - established_on_); 356 "Net.WebSocket.Duration", base::TimeTicks::Now() - established_on_);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 return CHANNEL_DELETED; 538 return CHANNEL_DELETED;
538 DCHECK_EQ(CONNECTED, state_); 539 DCHECK_EQ(CONNECTED, state_);
539 SetState(SEND_CLOSED); 540 SetState(SEND_CLOSED);
540 return CHANNEL_ALIVE; 541 return CHANNEL_ALIVE;
541 } 542 }
542 543
543 void WebSocketChannel::SendAddChannelRequestForTesting( 544 void WebSocketChannel::SendAddChannelRequestForTesting(
544 const GURL& socket_url, 545 const GURL& socket_url,
545 const std::vector<std::string>& requested_subprotocols, 546 const std::vector<std::string>& requested_subprotocols,
546 const url::Origin& origin, 547 const url::Origin& origin,
548 const GURL& first_party_for_cookies,
547 const std::string& additional_headers, 549 const std::string& additional_headers,
548 const WebSocketStreamCreator& creator) { 550 const WebSocketStreamCreator& creator) {
549 SendAddChannelRequestWithSuppliedCreator(socket_url, requested_subprotocols, 551 SendAddChannelRequestWithSuppliedCreator(socket_url, requested_subprotocols,
550 origin, additional_headers, creator); 552 origin, first_party_for_cookies,
553 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 GURL& first_party_for_cookies,
567 const std::string& additional_headers, 571 const std::string& additional_headers,
568 const WebSocketStreamCreator& creator) { 572 const WebSocketStreamCreator& creator) {
569 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); 573 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_);
570 if (!socket_url.SchemeIsWSOrWSS()) { 574 if (!socket_url.SchemeIsWSOrWSS()) {
571 // TODO(ricea): Kill the renderer (this error should have been caught by 575 // TODO(ricea): Kill the renderer (this error should have been caught by
572 // Javascript). 576 // Javascript).
573 ignore_result(event_interface_->OnFailChannel("Invalid scheme")); 577 ignore_result(event_interface_->OnFailChannel("Invalid scheme"));
574 // |this| is deleted here. 578 // |this| is deleted here.
575 return; 579 return;
576 } 580 }
577 socket_url_ = socket_url; 581 socket_url_ = socket_url;
578 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate( 582 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate(
579 new ConnectDelegate(this)); 583 new ConnectDelegate(this));
580 stream_request_ = creator.Run(socket_url_, requested_subprotocols, origin, 584 stream_request_ = creator.Run(socket_url_, requested_subprotocols, origin,
581 additional_headers, url_request_context_, 585 first_party_for_cookies, additional_headers,
582 BoundNetLog(), std::move(connect_delegate)); 586 url_request_context_, BoundNetLog(),
587 std::move(connect_delegate));
583 SetState(CONNECTING); 588 SetState(CONNECTING);
584 } 589 }
585 590
586 void WebSocketChannel::OnConnectSuccess( 591 void WebSocketChannel::OnConnectSuccess(
587 std::unique_ptr<WebSocketStream> stream) { 592 std::unique_ptr<WebSocketStream> stream) {
588 DCHECK(stream); 593 DCHECK(stream);
589 DCHECK_EQ(CONNECTING, state_); 594 DCHECK_EQ(CONNECTING, state_);
590 595
591 stream_ = std::move(stream); 596 stream_ = std::move(stream);
592 597
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 } 1178 }
1174 1179
1175 void WebSocketChannel::CloseTimeout() { 1180 void WebSocketChannel::CloseTimeout() {
1176 stream_->Close(); 1181 stream_->Close();
1177 SetState(CLOSED); 1182 SetState(CLOSED);
1178 DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""); 1183 DoDropChannel(false, kWebSocketErrorAbnormalClosure, "");
1179 // |this| has been deleted. 1184 // |this| has been deleted.
1180 } 1185 }
1181 1186
1182 } // namespace net 1187 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_channel.h ('k') | net/websockets/websocket_channel_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698