OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_loader_job.h" | 5 #include "content/browser/service_worker/service_worker_url_loader_job.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/browser/blob_storage/blob_url_loader_factory.h" | 8 #include "content/browser/blob_storage/blob_url_loader_factory.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_version.h" | 10 #include "content/browser/service_worker/service_worker_version.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 response_head_.headers->GetMimeType(&mime_type); | 175 response_head_.headers->GetMimeType(&mime_type); |
176 if (mime_type.empty()) | 176 if (mime_type.empty()) |
177 mime_type = "text/plain"; | 177 mime_type = "text/plain"; |
178 response_head_.mime_type = mime_type; | 178 response_head_.mime_type = mime_type; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void ServiceWorkerURLLoaderJob::CommitResponseHeaders() { | 182 void ServiceWorkerURLLoaderJob::CommitResponseHeaders() { |
183 DCHECK_EQ(Status::kStarted, status_); | 183 DCHECK_EQ(Status::kStarted, status_); |
184 status_ = Status::kSentHeader; | 184 status_ = Status::kSentHeader; |
185 url_loader_client_->OnReceiveResponse(response_head_, ssl_info_, nullptr); | 185 url_loader_client_->OnReceiveResponse( |
| 186 response_head_, base::nullopt /* TODO(scottmg): ssl info */, |
| 187 mojom::DownloadedTempFilePtr()); |
186 } | 188 } |
187 | 189 |
188 void ServiceWorkerURLLoaderJob::CommitCompleted(int error_code) { | 190 void ServiceWorkerURLLoaderJob::CommitCompleted(int error_code) { |
189 DCHECK_LT(status_, Status::kCompleted); | 191 DCHECK_LT(status_, Status::kCompleted); |
190 status_ = Status::kCompleted; | 192 status_ = Status::kCompleted; |
191 ResourceRequestCompletionStatus completion_status; | 193 ResourceRequestCompletionStatus completion_status; |
192 completion_status.error_code = error_code; | 194 completion_status.error_code = error_code; |
193 completion_status.completion_time = base::TimeTicks::Now(); | 195 completion_status.completion_time = base::TimeTicks::Now(); |
194 url_loader_client_->OnComplete(completion_status); | 196 url_loader_client_->OnComplete(completion_status); |
195 } | 197 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 240 |
239 DCHECK_EQ(fetch_result, SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 241 DCHECK_EQ(fetch_result, SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
240 | 242 |
241 // A response with status code 0 is Blink telling us to respond with | 243 // A response with status code 0 is Blink telling us to respond with |
242 // network error. | 244 // network error. |
243 if (response.status_code == 0) { | 245 if (response.status_code == 0) { |
244 DeliverErrorResponse(); | 246 DeliverErrorResponse(); |
245 return; | 247 return; |
246 } | 248 } |
247 | 249 |
248 // Creates a new HttpResponseInfo using the the ServiceWorker script's | |
249 // HttpResponseInfo to show HTTPS padlock. | |
250 // TODO(horo): When we support mixed-content (HTTP) no-cors requests from a | |
251 // ServiceWorker, we have to check the security level of the responses. | |
252 const net::HttpResponseInfo* main_script_http_info = | |
253 version->GetMainScriptHttpResponseInfo(); | |
254 DCHECK(main_script_http_info); | |
255 ssl_info_ = main_script_http_info->ssl_info; | |
256 | |
257 std::move(loader_callback_) | 250 std::move(loader_callback_) |
258 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, | 251 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, |
259 weak_factory_.GetWeakPtr(), response, | 252 weak_factory_.GetWeakPtr(), response, |
260 base::Passed(std::move(body_as_stream)))); | 253 base::Passed(std::move(body_as_stream)))); |
261 } | 254 } |
262 | 255 |
263 void ServiceWorkerURLLoaderJob::StartResponse( | 256 void ServiceWorkerURLLoaderJob::StartResponse( |
264 const ServiceWorkerResponse& response, | 257 const ServiceWorkerResponse& response, |
265 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, | 258 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, |
266 mojom::URLLoaderRequest request, | 259 mojom::URLLoaderRequest request, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 353 } |
361 | 354 |
362 void ServiceWorkerURLLoaderJob::OnComplete( | 355 void ServiceWorkerURLLoaderJob::OnComplete( |
363 const ResourceRequestCompletionStatus& status) { | 356 const ResourceRequestCompletionStatus& status) { |
364 DCHECK_EQ(Status::kSentHeader, status_); | 357 DCHECK_EQ(Status::kSentHeader, status_); |
365 status_ = Status::kCompleted; | 358 status_ = Status::kCompleted; |
366 url_loader_client_->OnComplete(status); | 359 url_loader_client_->OnComplete(status); |
367 } | 360 } |
368 | 361 |
369 } // namespace content | 362 } // namespace content |
OLD | NEW |