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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; | 243 ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; |
| 244 if (response_body_type_ == STREAM) | 244 if (response_body_type_ == STREAM) |
| 245 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; | 245 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; |
| 246 else if (response_body_type_ == BLOB) | 246 else if (response_body_type_ == BLOB) |
| 247 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; | 247 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; |
| 248 RecordResult(result); | 248 RecordResult(result); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ServiceWorkerURLRequestJob::FallbackToNetwork() { | 251 void ServiceWorkerURLRequestJob::FallbackToNetwork() { |
| 252 DCHECK_EQ(NOT_DETERMINED, response_type_); | 252 DCHECK_EQ(NOT_DETERMINED, response_type_); |
| 253 // TODO(shimazu): Remove the condition of FOREIGN_FETCH after figuring out | 253 DCHECK(!IsFallbackToRendererNeeded()); |
| 254 // what to do about CORS preflight and fallbacks for foreign fetch events. | |
| 255 // http://crbug.com/604084 | |
| 256 DCHECK(!IsFallbackToRendererNeeded() || | |
| 257 (fetch_type_ == ServiceWorkerFetchType::FOREIGN_FETCH)); | |
| 258 response_type_ = FALLBACK_TO_NETWORK; | 254 response_type_ = FALLBACK_TO_NETWORK; |
| 259 MaybeStartRequest(); | 255 MaybeStartRequest(); |
| 260 } | 256 } |
| 261 | 257 |
| 262 void ServiceWorkerURLRequestJob::FallbackToNetworkOrRenderer() { | 258 void ServiceWorkerURLRequestJob::FallbackToNetworkOrRenderer() { |
| 263 DCHECK_EQ(NOT_DETERMINED, response_type_); | 259 DCHECK_EQ(NOT_DETERMINED, response_type_); |
| 264 // TODO(shimazu): Remove the condition of FOREIGN_FETCH after figuring out | 260 // TODO(shimazu): Remove the condition of FOREIGN_FETCH after figuring out |
|
horo
2016/08/21 07:42:24
Nit: I think this comment is not appropriate here.
| |
| 265 // what to do about CORS preflight and fallbacks for foreign fetch events. | 261 // what to do about CORS preflight and fallbacks for foreign fetch events. |
| 266 // http://crbug.com/604084 | 262 // http://crbug.com/604084 |
| 267 DCHECK_NE(ServiceWorkerFetchType::FOREIGN_FETCH, fetch_type_); | 263 DCHECK_NE(ServiceWorkerFetchType::FOREIGN_FETCH, fetch_type_); |
| 268 if (IsFallbackToRendererNeeded()) { | 264 if (IsFallbackToRendererNeeded()) { |
| 269 response_type_ = FALLBACK_TO_RENDERER; | 265 response_type_ = FALLBACK_TO_RENDERER; |
| 270 } else { | 266 } else { |
| 271 response_type_ = FALLBACK_TO_NETWORK; | 267 response_type_ = FALLBACK_TO_NETWORK; |
| 272 } | 268 } |
| 273 MaybeStartRequest(); | 269 MaybeStartRequest(); |
| 274 } | 270 } |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 if (ShouldRecordResult()) | 865 if (ShouldRecordResult()) |
| 870 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_RESPONSE); | 866 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_RESPONSE); |
| 871 response_type_ = FALLBACK_TO_NETWORK; | 867 response_type_ = FALLBACK_TO_NETWORK; |
| 872 NotifyRestartRequired(); | 868 NotifyRestartRequired(); |
| 873 return; | 869 return; |
| 874 } | 870 } |
| 875 | 871 |
| 876 void ServiceWorkerURLRequestJob::FinalizeFallbackToRenderer() { | 872 void ServiceWorkerURLRequestJob::FinalizeFallbackToRenderer() { |
| 877 // TODO(mek): http://crbug.com/604084 Figure out what to do about CORS | 873 // TODO(mek): http://crbug.com/604084 Figure out what to do about CORS |
| 878 // preflight and fallbacks for foreign fetch events. | 874 // preflight and fallbacks for foreign fetch events. |
| 879 fall_back_required_ = fetch_type_ != ServiceWorkerFetchType::FOREIGN_FETCH; | 875 DCHECK_NE(fetch_type_, ServiceWorkerFetchType::FOREIGN_FETCH); |
| 876 fall_back_required_ = true; | |
| 880 if (ShouldRecordResult()) | 877 if (ShouldRecordResult()) |
| 881 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_FOR_CORS); | 878 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_FOR_CORS); |
| 882 CreateResponseHeader(400, "Service Worker Fallback Required", | 879 CreateResponseHeader(400, "Service Worker Fallback Required", |
| 883 ServiceWorkerHeaderMap()); | 880 ServiceWorkerHeaderMap()); |
| 884 response_type_ = FALLBACK_TO_RENDERER; | 881 response_type_ = FALLBACK_TO_RENDERER; |
| 885 CommitResponseHeader(); | 882 CommitResponseHeader(); |
| 886 } | 883 } |
| 887 | 884 |
| 888 bool ServiceWorkerURLRequestJob::IsFallbackToRendererNeeded() const { | 885 bool ServiceWorkerURLRequestJob::IsFallbackToRendererNeeded() const { |
| 889 // When the request_mode is |CORS| or |CORS-with-forced-preflight| and the | 886 // When the request_mode is |CORS| or |CORS-with-forced-preflight| and the |
| 890 // origin of the request URL is different from the security origin of the | 887 // origin of the request URL is different from the security origin of the |
| 891 // document, we can't simply fallback to the network in the browser process. | 888 // document, we can't simply fallback to the network in the browser process. |
| 892 // It is because the CORS preflight logic is implemented in the renderer. So | 889 // It is because the CORS preflight logic is implemented in the renderer. So |
| 893 // we return a fall_back_required response to the renderer. | 890 // we return a fall_back_required response to the renderer. |
| 891 // If fetch_type is |FOREIGN_FETCH| any required CORS checks will have already | |
| 892 // been done in the renderer (and if a preflight was necesary the request | |
| 893 // would never have reached foreign fetch), so such requests can always | |
| 894 // fallback to the network directly. | |
| 894 return !IsMainResourceLoad() && | 895 return !IsMainResourceLoad() && |
| 896 fetch_type_ != ServiceWorkerFetchType::FOREIGN_FETCH && | |
| 895 (request_mode_ == FETCH_REQUEST_MODE_CORS || | 897 (request_mode_ == FETCH_REQUEST_MODE_CORS || |
| 896 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) && | 898 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) && |
| 897 !request()->initiator().IsSameOriginWith( | 899 !request()->initiator().IsSameOriginWith( |
| 898 url::Origin(request()->url())); | 900 url::Origin(request()->url())); |
| 899 } | 901 } |
| 900 | 902 |
| 901 void ServiceWorkerURLRequestJob::SetResponseBodyType(ResponseBodyType type) { | 903 void ServiceWorkerURLRequestJob::SetResponseBodyType(ResponseBodyType type) { |
| 902 DCHECK_EQ(response_body_type_, UNKNOWN); | 904 DCHECK_EQ(response_body_type_, UNKNOWN); |
| 903 DCHECK_NE(type, UNKNOWN); | 905 DCHECK_NE(type, UNKNOWN); |
| 904 response_body_type_ = type; | 906 response_body_type_ = type; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), | 1040 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), |
| 1039 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, | 1041 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, |
| 1040 weak_factory_.GetWeakPtr(), active_worker), | 1042 weak_factory_.GetWeakPtr(), active_worker), |
| 1041 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, | 1043 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, |
| 1042 weak_factory_.GetWeakPtr()))); | 1044 weak_factory_.GetWeakPtr()))); |
| 1043 worker_start_time_ = base::TimeTicks::Now(); | 1045 worker_start_time_ = base::TimeTicks::Now(); |
| 1044 fetch_dispatcher_->Run(); | 1046 fetch_dispatcher_->Run(); |
| 1045 } | 1047 } |
| 1046 | 1048 |
| 1047 } // namespace content | 1049 } // namespace content |
| OLD | NEW |