Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job.cc

Issue 2255383002: Allow a foreign fetch event handler to not handle an event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove comment from FallbackToNetworkOrRenderer Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
265 // what to do about CORS preflight and fallbacks for foreign fetch events.
266 // http://crbug.com/604084
267 DCHECK_NE(ServiceWorkerFetchType::FOREIGN_FETCH, fetch_type_); 260 DCHECK_NE(ServiceWorkerFetchType::FOREIGN_FETCH, fetch_type_);
268 if (IsFallbackToRendererNeeded()) { 261 if (IsFallbackToRendererNeeded()) {
269 response_type_ = FALLBACK_TO_RENDERER; 262 response_type_ = FALLBACK_TO_RENDERER;
270 } else { 263 } else {
271 response_type_ = FALLBACK_TO_NETWORK; 264 response_type_ = FALLBACK_TO_NETWORK;
272 } 265 }
273 MaybeStartRequest(); 266 MaybeStartRequest();
274 } 267 }
275 268
276 void ServiceWorkerURLRequestJob::ForwardToServiceWorker() { 269 void ServiceWorkerURLRequestJob::ForwardToServiceWorker() {
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 if (ShouldRecordResult()) 862 if (ShouldRecordResult())
870 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_RESPONSE); 863 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_RESPONSE);
871 response_type_ = FALLBACK_TO_NETWORK; 864 response_type_ = FALLBACK_TO_NETWORK;
872 NotifyRestartRequired(); 865 NotifyRestartRequired();
873 return; 866 return;
874 } 867 }
875 868
876 void ServiceWorkerURLRequestJob::FinalizeFallbackToRenderer() { 869 void ServiceWorkerURLRequestJob::FinalizeFallbackToRenderer() {
877 // TODO(mek): http://crbug.com/604084 Figure out what to do about CORS 870 // TODO(mek): http://crbug.com/604084 Figure out what to do about CORS
878 // preflight and fallbacks for foreign fetch events. 871 // preflight and fallbacks for foreign fetch events.
879 fall_back_required_ = fetch_type_ != ServiceWorkerFetchType::FOREIGN_FETCH; 872 DCHECK_NE(fetch_type_, ServiceWorkerFetchType::FOREIGN_FETCH);
873 fall_back_required_ = true;
880 if (ShouldRecordResult()) 874 if (ShouldRecordResult())
881 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_FOR_CORS); 875 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_FALLBACK_FOR_CORS);
882 CreateResponseHeader(400, "Service Worker Fallback Required", 876 CreateResponseHeader(400, "Service Worker Fallback Required",
883 ServiceWorkerHeaderMap()); 877 ServiceWorkerHeaderMap());
884 response_type_ = FALLBACK_TO_RENDERER; 878 response_type_ = FALLBACK_TO_RENDERER;
885 CommitResponseHeader(); 879 CommitResponseHeader();
886 } 880 }
887 881
888 bool ServiceWorkerURLRequestJob::IsFallbackToRendererNeeded() const { 882 bool ServiceWorkerURLRequestJob::IsFallbackToRendererNeeded() const {
889 // When the request_mode is |CORS| or |CORS-with-forced-preflight| and the 883 // 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 884 // 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. 885 // 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 886 // It is because the CORS preflight logic is implemented in the renderer. So
893 // we return a fall_back_required response to the renderer. 887 // we return a fall_back_required response to the renderer.
888 // If fetch_type is |FOREIGN_FETCH| any required CORS checks will have already
889 // been done in the renderer (and if a preflight was necesary the request
890 // would never have reached foreign fetch), so such requests can always
891 // fallback to the network directly.
894 return !IsMainResourceLoad() && 892 return !IsMainResourceLoad() &&
893 fetch_type_ != ServiceWorkerFetchType::FOREIGN_FETCH &&
895 (request_mode_ == FETCH_REQUEST_MODE_CORS || 894 (request_mode_ == FETCH_REQUEST_MODE_CORS ||
896 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) && 895 request_mode_ == FETCH_REQUEST_MODE_CORS_WITH_FORCED_PREFLIGHT) &&
897 !request()->initiator().IsSameOriginWith( 896 !request()->initiator().IsSameOriginWith(
898 url::Origin(request()->url())); 897 url::Origin(request()->url()));
899 } 898 }
900 899
901 void ServiceWorkerURLRequestJob::SetResponseBodyType(ResponseBodyType type) { 900 void ServiceWorkerURLRequestJob::SetResponseBodyType(ResponseBodyType type) {
902 DCHECK_EQ(response_body_type_, UNKNOWN); 901 DCHECK_EQ(response_body_type_, UNKNOWN);
903 DCHECK_NE(type, UNKNOWN); 902 DCHECK_NE(type, UNKNOWN);
904 response_body_type_ = type; 903 response_body_type_ = type;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), 1039 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(),
1041 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, 1040 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent,
1042 weak_factory_.GetWeakPtr(), active_worker), 1041 weak_factory_.GetWeakPtr(), active_worker),
1043 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, 1042 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent,
1044 weak_factory_.GetWeakPtr()))); 1043 weak_factory_.GetWeakPtr())));
1045 worker_start_time_ = base::TimeTicks::Now(); 1044 worker_start_time_ = base::TimeTicks::Now();
1046 fetch_dispatcher_->Run(); 1045 fetch_dispatcher_->Run();
1047 } 1046 }
1048 1047
1049 } // namespace content 1048 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698