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_, nullptr); |
186 response_head_, base::nullopt /* TODO(scottmg): ssl info */, | |
187 mojom::DownloadedTempFilePtr()); | |
188 } | 186 } |
189 | 187 |
190 void ServiceWorkerURLLoaderJob::CommitCompleted(int error_code) { | 188 void ServiceWorkerURLLoaderJob::CommitCompleted(int error_code) { |
191 DCHECK_LT(status_, Status::kCompleted); | 189 DCHECK_LT(status_, Status::kCompleted); |
192 status_ = Status::kCompleted; | 190 status_ = Status::kCompleted; |
193 ResourceRequestCompletionStatus completion_status; | 191 ResourceRequestCompletionStatus completion_status; |
194 completion_status.error_code = error_code; | 192 completion_status.error_code = error_code; |
195 completion_status.completion_time = base::TimeTicks::Now(); | 193 completion_status.completion_time = base::TimeTicks::Now(); |
196 url_loader_client_->OnComplete(completion_status); | 194 url_loader_client_->OnComplete(completion_status); |
197 } | 195 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 238 |
241 DCHECK_EQ(fetch_result, SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 239 DCHECK_EQ(fetch_result, SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
242 | 240 |
243 // A response with status code 0 is Blink telling us to respond with | 241 // A response with status code 0 is Blink telling us to respond with |
244 // network error. | 242 // network error. |
245 if (response.status_code == 0) { | 243 if (response.status_code == 0) { |
246 DeliverErrorResponse(); | 244 DeliverErrorResponse(); |
247 return; | 245 return; |
248 } | 246 } |
249 | 247 |
| 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 |
250 std::move(loader_callback_) | 257 std::move(loader_callback_) |
251 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, | 258 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, |
252 weak_factory_.GetWeakPtr(), response, | 259 weak_factory_.GetWeakPtr(), response, |
253 base::Passed(std::move(body_as_stream)))); | 260 base::Passed(std::move(body_as_stream)))); |
254 } | 261 } |
255 | 262 |
256 void ServiceWorkerURLLoaderJob::StartResponse( | 263 void ServiceWorkerURLLoaderJob::StartResponse( |
257 const ServiceWorkerResponse& response, | 264 const ServiceWorkerResponse& response, |
258 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, | 265 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, |
259 mojom::URLLoaderRequest request, | 266 mojom::URLLoaderRequest request, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 360 } |
354 | 361 |
355 void ServiceWorkerURLLoaderJob::OnComplete( | 362 void ServiceWorkerURLLoaderJob::OnComplete( |
356 const ResourceRequestCompletionStatus& status) { | 363 const ResourceRequestCompletionStatus& status) { |
357 DCHECK_EQ(Status::kSentHeader, status_); | 364 DCHECK_EQ(Status::kSentHeader, status_); |
358 status_ = Status::kCompleted; | 365 status_ = Status::kCompleted; |
359 url_loader_client_->OnComplete(status); | 366 url_loader_client_->OnComplete(status); |
360 } | 367 } |
361 | 368 |
362 } // namespace content | 369 } // namespace content |
OLD | NEW |