| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if (!blob_data_handle) { | 251 if (!blob_data_handle) { |
| 252 // The renderer gave us a bad blob UUID. | 252 // The renderer gave us a bad blob UUID. |
| 253 DeliverErrorResponse(); | 253 DeliverErrorResponse(); |
| 254 return; | 254 return; |
| 255 } | 255 } |
| 256 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( | 256 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( |
| 257 blob_data_handle.Pass(), request()->context(), this); | 257 blob_data_handle.Pass(), request()->context(), this); |
| 258 blob_request_->Start(); | 258 blob_request_->Start(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 response_url_ = response.url; |
| 261 CreateResponseHeader( | 262 CreateResponseHeader( |
| 262 response.status_code, response.status_text, response.headers); | 263 response.status_code, response.status_text, response.headers); |
| 263 if (!blob_request_) | 264 if (!blob_request_) |
| 264 CommitResponseHeader(); | 265 CommitResponseHeader(); |
| 265 } | 266 } |
| 266 | 267 |
| 267 void ServiceWorkerURLRequestJob::CreateResponseHeader( | 268 void ServiceWorkerURLRequestJob::CreateResponseHeader( |
| 268 int status_code, | 269 int status_code, |
| 269 const std::string& status_text, | 270 const std::string& status_text, |
| 270 const std::map<std::string, std::string>& headers) { | 271 const std::map<std::string, std::string>& headers) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 header.append(it->first); | 287 header.append(it->first); |
| 287 header.append(": "); | 288 header.append(": "); |
| 288 header.append(it->second); | 289 header.append(it->second); |
| 289 http_response_headers_->AddHeader(header); | 290 http_response_headers_->AddHeader(header); |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 | 293 |
| 293 void ServiceWorkerURLRequestJob::CommitResponseHeader() { | 294 void ServiceWorkerURLRequestJob::CommitResponseHeader() { |
| 294 http_response_info_.reset(new net::HttpResponseInfo()); | 295 http_response_info_.reset(new net::HttpResponseInfo()); |
| 295 http_response_info_->headers.swap(http_response_headers_); | 296 http_response_info_->headers.swap(http_response_headers_); |
| 297 http_response_info_->was_fetched_via_service_worker = true; |
| 298 http_response_info_->original_url_via_service_worker = response_url_; |
| 296 NotifyHeadersComplete(); | 299 NotifyHeadersComplete(); |
| 297 } | 300 } |
| 298 | 301 |
| 299 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { | 302 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { |
| 300 // TODO(falken): Print an error to the console of the ServiceWorker and of | 303 // TODO(falken): Print an error to the console of the ServiceWorker and of |
| 301 // the requesting page. | 304 // the requesting page. |
| 302 CreateResponseHeader(500, | 305 CreateResponseHeader(500, |
| 303 "Service Worker Response Error", | 306 "Service Worker Response Error", |
| 304 std::map<std::string, std::string>()); | 307 std::map<std::string, std::string>()); |
| 305 CommitResponseHeader(); | 308 CommitResponseHeader(); |
| 306 } | 309 } |
| 307 | 310 |
| 308 } // namespace content | 311 } // namespace content |
| OLD | NEW |