| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_job.h" | 5 #include "net/websockets/websocket_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 // handshake message is completed. | 361 // handshake message is completed. |
| 362 handshake_response_->set_protocol_version( | 362 handshake_response_->set_protocol_version( |
| 363 handshake_request_->protocol_version()); | 363 handshake_request_->protocol_version()); |
| 364 AddCookieHeaderAndSend(); | 364 AddCookieHeaderAndSend(); |
| 365 return true; | 365 return true; |
| 366 } | 366 } |
| 367 | 367 |
| 368 void WebSocketJob::AddCookieHeaderAndSend() { | 368 void WebSocketJob::AddCookieHeaderAndSend() { |
| 369 bool allow = true; | 369 bool allow = true; |
| 370 if (delegate_ && !delegate_->CanGetCookies(socket_.get(), GetURLForCookies())) | 370 GURL url_for_cookies(socket_->url_for_cookies()); |
| 371 if (delegate_ && !delegate_->CanGetCookies(socket_.get(), url_for_cookies)) |
| 371 allow = false; | 372 allow = false; |
| 372 | 373 |
| 373 if (socket_.get() && delegate_ && state_ == CONNECTING) { | 374 if (socket_.get() && delegate_ && state_ == CONNECTING) { |
| 374 handshake_request_->RemoveHeaders(kCookieHeaders, | 375 handshake_request_->RemoveHeaders(kCookieHeaders, |
| 375 arraysize(kCookieHeaders)); | 376 arraysize(kCookieHeaders)); |
| 376 if (allow && socket_->context()->cookie_store()) { | 377 if (allow && socket_->context()->cookie_store()) { |
| 377 // Add cookies, including HttpOnly cookies. | 378 // Add cookies, including HttpOnly cookies. |
| 378 CookieOptions cookie_options; | 379 CookieOptions cookie_options; |
| 379 cookie_options.set_include_httponly(); | 380 cookie_options.set_include_httponly(); |
| 380 socket_->context()->cookie_store()->GetCookiesWithOptionsAsync( | 381 socket_->context()->cookie_store()->GetCookiesWithOptionsAsync( |
| 381 GetURLForCookies(), cookie_options, | 382 url_for_cookies, |
| 383 cookie_options, |
| 382 base::Bind(&WebSocketJob::LoadCookieCallback, | 384 base::Bind(&WebSocketJob::LoadCookieCallback, |
| 383 weak_ptr_factory_.GetWeakPtr())); | 385 weak_ptr_factory_.GetWeakPtr())); |
| 384 } else { | 386 } else { |
| 385 DoSendData(); | 387 DoSendData(); |
| 386 } | 388 } |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 | 391 |
| 390 void WebSocketJob::LoadCookieCallback(const std::string& cookie) { | 392 void WebSocketJob::LoadCookieCallback(const std::string& cookie) { |
| 391 if (!cookie.empty()) | 393 if (!cookie.empty()) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 504 } |
| 503 | 505 |
| 504 void WebSocketJob::SaveNextCookie() { | 506 void WebSocketJob::SaveNextCookie() { |
| 505 if (!socket_.get() || !delegate_ || state_ != CONNECTING) | 507 if (!socket_.get() || !delegate_ || state_ != CONNECTING) |
| 506 return; | 508 return; |
| 507 | 509 |
| 508 callback_pending_ = false; | 510 callback_pending_ = false; |
| 509 save_next_cookie_running_ = true; | 511 save_next_cookie_running_ = true; |
| 510 | 512 |
| 511 if (socket_->context()->cookie_store()) { | 513 if (socket_->context()->cookie_store()) { |
| 512 GURL url_for_cookies = GetURLForCookies(); | 514 GURL url_for_cookies(socket_->url_for_cookies()); |
| 513 | 515 |
| 514 CookieOptions options; | 516 CookieOptions options; |
| 515 options.set_include_httponly(); | 517 options.set_include_httponly(); |
| 516 | 518 |
| 517 // Loop as long as SetCookieWithOptionsAsync completes synchronously. Since | 519 // Loop as long as SetCookieWithOptionsAsync completes synchronously. Since |
| 518 // CookieMonster's asynchronous operation APIs queue the callback to run it | 520 // CookieMonster's asynchronous operation APIs queue the callback to run it |
| 519 // on the thread where the API was called, there won't be race. I.e. unless | 521 // on the thread where the API was called, there won't be race. I.e. unless |
| 520 // the callback is run synchronously, it won't be run in parallel with this | 522 // the callback is run synchronously, it won't be run in parallel with this |
| 521 // method. | 523 // method. |
| 522 while (!callback_pending_ && | 524 while (!callback_pending_ && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 callback_pending_ = false; | 558 callback_pending_ = false; |
| 557 | 559 |
| 558 // Resume SaveNextCookie if the caller of SetCookieWithOptionsAsync() exited | 560 // Resume SaveNextCookie if the caller of SetCookieWithOptionsAsync() exited |
| 559 // the loop. Otherwise, return. | 561 // the loop. Otherwise, return. |
| 560 if (save_next_cookie_running_) | 562 if (save_next_cookie_running_) |
| 561 return; | 563 return; |
| 562 | 564 |
| 563 SaveNextCookie(); | 565 SaveNextCookie(); |
| 564 } | 566 } |
| 565 | 567 |
| 566 GURL WebSocketJob::GetURLForCookies() const { | |
| 567 GURL url = socket_->url(); | |
| 568 std::string scheme = socket_->is_secure() ? "https" : "http"; | |
| 569 url_canon::Replacements<char> replacements; | |
| 570 replacements.SetScheme(scheme.c_str(), | |
| 571 url_parse::Component(0, scheme.length())); | |
| 572 return url.ReplaceComponents(replacements); | |
| 573 } | |
| 574 | |
| 575 const AddressList& WebSocketJob::address_list() const { | 568 const AddressList& WebSocketJob::address_list() const { |
| 576 return addresses_; | 569 return addresses_; |
| 577 } | 570 } |
| 578 | 571 |
| 579 int WebSocketJob::TrySpdyStream() { | 572 int WebSocketJob::TrySpdyStream() { |
| 580 if (!socket_.get()) | 573 if (!socket_.get()) |
| 581 return ERR_FAILED; | 574 return ERR_FAILED; |
| 582 | 575 |
| 583 if (!websocket_over_spdy_enabled_) | 576 if (!websocket_over_spdy_enabled_) |
| 584 return OK; | 577 return OK; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 688 |
| 696 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); | 689 scoped_refptr<IOBufferWithSize> next_buffer = send_buffer_queue_.front(); |
| 697 send_buffer_queue_.pop_front(); | 690 send_buffer_queue_.pop_front(); |
| 698 current_send_buffer_ = | 691 current_send_buffer_ = |
| 699 new DrainableIOBuffer(next_buffer.get(), next_buffer->size()); | 692 new DrainableIOBuffer(next_buffer.get(), next_buffer->size()); |
| 700 SendDataInternal(current_send_buffer_->data(), | 693 SendDataInternal(current_send_buffer_->data(), |
| 701 current_send_buffer_->BytesRemaining()); | 694 current_send_buffer_->BytesRemaining()); |
| 702 } | 695 } |
| 703 | 696 |
| 704 } // namespace net | 697 } // namespace net |
| OLD | NEW |