| 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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 } | 807 } |
| 808 | 808 |
| 809 void ResourceFetcher::reloadImagesIfNotDeferred() | 809 void ResourceFetcher::reloadImagesIfNotDeferred() |
| 810 { | 810 { |
| 811 for (Resource* resource : m_documentResources.values()) { | 811 for (Resource* resource : m_documentResources.values()) { |
| 812 if (resource->getType() == Resource::Image && resource->stillNeedsLoad()
&& !shouldDeferImageLoad(resource->url())) | 812 if (resource->getType() == Resource::Image && resource->stillNeedsLoad()
&& !shouldDeferImageLoad(resource->url())) |
| 813 const_cast<Resource*>(resource)->load(this); | 813 const_cast<Resource*>(resource)->load(this); |
| 814 } | 814 } |
| 815 } | 815 } |
| 816 | 816 |
| 817 void ResourceFetcher::didLoadResource(Resource* resource) | |
| 818 { | |
| 819 context().didLoadResource(resource); | |
| 820 } | |
| 821 | |
| 822 int ResourceFetcher::requestCount() const | 817 int ResourceFetcher::requestCount() const |
| 823 { | 818 { |
| 824 return m_loaders ? m_loaders->size() : 0; | 819 return m_loaders ? m_loaders->size() : 0; |
| 825 } | 820 } |
| 826 | 821 |
| 827 void ResourceFetcher::preloadStarted(Resource* resource) | 822 void ResourceFetcher::preloadStarted(Resource* resource) |
| 828 { | 823 { |
| 829 if (m_preloads && m_preloads->contains(resource)) | 824 if (m_preloads && m_preloads->contains(resource)) |
| 830 return; | 825 return; |
| 831 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); | 826 TRACE_EVENT_ASYNC_STEP_INTO0("blink.net", "Resource", resource, "Preload"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 | 865 |
| 871 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) | 866 ArchiveResource* ResourceFetcher::createArchive(Resource* resource) |
| 872 { | 867 { |
| 873 // Only the top-frame can load MHTML. | 868 // Only the top-frame can load MHTML. |
| 874 if (!context().isMainFrame()) | 869 if (!context().isMainFrame()) |
| 875 return nullptr; | 870 return nullptr; |
| 876 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()
); | 871 m_archive = MHTMLArchive::create(resource->url(), resource->resourceBuffer()
); |
| 877 return m_archive ? m_archive->mainResource() : nullptr; | 872 return m_archive ? m_archive->mainResource() : nullptr; |
| 878 } | 873 } |
| 879 | 874 |
| 880 void ResourceFetcher::didFinishLoading(Resource* resource, double finishTime, in
t64_t encodedDataLength) | 875 void ResourceFetcher::didFinishLoading(Resource* resource, double finishTime, in
t64_t encodedDataLength, DidFinishLoadingReason finishReason) |
| 881 { | 876 { |
| 882 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); | 877 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); |
| 883 // The ResourceLoader might be in |m_nonBlockingLoaders| for multipart respo
nses. | 878 DCHECK(resource); |
| 884 ASSERT(resource); | 879 |
| 885 ASSERT(!(m_loaders && m_loaders->contains(resource->loader()))); | 880 // When loading a multipart resource, make the loader non-block when |
| 881 // finishing loading the first part. |
| 882 if (finishReason == DidFinishFirstPartInMultipart) |
| 883 moveResourceLoaderToNonBlocking(resource->loader()); |
| 884 else |
| 885 removeResourceLoader(resource->loader()); |
| 886 DCHECK(!m_loaders || !m_loaders->contains(resource->loader())); |
| 887 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s || !m_nonBlockingLoaders->contains(resource->loader())); |
| 886 | 888 |
| 887 if (OwnPtr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(resource)
) { | 889 if (OwnPtr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(resource)
) { |
| 888 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { | 890 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { |
| 889 populateResourceTiming(info.get(), resource); | 891 populateResourceTiming(info.get(), resource); |
| 890 info->setLoadFinishTime(finishTime); | 892 info->setLoadFinishTime(finishTime); |
| 891 if (resource->options().requestInitiatorContext == DocumentContext) | 893 if (resource->options().requestInitiatorContext == DocumentContext) |
| 892 context().addResourceTiming(*info); | 894 context().addResourceTiming(*info); |
| 893 resource->reportResourceTimingToClients(*info); | 895 resource->reportResourceTimingToClients(*info); |
| 894 } | 896 } |
| 895 } | 897 } |
| 896 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod
edDataLength); | 898 context().dispatchDidFinishLoading(resource->identifier(), finishTime, encod
edDataLength); |
| 899 if (finishReason == DidFinishLoading) |
| 900 resource->finish(finishTime); |
| 901 context().didLoadResource(resource); |
| 897 } | 902 } |
| 898 | 903 |
| 899 void ResourceFetcher::didFailLoading(const Resource* resource, const ResourceErr
or& error) | 904 void ResourceFetcher::didFailLoading(Resource* resource, const ResourceError& er
ror) |
| 900 { | 905 { |
| 901 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); | 906 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource); |
| 902 removeResourceLoader(resource->loader()); | 907 removeResourceLoader(resource->loader()); |
| 903 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); | 908 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); |
| 904 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit
iatorTypeNames::internal; | 909 bool isInternalRequest = resource->options().initiatorInfo.name == FetchInit
iatorTypeNames::internal; |
| 905 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 910 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
| 911 resource->error(error); |
| 912 context().didLoadResource(resource); |
| 906 } | 913 } |
| 907 | 914 |
| 908 void ResourceFetcher::didReceiveResponse(Resource* resource, const ResourceRespo
nse& response) | 915 void ResourceFetcher::didReceiveResponse(Resource* resource, const ResourceRespo
nse& response) |
| 909 { | 916 { |
| 910 // If the response is fetched via ServiceWorker, the original URL of the res
ponse could be different from the URL of the request. | 917 // If the response is fetched via ServiceWorker, the original URL of the res
ponse could be different from the URL of the request. |
| 911 // We check the URL not to load the resources which are forbidden by the pag
e CSP. | 918 // We check the URL not to load the resources which are forbidden by the pag
e CSP. |
| 912 // https://w3c.github.io/webappsec-csp/#should-block-response | 919 // https://w3c.github.io/webappsec-csp/#should-block-response |
| 913 if (response.wasFetchedViaServiceWorker()) { | 920 if (response.wasFetchedViaServiceWorker()) { |
| 914 const KURL& originalURL = response.originalURLViaServiceWorker(); | 921 const KURL& originalURL = response.originalURLViaServiceWorker(); |
| 915 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType
(), resource->resourceRequest(), originalURL, resource->options())) { | 922 if (!originalURL.isEmpty() && !context().allowResponse(resource->getType
(), resource->resourceRequest(), originalURL, resource->options())) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 visitor->trace(m_context); | 1171 visitor->trace(m_context); |
| 1165 visitor->trace(m_archive); | 1172 visitor->trace(m_archive); |
| 1166 visitor->trace(m_loaders); | 1173 visitor->trace(m_loaders); |
| 1167 visitor->trace(m_nonBlockingLoaders); | 1174 visitor->trace(m_nonBlockingLoaders); |
| 1168 visitor->trace(m_documentResources); | 1175 visitor->trace(m_documentResources); |
| 1169 visitor->trace(m_preloads); | 1176 visitor->trace(m_preloads); |
| 1170 visitor->trace(m_resourceTimingInfoMap); | 1177 visitor->trace(m_resourceTimingInfoMap); |
| 1171 } | 1178 } |
| 1172 | 1179 |
| 1173 } // namespace blink | 1180 } // namespace blink |
| OLD | NEW |