| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 static Resource* resourceFromDataURIRequest(const ResourceRequest& request, cons
t ResourceLoaderOptions& resourceOptions) | 159 static Resource* resourceFromDataURIRequest(const ResourceRequest& request, cons
t ResourceLoaderOptions& resourceOptions) |
| 160 { | 160 { |
| 161 const KURL& url = request.url(); | 161 const KURL& url = request.url(); |
| 162 ASSERT(url.protocolIsData()); | 162 ASSERT(url.protocolIsData()); |
| 163 | 163 |
| 164 blink::WebString mimetype; | 164 blink::WebString mimetype; |
| 165 blink::WebString charset; | 165 blink::WebString charset; |
| 166 RefPtr<SharedBuffer> data = PassRefPtr<SharedBuffer>(blink::Platform::curren
t()->parseDataURL(url, mimetype, charset)); | 166 RefPtr<SharedBuffer> data = PassRefPtr<SharedBuffer>(blink::Platform::curren
t()->parseDataURL(url, mimetype, charset)); |
| 167 if (!data) | 167 if (!data) |
| 168 return 0; | 168 return nullptr; |
| 169 ResourceResponse response(url, mimetype, data->size(), charset, String()); | 169 ResourceResponse response(url, mimetype, data->size(), charset, String()); |
| 170 | 170 |
| 171 Resource* resource = createResource(Resource::Image, request, charset); | 171 Resource* resource = createResource(Resource::Image, request, charset); |
| 172 resource->setOptions(resourceOptions); | 172 resource->setOptions(resourceOptions); |
| 173 resource->responseReceived(response); | 173 resource->responseReceived(response); |
| 174 if (data->size()) | 174 if (data->size()) |
| 175 resource->setResourceBuffer(data); | 175 resource->setResourceBuffer(data); |
| 176 resource->finish(); | 176 resource->finish(); |
| 177 return resource; | 177 return resource; |
| 178 } | 178 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl
ectDocumentResourcesTimerFired) | 256 , m_garbageCollectDocumentResourcesTimer(this, &ResourceFetcher::garbageColl
ectDocumentResourcesTimerFired) |
| 257 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi
merFired) | 257 , m_resourceTimingReportTimer(this, &ResourceFetcher::resourceTimingReportTi
merFired) |
| 258 , m_autoLoadImages(true) | 258 , m_autoLoadImages(true) |
| 259 , m_imagesEnabled(true) | 259 , m_imagesEnabled(true) |
| 260 , m_allowStaleResources(false) | 260 , m_allowStaleResources(false) |
| 261 { | 261 { |
| 262 } | 262 } |
| 263 | 263 |
| 264 ResourceFetcher::~ResourceFetcher() | 264 ResourceFetcher::~ResourceFetcher() |
| 265 { | 265 { |
| 266 m_documentLoader = 0; | 266 m_documentLoader = nullptr; |
| 267 m_document = nullptr; | 267 m_document = nullptr; |
| 268 | 268 |
| 269 clearPreloads(); | 269 clearPreloads(); |
| 270 | 270 |
| 271 // Make sure no requests still point to this ResourceFetcher | 271 // Make sure no requests still point to this ResourceFetcher |
| 272 ASSERT(!m_requestCount); | 272 ASSERT(!m_requestCount); |
| 273 } | 273 } |
| 274 | 274 |
| 275 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const | 275 Resource* ResourceFetcher::cachedResource(const KURL& resourceURL) const |
| 276 { | 276 { |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 TRACE_EVENT0("blink", "ResourceFetcher::requestResource"); | 681 TRACE_EVENT0("blink", "ResourceFetcher::requestResource"); |
| 682 | 682 |
| 683 KURL url = request.resourceRequest().url(); | 683 KURL url = request.resourceRequest().url(); |
| 684 | 684 |
| 685 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource '%s', charset '%s
', priority=%d, forPreload=%u, type=%s", url.elidedString().latin1().data(), req
uest.charset().latin1().data(), request.priority(), request.forPreload(), Resour
ceTypeName(type)); | 685 WTF_LOG(ResourceLoading, "ResourceFetcher::requestResource '%s', charset '%s
', priority=%d, forPreload=%u, type=%s", url.elidedString().latin1().data(), req
uest.charset().latin1().data(), request.priority(), request.forPreload(), Resour
ceTypeName(type)); |
| 686 | 686 |
| 687 // If only the fragment identifiers differ, it is the same resource. | 687 // If only the fragment identifiers differ, it is the same resource. |
| 688 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); | 688 url = MemoryCache::removeFragmentIdentifierIfNeeded(url); |
| 689 | 689 |
| 690 if (!url.isValid()) | 690 if (!url.isValid()) |
| 691 return 0; | 691 return nullptr; |
| 692 | 692 |
| 693 if (!canRequest(type, request.resourceRequest(), url, request.options(), req
uest.forPreload(), request.originRestriction())) | 693 if (!canRequest(type, request.resourceRequest(), url, request.options(), req
uest.forPreload(), request.originRestriction())) |
| 694 return 0; | 694 return nullptr; |
| 695 | 695 |
| 696 if (LocalFrame* f = frame()) | 696 if (LocalFrame* f = frame()) |
| 697 f->loader().client()->dispatchWillRequestResource(&request); | 697 f->loader().client()->dispatchWillRequestResource(&request); |
| 698 | 698 |
| 699 if (!request.forPreload()) { | 699 if (!request.forPreload()) { |
| 700 V8DOMActivityLogger* activityLogger = 0; | 700 V8DOMActivityLogger* activityLogger = nullptr; |
| 701 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml
httprequest) | 701 if (request.options().initiatorInfo.name == FetchInitiatorTypeNames::xml
httprequest) |
| 702 activityLogger = V8DOMActivityLogger::currentActivityLogger(); | 702 activityLogger = V8DOMActivityLogger::currentActivityLogger(); |
| 703 else | 703 else |
| 704 activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolate
dWorld(); | 704 activityLogger = V8DOMActivityLogger::currentActivityLoggerIfIsolate
dWorld(); |
| 705 | 705 |
| 706 if (activityLogger) { | 706 if (activityLogger) { |
| 707 Vector<String> argv; | 707 Vector<String> argv; |
| 708 argv.append(Resource::resourceTypeToString(type, request.options().i
nitiatorInfo)); | 708 argv.append(Resource::resourceTypeToString(type, request.options().i
nitiatorInfo)); |
| 709 argv.append(url); | 709 argv.append(url); |
| 710 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); | 710 activityLogger->logEvent("blinkRequestResource", argv.size(), argv.d
ata()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 724 break; | 724 break; |
| 725 case Revalidate: | 725 case Revalidate: |
| 726 resource = createResourceForRevalidation(request, resource.get()); | 726 resource = createResourceForRevalidation(request, resource.get()); |
| 727 break; | 727 break; |
| 728 case Use: | 728 case Use: |
| 729 memoryCache()->updateForAccess(resource.get()); | 729 memoryCache()->updateForAccess(resource.get()); |
| 730 break; | 730 break; |
| 731 } | 731 } |
| 732 | 732 |
| 733 if (!resource) | 733 if (!resource) |
| 734 return 0; | 734 return nullptr; |
| 735 | 735 |
| 736 if (!resource->hasClients()) | 736 if (!resource->hasClients()) |
| 737 m_deadStatsRecorder.update(policy); | 737 m_deadStatsRecorder.update(policy); |
| 738 | 738 |
| 739 if (policy != Use) | 739 if (policy != Use) |
| 740 resource->setIdentifier(createUniqueIdentifier()); | 740 resource->setIdentifier(createUniqueIdentifier()); |
| 741 | 741 |
| 742 if (!request.forPreload() || policy != Use) { | 742 if (!request.forPreload() || policy != Use) { |
| 743 ResourceLoadPriority priority = loadPriority(type, request); | 743 ResourceLoadPriority priority = loadPriority(type, request); |
| 744 // When issuing another request for a resource that is already in-flight
make | 744 // When issuing another request for a resource that is already in-flight
make |
| 745 // sure to not demote the priority of the in-flight request. If the new
request | 745 // sure to not demote the priority of the in-flight request. If the new
request |
| 746 // isn't at the same priority as the in-flight request, only allow promo
tions. | 746 // isn't at the same priority as the in-flight request, only allow promo
tions. |
| 747 // This can happen when a visible image's priority is increased and then
another | 747 // This can happen when a visible image's priority is increased and then
another |
| 748 // reference to the image is parsed (which would be at a lower priority)
. | 748 // reference to the image is parsed (which would be at a lower priority)
. |
| 749 if (priority > resource->resourceRequest().priority()) { | 749 if (priority > resource->resourceRequest().priority()) { |
| 750 resource->mutableResourceRequest().setPriority(priority); | 750 resource->mutableResourceRequest().setPriority(priority); |
| 751 resource->didChangePriority(priority, 0); | 751 resource->didChangePriority(priority, 0); |
| 752 } | 752 } |
| 753 } | 753 } |
| 754 | 754 |
| 755 if (resourceNeedsLoad(resource.get(), request, policy)) { | 755 if (resourceNeedsLoad(resource.get(), request, policy)) { |
| 756 if (!shouldLoadNewResource(type)) { | 756 if (!shouldLoadNewResource(type)) { |
| 757 if (memoryCache()->contains(resource.get())) | 757 if (memoryCache()->contains(resource.get())) |
| 758 memoryCache()->remove(resource.get()); | 758 memoryCache()->remove(resource.get()); |
| 759 return 0; | 759 return nullptr; |
| 760 } | 760 } |
| 761 | 761 |
| 762 if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource
.get(), request.resourceRequest())) | 762 if (!m_documentLoader || !m_documentLoader->scheduleArchiveLoad(resource
.get(), request.resourceRequest())) |
| 763 resource->load(this, request.options()); | 763 resource->load(this, request.options()); |
| 764 | 764 |
| 765 // For asynchronous loads that immediately fail, it's sufficient to retu
rn a | 765 // For asynchronous loads that immediately fail, it's sufficient to retu
rn a |
| 766 // null Resource, as it indicates that something prevented the load from
starting. | 766 // null Resource, as it indicates that something prevented the load from
starting. |
| 767 // If there's a network error, that failure will happen asynchronously.
However, if | 767 // If there's a network error, that failure will happen asynchronously.
However, if |
| 768 // a sync load receives a network error, it will have already happened b
y this point. | 768 // a sync load receives a network error, it will have already happened b
y this point. |
| 769 // In that case, the requester should have access to the relevant Resour
ceError, so | 769 // In that case, the requester should have access to the relevant Resour
ceError, so |
| 770 // we need to return a non-null Resource. | 770 // we need to return a non-null Resource. |
| 771 if (resource->errorOccurred()) { | 771 if (resource->errorOccurred()) { |
| 772 if (memoryCache()->contains(resource.get())) | 772 if (memoryCache()->contains(resource.get())) |
| 773 memoryCache()->remove(resource.get()); | 773 memoryCache()->remove(resource.get()); |
| 774 return request.options().synchronousPolicy == RequestSynchronously ?
resource : 0; | 774 return request.options().synchronousPolicy == RequestSynchronously ?
resource : nullptr; |
| 775 } | 775 } |
| 776 } | 776 } |
| 777 | 777 |
| 778 // FIXME: Temporarily leave main resource caching disabled for chromium, | 778 // FIXME: Temporarily leave main resource caching disabled for chromium, |
| 779 // see https://bugs.webkit.org/show_bug.cgi?id=107962. Before caching main | 779 // see https://bugs.webkit.org/show_bug.cgi?id=107962. Before caching main |
| 780 // resources, we should be sure to understand the implications for memory | 780 // resources, we should be sure to understand the implications for memory |
| 781 // use. | 781 // use. |
| 782 // Remove main resource from cache to prevent reuse. | 782 // Remove main resource from cache to prevent reuse. |
| 783 if (type == Resource::MainResource) { | 783 if (type == Resource::MainResource) { |
| 784 ASSERT(policy != Use || m_documentLoader->substituteData().isValid()); | 784 ASSERT(policy != Use || m_documentLoader->substituteData().isValid()); |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 #if PRELOAD_DEBUG | 1265 #if PRELOAD_DEBUG |
| 1266 printf("PRELOADING %s\n", resource->url().string().latin1().data()); | 1266 printf("PRELOADING %s\n", resource->url().string().latin1().data()); |
| 1267 #endif | 1267 #endif |
| 1268 } | 1268 } |
| 1269 | 1269 |
| 1270 bool ResourceFetcher::isPreloaded(const String& urlString) const | 1270 bool ResourceFetcher::isPreloaded(const String& urlString) const |
| 1271 { | 1271 { |
| 1272 const KURL& url = m_document->completeURL(urlString); | 1272 const KURL& url = m_document->completeURL(urlString); |
| 1273 | 1273 |
| 1274 if (m_preloads) { | 1274 if (m_preloads) { |
| 1275 for (const auto& resource : *m_preloads) { | 1275 for (Resource* resource : *m_preloads) { |
| 1276 if (resource->url() == url) | 1276 if (resource->url() == url) |
| 1277 return true; | 1277 return true; |
| 1278 } | 1278 } |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 return false; | 1281 return false; |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 void ResourceFetcher::clearPreloads() | 1284 void ResourceFetcher::clearPreloads() |
| 1285 { | 1285 { |
| 1286 #if PRELOAD_DEBUG | 1286 #if PRELOAD_DEBUG |
| 1287 printPreloadStats(); | 1287 printPreloadStats(); |
| 1288 #endif | 1288 #endif |
| 1289 if (!m_preloads) | 1289 if (!m_preloads) |
| 1290 return; | 1290 return; |
| 1291 | 1291 |
| 1292 for (const auto& resource : *m_preloads) { | 1292 for (Resource* resource : *m_preloads) { |
| 1293 resource->decreasePreloadCount(); | 1293 resource->decreasePreloadCount(); |
| 1294 bool deleted = resource->deleteIfPossible(); | 1294 bool deleted = resource->deleteIfPossible(); |
| 1295 if (!deleted && resource->preloadResult() == Resource::PreloadNotReferen
ced) | 1295 if (!deleted && resource->preloadResult() == Resource::PreloadNotReferen
ced) |
| 1296 memoryCache()->remove(resource); | 1296 memoryCache()->remove(resource); |
| 1297 } | 1297 } |
| 1298 m_preloads.clear(); | 1298 m_preloads.clear(); |
| 1299 } | 1299 } |
| 1300 | 1300 |
| 1301 void ResourceFetcher::didFinishLoading(const Resource* resource, double finishTi
me, int64_t encodedDataLength) | 1301 void ResourceFetcher::didFinishLoading(const Resource* resource, double finishTi
me, int64_t encodedDataLength) |
| 1302 { | 1302 { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 { | 1456 { |
| 1457 if (!m_preloads) | 1457 if (!m_preloads) |
| 1458 return; | 1458 return; |
| 1459 | 1459 |
| 1460 unsigned scripts = 0; | 1460 unsigned scripts = 0; |
| 1461 unsigned scriptMisses = 0; | 1461 unsigned scriptMisses = 0; |
| 1462 unsigned stylesheets = 0; | 1462 unsigned stylesheets = 0; |
| 1463 unsigned stylesheetMisses = 0; | 1463 unsigned stylesheetMisses = 0; |
| 1464 unsigned images = 0; | 1464 unsigned images = 0; |
| 1465 unsigned imageMisses = 0; | 1465 unsigned imageMisses = 0; |
| 1466 for (const auto& resource : *m_preloads) { | 1466 for (Resource* resource : *m_preloads) { |
| 1467 if (resource->preloadResult() == Resource::PreloadNotReferenced) | 1467 if (resource->preloadResult() == Resource::PreloadNotReferenced) |
| 1468 printf("!! UNREFERENCED PRELOAD %s\n", resource->url().string().lati
n1().data()); | 1468 printf("!! UNREFERENCED PRELOAD %s\n", resource->url().string().lati
n1().data()); |
| 1469 else if (resource->preloadResult() == Resource::PreloadReferencedWhileCo
mplete) | 1469 else if (resource->preloadResult() == Resource::PreloadReferencedWhileCo
mplete) |
| 1470 printf("HIT COMPLETE PRELOAD %s\n", resource->url().string().latin1(
).data()); | 1470 printf("HIT COMPLETE PRELOAD %s\n", resource->url().string().latin1(
).data()); |
| 1471 else if (resource->preloadResult() == Resource::PreloadReferencedWhileLo
ading) | 1471 else if (resource->preloadResult() == Resource::PreloadReferencedWhileLo
ading) |
| 1472 printf("HIT LOADING PRELOAD %s\n", resource->url().string().latin1()
.data()); | 1472 printf("HIT LOADING PRELOAD %s\n", resource->url().string().latin1()
.data()); |
| 1473 | 1473 |
| 1474 if (resource->type() == Resource::Script) { | 1474 if (resource->type() == Resource::Script) { |
| 1475 scripts++; | 1475 scripts++; |
| 1476 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad
ing) | 1476 if (resource->preloadResult() < Resource::PreloadReferencedWhileLoad
ing) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 | 1542 |
| 1543 void ResourceFetcher::trace(Visitor* visitor) | 1543 void ResourceFetcher::trace(Visitor* visitor) |
| 1544 { | 1544 { |
| 1545 visitor->trace(m_document); | 1545 visitor->trace(m_document); |
| 1546 visitor->trace(m_loaders); | 1546 visitor->trace(m_loaders); |
| 1547 visitor->trace(m_multipartLoaders); | 1547 visitor->trace(m_multipartLoaders); |
| 1548 ResourceLoaderHost::trace(visitor); | 1548 ResourceLoaderHost::trace(visitor); |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 } | 1551 } |
| OLD | NEW |