| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 { | 217 { |
| 218 if (!m_context) | 218 if (!m_context) |
| 219 return nullptr; | 219 return nullptr; |
| 220 | 220 |
| 221 return m_context->loadingTaskRunner(); | 221 return m_context->loadingTaskRunner(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const | 224 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const |
| 225 { | 225 { |
| 226 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); | 226 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); |
| 227 const WeakPtrWillBeWeakMember<Resource>& resource = m_documentResources.get(
url); | 227 const WeakMember<Resource>& resource = m_documentResources.get(url); |
| 228 return resource.get(); | 228 return resource.get(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const | 231 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const |
| 232 { | 232 { |
| 233 // Redirects can change the response URL different from one of request. | 233 // Redirects can change the response URL different from one of request. |
| 234 bool forPreload = resource->isUnusedPreload(); | 234 bool forPreload = resource->isUnusedPreload(); |
| 235 if (!context().canRequest(resource->type(), resource->resourceRequest(), url
, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionForT
ype)) | 235 if (!context().canRequest(resource->type(), resource->resourceRequest(), url
, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionForT
ype)) |
| 236 return false; | 236 return false; |
| 237 | 237 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; | 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 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), request.charset()); | 342 RawPtr<Resource> resource = factory.create(request.resourceRequest(), reques
t.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 } | 354 } |
| 355 | 355 |
| 356 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) | 356 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) |
| 357 { | 357 { |
| 358 // 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. |
| 359 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { | 359 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { |
| 360 if (m_nonBlockingLoaders) | 360 if (m_nonBlockingLoaders) |
| 361 m_nonBlockingLoaders->remove(resource->loader()); | 361 m_nonBlockingLoaders->remove(resource->loader()); |
| 362 if (!m_loaders) | 362 if (!m_loaders) |
| 363 m_loaders = ResourceLoaderSet::create(); | 363 m_loaders = ResourceLoaderSet::create(); |
| 364 m_loaders->add(resource->loader()); | 364 m_loaders->add(resource->loader()); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::requestResource(FetchRequest&
request, const ResourceFactory& factory, const SubstituteData& substituteData) | 368 RawPtr<Resource> ResourceFetcher::requestResource(FetchRequest& request, const R
esourceFactory& factory, const SubstituteData& substituteData) |
| 369 { | 369 { |
| 370 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); |
| 371 | 371 |
| 372 context().upgradeInsecureRequest(request); | 372 context().upgradeInsecureRequest(request); |
| 373 context().addClientHintsIfNecessary(request); | 373 context().addClientHintsIfNecessary(request); |
| 374 context().addCSPHeaderIfNecessary(factory.type(), request); | 374 context().addCSPHeaderIfNecessary(factory.type(), request); |
| 375 | 375 |
| 376 KURL url = request.resourceRequest().url(); | 376 KURL url = request.resourceRequest().url(); |
| 377 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); | 377 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); |
| 378 | 378 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 398 Vector<String> argv; | 398 Vector<String> argv; |
| 399 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); | 399 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); |
| 400 argv.append(url); | 400 argv.append(url); |
| 401 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 401 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); | 405 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); |
| 406 if (isStaticData) | 406 if (isStaticData) |
| 407 preCacheData(request, factory, substituteData); | 407 preCacheData(request, factory, substituteData); |
| 408 RefPtrWillBeRawPtr<Resource> resource = memoryCache()->resourceForURL(url, g
etCacheIdentifier()); | 408 RawPtr<Resource> resource = memoryCache()->resourceForURL(url, getCacheIdent
ifier()); |
| 409 | 409 |
| 410 // 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. |
| 411 moveCachedNonBlockingResourceToBlocking(resource.get(), request); | 411 moveCachedNonBlockingResourceToBlocking(resource.get(), request); |
| 412 | 412 |
| 413 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); | 413 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); |
| 414 | 414 |
| 415 if (request.forPreload()) { | 415 if (request.forPreload()) { |
| 416 DEFINE_RESOURCE_HISTOGRAM("Preload."); | 416 DEFINE_RESOURCE_HISTOGRAM("Preload."); |
| 417 } else { | 417 } else { |
| 418 DEFINE_RESOURCE_HISTOGRAM(""); | 418 DEFINE_RESOURCE_HISTOGRAM(""); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); | 556 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); |
| 557 | 557 |
| 558 double stalenessLifetime = resource->stalenessLifetime(); | 558 double stalenessLifetime = resource->stalenessLifetime(); |
| 559 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { | 559 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { |
| 560 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()))); |
| 561 } | 561 } |
| 562 | 562 |
| 563 resource->setRevalidatingRequest(revalidatingRequest); | 563 resource->setRevalidatingRequest(revalidatingRequest); |
| 564 } | 564 } |
| 565 | 565 |
| 566 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::createResourceForLoading(Fetch
Request& request, const String& charset, const ResourceFactory& factory) | 566 RawPtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& request
, const String& charset, const ResourceFactory& factory) |
| 567 { | 567 { |
| 568 const String cacheIdentifier = getCacheIdentifier(); | 568 const String cacheIdentifier = getCacheIdentifier(); |
| 569 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); | 569 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); |
| 570 | 570 |
| 571 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()); |
| 572 | 572 |
| 573 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); | 573 initializeResourceRequest(request.mutableResourceRequest(), factory.type()); |
| 574 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), charset); | 574 RawPtr<Resource> resource = factory.create(request.resourceRequest(), charse
t); |
| 575 resource->setLinkPreload(request.isLinkPreload()); | 575 resource->setLinkPreload(request.isLinkPreload()); |
| 576 resource->setCacheIdentifier(cacheIdentifier); | 576 resource->setCacheIdentifier(cacheIdentifier); |
| 577 | 577 |
| 578 memoryCache()->add(resource.get()); | 578 memoryCache()->add(resource.get()); |
| 579 return resource; | 579 return resource; |
| 580 } | 580 } |
| 581 | 581 |
| 582 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 582 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
| 583 { | 583 { |
| 584 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... |
| 834 } | 834 } |
| 835 | 835 |
| 836 void ResourceFetcher::preloadStarted(Resource* resource) | 836 void ResourceFetcher::preloadStarted(Resource* resource) |
| 837 { | 837 { |
| 838 if (m_preloads && m_preloads->contains(resource)) | 838 if (m_preloads && m_preloads->contains(resource)) |
| 839 return; | 839 return; |
| 840 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 840 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
| 841 resource->increasePreloadCount(); | 841 resource->increasePreloadCount(); |
| 842 | 842 |
| 843 if (!m_preloads) | 843 if (!m_preloads) |
| 844 m_preloads = adoptPtrWillBeNoop(new WillBeHeapListHashSet<RefPtrWillBeMe
mber<Resource>>); | 844 m_preloads = (new HeapListHashSet<Member<Resource>>); |
| 845 m_preloads->add(resource); | 845 m_preloads->add(resource); |
| 846 | 846 |
| 847 #if PRELOAD_DEBUG | 847 #if PRELOAD_DEBUG |
| 848 printf("PRELOADING %s\n", resource->url().string().latin1().data()); | 848 printf("PRELOADING %s\n", resource->url().string().latin1().data()); |
| 849 #endif | 849 #endif |
| 850 } | 850 } |
| 851 | 851 |
| 852 bool ResourceFetcher::isPreloaded(const KURL& url) const | 852 bool ResourceFetcher::isPreloaded(const KURL& url) const |
| 853 { | 853 { |
| 854 if (m_preloads) { | 854 if (m_preloads) { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 visitor->trace(m_loaders); | 1203 visitor->trace(m_loaders); |
| 1204 visitor->trace(m_nonBlockingLoaders); | 1204 visitor->trace(m_nonBlockingLoaders); |
| 1205 #if ENABLE(OILPAN) | 1205 #if ENABLE(OILPAN) |
| 1206 visitor->trace(m_documentResources); | 1206 visitor->trace(m_documentResources); |
| 1207 visitor->trace(m_preloads); | 1207 visitor->trace(m_preloads); |
| 1208 visitor->trace(m_resourceTimingInfoMap); | 1208 visitor->trace(m_resourceTimingInfoMap); |
| 1209 #endif | 1209 #endif |
| 1210 } | 1210 } |
| 1211 | 1211 |
| 1212 } // namespace blink | 1212 } // namespace blink |
| OLD | NEW |