| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 m_validatedURLs.add(request.resourceRequest().url()); | 268 m_validatedURLs.add(request.resourceRequest().url()); |
| 269 } | 269 } |
| 270 | 270 |
| 271 static PassRefPtr<TracedValue> urlForTraceEvent(const KURL& url) | 271 static PassRefPtr<TracedValue> urlForTraceEvent(const KURL& url) |
| 272 { | 272 { |
| 273 RefPtr<TracedValue> value = TracedValue::create(); | 273 RefPtr<TracedValue> value = TracedValue::create(); |
| 274 value->setString("url", url.string()); | 274 value->setString("url", url.string()); |
| 275 return value.release(); | 275 return value.release(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 ResourcePtr<Resource> ResourceFetcher::preCacheData(const FetchRequest& request,
const ResourceFactory& factory, const SubstituteData& substituteData) | 278 void ResourceFetcher::preCacheData(const FetchRequest& request, const ResourceFa
ctory& factory, const SubstituteData& substituteData) |
| 279 { | 279 { |
| 280 const KURL& url = request.resourceRequest().url(); | 280 const KURL& url = request.resourceRequest().url(); |
| 281 ASSERT(url.protocolIsData() || substituteData.isValid()); | 281 ASSERT(url.protocolIsData() || substituteData.isValid()); |
| 282 | 282 |
| 283 // TODO(japhet): We only send main resource data: urls through WebURLLoader
for the benefit of | 283 // TODO(japhet): We only send main resource data: urls through WebURLLoader
for the benefit of |
| 284 // a service worker test (RenderViewImplTest.ServiceWorkerNetworkProviderSet
up), which is at a | 284 // a service worker test (RenderViewImplTest.ServiceWorkerNetworkProviderSet
up), which is at a |
| 285 // layer where it isn't easy to mock out a network load. It uses data: urls
to emulate the | 285 // layer where it isn't easy to mock out a network load. It uses data: urls
to emulate the |
| 286 // behavior it wants to test, which would otherwise be reserved for network
loads. | 286 // behavior it wants to test, which would otherwise be reserved for network
loads. |
| 287 if ((factory.type() == Resource::MainResource && !substituteData.isValid())
|| factory.type() == Resource::Raw) | 287 if ((factory.type() == Resource::MainResource && !substituteData.isValid())
|| factory.type() == Resource::Raw) |
| 288 return nullptr; | 288 return; |
| 289 | 289 |
| 290 const String cacheIdentifier = getCacheIdentifier(); | 290 const String cacheIdentifier = getCacheIdentifier(); |
| 291 if (Resource* oldResource = memoryCache()->resourceForURL(url, cacheIdentifi
er)) { | 291 if (Resource* oldResource = memoryCache()->resourceForURL(url, cacheIdentifi
er)) { |
| 292 // There's no reason to re-parse if we saved the data from the previous
parse. | 292 // There's no reason to re-parse if we saved the data from the previous
parse. |
| 293 if (request.options().dataBufferingPolicy != DoNotBufferData) | 293 if (request.options().dataBufferingPolicy != DoNotBufferData) |
| 294 return oldResource; | 294 return; |
| 295 memoryCache()->remove(oldResource); | 295 memoryCache()->remove(oldResource); |
| 296 } | 296 } |
| 297 | 297 |
| 298 WebString mimetype; | 298 WebString mimetype; |
| 299 WebString charset; | 299 WebString charset; |
| 300 RefPtr<SharedBuffer> data; | 300 RefPtr<SharedBuffer> data; |
| 301 if (substituteData.isValid()) { | 301 if (substituteData.isValid()) { |
| 302 mimetype = substituteData.mimeType(); | 302 mimetype = substituteData.mimeType(); |
| 303 charset = substituteData.textEncoding(); | 303 charset = substituteData.textEncoding(); |
| 304 data = substituteData.content(); | 304 data = substituteData.content(); |
| 305 } else { | 305 } else { |
| 306 data = PassRefPtr<SharedBuffer>(Platform::current()->parseDataURL(url, m
imetype, charset)); | 306 data = PassRefPtr<SharedBuffer>(Platform::current()->parseDataURL(url, m
imetype, charset)); |
| 307 if (!data) | 307 if (!data) |
| 308 return nullptr; | 308 return; |
| 309 } | 309 } |
| 310 ResourceResponse response(url, mimetype, data->size(), charset, String()); | 310 ResourceResponse response(url, mimetype, data->size(), charset, String()); |
| 311 response.setHTTPStatusCode(200); | 311 response.setHTTPStatusCode(200); |
| 312 response.setHTTPStatusText("OK"); | 312 response.setHTTPStatusText("OK"); |
| 313 | 313 |
| 314 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), r
equest.charset()); | 314 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), request.charset()); |
| 315 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad())
; | 315 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad())
; |
| 316 resource->setOptions(request.options()); | 316 resource->setOptions(request.options()); |
| 317 // FIXME: We should provide a body stream here. | 317 // FIXME: We should provide a body stream here. |
| 318 resource->responseReceived(response, nullptr); | 318 resource->responseReceived(response, nullptr); |
| 319 resource->setDataBufferingPolicy(BufferData); | 319 resource->setDataBufferingPolicy(BufferData); |
| 320 if (data->size()) | 320 if (data->size()) |
| 321 resource->setResourceBuffer(data); | 321 resource->setResourceBuffer(data); |
| 322 resource->setIdentifier(createUniqueIdentifier()); | 322 resource->setIdentifier(createUniqueIdentifier()); |
| 323 resource->setCacheIdentifier(cacheIdentifier); | 323 resource->setCacheIdentifier(cacheIdentifier); |
| 324 resource->finish(); | 324 resource->finish(); |
| 325 memoryCache()->add(resource.get()); | 325 memoryCache()->add(resource.get()); |
| 326 return resource; | |
| 327 } | 326 } |
| 328 | 327 |
| 329 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) | 328 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) |
| 330 { | 329 { |
| 331 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. | 330 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. |
| 332 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { | 331 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { |
| 333 if (m_nonBlockingLoaders) | 332 if (m_nonBlockingLoaders) |
| 334 m_nonBlockingLoaders->remove(resource->loader()); | 333 m_nonBlockingLoaders->remove(resource->loader()); |
| 335 if (!m_loaders) | 334 if (!m_loaders) |
| 336 m_loaders = ResourceLoaderSet::create(); | 335 m_loaders = ResourceLoaderSet::create(); |
| 337 m_loaders->add(resource->loader()); | 336 m_loaders->add(resource->loader()); |
| 338 } | 337 } |
| 339 } | 338 } |
| 340 | 339 |
| 341 ResourcePtr<Resource> ResourceFetcher::requestResource(FetchRequest& request, co
nst ResourceFactory& factory, const SubstituteData& substituteData) | 340 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::requestResource(FetchRequest&
request, const ResourceFactory& factory, const SubstituteData& substituteData) |
| 342 { | 341 { |
| 343 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); | 342 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); |
| 344 | 343 |
| 345 context().upgradeInsecureRequest(request); | 344 context().upgradeInsecureRequest(request); |
| 346 context().addClientHintsIfNecessary(request); | 345 context().addClientHintsIfNecessary(request); |
| 347 context().addCSPHeaderIfNecessary(factory.type(), request); | 346 context().addCSPHeaderIfNecessary(factory.type(), request); |
| 348 | 347 |
| 349 KURL url = request.resourceRequest().url(); | 348 KURL url = request.resourceRequest().url(); |
| 350 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); | 349 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); |
| 351 | 350 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 369 | 368 |
| 370 if (activityLogger) { | 369 if (activityLogger) { |
| 371 Vector<String> argv; | 370 Vector<String> argv; |
| 372 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); | 371 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); |
| 373 argv.append(url); | 372 argv.append(url); |
| 374 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 373 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
| 375 } | 374 } |
| 376 } | 375 } |
| 377 | 376 |
| 378 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); | 377 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); |
| 379 ResourcePtr<Resource> resource; | |
| 380 if (isStaticData) | 378 if (isStaticData) |
| 381 resource = preCacheData(request, factory, substituteData); | 379 preCacheData(request, factory, substituteData); |
| 382 if (!resource) | 380 RefPtrWillBeRawPtr<Resource> resource = memoryCache()->resourceForURL(url, g
etCacheIdentifier()); |
| 383 resource = memoryCache()->resourceForURL(url, getCacheIdentifier()); | |
| 384 | 381 |
| 385 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. | 382 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. |
| 386 moveCachedNonBlockingResourceToBlocking(resource.get(), request); | 383 moveCachedNonBlockingResourceToBlocking(resource.get(), request); |
| 387 | 384 |
| 388 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); | 385 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); |
| 389 | 386 |
| 390 String histogramName = "Blink.MemoryCache.RevalidationPolicy."; | 387 String histogramName = "Blink.MemoryCache.RevalidationPolicy."; |
| 391 if (request.forPreload()) | 388 if (request.forPreload()) |
| 392 histogramName.append("Preload."); | 389 histogramName.append("Preload."); |
| 393 histogramName.append(Resource::resourceTypeName(factory.type())); | 390 histogramName.append(Resource::resourceTypeName(factory.type())); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); | 528 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); |
| 532 | 529 |
| 533 double stalenessLifetime = resource->stalenessLifetime(); | 530 double stalenessLifetime = resource->stalenessLifetime(); |
| 534 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { | 531 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { |
| 535 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); | 532 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); |
| 536 } | 533 } |
| 537 | 534 |
| 538 resource->setRevalidatingRequest(revalidatingRequest); | 535 resource->setRevalidatingRequest(revalidatingRequest); |
| 539 } | 536 } |
| 540 | 537 |
| 541 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re
quest, const String& charset, const ResourceFactory& factory) | 538 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::createResourceForLoading(Fetch
Request& request, const String& charset, const ResourceFactory& factory) |
| 542 { | 539 { |
| 543 const String cacheIdentifier = getCacheIdentifier(); | 540 const String cacheIdentifier = getCacheIdentifier(); |
| 544 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); | 541 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); |
| 545 | 542 |
| 546 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque
st().url().elidedString().latin1().data()); | 543 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque
st().url().elidedString().latin1().data()); |
| 547 | 544 |
| 548 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); | 545 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); |
| 549 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c
harset); | 546 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), charset); |
| 550 resource->setLinkPreload(request.isLinkPreload()); | 547 resource->setLinkPreload(request.isLinkPreload()); |
| 551 resource->setCacheIdentifier(cacheIdentifier); | 548 resource->setCacheIdentifier(cacheIdentifier); |
| 552 | 549 |
| 553 memoryCache()->add(resource.get()); | 550 memoryCache()->add(resource.get()); |
| 554 return resource; | 551 return resource; |
| 555 } | 552 } |
| 556 | 553 |
| 557 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 554 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
| 558 { | 555 { |
| 559 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter
nal) | 556 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter
nal) |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 } | 806 } |
| 810 | 807 |
| 811 void ResourceFetcher::preloadStarted(Resource* resource) | 808 void ResourceFetcher::preloadStarted(Resource* resource) |
| 812 { | 809 { |
| 813 if (m_preloads && m_preloads->contains(resource)) | 810 if (m_preloads && m_preloads->contains(resource)) |
| 814 return; | 811 return; |
| 815 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 812 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
| 816 resource->increasePreloadCount(); | 813 resource->increasePreloadCount(); |
| 817 | 814 |
| 818 if (!m_preloads) | 815 if (!m_preloads) |
| 819 m_preloads = adoptPtrWillBeNoop(new WillBeHeapListHashSet<RawPtrWillBeMe
mber<Resource>>); | 816 m_preloads = adoptPtrWillBeNoop(new WillBeHeapListHashSet<RefPtrWillBeMe
mber<Resource>>); |
| 820 m_preloads->add(resource); | 817 m_preloads->add(resource); |
| 821 | 818 |
| 822 #if PRELOAD_DEBUG | 819 #if PRELOAD_DEBUG |
| 823 printf("PRELOADING %s\n", resource->url().string().latin1().data()); | 820 printf("PRELOADING %s\n", resource->url().string().latin1().data()); |
| 824 #endif | 821 #endif |
| 825 } | 822 } |
| 826 | 823 |
| 827 bool ResourceFetcher::isPreloaded(const KURL& url) const | 824 bool ResourceFetcher::isPreloaded(const KURL& url) const |
| 828 { | 825 { |
| 829 if (m_preloads) { | 826 if (m_preloads) { |
| 830 for (auto resource : *m_preloads) { | 827 for (auto resource : *m_preloads) { |
| 831 if (resource->url() == url) | 828 if (resource->url() == url) |
| 832 return true; | 829 return true; |
| 833 } | 830 } |
| 834 } | 831 } |
| 835 | 832 |
| 836 return false; | 833 return false; |
| 837 } | 834 } |
| 838 | 835 |
| 839 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) | 836 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) |
| 840 { | 837 { |
| 841 #if PRELOAD_DEBUG | 838 #if PRELOAD_DEBUG |
| 842 printPreloadStats(); | 839 printPreloadStats(); |
| 843 #endif | 840 #endif |
| 844 if (!m_preloads) | 841 if (!m_preloads) |
| 845 return; | 842 return; |
| 846 | 843 |
| 847 for (auto resource : *m_preloads) { | 844 for (auto resource : *m_preloads) { |
| 848 resource->decreasePreloadCount(); | 845 resource->decreasePreloadCount(); |
| 849 bool deleted = resource->deleteIfPossible(); | 846 if (resource->preloadResult() == Resource::PreloadNotReferenced && (poli
cy == ClearAllPreloads || !resource->isLinkPreload())) |
| 850 if (!deleted && resource->preloadResult() == Resource::PreloadNotReferen
ced && (policy == ClearAllPreloads || !resource->isLinkPreload())) | |
| 851 memoryCache()->remove(resource.get()); | 847 memoryCache()->remove(resource.get()); |
| 852 } | 848 } |
| 853 m_preloads.clear(); | 849 m_preloads.clear(); |
| 854 } | 850 } |
| 855 | 851 |
| 856 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) | 852 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) |
| 857 { | 853 { |
| 858 // Only the top-frame can load MHTML. | 854 // Only the top-frame can load MHTML. |
| 859 if (!context().isMainFrame()) | 855 if (!context().isMainFrame()) |
| 860 return nullptr; | 856 return nullptr; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 visitor->trace(m_loaders); | 1164 visitor->trace(m_loaders); |
| 1169 visitor->trace(m_nonBlockingLoaders); | 1165 visitor->trace(m_nonBlockingLoaders); |
| 1170 #if ENABLE(OILPAN) | 1166 #if ENABLE(OILPAN) |
| 1171 visitor->trace(m_documentResources); | 1167 visitor->trace(m_documentResources); |
| 1172 visitor->trace(m_preloads); | 1168 visitor->trace(m_preloads); |
| 1173 visitor->trace(m_resourceTimingInfoMap); | 1169 visitor->trace(m_resourceTimingInfoMap); |
| 1174 #endif | 1170 #endif |
| 1175 } | 1171 } |
| 1176 | 1172 |
| 1177 } // namespace blink | 1173 } // namespace blink |
| OLD | NEW |