OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 22 matching lines...) Expand all Loading... |
33 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
34 #include "net/url_request/url_request_error_job.h" | 34 #include "net/url_request/url_request_error_job.h" |
35 #include "net/url_request/url_request_redirect_job.h" | 35 #include "net/url_request/url_request_redirect_job.h" |
36 #include "net/url_request/url_request_throttler_header_adapter.h" | 36 #include "net/url_request/url_request_throttler_header_adapter.h" |
37 #include "net/url_request/url_request_throttler_manager.h" | 37 #include "net/url_request/url_request_throttler_manager.h" |
38 | 38 |
39 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 39 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
40 | 40 |
41 // TODO(darin): make sure the port blocking code is not lost | 41 // TODO(darin): make sure the port blocking code is not lost |
42 // static | 42 // static |
43 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, | 43 URLRequestJob* URLRequestHttpJob::Factory(net::URLRequest* request, |
44 const std::string& scheme) { | 44 const std::string& scheme) { |
45 DCHECK(scheme == "http" || scheme == "https"); | 45 DCHECK(scheme == "http" || scheme == "https"); |
46 | 46 |
47 int port = request->url().IntPort(); | 47 int port = request->url().IntPort(); |
48 if (!net::IsPortAllowedByDefault(port) && !net::IsPortAllowedByOverride(port)) | 48 if (!net::IsPortAllowedByDefault(port) && !net::IsPortAllowedByOverride(port)) |
49 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); | 49 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); |
50 | 50 |
51 if (!request->context() || | 51 if (!request->context() || |
52 !request->context()->http_transaction_factory()) { | 52 !request->context()->http_transaction_factory()) { |
53 NOTREACHED() << "requires a valid context"; | 53 NOTREACHED() << "requires a valid context"; |
(...skipping 16 matching lines...) Expand all Loading... |
70 GURL new_location = request->url().ReplaceComponents(replacements); | 70 GURL new_location = request->url().ReplaceComponents(replacements); |
71 return new URLRequestRedirectJob(request, new_location); | 71 return new URLRequestRedirectJob(request, new_location); |
72 } else { | 72 } else { |
73 // TODO(agl): implement opportunistic HTTPS upgrade. | 73 // TODO(agl): implement opportunistic HTTPS upgrade. |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 return new URLRequestHttpJob(request); | 77 return new URLRequestHttpJob(request); |
78 } | 78 } |
79 | 79 |
80 URLRequestHttpJob::URLRequestHttpJob(URLRequest* request) | 80 URLRequestHttpJob::URLRequestHttpJob(net::URLRequest* request) |
81 : URLRequestJob(request), | 81 : URLRequestJob(request), |
82 response_info_(NULL), | 82 response_info_(NULL), |
83 response_cookies_save_index_(0), | 83 response_cookies_save_index_(0), |
84 proxy_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), | 84 proxy_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), |
85 server_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), | 85 server_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), |
86 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( | 86 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( |
87 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), | 87 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), |
88 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( | 88 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( |
89 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), | 89 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), |
90 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( | 90 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 bool URLRequestHttpJob::IsSdchResponse() const { | 255 bool URLRequestHttpJob::IsSdchResponse() const { |
256 return sdch_dictionary_advertised_; | 256 return sdch_dictionary_advertised_; |
257 } | 257 } |
258 | 258 |
259 bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { | 259 bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { |
260 // We only allow redirects to certain "safe" protocols. This does not | 260 // We only allow redirects to certain "safe" protocols. This does not |
261 // restrict redirects to externally handled protocols. Our consumer would | 261 // restrict redirects to externally handled protocols. Our consumer would |
262 // need to take care of those. | 262 // need to take care of those. |
263 | 263 |
264 if (!URLRequest::IsHandledURL(location)) | 264 if (!net::URLRequest::IsHandledURL(location)) |
265 return true; | 265 return true; |
266 | 266 |
267 static const char* kSafeSchemes[] = { | 267 static const char* kSafeSchemes[] = { |
268 "http", | 268 "http", |
269 "https", | 269 "https", |
270 "ftp" | 270 "ftp" |
271 }; | 271 }; |
272 | 272 |
273 for (size_t i = 0; i < arraysize(kSafeSchemes); ++i) { | 273 for (size_t i = 0; i < arraysize(kSafeSchemes); ++i) { |
274 if (location.SchemeIs(kSafeSchemes[i])) | 274 if (location.SchemeIs(kSafeSchemes[i])) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 | 381 |
382 // No matter what, we want to report our status as IO pending since we will | 382 // No matter what, we want to report our status as IO pending since we will |
383 // be notifying our consumer asynchronously via OnStartCompleted. | 383 // be notifying our consumer asynchronously via OnStartCompleted. |
384 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 384 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
385 | 385 |
386 int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_); | 386 int rv = transaction_->RestartWithCertificate(client_cert, &start_callback_); |
387 if (rv == net::ERR_IO_PENDING) | 387 if (rv == net::ERR_IO_PENDING) |
388 return; | 388 return; |
389 | 389 |
390 // The transaction started synchronously, but we need to notify the | 390 // The transaction started synchronously, but we need to notify the |
391 // URLRequest delegate via the message loop. | 391 // net::URLRequest delegate via the message loop. |
392 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 392 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
393 this, &URLRequestHttpJob::OnStartCompleted, rv)); | 393 this, &URLRequestHttpJob::OnStartCompleted, rv)); |
394 } | 394 } |
395 | 395 |
396 void URLRequestHttpJob::ContinueDespiteLastError() { | 396 void URLRequestHttpJob::ContinueDespiteLastError() { |
397 // If the transaction was destroyed, then the job was cancelled. | 397 // If the transaction was destroyed, then the job was cancelled. |
398 if (!transaction_.get()) | 398 if (!transaction_.get()) |
399 return; | 399 return; |
400 | 400 |
401 DCHECK(!response_info_) << "should not have a response yet"; | 401 DCHECK(!response_info_) << "should not have a response yet"; |
402 | 402 |
403 // No matter what, we want to report our status as IO pending since we will | 403 // No matter what, we want to report our status as IO pending since we will |
404 // be notifying our consumer asynchronously via OnStartCompleted. | 404 // be notifying our consumer asynchronously via OnStartCompleted. |
405 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 405 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
406 | 406 |
407 int rv = transaction_->RestartIgnoringLastError(&start_callback_); | 407 int rv = transaction_->RestartIgnoringLastError(&start_callback_); |
408 if (rv == net::ERR_IO_PENDING) | 408 if (rv == net::ERR_IO_PENDING) |
409 return; | 409 return; |
410 | 410 |
411 // The transaction started synchronously, but we need to notify the | 411 // The transaction started synchronously, but we need to notify the |
412 // URLRequest delegate via the message loop. | 412 // net::URLRequest delegate via the message loop. |
413 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 413 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
414 this, &URLRequestHttpJob::OnStartCompleted, rv)); | 414 this, &URLRequestHttpJob::OnStartCompleted, rv)); |
415 } | 415 } |
416 | 416 |
417 bool URLRequestHttpJob::ReadRawData(net::IOBuffer* buf, int buf_size, | 417 bool URLRequestHttpJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
418 int *bytes_read) { | 418 int *bytes_read) { |
419 DCHECK_NE(buf_size, 0); | 419 DCHECK_NE(buf_size, 0); |
420 DCHECK(bytes_read); | 420 DCHECK(bytes_read); |
421 DCHECK(!read_in_progress_); | 421 DCHECK(!read_in_progress_); |
422 | 422 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 // Make sure the context is alive for the duration of the | 652 // Make sure the context is alive for the duration of the |
653 // transaction. | 653 // transaction. |
654 context_ = request_->context(); | 654 context_ = request_->context(); |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 if (rv == net::ERR_IO_PENDING) | 658 if (rv == net::ERR_IO_PENDING) |
659 return; | 659 return; |
660 | 660 |
661 // The transaction started synchronously, but we need to notify the | 661 // The transaction started synchronously, but we need to notify the |
662 // URLRequest delegate via the message loop. | 662 // net::URLRequest delegate via the message loop. |
663 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 663 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
664 this, &URLRequestHttpJob::OnStartCompleted, rv)); | 664 this, &URLRequestHttpJob::OnStartCompleted, rv)); |
665 } | 665 } |
666 | 666 |
667 void URLRequestHttpJob::AddExtraHeaders() { | 667 void URLRequestHttpJob::AddExtraHeaders() { |
668 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is | 668 // TODO(jar): Consider optimizing away SDCH advertising bytes when the URL is |
669 // probably an img or such (and SDCH encoding is not likely). | 669 // probably an img or such (and SDCH encoding is not likely). |
670 bool advertise_sdch = SdchManager::Global() && | 670 bool advertise_sdch = SdchManager::Global() && |
671 SdchManager::Global()->IsInSupportedDomain(request_->url()); | 671 SdchManager::Global()->IsInSupportedDomain(request_->url()); |
672 std::string avail_dictionaries; | 672 std::string avail_dictionaries; |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 HTTPSProberDelegate* delegate = | 934 HTTPSProberDelegate* delegate = |
935 new HTTPSProberDelegate(request_info_.url.host(), max_age, | 935 new HTTPSProberDelegate(request_info_.url.host(), max_age, |
936 include_subdomains, | 936 include_subdomains, |
937 ctx->transport_security_state()); | 937 ctx->transport_security_state()); |
938 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), | 938 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), |
939 delegate)) { | 939 delegate)) { |
940 delete delegate; | 940 delete delegate; |
941 } | 941 } |
942 } | 942 } |
943 } | 943 } |
OLD | NEW |