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_write_to_cache_job.h" | 5 #include "content/browser/service_worker/service_worker_write_to_cache_job.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
9 #include "content/browser/service_worker/service_worker_disk_cache.h" | 9 #include "content/browser/service_worker/service_worker_disk_cache.h" |
10 #include "content/browser/service_worker/service_worker_metrics.h" | 10 #include "content/browser/service_worker/service_worker_metrics.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 net::SSLCertRequestInfo* cert_request_info) { | 298 net::SSLCertRequestInfo* cert_request_info) { |
299 DCHECK_EQ(net_request_, request); | 299 DCHECK_EQ(net_request_, request); |
300 TRACE_EVENT0("ServiceWorker", | 300 TRACE_EVENT0("ServiceWorker", |
301 "ServiceWorkerWriteToCacheJob::OnCertificateRequested"); | 301 "ServiceWorkerWriteToCacheJob::OnCertificateRequested"); |
302 // TODO(michaeln): Pass this thru to our jobs client. | 302 // TODO(michaeln): Pass this thru to our jobs client. |
303 // see NotifyCertificateRequested. | 303 // see NotifyCertificateRequested. |
304 AsyncNotifyDoneHelper(net::URLRequestStatus( | 304 AsyncNotifyDoneHelper(net::URLRequestStatus( |
305 net::URLRequestStatus::FAILED, net::ERR_FAILED)); | 305 net::URLRequestStatus::FAILED, net::ERR_FAILED)); |
306 } | 306 } |
307 | 307 |
308 void ServiceWorkerWriteToCacheJob:: OnSSLCertificateError( | 308 void ServiceWorkerWriteToCacheJob::OnSSLCertificateError( |
309 net::URLRequest* request, | 309 net::URLRequest* request, |
310 const net::SSLInfo& ssl_info, | 310 const net::SSLInfo& ssl_info, |
311 bool fatal) { | 311 bool fatal) { |
312 DCHECK_EQ(net_request_, request); | 312 DCHECK_EQ(net_request_, request); |
313 TRACE_EVENT0("ServiceWorker", | 313 TRACE_EVENT0("ServiceWorker", |
314 "ServiceWorkerWriteToCacheJob::OnSSLCertificateError"); | 314 "ServiceWorkerWriteToCacheJob::OnSSLCertificateError"); |
315 // TODO(michaeln): Pass this thru to our jobs client, | 315 // TODO(michaeln): Pass this thru to our jobs client, |
316 // see NotifySSLCertificateError. | 316 // see NotifySSLCertificateError. |
317 AsyncNotifyDoneHelper(net::URLRequestStatus( | 317 AsyncNotifyDoneHelper(net::URLRequestStatus( |
318 net::URLRequestStatus::FAILED, net::ERR_FAILED)); | 318 net::URLRequestStatus::FAILED, net::ERR_INSECURE_RESPONSE)); |
319 } | 319 } |
320 | 320 |
321 void ServiceWorkerWriteToCacheJob::OnBeforeNetworkStart( | 321 void ServiceWorkerWriteToCacheJob::OnBeforeNetworkStart( |
322 net::URLRequest* request, | 322 net::URLRequest* request, |
323 bool* defer) { | 323 bool* defer) { |
324 DCHECK_EQ(net_request_, request); | 324 DCHECK_EQ(net_request_, request); |
325 TRACE_EVENT0("ServiceWorker", | 325 TRACE_EVENT0("ServiceWorker", |
326 "ServiceWorkerWriteToCacheJob::OnBeforeNetworkStart"); | 326 "ServiceWorkerWriteToCacheJob::OnBeforeNetworkStart"); |
327 NotifyBeforeNetworkStart(defer); | 327 NotifyBeforeNetworkStart(defer); |
328 } | 328 } |
329 | 329 |
330 void ServiceWorkerWriteToCacheJob::OnResponseStarted( | 330 void ServiceWorkerWriteToCacheJob::OnResponseStarted( |
331 net::URLRequest* request) { | 331 net::URLRequest* request) { |
332 DCHECK_EQ(net_request_, request); | 332 DCHECK_EQ(net_request_, request); |
333 if (!request->status().is_success()) { | 333 if (!request->status().is_success()) { |
334 AsyncNotifyDoneHelper(request->status()); | 334 AsyncNotifyDoneHelper(request->status()); |
335 return; | 335 return; |
336 } | 336 } |
337 if (request->GetResponseCode() / 100 != 2) { | 337 if (request->GetResponseCode() / 100 != 2) { |
338 AsyncNotifyDoneHelper(net::URLRequestStatus( | 338 AsyncNotifyDoneHelper(net::URLRequestStatus( |
339 net::URLRequestStatus::FAILED, net::ERR_FAILED)); | 339 net::URLRequestStatus::FAILED, net::ERR_FAILED)); |
340 // TODO(michaeln): Instead of error'ing immediately, send the net | 340 // TODO(michaeln): Instead of error'ing immediately, send the net |
341 // response to our consumer, just don't cache it? | 341 // response to our consumer, just don't cache it? |
342 return; | 342 return; |
343 } | 343 } |
| 344 // OnSSLCertificateError is not called when the HTTPS connection is reused. |
| 345 // So we check cert_status here. |
| 346 if (net::IsCertStatusError(request->ssl_info().cert_status)) { |
| 347 AsyncNotifyDoneHelper(net::URLRequestStatus( |
| 348 net::URLRequestStatus::FAILED, net::ERR_INSECURE_RESPONSE)); |
| 349 return; |
| 350 } |
344 // To prevent most user-uploaded content from being used as a serviceworker. | 351 // To prevent most user-uploaded content from being used as a serviceworker. |
345 if (version_->script_url() == url_) { | 352 if (version_->script_url() == url_) { |
346 std::string mime_type; | 353 std::string mime_type; |
347 request->GetMimeType(&mime_type); | 354 request->GetMimeType(&mime_type); |
348 if (mime_type != "application/x-javascript" && | 355 if (mime_type != "application/x-javascript" && |
349 mime_type != "text/javascript" && | 356 mime_type != "text/javascript" && |
350 mime_type != "application/javascript") { | 357 mime_type != "application/javascript") { |
351 AsyncNotifyDoneHelper(net::URLRequestStatus( | 358 AsyncNotifyDoneHelper(net::URLRequestStatus( |
352 net::URLRequestStatus::FAILED, net::ERR_INSECURE_RESPONSE)); | 359 net::URLRequestStatus::FAILED, net::ERR_INSECURE_RESPONSE)); |
353 return; | 360 return; |
(...skipping 29 matching lines...) Expand all Loading... |
383 const net::URLRequestStatus& status) { | 390 const net::URLRequestStatus& status) { |
384 DCHECK(!status.is_io_pending()); | 391 DCHECK(!status.is_io_pending()); |
385 DCHECK(!did_notify_finished_); | 392 DCHECK(!did_notify_finished_); |
386 version_->script_cache_map()->NotifyFinishedCaching(url_, status); | 393 version_->script_cache_map()->NotifyFinishedCaching(url_, status); |
387 did_notify_finished_ = true; | 394 did_notify_finished_ = true; |
388 SetStatus(status); | 395 SetStatus(status); |
389 NotifyDone(status); | 396 NotifyDone(status); |
390 } | 397 } |
391 | 398 |
392 } // namespace content | 399 } // namespace content |
OLD | NEW |