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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (ssl_client_auth_handler_) | 75 if (ssl_client_auth_handler_) |
76 ssl_client_auth_handler_->OnRequestCancelled(); | 76 ssl_client_auth_handler_->OnRequestCancelled(); |
77 | 77 |
78 // Run ResourceHandler destructor before we tear-down the rest of our state | 78 // Run ResourceHandler destructor before we tear-down the rest of our state |
79 // as the ResourceHandler may want to inspect the URLRequest and other state. | 79 // as the ResourceHandler may want to inspect the URLRequest and other state. |
80 handler_.reset(); | 80 handler_.reset(); |
81 } | 81 } |
82 | 82 |
83 void ResourceLoader::StartRequest() { | 83 void ResourceLoader::StartRequest() { |
84 if (delegate_->HandleExternalProtocol(this, request_->url())) { | 84 if (delegate_->HandleExternalProtocol(this, request_->url())) { |
85 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 85 CancelRequestInternal(net::OK_HANDLED_EXTERNALLY, false); |
86 return; | 86 return; |
87 } | 87 } |
88 | 88 |
89 // Give the handler a chance to delay the URLRequest from being started. | 89 // Give the handler a chance to delay the URLRequest from being started. |
90 bool defer_start = false; | 90 bool defer_start = false; |
91 if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), | 91 if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), |
92 &defer_start)) { | 92 &defer_start)) { |
93 Cancel(); | 93 Cancel(); |
94 return; | 94 return; |
95 } | 95 } |
96 | 96 |
97 if (defer_start) { | 97 if (defer_start) { |
98 deferred_stage_ = DEFERRED_START; | 98 deferred_stage_ = DEFERRED_START; |
99 } else { | 99 } else { |
100 StartRequestInternal(); | 100 StartRequestInternal(); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 void ResourceLoader::CancelRequest(bool from_renderer) { | 104 void ResourceLoader::CancelRequest(bool from_renderer) { |
105 CancelRequestInternal(net::ERR_ABORTED, from_renderer); | 105 CancelRequestInternal(net::ERR_ABORTED, from_renderer); |
106 } | 106 } |
107 | 107 |
| 108 void ResourceLoader::CancelWithError(int error) { |
| 109 CancelRequestInternal(error, false); |
| 110 } |
| 111 |
108 void ResourceLoader::ReportUploadProgress() { | 112 void ResourceLoader::ReportUploadProgress() { |
109 ResourceRequestInfoImpl* info = GetRequestInfo(); | 113 ResourceRequestInfoImpl* info = GetRequestInfo(); |
110 | 114 |
111 if (waiting_for_upload_progress_ack_) | 115 if (waiting_for_upload_progress_ack_) |
112 return; // Send one progress event at a time. | 116 return; // Send one progress event at a time. |
113 | 117 |
114 uint64 size = info->GetUploadSize(); | 118 uint64 size = info->GetUploadSize(); |
115 if (!size) | 119 if (!size) |
116 return; // Nothing to upload. | 120 return; // Nothing to upload. |
117 | 121 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 200 |
197 // Tell the renderer that this request was disallowed. | 201 // Tell the renderer that this request was disallowed. |
198 Cancel(); | 202 Cancel(); |
199 return; | 203 return; |
200 } | 204 } |
201 | 205 |
202 delegate_->DidReceiveRedirect(this, new_url); | 206 delegate_->DidReceiveRedirect(this, new_url); |
203 | 207 |
204 if (delegate_->HandleExternalProtocol(this, new_url)) { | 208 if (delegate_->HandleExternalProtocol(this, new_url)) { |
205 // The request is complete so we can remove it. | 209 // The request is complete so we can remove it. |
206 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 210 CancelRequestInternal(net::OK_HANDLED_EXTERNALLY, false); |
207 return; | 211 return; |
208 } | 212 } |
209 | 213 |
210 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 214 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
211 PopulateResourceResponse(request_.get(), response); | 215 PopulateResourceResponse(request_.get(), response); |
212 | 216 |
213 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, | 217 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, |
214 defer)) { | 218 defer)) { |
215 Cancel(); | 219 Cancel(); |
216 } | 220 } |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 } else { | 644 } else { |
641 OnResponseStarted(request_.get()); | 645 OnResponseStarted(request_.get()); |
642 } | 646 } |
643 } | 647 } |
644 | 648 |
645 void ResourceLoader::CallDidFinishLoading() { | 649 void ResourceLoader::CallDidFinishLoading() { |
646 delegate_->DidFinishLoading(this); | 650 delegate_->DidFinishLoading(this); |
647 } | 651 } |
648 | 652 |
649 } // namespace content | 653 } // namespace content |
OLD | NEW |