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

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

Issue 137983010: (Re)organize handling of CORS access control during resource loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: HTMLImportLoader no longer needs a ResourceFetcher Created 6 years, 11 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 | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/fetch/ResourceLoaderHost.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 m_resource->setSerializedCachedMetadata(data, length); 286 m_resource->setSerializedCachedMetadata(data, length);
287 } 287 }
288 288
289 void ResourceLoader::didSendData(blink::WebURLLoader*, unsigned long long bytesS ent, unsigned long long totalBytesToBeSent) 289 void ResourceLoader::didSendData(blink::WebURLLoader*, unsigned long long bytesS ent, unsigned long long totalBytesToBeSent)
290 { 290 {
291 ASSERT(m_state == Initialized); 291 ASSERT(m_state == Initialized);
292 RefPtr<ResourceLoader> protect(this); 292 RefPtr<ResourceLoader> protect(this);
293 m_resource->didSendData(bytesSent, totalBytesToBeSent); 293 m_resource->didSendData(bytesSent, totalBytesToBeSent);
294 } 294 }
295 295
296 bool ResourceLoader::responseNeedsAccessControlCheck() const
297 {
298 // If the fetch was (potentially) CORS enabled, an access control check of t he response is required.
299 return m_options.corsEnabled == IsCORSEnabled;
300 }
301
296 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR LResponse& response) 302 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR LResponse& response)
297 { 303 {
298 ASSERT(!response.isNull()); 304 ASSERT(!response.isNull());
299 ASSERT(m_state == Initialized); 305 ASSERT(m_state == Initialized);
300 306
301 bool isMultipartPayload = response.isMultipartPayload(); 307 bool isMultipartPayload = response.isMultipartPayload();
302 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse); 308 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted | | m_connectionState == ConnectionStateReceivedResponse);
303 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved. 309 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo nse can be interleaved.
304 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); 310 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition);
305 m_connectionState = ConnectionStateReceivedResponse; 311 m_connectionState = ConnectionStateReceivedResponse;
306 312
313 const ResourceResponse& resourceResponse = response.toResourceResponse();
314
315 if (responseNeedsAccessControlCheck()) {
316 m_resource->setResponse(resourceResponse);
317 if (!m_host->canAccessResource(m_resource, response.url())) {
318 cancel();
319 return;
320 }
321 }
322
307 // Reference the object in this method since the additional processing can d o 323 // Reference the object in this method since the additional processing can d o
308 // anything including removing the last reference to this object. 324 // anything including removing the last reference to this object.
309 RefPtr<ResourceLoader> protect(this); 325 RefPtr<ResourceLoader> protect(this);
310 m_resource->responseReceived(response.toResourceResponse()); 326 m_resource->responseReceived(resourceResponse);
311 if (m_state == Terminated) 327 if (m_state == Terminated)
312 return; 328 return;
313 329
314 m_host->didReceiveResponse(m_resource, response.toResourceResponse()); 330 m_host->didReceiveResponse(m_resource, resourceResponse);
315 331
316 if (response.toResourceResponse().isMultipart()) { 332 if (response.toResourceResponse().isMultipart()) {
317 // We don't count multiParts in a ResourceFetcher's request count 333 // We don't count multiParts in a ResourceFetcher's request count
318 m_requestCountTracker.clear(); 334 m_requestCountTracker.clear();
319 if (!m_resource->isImage()) { 335 if (!m_resource->isImage()) {
320 cancel(); 336 cancel();
321 return; 337 return;
322 } 338 }
323 } else if (isMultipartPayload) { 339 } else if (isMultipartPayload) {
324 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once. 340 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 didReceiveResponse(0, responseOut); 449 didReceiveResponse(0, responseOut);
434 if (m_state == Terminated) 450 if (m_state == Terminated)
435 return; 451 return;
436 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo(); 452 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse() .resourceLoadInfo();
437 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL oadInfo ? resourceLoadInfo->encodedDataLength : -1); 453 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL oadInfo ? resourceLoadInfo->encodedDataLength : -1);
438 m_resource->setResourceBuffer(dataOut); 454 m_resource->setResourceBuffer(dataOut);
439 didFinishLoading(0, monotonicallyIncreasingTime()); 455 didFinishLoading(0, monotonicallyIncreasingTime());
440 } 456 }
441 457
442 } 458 }
OLDNEW
« no previous file with comments | « Source/core/fetch/ResourceLoader.h ('k') | Source/core/fetch/ResourceLoaderHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698