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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (!substituteData.isValid()) | 352 if (!substituteData.isValid()) |
353 memoryCache()->add(resource); | 353 memoryCache()->add(resource); |
354 | 354 |
355 return resource; | 355 return resource; |
356 } | 356 } |
357 | 357 |
358 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) | 358 void ResourceFetcher::moveCachedNonBlockingResourceToBlocking(Resource* resource
, const FetchRequest& request) |
359 { | 359 { |
360 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. | 360 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
to not-block even after being preloaded and discovered. |
361 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { | 361 if (resource && resource->loader() && resource->isLoadEventBlockingResourceT
ype() && resource->isLinkPreload() && !request.forPreload()) { |
362 if (m_nonBlockingLoaders) | 362 m_nonBlockingLoaders.remove(resource->loader()); |
363 m_nonBlockingLoaders->remove(resource->loader()); | 363 m_loaders.add(resource->loader()); |
364 if (!m_loaders) | |
365 m_loaders = ResourceLoaderSet::create(); | |
366 m_loaders->add(resource->loader()); | |
367 } | 364 } |
368 } | 365 } |
369 | 366 |
370 void ResourceFetcher::updateMemoryCacheStats(Resource* resource, RevalidationPol
icy policy, const FetchRequest& request, const ResourceFactory& factory, bool i
sStaticData) const | 367 void ResourceFetcher::updateMemoryCacheStats(Resource* resource, RevalidationPol
icy policy, const FetchRequest& request, const ResourceFactory& factory, bool i
sStaticData) const |
371 { | 368 { |
372 if (isStaticData) | 369 if (isStaticData) |
373 return; | 370 return; |
374 | 371 |
375 if (request.forPreload()) { | 372 if (request.forPreload()) { |
376 DEFINE_RESOURCE_HISTOGRAM("Preload."); | 373 DEFINE_RESOURCE_HISTOGRAM("Preload."); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 void ResourceFetcher::reloadImagesIfNotDeferred() | 808 void ResourceFetcher::reloadImagesIfNotDeferred() |
812 { | 809 { |
813 for (Resource* resource : m_documentResources.values()) { | 810 for (Resource* resource : m_documentResources.values()) { |
814 if (resource->getType() == Resource::Image && resource->stillNeedsLoad()
&& !shouldDeferImageLoad(resource->url())) | 811 if (resource->getType() == Resource::Image && resource->stillNeedsLoad()
&& !shouldDeferImageLoad(resource->url())) |
815 const_cast<Resource*>(resource)->load(this); | 812 const_cast<Resource*>(resource)->load(this); |
816 } | 813 } |
817 } | 814 } |
818 | 815 |
819 int ResourceFetcher::requestCount() const | 816 int ResourceFetcher::requestCount() const |
820 { | 817 { |
821 return m_loaders ? m_loaders->size() : 0; | 818 return m_loaders.size(); |
822 } | 819 } |
823 | 820 |
824 void ResourceFetcher::preloadStarted(Resource* resource) | 821 void ResourceFetcher::preloadStarted(Resource* resource) |
825 { | 822 { |
826 if (m_preloads && m_preloads->contains(resource)) | 823 if (m_preloads && m_preloads->contains(resource)) |
827 return; | 824 return; |
828 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 825 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
829 resource->increasePreloadCount(); | 826 resource->increasePreloadCount(); |
830 | 827 |
831 if (!m_preloads) | 828 if (!m_preloads) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 { | 870 { |
874 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); | 871 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); |
875 DCHECK(resource); | 872 DCHECK(resource); |
876 | 873 |
877 // When loading a multipart resource, make the loader non-block when | 874 // When loading a multipart resource, make the loader non-block when |
878 // finishing loading the first part. | 875 // finishing loading the first part. |
879 if (finishReason == DidFinishFirstPartInMultipart) | 876 if (finishReason == DidFinishFirstPartInMultipart) |
880 moveResourceLoaderToNonBlocking(resource->loader()); | 877 moveResourceLoaderToNonBlocking(resource->loader()); |
881 else | 878 else |
882 removeResourceLoader(resource->loader()); | 879 removeResourceLoader(resource->loader()); |
883 DCHECK(!m_loaders || !m_loaders->contains(resource->loader())); | 880 DCHECK(!m_loaders.contains(resource->loader())); |
884 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s || !m_nonBlockingLoaders->contains(resource->loader())); | 881 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s.contains(resource->loader())); |
885 | 882 |
886 if (OwnPtr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(resource)
) { | 883 if (OwnPtr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(resource)
) { |
887 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { | 884 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { |
888 populateResourceTiming(info.get(), resource); | 885 populateResourceTiming(info.get(), resource); |
889 info->setLoadFinishTime(finishTime); | 886 info->setLoadFinishTime(finishTime); |
890 if (resource->options().requestInitiatorContext == DocumentContext) | 887 if (resource->options().requestInitiatorContext == DocumentContext) |
891 context().addResourceTiming(*info); | 888 context().addResourceTiming(*info); |
892 resource->reportResourceTimingToClients(*info); | 889 resource->reportResourceTimingToClients(*info); |
893 } | 890 } |
894 } | 891 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 context().dispatchDidDownloadData(resource->identifier(), dataLength, encode
dDataLength); | 933 context().dispatchDidDownloadData(resource->identifier(), dataLength, encode
dDataLength); |
937 } | 934 } |
938 | 935 |
939 void ResourceFetcher::acceptDataFromThreadedReceiver(unsigned long identifier, c
onst char* data, int dataLength, int encodedDataLength) | 936 void ResourceFetcher::acceptDataFromThreadedReceiver(unsigned long identifier, c
onst char* data, int dataLength, int encodedDataLength) |
940 { | 937 { |
941 context().dispatchDidReceiveData(identifier, data, dataLength, encodedDataLe
ngth); | 938 context().dispatchDidReceiveData(identifier, data, dataLength, encodedDataLe
ngth); |
942 } | 939 } |
943 | 940 |
944 void ResourceFetcher::moveResourceLoaderToNonBlocking(ResourceLoader* loader) | 941 void ResourceFetcher::moveResourceLoaderToNonBlocking(ResourceLoader* loader) |
945 { | 942 { |
946 if (!m_nonBlockingLoaders) | 943 m_nonBlockingLoaders.add(loader); |
947 m_nonBlockingLoaders = ResourceLoaderSet::create(); | 944 m_loaders.remove(loader); |
948 m_nonBlockingLoaders->add(loader); | |
949 m_loaders->remove(loader); | |
950 } | 945 } |
951 | 946 |
952 void ResourceFetcher::willStartLoadingResource(Resource* resource, ResourceLoade
r* loader, ResourceRequest& request) | 947 void ResourceFetcher::willStartLoadingResource(Resource* resource, ResourceLoade
r* loader, ResourceRequest& request) |
953 { | 948 { |
954 if (resource->shouldBlockLoadEvent()) { | 949 if (resource->shouldBlockLoadEvent()) |
955 if (!m_loaders) | 950 m_loaders.add(loader); |
956 m_loaders = ResourceLoaderSet::create(); | 951 else |
957 m_loaders->add(loader); | 952 m_nonBlockingLoaders.add(loader); |
958 } else { | |
959 if (!m_nonBlockingLoaders) | |
960 m_nonBlockingLoaders = ResourceLoaderSet::create(); | |
961 m_nonBlockingLoaders->add(loader); | |
962 } | |
963 | 953 |
964 context().willStartLoadingResource(resource, request); | 954 context().willStartLoadingResource(resource, request); |
965 storeResourceTimingInitiatorInformation(resource); | 955 storeResourceTimingInitiatorInformation(resource); |
966 | 956 |
967 context().dispatchWillSendRequest(resource->identifier(), request, ResourceR
esponse(), resource->options().initiatorInfo); | 957 context().dispatchWillSendRequest(resource->identifier(), request, ResourceR
esponse(), resource->options().initiatorInfo); |
968 } | 958 } |
969 | 959 |
970 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) | 960 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) |
971 { | 961 { |
972 if (m_loaders && m_loaders->contains(loader)) | 962 if (m_loaders.contains(loader)) |
973 m_loaders->remove(loader); | 963 m_loaders.remove(loader); |
974 else if (m_nonBlockingLoaders && m_nonBlockingLoaders->contains(loader)) | 964 else if (m_nonBlockingLoaders.contains(loader)) |
975 m_nonBlockingLoaders->remove(loader); | 965 m_nonBlockingLoaders.remove(loader); |
976 else | 966 else |
977 ASSERT_NOT_REACHED(); | 967 ASSERT_NOT_REACHED(); |
978 } | 968 } |
979 | 969 |
980 void ResourceFetcher::stopFetching() | 970 void ResourceFetcher::stopFetching() |
981 { | 971 { |
982 if (m_nonBlockingLoaders) | 972 m_nonBlockingLoaders.cancelAll(); |
983 m_nonBlockingLoaders->cancelAll(); | 973 m_loaders.cancelAll(); |
984 if (m_loaders) | |
985 m_loaders->cancelAll(); | |
986 } | 974 } |
987 | 975 |
988 bool ResourceFetcher::isFetching() const | 976 bool ResourceFetcher::isFetching() const |
989 { | 977 { |
990 return m_loaders && !m_loaders->isEmpty(); | 978 return !m_loaders.isEmpty(); |
991 } | 979 } |
992 | 980 |
993 void ResourceFetcher::setDefersLoading(bool defers) | 981 void ResourceFetcher::setDefersLoading(bool defers) |
994 { | 982 { |
995 if (m_loaders) | 983 m_loaders.setAllDefersLoading(defers); |
996 m_loaders->setAllDefersLoading(defers); | 984 m_nonBlockingLoaders.setAllDefersLoading(defers); |
997 if (m_nonBlockingLoaders) | |
998 m_nonBlockingLoaders->setAllDefersLoading(defers); | |
999 } | 985 } |
1000 | 986 |
1001 bool ResourceFetcher::defersLoading() const | 987 bool ResourceFetcher::defersLoading() const |
1002 { | 988 { |
1003 return context().defersLoading(); | 989 return context().defersLoading(); |
1004 } | 990 } |
1005 | 991 |
1006 static bool isManualRedirectFetchRequest(const ResourceRequest& request) | 992 static bool isManualRedirectFetchRequest(const ResourceRequest& request) |
1007 { | 993 { |
1008 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual
&& request.requestContext() == WebURLRequest::RequestContextFetch; | 994 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual
&& request.requestContext() == WebURLRequest::RequestContextFetch; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 visitor->trace(m_context); | 1216 visitor->trace(m_context); |
1231 visitor->trace(m_archive); | 1217 visitor->trace(m_archive); |
1232 visitor->trace(m_loaders); | 1218 visitor->trace(m_loaders); |
1233 visitor->trace(m_nonBlockingLoaders); | 1219 visitor->trace(m_nonBlockingLoaders); |
1234 visitor->trace(m_documentResources); | 1220 visitor->trace(m_documentResources); |
1235 visitor->trace(m_preloads); | 1221 visitor->trace(m_preloads); |
1236 visitor->trace(m_resourceTimingInfoMap); | 1222 visitor->trace(m_resourceTimingInfoMap); |
1237 } | 1223 } |
1238 | 1224 |
1239 } // namespace blink | 1225 } // namespace blink |
OLD | NEW |