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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceLoader.cpp

Issue 1478103002: [WIP] [service worker] Fix detach controller and fallback to network mechanism (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved.
3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 327
328 bool isMultipartPayload = response.isMultipartPayload(); 328 bool isMultipartPayload = response.isMultipartPayload();
329 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse); 329 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse);
330 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. 330 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved.
331 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); 331 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition);
332 m_connectionState = ConnectionStateReceivedResponse; 332 m_connectionState = ConnectionStateReceivedResponse;
333 333
334 const ResourceResponse& resourceResponse = response.toResourceResponse(); 334 const ResourceResponse& resourceResponse = response.toResourceResponse();
335 TRACE_EVENT1("devtools.timeline", "ResourceReceiveResponse", "data", Inspect orReceiveResponseEvent::data(m_resource->identifier(), resourceResponse)); 335 TRACE_EVENT1("devtools.timeline", "ResourceReceiveResponse", "data", Inspect orReceiveResponseEvent::data(m_resource->identifier(), resourceResponse));
336 336
337 if (responseNeedsAccessControlCheck()) { 337 if (response.wasFetchedViaServiceWorker()) {
338 if (response.wasFetchedViaServiceWorker()) { 338 if (response.wasFallbackRequiredByServiceWorker()) {
339 if (response.wasFallbackRequiredByServiceWorker()) { 339 // Fallback can be required in two cases:
340 // 1) The SW let a cross-origin request fallback to network. In that
341 // case, retry the request without the SW if CORS was enabled;
342 // otherwise, fail the request as disallowed.
343 // 2) The browser failed to dispatch the main resource request to
344 // the SW. In that case, retry the request without the SW.
345 if (responseNeedsAccessControlCheck() || m_resource->type() == Resou rce::MainResource) {
340 m_loader->cancel(); 346 m_loader->cancel();
341 m_loader.clear(); 347 m_loader.clear();
342 m_connectionState = ConnectionStateStarted; 348 m_connectionState = ConnectionStateStarted;
343 m_loader = adoptPtr(Platform::current()->createURLLoader()); 349 m_loader = adoptPtr(Platform::current()->createURLLoader());
344 ASSERT(m_loader); 350 ASSERT(m_loader);
345 ASSERT(!m_request.skipServiceWorker()); 351 // skipServiceWorker can be true if this request was redirected.
352 // ASSERT(!m_request.skipServiceWorker());
falken 2015/11/26 10:36:42 This ASSERT is probably meaning to say "we must no
346 m_request.setSkipServiceWorker(true); 353 m_request.setSkipServiceWorker(true);
347 WrappedResourceRequest wrappedRequest(m_request); 354 WrappedResourceRequest wrappedRequest(m_request);
348 m_loader->loadAsynchronously(wrappedRequest, this); 355 m_loader->loadAsynchronously(wrappedRequest, this);
349 return; 356 return;
350 } 357 }
351 } else { 358 }
352 // If the response successfully validated a cached resource, perform 359 } else if (responseNeedsAccessControlCheck()) {
353 // the access control with respect to it. Need to do this right here 360 // If the response successfully validated a cached resource, perform
354 // before the resource switches clients over to that validated resou rce. 361 // the access control with respect to it. Need to do this right here
355 Resource* resource = m_resource; 362 // before the resource switches clients over to that validated resource.
356 if (!resource->isCacheValidator() || resourceResponse.httpStatusCode () != 304) 363 Resource* resource = m_resource;
357 m_resource->setResponse(resourceResponse); 364 if (!resource->isCacheValidator() || resourceResponse.httpStatusCode() ! = 304)
358 if (!m_fetcher->canAccessResource(resource, m_options.securityOrigin .get(), response.url(), ResourceFetcher::ShouldLogAccessControlErrors)) { 365 m_resource->setResponse(resourceResponse);
359 m_fetcher->didReceiveResponse(m_resource, resourceResponse); 366 if (!m_fetcher->canAccessResource(resource, m_options.securityOrigin.get (), response.url(), ResourceFetcher::ShouldLogAccessControlErrors)) {
360 cancel(ResourceError::cancelledDueToAccessCheckError(KURL(respon se.url()))); 367 m_fetcher->didReceiveResponse(m_resource, resourceResponse);
361 return; 368 cancel(ResourceError::cancelledDueToAccessCheckError(KURL(response.u rl())));
362 } 369 return;
363 } 370 }
364 } 371 }
365 372
366 m_resource->responseReceived(resourceResponse, handle.release()); 373 m_resource->responseReceived(resourceResponse, handle.release());
367 if (m_state == Terminated) 374 if (m_state == Terminated)
368 return; 375 return;
369 376
370 m_fetcher->didReceiveResponse(m_resource, resourceResponse); 377 m_fetcher->didReceiveResponse(m_resource, resourceResponse);
371 if (m_state == Terminated) 378 if (m_state == Terminated)
372 return; 379 return;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); 532 didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength);
526 } 533 }
527 534
528 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const 535 ResourceRequest& ResourceLoader::applyOptions(ResourceRequest& request) const
529 { 536 {
530 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials); 537 request.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredC redentials);
531 return request; 538 return request;
532 } 539 }
533 540
534 } 541 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698