| 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 PassOwnPtr<TracedValue> urlForTraceEvent(const KURL& url) | 299 static PassOwnPtr<TracedValue> urlForTraceEvent(const KURL& url) |
| 300 { | 300 { |
| 301 OwnPtr<TracedValue> value = TracedValue::create(); | 301 OwnPtr<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 void ResourceFetcher::preCacheData(const FetchRequest& request, const ResourceFa
ctory& factory, const SubstituteData& substituteData) | 306 PassRefPtrWillBeRawPtr<Resource> ResourceFetcher::resourceForStaticData(const Fe
tchRequest& request, const ResourceFactory& factory, const SubstituteData& subst
ituteData) |
| 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; | 316 return nullptr; |
| 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; | 322 return oldResource; |
| 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; | 336 return nullptr; |
| 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 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.release(); |
| 354 } | 355 } |
| 355 | 356 |
| 356 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) | 357 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) |
| 357 { | 358 { |
| 358 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. | 359 // 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()) { | 360 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { |
| 360 if (m_nonBlockingLoaders) | 361 if (m_nonBlockingLoaders) |
| 361 m_nonBlockingLoaders->remove(resource->loader()); | 362 m_nonBlockingLoaders->remove(resource->loader()); |
| 362 if (!m_loaders) | 363 if (!m_loaders) |
| 363 m_loaders = ResourceLoaderSet::create(); | 364 m_loaders = ResourceLoaderSet::create(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 397 |
| 397 if (activityLogger) { | 398 if (activityLogger) { |
| 398 Vector<String> argv; | 399 Vector<String> argv; |
| 399 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); | 400 argv.append(Resource::resourceTypeToString(factory.type(), request.o
ptions().initiatorInfo)); |
| 400 argv.append(url); | 401 argv.append(url); |
| 401 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 402 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
| 402 } | 403 } |
| 403 } | 404 } |
| 404 | 405 |
| 405 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); | 406 bool isStaticData = request.resourceRequest().url().protocolIsData() || subs
tituteData.isValid(); |
| 407 RefPtrWillBeRawPtr<Resource> resource(nullptr); |
| 406 if (isStaticData) | 408 if (isStaticData) |
| 407 preCacheData(request, factory, substituteData); | 409 resource = resourceForStaticData(request, factory, substituteData); |
| 408 RefPtrWillBeRawPtr<Resource> resource = memoryCache()->resourceForURL(url, g
etCacheIdentifier()); | 410 if (!resource) |
| 411 resource = memoryCache()->resourceForURL(url, getCacheIdentifier()); |
| 409 | 412 |
| 410 // See if we can use an existing resource from the cache. If so, we need to
move it to be load blocking. | 413 // 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); | 414 moveCachedNonBlockingResourceToBlocking(resource.get(), request); |
| 412 | 415 |
| 413 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); | 416 const RevalidationPolicy policy = determineRevalidationPolicy(factory.type()
, request, resource.get(), isStaticData); |
| 414 | 417 |
| 415 if (request.forPreload()) { | 418 if (request.forPreload()) { |
| 416 DEFINE_RESOURCE_HISTOGRAM("Preload."); | 419 DEFINE_RESOURCE_HISTOGRAM("Preload."); |
| 417 } else { | 420 } else { |
| 418 DEFINE_RESOURCE_HISTOGRAM(""); | 421 DEFINE_RESOURCE_HISTOGRAM(""); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 visitor->trace(m_loaders); | 1213 visitor->trace(m_loaders); |
| 1211 visitor->trace(m_nonBlockingLoaders); | 1214 visitor->trace(m_nonBlockingLoaders); |
| 1212 #if ENABLE(OILPAN) | 1215 #if ENABLE(OILPAN) |
| 1213 visitor->trace(m_documentResources); | 1216 visitor->trace(m_documentResources); |
| 1214 visitor->trace(m_preloads); | 1217 visitor->trace(m_preloads); |
| 1215 visitor->trace(m_resourceTimingInfoMap); | 1218 visitor->trace(m_resourceTimingInfoMap); |
| 1216 #endif | 1219 #endif |
| 1217 } | 1220 } |
| 1218 | 1221 |
| 1219 } // namespace blink | 1222 } // namespace blink |
| OLD | NEW |