OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
rights reserved. |
6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 6 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 return ResourceRequest::TargetIsTextTrack; | 213 return ResourceRequest::TargetIsTextTrack; |
214 case Resource::SVGDocument: | 214 case Resource::SVGDocument: |
215 return ResourceRequest::TargetIsImage; | 215 return ResourceRequest::TargetIsImage; |
216 case Resource::Media: | 216 case Resource::Media: |
217 return ResourceRequest::TargetIsMedia; | 217 return ResourceRequest::TargetIsMedia; |
218 } | 218 } |
219 ASSERT_NOT_REACHED(); | 219 ASSERT_NOT_REACHED(); |
220 return ResourceRequest::TargetIsSubresource; | 220 return ResourceRequest::TargetIsSubresource; |
221 } | 221 } |
222 | 222 |
223 static void reportFontResourceCORSFailed(Resource* resource, const KURL& url, Lo
calFrame* frame) | |
224 { | |
225 FontResource* fontResource = toFontResource(resource); | |
226 fontResource->setCORSFailed(); | |
227 if (frame && frame->document()) | |
228 frame->document()->addConsoleMessage(JSMessageSource, WarningMessageLeve
l, "Blink is considering rejecting non spec-compliant cross-origin web font requ
ests: " + url.string() + ". Please use Access-Control-Allow-Origin to make these
requests spec-compliant."); | |
229 } | |
230 | |
231 ResourceFetcher::ResourceFetcher(DocumentLoader* documentLoader) | 223 ResourceFetcher::ResourceFetcher(DocumentLoader* documentLoader) |
232 : m_document(nullptr) | 224 : m_document(nullptr) |
233 , m_documentLoader(documentLoader) | 225 , m_documentLoader(documentLoader) |
234 , m_requestCount(0) | 226 , m_requestCount(0) |
235 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl
ectDocumentResourcesTimerFired) | 227 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl
ectDocumentResourcesTimerFired) |
236 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi
merFired) | 228 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi
merFired) |
237 , m_autoLoadImages(true) | 229 , m_autoLoadImages(true) |
238 , m_imagesEnabled(true) | 230 , m_imagesEnabled(true) |
239 , m_allowStaleResources(false) | 231 , m_allowStaleResources(false) |
240 { | 232 { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 return false; | 598 return false; |
607 | 599 |
608 if (!sourceOrigin && document()) | 600 if (!sourceOrigin && document()) |
609 sourceOrigin = document()->securityOrigin(); | 601 sourceOrigin = document()->securityOrigin(); |
610 | 602 |
611 if (sourceOrigin->canRequest(url)) | 603 if (sourceOrigin->canRequest(url)) |
612 return true; | 604 return true; |
613 | 605 |
614 String errorDescription; | 606 String errorDescription; |
615 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) { | 607 if (!resource->passesAccessControlCheck(sourceOrigin, errorDescription)) { |
616 // FIXME: Remove later, http://crbug.com/286681 | |
617 if (resource->type() == Resource::Font) { | |
618 reportFontResourceCORSFailed(resource, url, frame()); | |
619 return false; | |
620 } | |
621 | |
622 if (frame() && frame()->document()) { | 608 if (frame() && frame()->document()) { |
623 String resourceType = Resource::resourceTypeToString(resource->type(
), resource->options().initiatorInfo); | 609 String resourceType = Resource::resourceTypeToString(resource->type(
), resource->options().initiatorInfo); |
624 frame()->document()->addConsoleMessage(JSMessageSource, ErrorMessage
Level, resourceType + " from origin '" + SecurityOrigin::create(url)->toString()
+ "' has been blocked from loading by Cross-Origin Resource Sharing policy: " +
errorDescription); | 610 frame()->document()->addConsoleMessage(JSMessageSource, ErrorMessage
Level, resourceType + " from origin '" + SecurityOrigin::create(url)->toString()
+ "' has been blocked from loading by Cross-Origin Resource Sharing policy: " +
errorDescription); |
625 } | 611 } |
626 return false; | 612 return false; |
627 } | 613 } |
628 return true; | 614 return true; |
629 } | 615 } |
630 | 616 |
631 bool ResourceFetcher::shouldLoadNewResource(Resource::Type type) const | 617 bool ResourceFetcher::shouldLoadNewResource(Resource::Type type) const |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 { | 1350 { |
1365 if (!canRequest(resource->type(), request.url(), options, false, FetchReques
t::UseDefaultOriginRestrictionForType)) | 1351 if (!canRequest(resource->type(), request.url(), options, false, FetchReques
t::UseDefaultOriginRestrictionForType)) |
1366 return false; | 1352 return false; |
1367 if (options.corsEnabled == IsCORSEnabled) { | 1353 if (options.corsEnabled == IsCORSEnabled) { |
1368 SecurityOrigin* sourceOrigin = options.securityOrigin.get(); | 1354 SecurityOrigin* sourceOrigin = options.securityOrigin.get(); |
1369 if (!sourceOrigin && document()) | 1355 if (!sourceOrigin && document()) |
1370 sourceOrigin = document()->securityOrigin(); | 1356 sourceOrigin = document()->securityOrigin(); |
1371 | 1357 |
1372 String errorMessage; | 1358 String errorMessage; |
1373 if (!CrossOriginAccessControl::handleRedirect(resource, sourceOrigin, re
quest, redirectResponse, options, errorMessage)) { | 1359 if (!CrossOriginAccessControl::handleRedirect(resource, sourceOrigin, re
quest, redirectResponse, options, errorMessage)) { |
1374 // FIXME: Remove later, http://crbug.com/286681 | |
1375 if (resource->type() == Resource::Font) { | |
1376 reportFontResourceCORSFailed(resource, request.url(), frame()); | |
1377 return false; | |
1378 } | |
1379 | |
1380 if (frame() && frame()->document()) | 1360 if (frame() && frame()->document()) |
1381 frame()->document()->addConsoleMessage(JSMessageSource, ErrorMes
sageLevel, errorMessage); | 1361 frame()->document()->addConsoleMessage(JSMessageSource, ErrorMes
sageLevel, errorMessage); |
1382 return false; | 1362 return false; |
1383 } | 1363 } |
1384 } | 1364 } |
1385 if (resource->type() == Resource::Image && shouldDeferImageLoad(request.url(
))) | 1365 if (resource->type() == Resource::Image && shouldDeferImageLoad(request.url(
))) |
1386 return false; | 1366 return false; |
1387 return true; | 1367 return true; |
1388 } | 1368 } |
1389 | 1369 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 } | 1470 } |
1491 } | 1471 } |
1492 | 1472 |
1493 void ResourceFetcher::trace(Visitor* visitor) | 1473 void ResourceFetcher::trace(Visitor* visitor) |
1494 { | 1474 { |
1495 visitor->trace(m_document); | 1475 visitor->trace(m_document); |
1496 ResourceLoaderHost::trace(visitor); | 1476 ResourceLoaderHost::trace(visitor); |
1497 } | 1477 } |
1498 | 1478 |
1499 } | 1479 } |
OLD | NEW |