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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
6 rights reserved. | 6 rights reserved. |
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
8 | 8 |
9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 // Fall back to the network if the archive doesn't contain the resource. | 413 // Fall back to the network if the archive doesn't contain the resource. |
414 if (!archiveResource) | 414 if (!archiveResource) |
415 return nullptr; | 415 return nullptr; |
416 data = archiveResource->data(); | 416 data = archiveResource->data(); |
417 response.setURL(url); | 417 response.setURL(url); |
418 response.setMimeType(archiveResource->mimeType()); | 418 response.setMimeType(archiveResource->mimeType()); |
419 response.setExpectedContentLength(data->size()); | 419 response.setExpectedContentLength(data->size()); |
420 response.setTextEncodingName(archiveResource->textEncoding()); | 420 response.setTextEncodingName(archiveResource->textEncoding()); |
421 } | 421 } |
422 | 422 |
423 Resource* resource = factory.create(request.resourceRequest(), | 423 Resource* resource = |
424 request.options(), request.charset()); | 424 factory.create(request.resourceRequest(), request.options(), |
| 425 request.charset(), &context()); |
425 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad()); | 426 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad()); |
426 // FIXME: We should provide a body stream here. | 427 // FIXME: We should provide a body stream here. |
427 resource->responseReceived(response, nullptr); | 428 resource->responseReceived(response, nullptr); |
428 resource->setDataBufferingPolicy(BufferData); | 429 resource->setDataBufferingPolicy(BufferData); |
429 if (data->size()) | 430 if (data->size()) |
430 resource->setResourceBuffer(data); | 431 resource->setResourceBuffer(data); |
431 resource->setIdentifier(createUniqueIdentifier()); | 432 resource->setIdentifier(createUniqueIdentifier()); |
432 resource->setCacheIdentifier(cacheIdentifier); | 433 resource->setCacheIdentifier(cacheIdentifier); |
433 resource->finish(); | 434 resource->finish(); |
434 | 435 |
435 if (!substituteData.isValid()) | 436 if (!substituteData.isValid()) |
436 memoryCache()->add(resource); | 437 memoryCache()->add(resource); |
437 | 438 |
438 return resource; | 439 return resource; |
439 } | 440 } |
440 | 441 |
441 Resource* ResourceFetcher::resourceForBlockedRequest( | 442 Resource* ResourceFetcher::resourceForBlockedRequest( |
442 const FetchRequest& request, | 443 const FetchRequest& request, |
443 const ResourceFactory& factory, | 444 const ResourceFactory& factory, |
444 ResourceRequestBlockedReason blockedReason) { | 445 ResourceRequestBlockedReason blockedReason) { |
445 Resource* resource = factory.create(request.resourceRequest(), | 446 Resource* resource = |
446 request.options(), request.charset()); | 447 factory.create(request.resourceRequest(), request.options(), |
| 448 request.charset(), &context()); |
447 resource->error(ResourceError::cancelledDueToAccessCheckError(request.url(), | 449 resource->error(ResourceError::cancelledDueToAccessCheckError(request.url(), |
448 blockedReason)); | 450 blockedReason)); |
449 return resource; | 451 return resource; |
450 } | 452 } |
451 | 453 |
452 void ResourceFetcher::makePreloadedResourceBlockOnloadIfNeeded( | 454 void ResourceFetcher::makePreloadedResourceBlockOnloadIfNeeded( |
453 Resource* resource, | 455 Resource* resource, |
454 const FetchRequest& request) { | 456 const FetchRequest& request) { |
455 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue | 457 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue |
456 // to not-block even after being preloaded and discovered. | 458 // to not-block even after being preloaded and discovered. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; | 577 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; |
576 if (isStaticData) { | 578 if (isStaticData) { |
577 resource = resourceForStaticData(request, factory, substituteData); | 579 resource = resourceForStaticData(request, factory, substituteData); |
578 // Abort the request if the archive doesn't contain the resource, except in | 580 // Abort the request if the archive doesn't contain the resource, except in |
579 // the case of data URLs which might have resources such as fonts that need | 581 // the case of data URLs which might have resources such as fonts that need |
580 // to be decoded only on demand. These data URLs are allowed to be | 582 // to be decoded only on demand. These data URLs are allowed to be |
581 // processed using the normal ResourceFetcher machinery. | 583 // processed using the normal ResourceFetcher machinery. |
582 if (!resource && !isDataUrl && m_archive) | 584 if (!resource && !isDataUrl && m_archive) |
583 return nullptr; | 585 return nullptr; |
584 } | 586 } |
585 if (!resource) { | 587 if (!resource && isMainThread()) { |
586 resource = | 588 resource = |
587 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); | 589 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); |
588 } | 590 } |
589 | 591 |
590 // If we got a preloaded resource from the cache for a non-preload request, | 592 // If we got a preloaded resource from the cache for a non-preload request, |
591 // we may need to make it block the onload event. | 593 // we may need to make it block the onload event. |
592 makePreloadedResourceBlockOnloadIfNeeded(resource, request); | 594 makePreloadedResourceBlockOnloadIfNeeded(resource, request); |
593 | 595 |
594 const RevalidationPolicy policy = determineRevalidationPolicy( | 596 const RevalidationPolicy policy = determineRevalidationPolicy( |
595 factory.type(), request, resource, isStaticData); | 597 factory.type(), request, resource, isStaticData); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); | 726 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); |
725 | 727 |
726 resource->setRevalidatingRequest(revalidatingRequest); | 728 resource->setRevalidatingRequest(revalidatingRequest); |
727 } | 729 } |
728 | 730 |
729 Resource* ResourceFetcher::createResourceForLoading( | 731 Resource* ResourceFetcher::createResourceForLoading( |
730 FetchRequest& request, | 732 FetchRequest& request, |
731 const String& charset, | 733 const String& charset, |
732 const ResourceFactory& factory) { | 734 const ResourceFactory& factory) { |
733 const String cacheIdentifier = getCacheIdentifier(); | 735 const String cacheIdentifier = getCacheIdentifier(); |
734 DCHECK(!memoryCache()->resourceForURL(request.resourceRequest().url(), | 736 |
| 737 DCHECK(!isMainThread() || |
| 738 !memoryCache()->resourceForURL(request.resourceRequest().url(), |
735 cacheIdentifier)); | 739 cacheIdentifier)); |
736 | 740 |
737 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " | 741 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " |
738 << request.resourceRequest().url().elidedString(); | 742 << request.resourceRequest().url().elidedString(); |
739 | 743 |
740 Resource* resource = | 744 Resource* resource = factory.create(request.resourceRequest(), |
741 factory.create(request.resourceRequest(), request.options(), charset); | 745 request.options(), charset, &context()); |
742 resource->setLinkPreload(request.isLinkPreload()); | 746 resource->setLinkPreload(request.isLinkPreload()); |
743 if (request.isSpeculativePreload()) { | 747 if (request.isSpeculativePreload()) { |
744 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); | 748 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); |
745 } | 749 } |
746 resource->setCacheIdentifier(cacheIdentifier); | 750 resource->setCacheIdentifier(cacheIdentifier); |
747 | 751 |
748 // - Don't add main resource to cache to prevent reuse. | 752 // - Don't add main resource to cache to prevent reuse. |
749 // - Don't add the resource if its body will not be stored. | 753 // - Don't add the resource if its body will not be stored. |
750 if (factory.type() != Resource::MainResource && | 754 if (isMainThread() && factory.type() != Resource::MainResource && |
751 request.options().dataBufferingPolicy != DoNotBufferData) { | 755 request.options().dataBufferingPolicy != DoNotBufferData) { |
752 memoryCache()->add(resource); | 756 memoryCache()->add(resource); |
753 } | 757 } |
754 return resource; | 758 return resource; |
755 } | 759 } |
756 | 760 |
757 void ResourceFetcher::storePerformanceTimingInitiatorInformation( | 761 void ResourceFetcher::storePerformanceTimingInitiatorInformation( |
758 Resource* resource) { | 762 Resource* resource) { |
759 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; | 763 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
760 if (fetchInitiator == FetchInitiatorTypeNames::internal) | 764 if (fetchInitiator == FetchInitiatorTypeNames::internal) |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 DCHECK(loader); | 1252 DCHECK(loader); |
1249 // TODO(yoav): Convert CHECK to DCHECK if no crash reports come in. | 1253 // TODO(yoav): Convert CHECK to DCHECK if no crash reports come in. |
1250 CHECK(m_loaders.contains(loader)); | 1254 CHECK(m_loaders.contains(loader)); |
1251 m_nonBlockingLoaders.insert(loader); | 1255 m_nonBlockingLoaders.insert(loader); |
1252 m_loaders.erase(loader); | 1256 m_loaders.erase(loader); |
1253 } | 1257 } |
1254 | 1258 |
1255 bool ResourceFetcher::startLoad(Resource* resource) { | 1259 bool ResourceFetcher::startLoad(Resource* resource) { |
1256 DCHECK(resource); | 1260 DCHECK(resource); |
1257 DCHECK(resource->stillNeedsLoad()); | 1261 DCHECK(resource->stillNeedsLoad()); |
1258 if (!context().shouldLoadNewResource(resource->getType())) { | 1262 if (isMainThread() && !context().shouldLoadNewResource(resource->getType())) { |
1259 memoryCache()->remove(resource); | 1263 memoryCache()->remove(resource); |
1260 return false; | 1264 return false; |
1261 } | 1265 } |
1262 | 1266 |
1263 ResourceRequest request(resource->resourceRequest()); | 1267 ResourceRequest request(resource->resourceRequest()); |
1264 ResourceResponse response; | 1268 ResourceResponse response; |
1265 | 1269 |
1266 blink::probe::PlatformSendRequest probe(&context(), resource->identifier(), | 1270 blink::probe::PlatformSendRequest probe(&context(), resource->identifier(), |
1267 request, response, | 1271 request, response, |
1268 resource->options().initiatorInfo); | 1272 resource->options().initiatorInfo); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 visitor->trace(m_context); | 1575 visitor->trace(m_context); |
1572 visitor->trace(m_archive); | 1576 visitor->trace(m_archive); |
1573 visitor->trace(m_loaders); | 1577 visitor->trace(m_loaders); |
1574 visitor->trace(m_nonBlockingLoaders); | 1578 visitor->trace(m_nonBlockingLoaders); |
1575 visitor->trace(m_documentResources); | 1579 visitor->trace(m_documentResources); |
1576 visitor->trace(m_preloads); | 1580 visitor->trace(m_preloads); |
1577 visitor->trace(m_resourceTimingInfoMap); | 1581 visitor->trace(m_resourceTimingInfoMap); |
1578 } | 1582 } |
1579 | 1583 |
1580 } // namespace blink | 1584 } // namespace blink |
OLD | NEW |