| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 { | 218 { |
| 219 if (!m_context) | 219 if (!m_context) |
| 220 return nullptr; | 220 return nullptr; |
| 221 | 221 |
| 222 return m_context->loadingTaskRunner(); | 222 return m_context->loadingTaskRunner(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const | 225 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const |
| 226 { | 226 { |
| 227 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); | 227 KURL url = MemoryCache::removeFragmentIdentifierIfNeeded(resourceURL); |
| 228 const WeakPtrWillBeWeakMember<Resource>& resource = m_documentResources.get(
url); | 228 const WeakMember<Resource>& resource = m_documentResources.get(url); |
| 229 return resource.get(); | 229 return resource.get(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const | 232 bool ResourceFetcher::canAccessResource(Resource* resource, SecurityOrigin* sour
ceOrigin, const KURL& url, AccessControlLoggingDecision logErrorsDecision) const |
| 233 { | 233 { |
| 234 // Redirects can change the response URL different from one of request. | 234 // Redirects can change the response URL different from one of request. |
| 235 bool forPreload = resource->isUnusedPreload(); | 235 bool forPreload = resource->isUnusedPreload(); |
| 236 if (!context().canRequest(resource->getType(), resource->resourceRequest(),
url, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionF
orType)) | 236 if (!context().canRequest(resource->getType(), resource->resourceRequest(),
url, resource->options(), forPreload, FetchRequest::UseDefaultOriginRestrictionF
orType)) |
| 237 return false; | 237 return false; |
| 238 | 238 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 m_validatedURLs.add(request.resourceRequest().url()); | 295 m_validatedURLs.add(request.resourceRequest().url()); |
| 296 } | 296 } |
| 297 | 297 |
| 298 static PassOwnPtr<TracedValue> urlForTraceEvent(const KURL& url) | 298 static PassOwnPtr<TracedValue> urlForTraceEvent(const KURL& url) |
| 299 { | 299 { |
| 300 OwnPtr<TracedValue> value = TracedValue::create(); | 300 OwnPtr<TracedValue> value = TracedValue::create(); |
| 301 value->setString("url", url.getString()); | 301 value->setString("url", url.getString()); |
| 302 return value.release(); | 302 return value.release(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::resourceForStaticData(const Fe
tchRequest& request, const ResourceFactory& factory, const SubstituteData& subst
ituteData) | 305 RawPtr<Resource> ResourceFetcher::resourceForStaticData(const FetchRequest& requ
est, const ResourceFactory& factory, const SubstituteData& substituteData) |
| 306 { | 306 { |
| 307 const KURL& url = request.resourceRequest().url(); | 307 const KURL& url = request.resourceRequest().url(); |
| 308 ASSERT(url.protocolIsData() || substituteData.isValid() || m_archive); | 308 ASSERT(url.protocolIsData() || substituteData.isValid() || m_archive); |
| 309 | 309 |
| 310 // TODO(japhet): We only send main resource data: urls through WebURLLoader
for the benefit of | 310 // TODO(japhet): We only send main resource data: urls through WebURLLoader
for the benefit of |
| 311 // a service worker test (RenderViewImplTest.ServiceWorkerNetworkProviderSet
up), which is at a | 311 // a service worker test (RenderViewImplTest.ServiceWorkerNetworkProviderSet
up), which is at a |
| 312 // layer where it isn't easy to mock out a network load. It uses data: urls
to emulate the | 312 // layer where it isn't easy to mock out a network load. It uses data: urls
to emulate the |
| 313 // behavior it wants to test, which would otherwise be reserved for network
loads. | 313 // behavior it wants to test, which would otherwise be reserved for network
loads. |
| 314 if (!m_archive && !substituteData.isValid() && (factory.type() == Resource::
MainResource || factory.type() == Resource::Raw)) | 314 if (!m_archive && !substituteData.isValid() && (factory.type() == Resource::
MainResource || factory.type() == Resource::Raw)) |
| 315 return nullptr; | 315 return nullptr; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 340 return nullptr; | 340 return nullptr; |
| 341 mimetype = archiveResource->mimeType(); | 341 mimetype = archiveResource->mimeType(); |
| 342 charset = archiveResource->textEncoding(); | 342 charset = archiveResource->textEncoding(); |
| 343 data = archiveResource->data(); | 343 data = archiveResource->data(); |
| 344 } | 344 } |
| 345 | 345 |
| 346 ResourceResponse response(url, mimetype, data->size(), charset, String()); | 346 ResourceResponse response(url, mimetype, data->size(), charset, String()); |
| 347 response.setHTTPStatusCode(200); | 347 response.setHTTPStatusCode(200); |
| 348 response.setHTTPStatusText("OK"); | 348 response.setHTTPStatusText("OK"); |
| 349 | 349 |
| 350 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), request.options(), request.charset()); | 350 RawPtr<Resource> resource = factory.create(request.resourceRequest(), reques
t.options(), request.charset()); |
| 351 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad())
; | 351 resource->setNeedsSynchronousCacheHit(substituteData.forceSynchronousLoad())
; |
| 352 // FIXME: We should provide a body stream here. | 352 // FIXME: We should provide a body stream here. |
| 353 resource->responseReceived(response, nullptr); | 353 resource->responseReceived(response, nullptr); |
| 354 resource->setDataBufferingPolicy(BufferData); | 354 resource->setDataBufferingPolicy(BufferData); |
| 355 if (data->size()) | 355 if (data->size()) |
| 356 resource->setResourceBuffer(data); | 356 resource->setResourceBuffer(data); |
| 357 resource->setIdentifier(createUniqueIdentifier()); | 357 resource->setIdentifier(createUniqueIdentifier()); |
| 358 resource->setCacheIdentifier(cacheIdentifier); | 358 resource->setCacheIdentifier(cacheIdentifier); |
| 359 resource->finish(); | 359 resource->finish(); |
| 360 | 360 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 389 | 389 |
| 390 // Aims to count Resource only referenced from MemoryCache (i.e. what | 390 // Aims to count Resource only referenced from MemoryCache (i.e. what |
| 391 // would be dead if MemoryCache holds weak references to Resource). | 391 // would be dead if MemoryCache holds weak references to Resource). |
| 392 // Currently we check references to Resource from ResourceClient and | 392 // Currently we check references to Resource from ResourceClient and |
| 393 // |m_preloads| only, because they are major sources of references. | 393 // |m_preloads| only, because they are major sources of references. |
| 394 if (resource && !resource->hasClientsOrObservers() && (!m_preloads || !m_pre
loads->contains(resource))) { | 394 if (resource && !resource->hasClientsOrObservers() && (!m_preloads || !m_pre
loads->contains(resource))) { |
| 395 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 395 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::requestResource(FetchRequest&
request, const ResourceFactory& factory, const SubstituteData& substituteData) | 399 RawPtr<Resource> ResourceFetcher::requestResource(FetchRequest& request, const R
esourceFactory& factory, const SubstituteData& substituteData) |
| 400 { | 400 { |
| 401 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); | 401 ASSERT(request.options().synchronousPolicy == RequestAsynchronously || facto
ry.type() == Resource::Raw || factory.type() == Resource::XSLStyleSheet); |
| 402 | 402 |
| 403 context().upgradeInsecureRequest(request); | 403 context().upgradeInsecureRequest(request); |
| 404 context().addClientHintsIfNecessary(request); | 404 context().addClientHintsIfNecessary(request); |
| 405 context().addCSPHeaderIfNecessary(factory.type(), request); | 405 context().addCSPHeaderIfNecessary(factory.type(), request); |
| 406 | 406 |
| 407 KURL url = request.resourceRequest().url(); | 407 KURL url = request.resourceRequest().url(); |
| 408 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); | 408 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", urlForTrace
Event(url)); |
| 409 | 409 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 427 | 427 |
| 428 if (activityLogger) { | 428 if (activityLogger) { |
| 429 Vector<String> argv; | 429 Vector<String> argv; |
| 430 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); | 430 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); |
| 431 argv.append(url); | 431 argv.append(url); |
| 432 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 432 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid() || m_archive; | 436 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid() || m_archive; |
| 437 RefPtrWillBeRawPtr<Resource> resource(nullptr); | 437 RawPtr<Resource> resource(nullptr); |
| 438 if (isStaticData) | 438 if (isStaticData) |
| 439 resource = resourceForStaticData(request, factory, substituteData); | 439 resource = resourceForStaticData(request, factory, substituteData); |
| 440 if (!resource) | 440 if (!resource) |
| 441 resource = memoryCache()->resourceForURL(url, getCacheIdentifier()); | 441 resource = memoryCache()->resourceForURL(url, getCacheIdentifier()); |
| 442 | 442 |
| 443 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. | 443 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. |
| 444 moveCachedNonBlockingResourceToBlocking(resource.get(), request); | 444 moveCachedNonBlockingResourceToBlocking(resource.get(), request); |
| 445 | 445 |
| 446 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); | 446 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); |
| 447 | 447 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); | 563 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); |
| 564 | 564 |
| 565 double stalenessLifetime = resource->stalenessLifetime(); | 565 double stalenessLifetime = resource->stalenessLifetime(); |
| 566 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { | 566 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { |
| 567 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); | 567 revalidatingRequest.setHTTPHeaderField(HTTPNames::Resource_Freshness, At
omicString(String::format("max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf"
, resource->freshnessLifetime(), stalenessLifetime, resource->currentAge()))); |
| 568 } | 568 } |
| 569 | 569 |
| 570 resource->setRevalidatingRequest(revalidatingRequest); | 570 resource->setRevalidatingRequest(revalidatingRequest); |
| 571 } | 571 } |
| 572 | 572 |
| 573 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::createResourceForLoading(Fetch
Request& request, const String& charset, const ResourceFactory& factory) | 573 RawPtr<Resource> ResourceFetcher::createResourceForLoading(FetchRequest& request
, const String& charset, const ResourceFactory& factory) |
| 574 { | 574 { |
| 575 const String cacheIdentifier = getCacheIdentifier(); | 575 const String cacheIdentifier = getCacheIdentifier(); |
| 576 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); | 576 ASSERT(!memoryCache()->resourceForURL(request.resourceRequest().url(), cache
Identifier)); |
| 577 | 577 |
| 578 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque
st().url().elidedString().latin1().data()); | 578 WTF_LOG(ResourceLoading, "Loading Resource for '%s'.", request.resourceReque
st().url().elidedString().latin1().data()); |
| 579 | 579 |
| 580 RefPtrWillBeRawPtr<Resource> resource = factory.create(request.resourceReque
st(), request.options(), charset); | 580 RawPtr<Resource> resource = factory.create(request.resourceRequest(), reques
t.options(), charset); |
| 581 resource->setLinkPreload(request.isLinkPreload()); | 581 resource->setLinkPreload(request.isLinkPreload()); |
| 582 resource->setCacheIdentifier(cacheIdentifier); | 582 resource->setCacheIdentifier(cacheIdentifier); |
| 583 | 583 |
| 584 // Don't add main resource to cache to prevent reuse. | 584 // Don't add main resource to cache to prevent reuse. |
| 585 if (factory.type() != Resource::MainResource) | 585 if (factory.type() != Resource::MainResource) |
| 586 memoryCache()->add(resource.get()); | 586 memoryCache()->add(resource.get()); |
| 587 return resource; | 587 return resource; |
| 588 } | 588 } |
| 589 | 589 |
| 590 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 590 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } | 847 } |
| 848 | 848 |
| 849 void ResourceFetcher::preloadStarted(Resource* resource) | 849 void ResourceFetcher::preloadStarted(Resource* resource) |
| 850 { | 850 { |
| 851 if (m_preloads && m_preloads->contains(resource)) | 851 if (m_preloads && m_preloads->contains(resource)) |
| 852 return; | 852 return; |
| 853 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 853 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
| 854 resource->increasePreloadCount(); | 854 resource->increasePreloadCount(); |
| 855 | 855 |
| 856 if (!m_preloads) | 856 if (!m_preloads) |
| 857 m_preloads = adoptPtrWillBeNoop(new WillBeHeapListHashSet<RefPtrWillBeMe
mber<Resource>>); | 857 m_preloads = adoptPtrWillBeNoop(new HeapListHashSet<Member<Resource>>); |
| 858 m_preloads->add(resource); | 858 m_preloads->add(resource); |
| 859 | 859 |
| 860 #if PRELOAD_DEBUG | 860 #if PRELOAD_DEBUG |
| 861 printf("PRELOADING %s\n", resource->url().string().latin1().data()); | 861 printf("PRELOADING %s\n", resource->url().string().latin1().data()); |
| 862 #endif | 862 #endif |
| 863 } | 863 } |
| 864 | 864 |
| 865 bool ResourceFetcher::isPreloaded(const KURL& url) const | 865 bool ResourceFetcher::isPreloaded(const KURL& url) const |
| 866 { | 866 { |
| 867 if (m_preloads) { | 867 if (m_preloads) { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 visitor->trace(m_loaders); | 1193 visitor->trace(m_loaders); |
| 1194 visitor->trace(m_nonBlockingLoaders); | 1194 visitor->trace(m_nonBlockingLoaders); |
| 1195 #if ENABLE(OILPAN) | 1195 #if ENABLE(OILPAN) |
| 1196 visitor->trace(m_documentResources); | 1196 visitor->trace(m_documentResources); |
| 1197 visitor->trace(m_preloads); | 1197 visitor->trace(m_preloads); |
| 1198 visitor->trace(m_resourceTimingInfoMap); | 1198 visitor->trace(m_resourceTimingInfoMap); |
| 1199 #endif | 1199 #endif |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 } // namespace blink | 1202 } // namespace blink |
| OLD | NEW |