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 net::UploadProgress progress = request_->GetUploadProgress(); | 116 net::UploadProgress progress = request_->GetUploadProgress(); |
111 if (!progress.size()) | 117 if (!progress.size()) |
112 return; // Nothing to upload. | 118 return; // Nothing to upload. |
113 | 119 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 204 |
199 // Tell the renderer that this request was disallowed. | 205 // Tell the renderer that this request was disallowed. |
200 Cancel(); | 206 Cancel(); |
201 return; | 207 return; |
202 } | 208 } |
203 | 209 |
204 delegate_->DidReceiveRedirect(this, new_url); | 210 delegate_->DidReceiveRedirect(this, new_url); |
205 | 211 |
206 if (delegate_->HandleExternalProtocol(this, new_url)) { | 212 if (delegate_->HandleExternalProtocol(this, new_url)) { |
207 // The request is complete so we can remove it. | 213 // The request is complete so we can remove it. |
208 CancelRequestInternal(net::ERR_UNKNOWN_URL_SCHEME, false); | 214 CancelAndIgnore(); |
209 return; | 215 return; |
210 } | 216 } |
211 | 217 |
212 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 218 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
213 PopulateResourceResponse(request_.get(), response); | 219 PopulateResourceResponse(request_.get(), response); |
214 | 220 |
215 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, | 221 if (!handler_->OnRequestRedirected(info->GetRequestID(), new_url, response, |
216 defer)) { | 222 defer)) { |
217 Cancel(); | 223 Cancel(); |
218 } else if (*defer) { | 224 } else if (*defer) { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // we resume. | 569 // we resume. |
564 deferred_stage_ = DEFERRED_FINISH; | 570 deferred_stage_ = DEFERRED_FINISH; |
565 } | 571 } |
566 } | 572 } |
567 | 573 |
568 void ResourceLoader::CallDidFinishLoading() { | 574 void ResourceLoader::CallDidFinishLoading() { |
569 delegate_->DidFinishLoading(this); | 575 delegate_->DidFinishLoading(this); |
570 } | 576 } |
571 | 577 |
572 } // namespace content | 578 } // namespace content |
OLD | NEW |