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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 m_validatedURLs.add(request.resourceRequest().url()); | 296 m_validatedURLs.add(request.resourceRequest().url()); |
297 } | 297 } |
298 | 298 |
299 static PassRefPtr<TracedValue> urlForTraceEvent(const KURL& url) | 299 static PassRefPtr<TracedValue> urlForTraceEvent(const KURL& url) |
300 { | 300 { |
301 RefPtr<TracedValue> value = TracedValue::create(); | 301 RefPtr<TracedValue> value = TracedValue::create(); |
302 value->setString("url", url.string()); | 302 value->setString("url", url.string()); |
303 return value.release(); | 303 return value.release(); |
304 } | 304 } |
305 | 305 |
306 ResourcePtr<Resource> ResourceFetcher::preCacheData(const FetchRequest& request,
const ResourceFactory& factory, const SubstituteData& substituteData) | 306 void ResourceFetcher::preCacheData(const FetchRequest& request, const ResourceFa
ctory& factory, const SubstituteData& substituteData) |
307 { | 307 { |
308 const KURL& url = request.resourceRequest().url(); | 308 const KURL& url = request.resourceRequest().url(); |
309 ASSERT(url.protocolIsData() || substituteData.isValid()); | 309 ASSERT(url.protocolIsData() || substituteData.isValid()); |
310 | 310 |
311 // TODO(japhet): We only send main resource data: urls through WebURLLoader
for the benefit of | 311 // TODO(japhet): We only send main resource data: urls through WebURLLoader
for the benefit of |
312 // a service worker test (RenderViewImplTest.ServiceWorkerNetworkProviderSet
up), which is at a | 312 // a service worker test (RenderViewImplTest.ServiceWorkerNetworkProviderSet
up), which is at a |
313 // layer where it isn't easy to mock out a network load. It uses data: urls
to emulate the | 313 // layer where it isn't easy to mock out a network load. It uses data: urls
to emulate the |
314 // behavior it wants to test, which would otherwise be reserved for network
loads. | 314 // behavior it wants to test, which would otherwise be reserved for network
loads. |
315 if ((factory.type() == Resource::MainResource && !substituteData.isValid())
|| factory.type() == Resource::Raw) | 315 if ((factory.type() == Resource::MainResource && !substituteData.isValid())
|| factory.type() == Resource::Raw) |
316 return nullptr; | 316 return; |
317 | 317 |
318 const String cacheIdentifier = getCacheIdentifier(); | 318 const String cacheIdentifier = getCacheIdentifier(); |
319 if (Resource* oldResource = memoryCache()->resourceForURL(url, cacheIdentifi
er)) { | 319 if (Resource* oldResource = memoryCache()->resourceForURL(url, cacheIdentifi
er)) { |
320 // There's no reason to re-parse if we saved the data from the previous
parse. | 320 // There's no reason to re-parse if we saved the data from the previous
parse. |
321 if (request.options().dataBufferingPolicy != DoNotBufferData) | 321 if (request.options().dataBufferingPolicy != DoNotBufferData) |
322 return oldResource; | 322 return; |
323 memoryCache()->remove(oldResource); | 323 memoryCache()->remove(oldResource); |
324 } | 324 } |
325 | 325 |
326 WebString mimetype; | 326 WebString mimetype; |
327 WebString charset; | 327 WebString charset; |
328 RefPtr<SharedBuffer> data; | 328 RefPtr<SharedBuffer> data; |
329 if (substituteData.isValid()) { | 329 if (substituteData.isValid()) { |
330 mimetype = substituteData.mimeType(); | 330 mimetype = substituteData.mimeType(); |
331 charset = substituteData.textEncoding(); | 331 charset = substituteData.textEncoding(); |
332 data = substituteData.content(); | 332 data = substituteData.content(); |
333 } else { | 333 } else { |
334 data = PassRefPtr<SharedBuffer>(Platform::current()->parseDataURL(url, m
imetype, charset)); | 334 data = PassRefPtr<SharedBuffer>(Platform::current()->parseDataURL(url, m
imetype, charset)); |
335 if (!data) | 335 if (!data) |
336 return nullptr; | 336 return; |
337 } | 337 } |
338 ResourceResponse response(url, mimetype, data->size(), charset, String()); | 338 ResourceResponse response(url, mimetype, data->size(), charset, String()); |
339 response.setHTTPStatusCode(200); | 339 response.setHTTPStatusCode(200); |
340 response.setHTTPStatusText("OK"); | 340 response.setHTTPStatusText("OK"); |
341 | 341 |
342 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), r
equest.charset()); | 342 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), request.charset()); |
343 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad())
; | 343 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad())
; |
344 resource->setOptions(request.options()); | 344 resource->setOptions(request.options()); |
345 // FIXME: We should provide a body stream here. | 345 // FIXME: We should provide a body stream here. |
346 resource->responseReceived(response, nullptr); | 346 resource->responseReceived(response, nullptr); |
347 resource->setDataBufferingPolicy(BufferData); | 347 resource->setDataBufferingPolicy(BufferData); |
348 if (data->size()) | 348 if (data->size()) |
349 resource->setResourceBuffer(data); | 349 resource->setResourceBuffer(data); |
350 resource->setIdentifier(createUniqueIdentifier()); | 350 resource->setIdentifier(createUniqueIdentifier()); |
351 resource->setCacheIdentifier(cacheIdentifier); | 351 resource->setCacheIdentifier(cacheIdentifier); |
352 resource->finish(); | 352 resource->finish(); |
353 memoryCache()->add(resource.get()); | 353 memoryCache()->add(resource.get()); |
354 return resource; | |
355 } | 354 } |
356 | 355 |
357 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) | 356 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) |
358 { | 357 { |
359 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. | 358 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. |
360 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { | 359 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { |
361 if (m_nonBlockingLoaders) | 360 if (m_nonBlockingLoaders) |
362 m_nonBlockingLoaders->remove(resource->loader()); | 361 m_nonBlockingLoaders->remove(resource->loader()); |
363 if (!m_loaders) | 362 if (!m_loaders) |
364 m_loaders = ResourceLoaderSet::create(); | 363 m_loaders = ResourceLoaderSet::create(); |
365 m_loaders->add(resource->loader()); | 364 m_loaders->add(resource->loader()); |
366 } | 365 } |
367 } | 366 } |
368 | 367 |
369 ResourcePtr<Resource> ResourceFetcher::requestResource(FetchRequest& request, co
nst ResourceFactory& factory, const SubstituteData& substituteData) | 368 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::requestResource(FetchRequest&
request, const ResourceFactory& factory, const SubstituteData& substituteData) |
370 { | 369 { |
371 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); | 370 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); |
372 | 371 |
373 context().upgradeInsecureRequest(request); | 372 context().upgradeInsecureRequest(request); |
374 context().addClientHintsIfNecessary(request); | 373 context().addClientHintsIfNecessary(request); |
375 context().addCSPHeaderIfNecessary(factory.type(), request); | 374 context().addCSPHeaderIfNecessary(factory.type(), request); |
376 | 375 |
377 KURL url = request.resourceRequest().url(); | 376 KURL url = request.resourceRequest().url(); |
378 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); | 377 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); |
379 | 378 |
(...skipping 17 matching lines...) Expand all Loading... |
397 | 396 |
398 if (activityLogger) { | 397 if (activityLogger) { |
399 Vector<String> argv; | 398 Vector<String> argv; |
400 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); | 399 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); |
401 argv.append(url); | 400 argv.append(url); |
402 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 401 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
403 } | 402 } |
404 } | 403 } |
405 | 404 |
406 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); | 405 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); |
407 ResourcePtr<Resource> resource; | |
408 if (isStaticData) | 406 if (isStaticData) |
409 resource = preCacheData(request, factory, substituteData); | 407 preCacheData(request, factory, substituteData); |
410 if (!resource) | 408 RefPtrWillBeRawPtr<Resource> resource = memoryCache()->resourceForURL(url, g
etCacheIdentifier()); |
411 resource = memoryCache()->resourceForURL(url, getCacheIdentifier()); | |
412 | 409 |
413 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. | 410 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. |
414 moveCachedNonBlockingResourceToBlocking(resource.get(), request); | 411 moveCachedNonBlockingResourceToBlocking(resource.get(), request); |
415 | 412 |
416 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); | 413 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); |
417 | 414 |
418 if (request.forPreload()) { | 415 if (request.forPreload()) { |
419 DEFINE_RESOURCE_HISTOGRAM("Preload."); | 416 DEFINE_RESOURCE_HISTOGRAM("Preload."); |
420 } else { | 417 } else { |
421 DEFINE_RESOURCE_HISTOGRAM(""); | 418 DEFINE_RESOURCE_HISTOGRAM(""); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); | 556 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); |
560 | 557 |
561 double stalenessLifetime = resource->stalenessLifetime(); | 558 double stalenessLifetime = resource->stalenessLifetime(); |
562 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { | 559 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { |
563 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); | 560 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); |
564 } | 561 } |
565 | 562 |
566 resource->setRevalidatingRequest(revalidatingRequest); | 563 resource->setRevalidatingRequest(revalidatingRequest); |
567 } | 564 } |
568 | 565 |
569 ResourcePtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& re
quest, const String& charset, const ResourceFactory& factory) | 566 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::createResourceForLoading(Fetch
Request& request, const String& charset, const ResourceFactory& factory) |
570 { | 567 { |
571 const String cacheIdentifier = getCacheIdentifier(); | 568 const String cacheIdentifier = getCacheIdentifier(); |
572 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); | 569 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); |
573 | 570 |
574 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque
st().url().elidedString().latin1().data()); | 571 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque
st().url().elidedString().latin1().data()); |
575 | 572 |
576 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); | 573 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); |
577 ResourcePtr<Resource> resource = factory.create(request.resourceRequest(), c
harset); | 574 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), charset); |
578 resource->setLinkPreload(request.isLinkPreload()); | 575 resource->setLinkPreload(request.isLinkPreload()); |
579 resource->setCacheIdentifier(cacheIdentifier); | 576 resource->setCacheIdentifier(cacheIdentifier); |
580 | 577 |
581 memoryCache()->add(resource.get()); | 578 memoryCache()->add(resource.get()); |
582 return resource; | 579 return resource; |
583 } | 580 } |
584 | 581 |
585 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 582 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
586 { | 583 { |
587 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter
nal) | 584 if (resource->options().initiatorInfo.name == FetchInitiatorTypeNames::inter
nal) |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 } | 834 } |
838 | 835 |
839 void ResourceFetcher::preloadStarted(Resource* resource) | 836 void ResourceFetcher::preloadStarted(Resource* resource) |
840 { | 837 { |
841 if (m_preloads && m_preloads->contains(resource)) | 838 if (m_preloads && m_preloads->contains(resource)) |
842 return; | 839 return; |
843 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 840 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
844 resource->increasePreloadCount(); | 841 resource->increasePreloadCount(); |
845 | 842 |
846 if (!m_preloads) | 843 if (!m_preloads) |
847 m_preloads = adoptPtrWillBeNoop(new WillBeHeapListHashSet<RawPtrWillBeMe
mber<Resource>>); | 844 m_preloads = adoptPtrWillBeNoop(new WillBeHeapListHashSet<RefPtrWillBeMe
mber<Resource>>); |
848 m_preloads->add(resource); | 845 m_preloads->add(resource); |
849 | 846 |
850 #if PRELOAD_DEBUG | 847 #if PRELOAD_DEBUG |
851 printf("PRELOADING %s\n", resource->url().string().latin1().data()); | 848 printf("PRELOADING %s\n", resource->url().string().latin1().data()); |
852 #endif | 849 #endif |
853 } | 850 } |
854 | 851 |
855 bool ResourceFetcher::isPreloaded(const KURL& url) const | 852 bool ResourceFetcher::isPreloaded(const KURL& url) const |
856 { | 853 { |
857 if (m_preloads) { | 854 if (m_preloads) { |
858 for (auto resource : *m_preloads) { | 855 for (auto resource : *m_preloads) { |
859 if (resource->url() == url) | 856 if (resource->url() == url) |
860 return true; | 857 return true; |
861 } | 858 } |
862 } | 859 } |
863 | 860 |
864 return false; | 861 return false; |
865 } | 862 } |
866 | 863 |
867 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) | 864 void ResourceFetcher::clearPreloads(ClearPreloadsPolicy policy) |
868 { | 865 { |
869 #if PRELOAD_DEBUG | 866 #if PRELOAD_DEBUG |
870 printPreloadStats(); | 867 printPreloadStats(); |
871 #endif | 868 #endif |
872 if (!m_preloads) | 869 if (!m_preloads) |
873 return; | 870 return; |
874 | 871 |
875 for (auto resource : *m_preloads) { | 872 for (auto resource : *m_preloads) { |
876 resource->decreasePreloadCount(); | 873 resource->decreasePreloadCount(); |
877 bool deleted = resource->deleteIfPossible(); | 874 if (resource->preloadResult() == Resource::PreloadNotReferenced && (poli
cy == ClearAllPreloads || !resource->isLinkPreload())) |
878 if (!deleted && resource->preloadResult() == Resource::PreloadNotReferen
ced && (policy == ClearAllPreloads || !resource->isLinkPreload())) | |
879 memoryCache()->remove(resource.get()); | 875 memoryCache()->remove(resource.get()); |
880 } | 876 } |
881 m_preloads.clear(); | 877 m_preloads.clear(); |
882 } | 878 } |
883 | 879 |
884 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) | 880 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) |
885 { | 881 { |
886 // Only the top-frame can load MHTML. | 882 // Only the top-frame can load MHTML. |
887 if (!context().isMainFrame()) | 883 if (!context().isMainFrame()) |
888 return nullptr; | 884 return nullptr; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 visitor->trace(m_loaders); | 1203 visitor->trace(m_loaders); |
1208 visitor->trace(m_nonBlockingLoaders); | 1204 visitor->trace(m_nonBlockingLoaders); |
1209 #if ENABLE(OILPAN) | 1205 #if ENABLE(OILPAN) |
1210 visitor->trace(m_documentResources); | 1206 visitor->trace(m_documentResources); |
1211 visitor->trace(m_preloads); | 1207 visitor->trace(m_preloads); |
1212 visitor->trace(m_resourceTimingInfoMap); | 1208 visitor->trace(m_resourceTimingInfoMap); |
1213 #endif | 1209 #endif |
1214 } | 1210 } |
1215 | 1211 |
1216 } // namespace blink | 1212 } // namespace blink |
OLD | NEW |