| 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 "content/browser/renderer_host/resource_loader.h" | 5 #include "content/browser/renderer_host/resource_loader.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
| 10 #include "content/browser/renderer_host/doomed_resource_handler.h" | 10 #include "content/browser/renderer_host/doomed_resource_handler.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "webkit/appcache/appcache_interceptor.h" | 21 #include "webkit/appcache/appcache_interceptor.h" |
| 22 | 22 |
| 23 using base::TimeDelta; | 23 using base::TimeDelta; |
| 24 using base::TimeTicks; | 24 using base::TimeTicks; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void PopulateResourceResponse(net::URLRequest* request, | 29 void PopulateResourceResponse(net::URLRequest* request, |
| 30 ResourceResponse* response) { | 30 ResourceResponse* response) { |
| 31 response->head.status = request->status(); | 31 response->head.error_code = request->status().error(); |
| 32 response->head.request_time = request->request_time(); | 32 response->head.request_time = request->request_time(); |
| 33 response->head.response_time = request->response_time(); | 33 response->head.response_time = request->response_time(); |
| 34 response->head.headers = request->response_headers(); | 34 response->head.headers = request->response_headers(); |
| 35 request->GetCharset(&response->head.charset); | 35 request->GetCharset(&response->head.charset); |
| 36 response->head.content_length = request->GetExpectedContentSize(); | 36 response->head.content_length = request->GetExpectedContentSize(); |
| 37 request->GetMimeType(&response->head.mime_type); | 37 request->GetMimeType(&response->head.mime_type); |
| 38 net::HttpResponseInfo response_info = request->response_info(); | 38 net::HttpResponseInfo response_info = request->response_info(); |
| 39 response->head.was_fetched_via_spdy = response_info.was_fetched_via_spdy; | 39 response->head.was_fetched_via_spdy = response_info.was_fetched_via_spdy; |
| 40 response->head.was_npn_negotiated = response_info.was_npn_negotiated; | 40 response->head.was_npn_negotiated = response_info.was_npn_negotiated; |
| 41 response->head.npn_negotiated_protocol = | 41 response->head.npn_negotiated_protocol = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 70 if (ssl_client_auth_handler_) | 70 if (ssl_client_auth_handler_) |
| 71 ssl_client_auth_handler_->OnRequestCancelled(); | 71 ssl_client_auth_handler_->OnRequestCancelled(); |
| 72 | 72 |
| 73 // Run ResourceHandler destructor before we tear-down the rest of our state | 73 // Run ResourceHandler destructor before we tear-down the rest of our state |
| 74 // as the ResourceHandler may want to inspect the URLRequest and other state. | 74 // as the ResourceHandler may want to inspect the URLRequest and other state. |
| 75 handler_.reset(); | 75 handler_.reset(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ResourceLoader::StartRequest() { | 78 void ResourceLoader::StartRequest() { |
| 79 if (delegate_->HandleExternalProtocol(this, request_->url())) { | 79 if (delegate_->HandleExternalProtocol(this, request_->url())) { |
| 80 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 80 HandledExternally(); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Give the handler a chance to delay the URLRequest from being started. | 84 // Give the handler a chance to delay the URLRequest from being started. |
| 85 bool defer_start = false; | 85 bool defer_start = false; |
| 86 if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), | 86 if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), |
| 87 &defer_start)) { | 87 &defer_start)) { |
| 88 Cancel(); | 88 Cancel(); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 if (defer_start) { | 92 if (defer_start) { |
| 93 deferred_stage_ = DEFERRED_START; | 93 deferred_stage_ = DEFERRED_START; |
| 94 } else { | 94 } else { |
| 95 StartRequestInternal(); | 95 StartRequestInternal(); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ResourceLoader::CancelRequest(bool from_renderer) { | 99 void ResourceLoader::CancelRequest(bool from_renderer) { |
| 100 CancelRequestInternal(net::ERR_ABORTED, from_renderer); | 100 CancelRequestInternal(net::ERR_ABORTED, from_renderer); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ResourceLoader::CancelWithError(int error) { |
| 104 CancelRequestInternal(error, false); |
| 105 } |
| 106 |
| 107 void ResourceLoader::HandledExternally() { |
| 108 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 109 info->set_handled_externally(true); |
| 110 CancelRequest(false); |
| 111 } |
| 112 |
| 103 void ResourceLoader::ReportUploadProgress() { | 113 void ResourceLoader::ReportUploadProgress() { |
| 104 ResourceRequestInfoImpl* info = GetRequestInfo(); | 114 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 105 | 115 |
| 106 if (waiting_for_upload_progress_ack_) | 116 if (waiting_for_upload_progress_ack_) |
| 107 return; // Send one progress event at a time. | 117 return; // Send one progress event at a time. |
| 108 | 118 |
| 109 uint64 size = info->GetUploadSize(); | 119 uint64 size = info->GetUploadSize(); |
| 110 if (!size) | 120 if (!size) |
| 111 return; // Nothing to upload. | 121 return; // Nothing to upload. |
| 112 | 122 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 206 |
| 197 // Tell the renderer that this request was disallowed. | 207 // Tell the renderer that this request was disallowed. |
| 198 Cancel(); | 208 Cancel(); |
| 199 return; | 209 return; |
| 200 } | 210 } |
| 201 | 211 |
| 202 delegate_->DidReceiveRedirect(this, new_url); | 212 delegate_->DidReceiveRedirect(this, new_url); |
| 203 | 213 |
| 204 if (delegate_->HandleExternalProtocol(this, new_url)) { | 214 if (delegate_->HandleExternalProtocol(this, new_url)) { |
| 205 // The request is complete so we can remove it. | 215 // The request is complete so we can remove it. |
| 206 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 216 HandledExternally(); |
| 207 return; | 217 return; |
| 208 } | 218 } |
| 209 | 219 |
| 210 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 220 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 211 PopulateResourceResponse(request_.get(), response); | 221 PopulateResourceResponse(request_.get(), response); |
| 212 | 222 |
| 213 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, | 223 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, |
| 214 defer)) { | 224 defer)) { |
| 215 Cancel(); | 225 Cancel(); |
| 216 } else if (*defer) { | 226 } else if (*defer) { |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 // we resume. | 567 // we resume. |
| 558 deferred_stage_ = DEFERRED_FINISH; | 568 deferred_stage_ = DEFERRED_FINISH; |
| 559 } | 569 } |
| 560 } | 570 } |
| 561 | 571 |
| 562 void ResourceLoader::CallDidFinishLoading() { | 572 void ResourceLoader::CallDidFinishLoading() { |
| 563 delegate_->DidFinishLoading(this); | 573 delegate_->DidFinishLoading(this); |
| 564 } | 574 } |
| 565 | 575 |
| 566 } // namespace content | 576 } // namespace content |
| OLD | NEW |