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

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

Issue 2676163002: Refactor the forPreload flag to mean speculative preload. (Closed)
Patch Set: Created 3 years, 10 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
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 252
253 FetchContext& ResourceLoader::context() const { 253 FetchContext& ResourceLoader::context() const {
254 return m_fetcher->context(); 254 return m_fetcher->context();
255 } 255 }
256 256
257 ResourceRequestBlockedReason ResourceLoader::canAccessResponse( 257 ResourceRequestBlockedReason ResourceLoader::canAccessResponse(
258 Resource* resource, 258 Resource* resource,
259 const ResourceResponse& response) const { 259 const ResourceResponse& response) const {
260 // Redirects can change the response URL different from one of request. 260 // Redirects can change the response URL different from one of request.
261 bool forPreload = resource->isUnusedPreload(); 261 bool unusedPreload = resource->isUnusedPreload();
262 ResourceRequestBlockedReason blockedReason = 262 ResourceRequestBlockedReason blockedReason =
263 context().canRequest(resource->getType(), resource->resourceRequest(), 263 context().canRequest(resource->getType(), resource->resourceRequest(),
264 response.url(), resource->options(), forPreload, 264 response.url(), resource->options(), unusedPreload,
Charlie Harrison 2017/02/05 18:39:12 nit: inline comment that this bool is used to supp
Yoav Weiss 2017/02/06 09:58:35 enummed
265 FetchRequest::UseDefaultOriginRestrictionForType); 265 FetchRequest::UseDefaultOriginRestrictionForType);
266 if (blockedReason != ResourceRequestBlockedReason::None) 266 if (blockedReason != ResourceRequestBlockedReason::None)
267 return blockedReason; 267 return blockedReason;
268 268
269 SecurityOrigin* sourceOrigin = resource->options().securityOrigin.get(); 269 SecurityOrigin* sourceOrigin = resource->options().securityOrigin.get();
270 if (!sourceOrigin) 270 if (!sourceOrigin)
271 sourceOrigin = context().getSecurityOrigin(); 271 sourceOrigin = context().getSecurityOrigin();
272 272
273 if (sourceOrigin->canRequestNoSuborigin(response.url())) 273 if (sourceOrigin->canRequestNoSuborigin(response.url()))
274 return ResourceRequestBlockedReason::None; 274 return ResourceRequestBlockedReason::None;
275 275
276 // Use the original response instead of the 304 response for a successful 276 // Use the original response instead of the 304 response for a successful
277 // revaldiation. 277 // revaldiation.
278 const ResourceResponse& responseForAccessControl = 278 const ResourceResponse& responseForAccessControl =
279 (resource->isCacheValidator() && response.httpStatusCode() == 304) 279 (resource->isCacheValidator() && response.httpStatusCode() == 304)
280 ? resource->response() 280 ? resource->response()
281 : response; 281 : response;
282 282
283 CrossOriginAccessControl::AccessStatus corsStatus = 283 CrossOriginAccessControl::AccessStatus corsStatus =
284 CrossOriginAccessControl::checkAccess( 284 CrossOriginAccessControl::checkAccess(
285 responseForAccessControl, resource->options().allowCredentials, 285 responseForAccessControl, resource->options().allowCredentials,
286 sourceOrigin); 286 sourceOrigin);
287 if (corsStatus != CrossOriginAccessControl::kAccessAllowed) { 287 if (corsStatus != CrossOriginAccessControl::kAccessAllowed) {
288 resource->setCORSFailed(); 288 resource->setCORSFailed();
289 if (!forPreload) { 289 if (!unusedPreload) {
290 String resourceType = Resource::resourceTypeToString( 290 String resourceType = Resource::resourceTypeToString(
291 resource->getType(), resource->options().initiatorInfo.name); 291 resource->getType(), resource->options().initiatorInfo.name);
292 StringBuilder builder; 292 StringBuilder builder;
293 builder.append("Access to "); 293 builder.append("Access to ");
294 builder.append(resourceType); 294 builder.append(resourceType);
295 builder.append(" at '"); 295 builder.append(" at '");
296 builder.append(response.url().getString()); 296 builder.append(response.url().getString());
297 builder.append("' from origin '"); 297 builder.append("' from origin '");
298 builder.append(sourceOrigin->toString()); 298 builder.append(sourceOrigin->toString());
299 builder.append("' has been blocked by CORS policy: "); 299 builder.append("' has been blocked by CORS policy: ");
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 return; 513 return;
514 514
515 // Don't activate if cache policy is explicitly set. 515 // Don't activate if cache policy is explicitly set.
516 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy) 516 if (request.getCachePolicy() != WebCachePolicy::UseProtocolCachePolicy)
517 return; 517 return;
518 518
519 m_isCacheAwareLoadingActivated = true; 519 m_isCacheAwareLoadingActivated = true;
520 } 520 }
521 521
522 } // namespace blink 522 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698