| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "net/base/cert_status_flags.h" | 18 #include "net/base/cert_status_flags.h" |
| 19 #include "net/base/cookie_policy.h" | |
| 20 #include "net/base/cookie_store.h" | 19 #include "net/base/cookie_store.h" |
| 21 #include "net/base/filter.h" | 20 #include "net/base/filter.h" |
| 22 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
| 23 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 24 #include "net/base/mime_util.h" | 23 #include "net/base/mime_util.h" |
| 25 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 26 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 27 #include "net/base/sdch_manager.h" | 26 #include "net/base/sdch_manager.h" |
| 28 #include "net/base/ssl_cert_request_info.h" | 27 #include "net/base/ssl_cert_request_info.h" |
| 29 #include "net/base/ssl_config_service.h" | 28 #include "net/base/ssl_config_service.h" |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 context->accept_charset()); | 419 context->accept_charset()); |
| 421 } | 420 } |
| 422 } | 421 } |
| 423 } | 422 } |
| 424 | 423 |
| 425 void URLRequestHttpJob::AddCookieHeaderAndStart() { | 424 void URLRequestHttpJob::AddCookieHeaderAndStart() { |
| 426 // No matter what, we want to report our status as IO pending since we will | 425 // No matter what, we want to report our status as IO pending since we will |
| 427 // be notifying our consumer asynchronously via OnStartCompleted. | 426 // be notifying our consumer asynchronously via OnStartCompleted. |
| 428 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 427 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 429 | 428 |
| 430 int policy = OK; | 429 // If the request was destroyed, then there is no more work to do. |
| 430 if (!request_) |
| 431 return; |
| 431 | 432 |
| 432 if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) { | 433 bool allow = true; |
| 433 policy = ERR_FAILED; | 434 if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES || |
| 434 } else if (request_->context()->cookie_policy()) { | 435 (request_->delegate() && |
| 435 policy = request_->context()->cookie_policy()->CanGetCookies( | 436 !request_->delegate()->CanGetCookies(request_))) { |
| 436 request_->url(), | 437 allow = false; |
| 437 request_->first_party_for_cookies()); | |
| 438 } | 438 } |
| 439 | 439 |
| 440 OnCanGetCookiesCompleted(policy); | 440 OnCanGetCookiesCompleted(allow); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() { | 443 void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() { |
| 444 DCHECK(transaction_.get()); | 444 DCHECK(transaction_.get()); |
| 445 | 445 |
| 446 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); | 446 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); |
| 447 DCHECK(response_info); | 447 DCHECK(response_info); |
| 448 | 448 |
| 449 response_cookies_.clear(); | 449 response_cookies_.clear(); |
| 450 response_cookies_save_index_ = 0; | 450 response_cookies_save_index_ = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 461 response_cookies_save_index_ = 0; | 461 response_cookies_save_index_ = 0; |
| 462 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 462 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
| 463 NotifyHeadersComplete(); | 463 NotifyHeadersComplete(); |
| 464 return; | 464 return; |
| 465 } | 465 } |
| 466 | 466 |
| 467 // No matter what, we want to report our status as IO pending since we will | 467 // No matter what, we want to report our status as IO pending since we will |
| 468 // be notifying our consumer asynchronously via OnStartCompleted. | 468 // be notifying our consumer asynchronously via OnStartCompleted. |
| 469 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 469 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 470 | 470 |
| 471 int policy = OK; | 471 bool allow = true; |
| 472 | 472 CookieOptions options; |
| 473 if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) { | 473 if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) { |
| 474 policy = ERR_FAILED; | 474 allow = false; |
| 475 } else if (request_->context()->cookie_policy()) { | 475 } else if (request_->delegate() && request_->context()->cookie_store()) { |
| 476 policy = request_->context()->cookie_policy()->CanSetCookie( | 476 CookieOptions options; |
| 477 request_->url(), | 477 options.set_include_httponly(); |
| 478 request_->first_party_for_cookies(), | 478 if (request_->delegate()->CanSetCookie( |
| 479 response_cookies_[response_cookies_save_index_]); | 479 request_, |
| 480 response_cookies_[response_cookies_save_index_], &options)) { |
| 481 request_->context()->cookie_store()->SetCookieWithOptions( |
| 482 request_->url(), response_cookies_[response_cookies_save_index_], |
| 483 options); |
| 484 } |
| 480 } | 485 } |
| 481 | 486 |
| 482 OnCanSetCookieCompleted(policy); | 487 OnCanSetCookieCompleted(); |
| 483 } | 488 } |
| 484 | 489 |
| 485 void URLRequestHttpJob::FetchResponseCookies( | 490 void URLRequestHttpJob::FetchResponseCookies( |
| 486 const HttpResponseInfo* response_info, | 491 const HttpResponseInfo* response_info, |
| 487 std::vector<std::string>* cookies) { | 492 std::vector<std::string>* cookies) { |
| 488 std::string name = "Set-Cookie"; | 493 std::string name = "Set-Cookie"; |
| 489 std::string value; | 494 std::string value; |
| 490 | 495 |
| 491 void* iter = NULL; | 496 void* iter = NULL; |
| 492 while (response_info->headers->EnumerateHeader(&iter, name, &value)) { | 497 while (response_info->headers->EnumerateHeader(&iter, name, &value)) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 new HTTPSProberDelegateImpl(request_info_.url.host(), max_age, | 581 new HTTPSProberDelegateImpl(request_info_.url.host(), max_age, |
| 577 include_subdomains, | 582 include_subdomains, |
| 578 ctx->transport_security_state()); | 583 ctx->transport_security_state()); |
| 579 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), | 584 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), |
| 580 delegate)) { | 585 delegate)) { |
| 581 delete delegate; | 586 delete delegate; |
| 582 } | 587 } |
| 583 } | 588 } |
| 584 } | 589 } |
| 585 | 590 |
| 586 void URLRequestHttpJob::OnCanGetCookiesCompleted(int policy) { | 591 void URLRequestHttpJob::OnCanGetCookiesCompleted(bool allow) { |
| 587 // If the request was destroyed, then there is no more work to do. | 592 if (request_->context()->cookie_store() && allow) { |
| 588 if (request_ && request_->delegate()) { | 593 CookieOptions options; |
| 589 if (request_->context()->cookie_store()) { | 594 options.set_include_httponly(); |
| 590 if (policy == ERR_ACCESS_DENIED) { | 595 std::string cookies = |
| 591 request_->delegate()->OnGetCookies(request_, true); | 596 request_->context()->cookie_store()->GetCookiesWithOptions( |
| 592 } else if (policy == OK) { | 597 request_->url(), options); |
| 593 request_->delegate()->OnGetCookies(request_, false); | 598 if (!cookies.empty()) { |
| 594 CookieOptions options; | 599 request_info_.extra_headers.SetHeader( |
| 595 options.set_include_httponly(); | 600 HttpRequestHeaders::kCookie, cookies); |
| 596 std::string cookies = | |
| 597 request_->context()->cookie_store()->GetCookiesWithOptions( | |
| 598 request_->url(), options); | |
| 599 if (!cookies.empty()) { | |
| 600 request_info_.extra_headers.SetHeader( | |
| 601 HttpRequestHeaders::kCookie, cookies); | |
| 602 } | |
| 603 } | |
| 604 } | 601 } |
| 605 // We may have been canceled within OnGetCookies. | 602 } |
| 606 if (GetStatus().is_success()) { | 603 // We may have been canceled within CanGetCookies. |
| 607 StartTransaction(); | 604 if (GetStatus().is_success()) { |
| 608 } else { | 605 StartTransaction(); |
| 609 NotifyCanceled(); | 606 } else { |
| 610 } | 607 NotifyCanceled(); |
| 611 } | 608 } |
| 612 } | 609 } |
| 613 | 610 |
| 614 void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) { | 611 void URLRequestHttpJob::OnCanSetCookieCompleted() { |
| 615 // If the request was destroyed, then there is no more work to do. | 612 response_cookies_save_index_++; |
| 616 if (request_ && request_->delegate()) { | 613 // We may have been canceled within OnSetCookie. |
| 617 if (request_->context()->cookie_store()) { | 614 if (GetStatus().is_success()) { |
| 618 if (policy == ERR_ACCESS_DENIED) { | 615 SaveNextCookie(); |
| 619 CookieOptions options; | 616 } else { |
| 620 options.set_include_httponly(); | 617 NotifyCanceled(); |
| 621 request_->delegate()->OnSetCookie( | |
| 622 request_, | |
| 623 response_cookies_[response_cookies_save_index_], | |
| 624 options, | |
| 625 true); | |
| 626 } else if (policy == OK || policy == OK_FOR_SESSION_ONLY) { | |
| 627 // OK to save the current response cookie now. | |
| 628 CookieOptions options; | |
| 629 options.set_include_httponly(); | |
| 630 if (policy == OK_FOR_SESSION_ONLY) | |
| 631 options.set_force_session(); | |
| 632 request_->context()->cookie_store()->SetCookieWithOptions( | |
| 633 request_->url(), response_cookies_[response_cookies_save_index_], | |
| 634 options); | |
| 635 request_->delegate()->OnSetCookie( | |
| 636 request_, | |
| 637 response_cookies_[response_cookies_save_index_], | |
| 638 options, | |
| 639 false); | |
| 640 } | |
| 641 } | |
| 642 response_cookies_save_index_++; | |
| 643 // We may have been canceled within OnSetCookie. | |
| 644 if (GetStatus().is_success()) { | |
| 645 SaveNextCookie(); | |
| 646 } else { | |
| 647 NotifyCanceled(); | |
| 648 } | |
| 649 } | 618 } |
| 650 } | 619 } |
| 651 | 620 |
| 652 void URLRequestHttpJob::OnStartCompleted(int result) { | 621 void URLRequestHttpJob::OnStartCompleted(int result) { |
| 653 RecordTimer(); | 622 RecordTimer(); |
| 654 | 623 |
| 655 // If the request was destroyed, then there is no more work to do. | 624 // If the request was destroyed, then there is no more work to do. |
| 656 if (!request_ || !request_->delegate()) | 625 if (!request_ || !request_->delegate()) |
| 657 return; | 626 return; |
| 658 | 627 |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1399 } | 1368 } |
| 1400 | 1369 |
| 1401 bool URLRequestHttpJob::IsCompressibleContent() const { | 1370 bool URLRequestHttpJob::IsCompressibleContent() const { |
| 1402 std::string mime_type; | 1371 std::string mime_type; |
| 1403 return GetMimeType(&mime_type) && | 1372 return GetMimeType(&mime_type) && |
| 1404 (IsSupportedJavascriptMimeType(mime_type.c_str()) || | 1373 (IsSupportedJavascriptMimeType(mime_type.c_str()) || |
| 1405 IsSupportedNonImageMimeType(mime_type.c_str())); | 1374 IsSupportedNonImageMimeType(mime_type.c_str())); |
| 1406 } | 1375 } |
| 1407 | 1376 |
| 1408 } // namespace net | 1377 } // namespace net |
| OLD | NEW |