Chromium Code Reviews| 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 <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 // Treat a response whose status is 0 as a Network Error. | 531 // Treat a response whose status is 0 as a Network Error. |
| 532 if (response.status_code == 0) { | 532 if (response.status_code == 0) { |
| 533 NotifyDone( | 533 NotifyDone( |
| 534 net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED)); | 534 net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_FAILED)); |
| 535 return; | 535 return; |
| 536 } | 536 } |
| 537 | 537 |
| 538 fetch_end_time_ = base::TimeTicks::Now(); | 538 fetch_end_time_ = base::TimeTicks::Now(); |
| 539 load_timing_info_.send_end = fetch_end_time_; | 539 load_timing_info_.send_end = fetch_end_time_; |
| 540 | 540 |
| 541 // Creates a new HttpResponseInfo using the the ServiceWorker script's | |
| 542 // HttpResponseInfo to show HTTPS padlock. | |
| 543 // TODO(horo): When we support mixed-content (HTTP) no-cors requests from a | |
| 544 // ServiceWorker, we have to check the security level of the responses. | |
| 545 DCHECK(!http_response_info_); | |
| 546 const net::HttpResponseInfo* main_script_http_info = | |
| 547 provider_host_->active_version()->GetMainScriptHttpResponseInfo(); | |
| 548 DCHECK(main_script_http_info); | |
| 549 http_response_info_.reset(new net::HttpResponseInfo(*main_script_http_info)); | |
| 550 | |
| 541 // Set up a request for reading the stream. | 551 // Set up a request for reading the stream. |
| 542 if (response.stream_url.is_valid()) { | 552 if (response.stream_url.is_valid()) { |
| 543 DCHECK(response.blob_uuid.empty()); | 553 DCHECK(response.blob_uuid.empty()); |
| 544 DCHECK(provider_host_->active_version()); | 554 DCHECK(provider_host_->active_version()); |
| 545 streaming_version_ = provider_host_->active_version(); | 555 streaming_version_ = provider_host_->active_version(); |
| 546 streaming_version_->AddStreamingURLRequestJob(this); | 556 streaming_version_->AddStreamingURLRequestJob(this); |
| 547 response_url_ = response.url; | 557 response_url_ = response.url; |
| 548 service_worker_response_type_ = response.response_type; | 558 service_worker_response_type_ = response.response_type; |
| 549 CreateResponseHeader( | 559 CreateResponseHeader( |
| 550 response.status_code, response.status_text, response.headers); | 560 response.status_code, response.status_text, response.headers); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 std::string header; | 613 std::string header; |
| 604 header.reserve(it->first.size() + 2 + it->second.size()); | 614 header.reserve(it->first.size() + 2 + it->second.size()); |
| 605 header.append(it->first); | 615 header.append(it->first); |
| 606 header.append(": "); | 616 header.append(": "); |
| 607 header.append(it->second); | 617 header.append(it->second); |
| 608 http_response_headers_->AddHeader(header); | 618 http_response_headers_->AddHeader(header); |
| 609 } | 619 } |
| 610 } | 620 } |
| 611 | 621 |
| 612 void ServiceWorkerURLRequestJob::CommitResponseHeader() { | 622 void ServiceWorkerURLRequestJob::CommitResponseHeader() { |
| 613 http_response_info_.reset(new net::HttpResponseInfo()); | 623 if (!http_response_info_) |
| 624 http_response_info_.reset(new net::HttpResponseInfo()); | |
| 614 http_response_info_->headers.swap(http_response_headers_); | 625 http_response_info_->headers.swap(http_response_headers_); |
| 626 http_response_info_->vary_data = net::HttpVaryData(); | |
| 627 http_response_info_->metadata = nullptr; | |
| 615 NotifyHeadersComplete(); | 628 NotifyHeadersComplete(); |
|
Ryan Sleevi
2015/01/30 23:20:43
My understanding is that |request_time| and |respo
horo
2015/01/31 08:34:07
Ah, in current implementation, info->request_time
| |
| 616 } | 629 } |
| 617 | 630 |
| 618 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { | 631 void ServiceWorkerURLRequestJob::DeliverErrorResponse() { |
| 619 // TODO(falken): Print an error to the console of the ServiceWorker and of | 632 // TODO(falken): Print an error to the console of the ServiceWorker and of |
| 620 // the requesting page. | 633 // the requesting page. |
| 621 CreateResponseHeader( | 634 CreateResponseHeader( |
| 622 500, "Service Worker Response Error", ServiceWorkerHeaderMap()); | 635 500, "Service Worker Response Error", ServiceWorkerHeaderMap()); |
| 623 CommitResponseHeader(); | 636 CommitResponseHeader(); |
| 624 } | 637 } |
| 625 | 638 |
| 626 void ServiceWorkerURLRequestJob::ClearStream() { | 639 void ServiceWorkerURLRequestJob::ClearStream() { |
| 627 if (streaming_version_) { | 640 if (streaming_version_) { |
| 628 streaming_version_->RemoveStreamingURLRequestJob(this); | 641 streaming_version_->RemoveStreamingURLRequestJob(this); |
| 629 streaming_version_ = nullptr; | 642 streaming_version_ = nullptr; |
| 630 } | 643 } |
| 631 if (stream_) { | 644 if (stream_) { |
| 632 stream_->RemoveReadObserver(this); | 645 stream_->RemoveReadObserver(this); |
| 633 stream_->Abort(); | 646 stream_->Abort(); |
| 634 stream_ = nullptr; | 647 stream_ = nullptr; |
| 635 } | 648 } |
| 636 if (!waiting_stream_url_.is_empty()) { | 649 if (!waiting_stream_url_.is_empty()) { |
| 637 StreamRegistry* stream_registry = | 650 StreamRegistry* stream_registry = |
| 638 GetStreamContextForResourceContext(resource_context_)->registry(); | 651 GetStreamContextForResourceContext(resource_context_)->registry(); |
| 639 stream_registry->RemoveRegisterObserver(waiting_stream_url_); | 652 stream_registry->RemoveRegisterObserver(waiting_stream_url_); |
| 640 stream_registry->AbortPendingStream(waiting_stream_url_); | 653 stream_registry->AbortPendingStream(waiting_stream_url_); |
| 641 } | 654 } |
| 642 } | 655 } |
| 643 | 656 |
| 644 } // namespace content | 657 } // namespace content |
| OLD | NEW |