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( | 185 url_loader_client_->OnReceiveResponse(response_head_, ssl_info_, |
186 response_head_, base::nullopt /* TODO(scottmg): ssl info */, | 186 mojom::DownloadedTempFilePtr()); |
187 mojom::DownloadedTempFilePtr()); | |
188 } | 187 } |
189 | 188 |
190 void ServiceWorkerURLLoaderJob::CommitCompleted(int error_code) { | 189 void ServiceWorkerURLLoaderJob::CommitCompleted(int error_code) { |
191 DCHECK_LT(status_, Status::kCompleted); | 190 DCHECK_LT(status_, Status::kCompleted); |
192 status_ = Status::kCompleted; | 191 status_ = Status::kCompleted; |
193 ResourceRequestCompletionStatus completion_status; | 192 ResourceRequestCompletionStatus completion_status; |
194 completion_status.error_code = error_code; | 193 completion_status.error_code = error_code; |
195 completion_status.completion_time = base::TimeTicks::Now(); | 194 completion_status.completion_time = base::TimeTicks::Now(); |
196 url_loader_client_->OnComplete(completion_status); | 195 url_loader_client_->OnComplete(completion_status); |
197 } | 196 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 239 |
241 DCHECK_EQ(fetch_result, SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 240 DCHECK_EQ(fetch_result, SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
242 | 241 |
243 // A response with status code 0 is Blink telling us to respond with | 242 // A response with status code 0 is Blink telling us to respond with |
244 // network error. | 243 // network error. |
245 if (response.status_code == 0) { | 244 if (response.status_code == 0) { |
246 DeliverErrorResponse(); | 245 DeliverErrorResponse(); |
247 return; | 246 return; |
248 } | 247 } |
249 | 248 |
| 249 // Creates a new HttpResponseInfo using the the ServiceWorker script's |
| 250 // HttpResponseInfo to show HTTPS padlock. |
| 251 // TODO(horo): When we support mixed-content (HTTP) no-cors requests from a |
| 252 // ServiceWorker, we have to check the security level of the responses. |
| 253 const net::HttpResponseInfo* main_script_http_info = |
| 254 version->GetMainScriptHttpResponseInfo(); |
| 255 DCHECK(main_script_http_info); |
| 256 ssl_info_ = main_script_http_info->ssl_info; |
| 257 |
250 std::move(loader_callback_) | 258 std::move(loader_callback_) |
251 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, | 259 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, |
252 weak_factory_.GetWeakPtr(), response, | 260 weak_factory_.GetWeakPtr(), response, |
253 base::Passed(std::move(body_as_stream)))); | 261 base::Passed(std::move(body_as_stream)))); |
254 } | 262 } |
255 | 263 |
256 void ServiceWorkerURLLoaderJob::StartResponse( | 264 void ServiceWorkerURLLoaderJob::StartResponse( |
257 const ServiceWorkerResponse& response, | 265 const ServiceWorkerResponse& response, |
258 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, | 266 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, |
259 mojom::URLLoaderRequest request, | 267 mojom::URLLoaderRequest request, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 361 } |
354 | 362 |
355 void ServiceWorkerURLLoaderJob::OnComplete( | 363 void ServiceWorkerURLLoaderJob::OnComplete( |
356 const ResourceRequestCompletionStatus& status) { | 364 const ResourceRequestCompletionStatus& status) { |
357 DCHECK_EQ(Status::kSentHeader, status_); | 365 DCHECK_EQ(Status::kSentHeader, status_); |
358 status_ = Status::kCompleted; | 366 status_ = Status::kCompleted; |
359 url_loader_client_->OnComplete(status); | 367 url_loader_client_->OnComplete(status); |
360 } | 368 } |
361 | 369 |
362 } // namespace content | 370 } // namespace content |
OLD | NEW |