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 | 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
6 rights reserved. | 6 rights reserved. |
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
8 | 8 |
9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 FetchRequest& request, | 723 FetchRequest& request, |
724 const String& charset, | 724 const String& charset, |
725 const ResourceFactory& factory) { | 725 const ResourceFactory& factory) { |
726 const String cacheIdentifier = getCacheIdentifier(); | 726 const String cacheIdentifier = getCacheIdentifier(); |
727 DCHECK(!memoryCache()->resourceForURL(request.resourceRequest().url(), | 727 DCHECK(!memoryCache()->resourceForURL(request.resourceRequest().url(), |
728 cacheIdentifier)); | 728 cacheIdentifier)); |
729 | 729 |
730 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " | 730 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " |
731 << request.resourceRequest().url().elidedString(); | 731 << request.resourceRequest().url().elidedString(); |
732 | 732 |
| 733 if (request.isCacheAwareLoadingEnabled()) |
| 734 request.mutableResourceRequest().mayActivateCacheAwareLoading(); |
| 735 |
733 Resource* resource = | 736 Resource* resource = |
734 factory.create(request.resourceRequest(), request.options(), charset); | 737 factory.create(request.resourceRequest(), request.options(), charset); |
735 resource->setLinkPreload(request.isLinkPreload()); | 738 resource->setLinkPreload(request.isLinkPreload()); |
736 if (request.forPreload()) { | 739 if (request.forPreload()) { |
737 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); | 740 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); |
738 } | 741 } |
739 resource->setCacheIdentifier(cacheIdentifier); | 742 resource->setCacheIdentifier(cacheIdentifier); |
740 | 743 |
741 // Don't add main resource to cache to prevent reuse. | 744 // Don't add main resource to cache to prevent reuse. |
742 if (factory.type() != Resource::MainResource) | 745 if (factory.type() != Resource::MainResource) |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 return m_archive ? m_archive->mainResource() : nullptr; | 1117 return m_archive ? m_archive->mainResource() : nullptr; |
1115 } | 1118 } |
1116 | 1119 |
1117 void ResourceFetcher::didFinishLoading(Resource* resource, | 1120 void ResourceFetcher::didFinishLoading(Resource* resource, |
1118 double finishTime, | 1121 double finishTime, |
1119 int64_t encodedDataLength, | 1122 int64_t encodedDataLength, |
1120 DidFinishLoadingReason finishReason) { | 1123 DidFinishLoadingReason finishReason) { |
1121 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1124 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); |
1122 DCHECK(resource); | 1125 DCHECK(resource); |
1123 | 1126 |
| 1127 // Restore original cache policy if cache-aware loading was activated. |
| 1128 if (resource->resourceRequest().isCacheAwareLoadingActivated()) |
| 1129 resource->deactivateCacheAwareLoading(); |
| 1130 |
1124 // When loading a multipart resource, make the loader non-block when finishing | 1131 // When loading a multipart resource, make the loader non-block when finishing |
1125 // loading the first part. | 1132 // loading the first part. |
1126 if (finishReason == DidFinishFirstPartInMultipart) | 1133 if (finishReason == DidFinishFirstPartInMultipart) |
1127 moveResourceLoaderToNonBlocking(resource->loader()); | 1134 moveResourceLoaderToNonBlocking(resource->loader()); |
1128 else | 1135 else |
1129 removeResourceLoader(resource->loader()); | 1136 removeResourceLoader(resource->loader()); |
1130 DCHECK(!m_loaders.contains(resource->loader())); | 1137 DCHECK(!m_loaders.contains(resource->loader())); |
1131 DCHECK(finishReason == DidFinishFirstPartInMultipart || | 1138 DCHECK(finishReason == DidFinishFirstPartInMultipart || |
1132 !m_nonBlockingLoaders.contains(resource->loader())); | 1139 !m_nonBlockingLoaders.contains(resource->loader())); |
1133 | 1140 |
(...skipping 27 matching lines...) Expand all Loading... |
1161 } | 1168 } |
1162 context().dispatchDidFinishLoading(resource->identifier(), finishTime, | 1169 context().dispatchDidFinishLoading(resource->identifier(), finishTime, |
1163 encodedDataLength); | 1170 encodedDataLength); |
1164 if (finishReason == DidFinishLoading) | 1171 if (finishReason == DidFinishLoading) |
1165 resource->finish(finishTime); | 1172 resource->finish(finishTime); |
1166 context().didLoadResource(resource); | 1173 context().didLoadResource(resource); |
1167 } | 1174 } |
1168 | 1175 |
1169 void ResourceFetcher::didFailLoading(Resource* resource, | 1176 void ResourceFetcher::didFailLoading(Resource* resource, |
1170 const ResourceError& error) { | 1177 const ResourceError& error) { |
| 1178 if (resource->resourceRequest().isCacheAwareLoadingActivated() && |
| 1179 error.isCacheMiss()) { |
| 1180 // Loading from disk cache fails, restore original cache policy and retry. |
| 1181 resource->deactivateCacheAwareLoading(); |
| 1182 resource->willReloadAfterDiskCacheMiss(); |
| 1183 resource->loader()->start(resource->resourceRequest(), |
| 1184 context().loadingTaskRunner(), |
| 1185 context().defersLoading()); |
| 1186 return; |
| 1187 } |
| 1188 |
1171 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1189 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); |
1172 removeResourceLoader(resource->loader()); | 1190 removeResourceLoader(resource->loader()); |
1173 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); | 1191 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); |
1174 bool isInternalRequest = resource->options().initiatorInfo.name == | 1192 bool isInternalRequest = resource->options().initiatorInfo.name == |
1175 FetchInitiatorTypeNames::internal; | 1193 FetchInitiatorTypeNames::internal; |
1176 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 1194 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
1177 resource->error(error); | 1195 resource->error(error); |
1178 context().didLoadResource(resource); | 1196 context().didLoadResource(resource); |
1179 } | 1197 } |
1180 | 1198 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 resource->options()); | 1293 resource->options()); |
1276 | 1294 |
1277 // Resource requests from suborigins should not be intercepted by the service | 1295 // Resource requests from suborigins should not be intercepted by the service |
1278 // worker of the physical origin. This has the effect that, for now, | 1296 // worker of the physical origin. This has the effect that, for now, |
1279 // suborigins do not work with service workers. See | 1297 // suborigins do not work with service workers. See |
1280 // https://w3c.github.io/webappsec-suborigins/. | 1298 // https://w3c.github.io/webappsec-suborigins/. |
1281 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); | 1299 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); |
1282 if (sourceOrigin && sourceOrigin->hasSuborigin()) | 1300 if (sourceOrigin && sourceOrigin->hasSuborigin()) |
1283 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); | 1301 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); |
1284 | 1302 |
| 1303 // TODO(632580): Workaround to persist cache-aware state, remove after fixed. |
| 1304 resource->setResourceRequest(request); |
| 1305 |
1285 ResourceLoader* loader = ResourceLoader::create(this, resource); | 1306 ResourceLoader* loader = ResourceLoader::create(this, resource); |
1286 if (resource->shouldBlockLoadEvent()) | 1307 if (resource->shouldBlockLoadEvent()) |
1287 m_loaders.add(loader); | 1308 m_loaders.add(loader); |
1288 else | 1309 else |
1289 m_nonBlockingLoaders.add(loader); | 1310 m_nonBlockingLoaders.add(loader); |
1290 | 1311 |
1291 storeResourceTimingInitiatorInformation(resource); | 1312 storeResourceTimingInitiatorInformation(resource); |
1292 resource->setFetcherSecurityOrigin(sourceOrigin); | 1313 resource->setFetcherSecurityOrigin(sourceOrigin); |
1293 loader->start(request, context().loadingTaskRunner(), | 1314 loader->start(request, context().loadingTaskRunner(), |
1294 context().defersLoading()); | 1315 context().defersLoading()); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 visitor->trace(m_context); | 1633 visitor->trace(m_context); |
1613 visitor->trace(m_archive); | 1634 visitor->trace(m_archive); |
1614 visitor->trace(m_loaders); | 1635 visitor->trace(m_loaders); |
1615 visitor->trace(m_nonBlockingLoaders); | 1636 visitor->trace(m_nonBlockingLoaders); |
1616 visitor->trace(m_documentResources); | 1637 visitor->trace(m_documentResources); |
1617 visitor->trace(m_preloads); | 1638 visitor->trace(m_preloads); |
1618 visitor->trace(m_resourceTimingInfoMap); | 1639 visitor->trace(m_resourceTimingInfoMap); |
1619 } | 1640 } |
1620 | 1641 |
1621 } // namespace blink | 1642 } // namespace blink |
OLD | NEW |