OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service_worker/service_worker_url_request_job.h" | 5 #include "content/browser/service_worker/service_worker_url_request_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 9 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
10 #include "content/browser/service_worker/service_worker_provider_host.h" | 10 #include "content/browser/service_worker/service_worker_provider_host.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 162 } |
163 | 163 |
164 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { | 164 const net::HttpResponseInfo* ServiceWorkerURLRequestJob::http_info() const { |
165 if (!http_response_info_) | 165 if (!http_response_info_) |
166 return NULL; | 166 return NULL; |
167 if (range_response_info_) | 167 if (range_response_info_) |
168 return range_response_info_.get(); | 168 return range_response_info_.get(); |
169 return http_response_info_.get(); | 169 return http_response_info_.get(); |
170 } | 170 } |
171 | 171 |
| 172 void ServiceWorkerURLRequestJob::GetExtraResponseInfo( |
| 173 bool* was_fetched_via_service_worker, |
| 174 GURL* original_url_via_service_worker) const { |
| 175 if (response_type_ != FORWARD_TO_SERVICE_WORKER) { |
| 176 *was_fetched_via_service_worker = false; |
| 177 *original_url_via_service_worker = GURL(); |
| 178 return; |
| 179 } |
| 180 *was_fetched_via_service_worker = true; |
| 181 *original_url_via_service_worker = response_url_; |
| 182 } |
| 183 |
| 184 |
172 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { | 185 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { |
173 } | 186 } |
174 | 187 |
175 void ServiceWorkerURLRequestJob::MaybeStartRequest() { | 188 void ServiceWorkerURLRequestJob::MaybeStartRequest() { |
176 if (is_started_ && response_type_ != NOT_DETERMINED) { | 189 if (is_started_ && response_type_ != NOT_DETERMINED) { |
177 // Start asynchronously. | 190 // Start asynchronously. |
178 base::MessageLoop::current()->PostTask( | 191 base::MessageLoop::current()->PostTask( |
179 FROM_HERE, | 192 FROM_HERE, |
180 base::Bind(&ServiceWorkerURLRequestJob::StartRequest, | 193 base::Bind(&ServiceWorkerURLRequestJob::StartRequest, |
181 weak_factory_.GetWeakPtr())); | 194 weak_factory_.GetWeakPtr())); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (!blob_data_handle) { | 264 if (!blob_data_handle) { |
252 // The renderer gave us a bad blob UUID. | 265 // The renderer gave us a bad blob UUID. |
253 DeliverErrorResponse(); | 266 DeliverErrorResponse(); |
254 return; | 267 return; |
255 } | 268 } |
256 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( | 269 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( |
257 blob_data_handle.Pass(), request()->context(), this); | 270 blob_data_handle.Pass(), request()->context(), this); |
258 blob_request_->Start(); | 271 blob_request_->Start(); |
259 } | 272 } |
260 | 273 |
| 274 response_url_ = response.url; |
261 CreateResponseHeader( | 275 CreateResponseHeader( |
262 response.status_code, response.status_text, response.headers); | 276 response.status_code, response.status_text, response.headers); |
263 if (!blob_request_) | 277 if (!blob_request_) |
264 CommitResponseHeader(); | 278 CommitResponseHeader(); |
265 } | 279 } |
266 | 280 |
267 void ServiceWorkerURLRequestJob::CreateResponseHeader( | 281 void ServiceWorkerURLRequestJob::CreateResponseHeader( |
268 int status_code, | 282 int status_code, |
269 const std::string& status_text, | 283 const std::string& status_text, |
270 const std::map<std::string, std::string>& headers) { | 284 const std::map<std::string, std::string>& headers) { |
(...skipping 28 matching lines...) Expand all Loading... |
299 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { | 313 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { |
300 // TODO(falken): Print an error to the console of the ServiceWorker and of | 314 // TODO(falken): Print an error to the console of the ServiceWorker and of |
301 // the requesting page. | 315 // the requesting page. |
302 CreateResponseHeader(500, | 316 CreateResponseHeader(500, |
303 "Service Worker Response Error", | 317 "Service Worker Response Error", |
304 std::map<std::string, std::string>()); | 318 std::map<std::string, std::string>()); |
305 CommitResponseHeader(); | 319 CommitResponseHeader(); |
306 } | 320 } |
307 | 321 |
308 } // namespace content | 322 } // namespace content |
OLD | NEW |