| 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 29 matching lines...) Expand all Loading... |
| 71 if (ssl_client_auth_handler_) | 71 if (ssl_client_auth_handler_) |
| 72 ssl_client_auth_handler_->OnRequestCancelled(); | 72 ssl_client_auth_handler_->OnRequestCancelled(); |
| 73 | 73 |
| 74 // Run ResourceHandler destructor before we tear-down the rest of our state | 74 // Run ResourceHandler destructor before we tear-down the rest of our state |
| 75 // as the ResourceHandler may want to inspect the URLRequest and other state. | 75 // as the ResourceHandler may want to inspect the URLRequest and other state. |
| 76 handler_.reset(); | 76 handler_.reset(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ResourceLoader::StartRequest() { | 79 void ResourceLoader::StartRequest() { |
| 80 if (delegate_->HandleExternalProtocol(this, request_->url())) { | 80 if (delegate_->HandleExternalProtocol(this, request_->url())) { |
| 81 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 81 CancelAndIgnore(); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Give the handler a chance to delay the URLRequest from being started. | 85 // Give the handler a chance to delay the URLRequest from being started. |
| 86 bool defer_start = false; | 86 bool defer_start = false; |
| 87 if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), | 87 if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), |
| 88 &defer_start)) { | 88 &defer_start)) { |
| 89 Cancel(); | 89 Cancel(); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 | 92 |
| 93 if (defer_start) { | 93 if (defer_start) { |
| 94 deferred_stage_ = DEFERRED_START; | 94 deferred_stage_ = DEFERRED_START; |
| 95 } else { | 95 } else { |
| 96 StartRequestInternal(); | 96 StartRequestInternal(); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ResourceLoader::CancelRequest(bool from_renderer) { | 100 void ResourceLoader::CancelRequest(bool from_renderer) { |
| 101 CancelRequestInternal(net::ERR_ABORTED, from_renderer); | 101 CancelRequestInternal(net::ERR_ABORTED, from_renderer); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void ResourceLoader::CancelAndIgnore() { |
| 105 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 106 info->set_was_ignored_by_handler(true); |
| 107 CancelRequest(false); |
| 108 } |
| 109 |
| 104 void ResourceLoader::ReportUploadProgress() { | 110 void ResourceLoader::ReportUploadProgress() { |
| 105 ResourceRequestInfoImpl* info = GetRequestInfo(); | 111 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 106 | 112 |
| 107 if (waiting_for_upload_progress_ack_) | 113 if (waiting_for_upload_progress_ack_) |
| 108 return; // Send one progress event at a time. | 114 return; // Send one progress event at a time. |
| 109 | 115 |
| 110 uint64 size = info->GetUploadSize(); | 116 uint64 size = info->GetUploadSize(); |
| 111 if (!size) | 117 if (!size) |
| 112 return; // Nothing to upload. | 118 return; // Nothing to upload. |
| 113 | 119 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 203 |
| 198 // Tell the renderer that this request was disallowed. | 204 // Tell the renderer that this request was disallowed. |
| 199 Cancel(); | 205 Cancel(); |
| 200 return; | 206 return; |
| 201 } | 207 } |
| 202 | 208 |
| 203 delegate_->DidReceiveRedirect(this, new_url); | 209 delegate_->DidReceiveRedirect(this, new_url); |
| 204 | 210 |
| 205 if (delegate_->HandleExternalProtocol(this, new_url)) { | 211 if (delegate_->HandleExternalProtocol(this, new_url)) { |
| 206 // The request is complete so we can remove it. | 212 // The request is complete so we can remove it. |
| 207 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 213 CancelAndIgnore(); |
| 208 return; | 214 return; |
| 209 } | 215 } |
| 210 | 216 |
| 211 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 217 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 212 PopulateResourceResponse(request_.get(), response); | 218 PopulateResourceResponse(request_.get(), response); |
| 213 | 219 |
| 214 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, | 220 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, |
| 215 defer)) { | 221 defer)) { |
| 216 Cancel(); | 222 Cancel(); |
| 217 } else if (*defer) { | 223 } else if (*defer) { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // we resume. | 568 // we resume. |
| 563 deferred_stage_ = DEFERRED_FINISH; | 569 deferred_stage_ = DEFERRED_FINISH; |
| 564 } | 570 } |
| 565 } | 571 } |
| 566 | 572 |
| 567 void ResourceLoader::CallDidFinishLoading() { | 573 void ResourceLoader::CallDidFinishLoading() { |
| 568 delegate_->DidFinishLoading(this); | 574 delegate_->DidFinishLoading(this); |
| 569 } | 575 } |
| 570 | 576 |
| 571 } // namespace content | 577 } // namespace content |
| OLD | NEW |