| 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" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return new URLRequestHttpJob(request); | 199 return new URLRequestHttpJob(request); |
| 200 } | 200 } |
| 201 | 201 |
| 202 | 202 |
| 203 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) | 203 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) |
| 204 : URLRequestJob(request), | 204 : URLRequestJob(request), |
| 205 response_info_(NULL), | 205 response_info_(NULL), |
| 206 response_cookies_save_index_(0), | 206 response_cookies_save_index_(0), |
| 207 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 207 proxy_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 208 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), | 208 server_auth_state_(AUTH_STATE_DONT_NEED_AUTH), |
| 209 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( | |
| 210 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), | |
| 211 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( | |
| 212 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), | |
| 213 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 209 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
| 214 this, &URLRequestHttpJob::OnStartCompleted)), | 210 this, &URLRequestHttpJob::OnStartCompleted)), |
| 215 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( | 211 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( |
| 216 this, &URLRequestHttpJob::OnReadCompleted)), | 212 this, &URLRequestHttpJob::OnReadCompleted)), |
| 217 read_in_progress_(false), | 213 read_in_progress_(false), |
| 218 transaction_(NULL), | 214 transaction_(NULL), |
| 219 throttling_entry_(URLRequestThrottlerManager::GetInstance()-> | 215 throttling_entry_(URLRequestThrottlerManager::GetInstance()-> |
| 220 RegisterRequestUrl(request->url())), | 216 RegisterRequestUrl(request->url())), |
| 221 sdch_dictionary_advertised_(false), | 217 sdch_dictionary_advertised_(false), |
| 222 sdch_test_activated_(false), | 218 sdch_test_activated_(false), |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 HttpRequestHeaders::kAcceptCharset, | 403 HttpRequestHeaders::kAcceptCharset, |
| 408 context->accept_charset()); | 404 context->accept_charset()); |
| 409 } | 405 } |
| 410 } | 406 } |
| 411 | 407 |
| 412 void URLRequestHttpJob::AddCookieHeaderAndStart() { | 408 void URLRequestHttpJob::AddCookieHeaderAndStart() { |
| 413 // No matter what, we want to report our status as IO pending since we will | 409 // No matter what, we want to report our status as IO pending since we will |
| 414 // be notifying our consumer asynchronously via OnStartCompleted. | 410 // be notifying our consumer asynchronously via OnStartCompleted. |
| 415 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 411 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 416 | 412 |
| 417 AddRef(); // Balanced in OnCanGetCookiesCompleted | |
| 418 | |
| 419 int policy = OK; | 413 int policy = OK; |
| 420 | 414 |
| 421 if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) { | 415 if (request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES) { |
| 422 policy = ERR_FAILED; | 416 policy = ERR_FAILED; |
| 423 } else if (request_->context()->cookie_policy()) { | 417 } else if (request_->context()->cookie_policy()) { |
| 424 policy = request_->context()->cookie_policy()->CanGetCookies( | 418 policy = request_->context()->cookie_policy()->CanGetCookies( |
| 425 request_->url(), | 419 request_->url(), |
| 426 request_->first_party_for_cookies(), | 420 request_->first_party_for_cookies()); |
| 427 &can_get_cookies_callback_); | |
| 428 if (policy == ERR_IO_PENDING) | |
| 429 return; // Wait for completion callback | |
| 430 } | 421 } |
| 431 | 422 |
| 432 OnCanGetCookiesCompleted(policy); | 423 OnCanGetCookiesCompleted(policy); |
| 433 } | 424 } |
| 434 | 425 |
| 435 void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() { | 426 void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() { |
| 436 DCHECK(transaction_.get()); | 427 DCHECK(transaction_.get()); |
| 437 | 428 |
| 438 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); | 429 const HttpResponseInfo* response_info = transaction_->GetResponseInfo(); |
| 439 DCHECK(response_info); | 430 DCHECK(response_info); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 453 response_cookies_save_index_ = 0; | 444 response_cookies_save_index_ = 0; |
| 454 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 445 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
| 455 NotifyHeadersComplete(); | 446 NotifyHeadersComplete(); |
| 456 return; | 447 return; |
| 457 } | 448 } |
| 458 | 449 |
| 459 // No matter what, we want to report our status as IO pending since we will | 450 // No matter what, we want to report our status as IO pending since we will |
| 460 // be notifying our consumer asynchronously via OnStartCompleted. | 451 // be notifying our consumer asynchronously via OnStartCompleted. |
| 461 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 452 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 462 | 453 |
| 463 AddRef(); // Balanced in OnCanSetCookieCompleted | |
| 464 | |
| 465 int policy = OK; | 454 int policy = OK; |
| 466 | 455 |
| 467 if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) { | 456 if (request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) { |
| 468 policy = ERR_FAILED; | 457 policy = ERR_FAILED; |
| 469 } else if (request_->context()->cookie_policy()) { | 458 } else if (request_->context()->cookie_policy()) { |
| 470 policy = request_->context()->cookie_policy()->CanSetCookie( | 459 policy = request_->context()->cookie_policy()->CanSetCookie( |
| 471 request_->url(), | 460 request_->url(), |
| 472 request_->first_party_for_cookies(), | 461 request_->first_party_for_cookies(), |
| 473 response_cookies_[response_cookies_save_index_], | 462 response_cookies_[response_cookies_save_index_]); |
| 474 &can_set_cookie_callback_); | |
| 475 if (policy == ERR_IO_PENDING) | |
| 476 return; // Wait for completion callback | |
| 477 } | 463 } |
| 478 | 464 |
| 479 OnCanSetCookieCompleted(policy); | 465 OnCanSetCookieCompleted(policy); |
| 480 } | 466 } |
| 481 | 467 |
| 482 void URLRequestHttpJob::FetchResponseCookies( | 468 void URLRequestHttpJob::FetchResponseCookies( |
| 483 const HttpResponseInfo* response_info, | 469 const HttpResponseInfo* response_info, |
| 484 std::vector<std::string>* cookies) { | 470 std::vector<std::string>* cookies) { |
| 485 std::string name = "Set-Cookie"; | 471 std::string name = "Set-Cookie"; |
| 486 std::string value; | 472 std::string value; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } | 585 } |
| 600 } | 586 } |
| 601 } | 587 } |
| 602 // We may have been canceled within OnGetCookies. | 588 // We may have been canceled within OnGetCookies. |
| 603 if (GetStatus().is_success()) { | 589 if (GetStatus().is_success()) { |
| 604 StartTransaction(); | 590 StartTransaction(); |
| 605 } else { | 591 } else { |
| 606 NotifyCanceled(); | 592 NotifyCanceled(); |
| 607 } | 593 } |
| 608 } | 594 } |
| 609 Release(); // Balance AddRef taken in AddCookieHeaderAndStart | |
| 610 } | 595 } |
| 611 | 596 |
| 612 void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) { | 597 void URLRequestHttpJob::OnCanSetCookieCompleted(int policy) { |
| 613 // If the request was destroyed, then there is no more work to do. | 598 // If the request was destroyed, then there is no more work to do. |
| 614 if (request_ && request_->delegate()) { | 599 if (request_ && request_->delegate()) { |
| 615 if (request_->context()->cookie_store()) { | 600 if (request_->context()->cookie_store()) { |
| 616 if (policy == ERR_ACCESS_DENIED) { | 601 if (policy == ERR_ACCESS_DENIED) { |
| 617 CookieOptions options; | 602 CookieOptions options; |
| 618 options.set_include_httponly(); | 603 options.set_include_httponly(); |
| 619 request_->delegate()->OnSetCookie( | 604 request_->delegate()->OnSetCookie( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 638 } | 623 } |
| 639 } | 624 } |
| 640 response_cookies_save_index_++; | 625 response_cookies_save_index_++; |
| 641 // We may have been canceled within OnSetCookie. | 626 // We may have been canceled within OnSetCookie. |
| 642 if (GetStatus().is_success()) { | 627 if (GetStatus().is_success()) { |
| 643 SaveNextCookie(); | 628 SaveNextCookie(); |
| 644 } else { | 629 } else { |
| 645 NotifyCanceled(); | 630 NotifyCanceled(); |
| 646 } | 631 } |
| 647 } | 632 } |
| 648 Release(); // Balance AddRef taken in SaveNextCookie | |
| 649 } | 633 } |
| 650 | 634 |
| 651 void URLRequestHttpJob::OnStartCompleted(int result) { | 635 void URLRequestHttpJob::OnStartCompleted(int result) { |
| 652 RecordTimer(); | 636 RecordTimer(); |
| 653 | 637 |
| 654 // If the request was destroyed, then there is no more work to do. | 638 // If the request was destroyed, then there is no more work to do. |
| 655 if (!request_ || !request_->delegate()) | 639 if (!request_ || !request_->delegate()) |
| 656 return; | 640 return; |
| 657 | 641 |
| 658 // If the transaction was destroyed, then the job was cancelled, and | 642 // If the transaction was destroyed, then the job was cancelled, and |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 } | 1338 } |
| 1355 | 1339 |
| 1356 bool URLRequestHttpJob::IsCompressibleContent() const { | 1340 bool URLRequestHttpJob::IsCompressibleContent() const { |
| 1357 std::string mime_type; | 1341 std::string mime_type; |
| 1358 return GetMimeType(&mime_type) && | 1342 return GetMimeType(&mime_type) && |
| 1359 (IsSupportedJavascriptMimeType(mime_type.c_str()) || | 1343 (IsSupportedJavascriptMimeType(mime_type.c_str()) || |
| 1360 IsSupportedNonImageMimeType(mime_type.c_str())); | 1344 IsSupportedNonImageMimeType(mime_type.c_str())); |
| 1361 } | 1345 } |
| 1362 | 1346 |
| 1363 } // namespace net | 1347 } // namespace net |
| OLD | NEW |