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 return; |
| 178 } |
| 179 *was_fetched_via_service_worker = true; |
| 180 *original_url_via_service_worker = response_url_; |
| 181 } |
| 182 |
| 183 |
172 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { | 184 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { |
173 } | 185 } |
174 | 186 |
175 void ServiceWorkerURLRequestJob::MaybeStartRequest() { | 187 void ServiceWorkerURLRequestJob::MaybeStartRequest() { |
176 if (is_started_ && response_type_ != NOT_DETERMINED) { | 188 if (is_started_ && response_type_ != NOT_DETERMINED) { |
177 // Start asynchronously. | 189 // Start asynchronously. |
178 base::MessageLoop::current()->PostTask( | 190 base::MessageLoop::current()->PostTask( |
179 FROM_HERE, | 191 FROM_HERE, |
180 base::Bind(&ServiceWorkerURLRequestJob::StartRequest, | 192 base::Bind(&ServiceWorkerURLRequestJob::StartRequest, |
181 weak_factory_.GetWeakPtr())); | 193 weak_factory_.GetWeakPtr())); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (!blob_data_handle) { | 263 if (!blob_data_handle) { |
252 // The renderer gave us a bad blob UUID. | 264 // The renderer gave us a bad blob UUID. |
253 DeliverErrorResponse(); | 265 DeliverErrorResponse(); |
254 return; | 266 return; |
255 } | 267 } |
256 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( | 268 blob_request_ = webkit_blob::BlobProtocolHandler::CreateBlobRequest( |
257 blob_data_handle.Pass(), request()->context(), this); | 269 blob_data_handle.Pass(), request()->context(), this); |
258 blob_request_->Start(); | 270 blob_request_->Start(); |
259 } | 271 } |
260 | 272 |
| 273 response_url_ = response.url; |
261 CreateResponseHeader( | 274 CreateResponseHeader( |
262 response.status_code, response.status_text, response.headers); | 275 response.status_code, response.status_text, response.headers); |
263 if (!blob_request_) | 276 if (!blob_request_) |
264 CommitResponseHeader(); | 277 CommitResponseHeader(); |
265 } | 278 } |
266 | 279 |
267 void ServiceWorkerURLRequestJob::CreateResponseHeader( | 280 void ServiceWorkerURLRequestJob::CreateResponseHeader( |
268 int status_code, | 281 int status_code, |
269 const std::string& status_text, | 282 const std::string& status_text, |
270 const std::map<std::string, std::string>& headers) { | 283 const std::map<std::string, std::string>& headers) { |
(...skipping 28 matching lines...) Expand all Loading... |
299 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { | 312 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { |
300 // TODO(falken): Print an error to the console of the ServiceWorker and of | 313 // TODO(falken): Print an error to the console of the ServiceWorker and of |
301 // the requesting page. | 314 // the requesting page. |
302 CreateResponseHeader(500, | 315 CreateResponseHeader(500, |
303 "Service Worker Response Error", | 316 "Service Worker Response Error", |
304 std::map<std::string, std::string>()); | 317 std::map<std::string, std::string>()); |
305 CommitResponseHeader(); | 318 CommitResponseHeader(); |
306 } | 319 } |
307 | 320 |
308 } // namespace content | 321 } // namespace content |
OLD | NEW |