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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 context().didLoadResource(resource); | 1173 context().didLoadResource(resource); |
1167 | 1174 |
1168 if (resource->isImage() && | 1175 if (resource->isImage() && |
1169 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { | 1176 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { |
1170 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); | 1177 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); |
1171 } | 1178 } |
1172 } | 1179 } |
1173 | 1180 |
1174 void ResourceFetcher::didFailLoading(Resource* resource, | 1181 void ResourceFetcher::didFailLoading(Resource* resource, |
1175 const ResourceError& error) { | 1182 const ResourceError& error) { |
| 1183 if (resource->resourceRequest().isCacheAwareLoadingActivated() && |
| 1184 error.isCacheMiss()) { |
| 1185 // Loading from disk cache fails, restore original cache policy and retry. |
| 1186 resource->deactivateCacheAwareLoading(); |
| 1187 resource->willReloadAfterDiskCacheMiss(); |
| 1188 resource->loader()->start(resource->resourceRequest(), |
| 1189 context().loadingTaskRunner(), |
| 1190 context().defersLoading()); |
| 1191 return; |
| 1192 } |
| 1193 |
1176 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1194 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); |
1177 removeResourceLoader(resource->loader()); | 1195 removeResourceLoader(resource->loader()); |
1178 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); | 1196 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); |
1179 bool isInternalRequest = resource->options().initiatorInfo.name == | 1197 bool isInternalRequest = resource->options().initiatorInfo.name == |
1180 FetchInitiatorTypeNames::internal; | 1198 FetchInitiatorTypeNames::internal; |
1181 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 1199 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
1182 resource->error(error); | 1200 resource->error(error); |
1183 context().didLoadResource(resource); | 1201 context().didLoadResource(resource); |
1184 | 1202 |
1185 if (resource->isImage() && | 1203 if (resource->isImage() && |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 resource->options()); | 1303 resource->options()); |
1286 | 1304 |
1287 // Resource requests from suborigins should not be intercepted by the service | 1305 // Resource requests from suborigins should not be intercepted by the service |
1288 // worker of the physical origin. This has the effect that, for now, | 1306 // worker of the physical origin. This has the effect that, for now, |
1289 // suborigins do not work with service workers. See | 1307 // suborigins do not work with service workers. See |
1290 // https://w3c.github.io/webappsec-suborigins/. | 1308 // https://w3c.github.io/webappsec-suborigins/. |
1291 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); | 1309 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); |
1292 if (sourceOrigin && sourceOrigin->hasSuborigin()) | 1310 if (sourceOrigin && sourceOrigin->hasSuborigin()) |
1293 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); | 1311 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); |
1294 | 1312 |
| 1313 // TODO(shaochuan): Workaround to persist cache-aware state, remove after |
| 1314 // fixed. crbug.com/632580 |
| 1315 resource->setResourceRequest(request); |
| 1316 |
1295 ResourceLoader* loader = ResourceLoader::create(this, resource); | 1317 ResourceLoader* loader = ResourceLoader::create(this, resource); |
1296 if (resource->shouldBlockLoadEvent()) | 1318 if (resource->shouldBlockLoadEvent()) |
1297 m_loaders.add(loader); | 1319 m_loaders.add(loader); |
1298 else | 1320 else |
1299 m_nonBlockingLoaders.add(loader); | 1321 m_nonBlockingLoaders.add(loader); |
1300 | 1322 |
1301 storeResourceTimingInitiatorInformation(resource); | 1323 storeResourceTimingInitiatorInformation(resource); |
1302 resource->setFetcherSecurityOrigin(sourceOrigin); | 1324 resource->setFetcherSecurityOrigin(sourceOrigin); |
1303 loader->start(request, context().loadingTaskRunner(), | 1325 loader->start(request, context().loadingTaskRunner(), |
1304 context().defersLoading()); | 1326 context().defersLoading()); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 visitor->trace(m_context); | 1644 visitor->trace(m_context); |
1623 visitor->trace(m_archive); | 1645 visitor->trace(m_archive); |
1624 visitor->trace(m_loaders); | 1646 visitor->trace(m_loaders); |
1625 visitor->trace(m_nonBlockingLoaders); | 1647 visitor->trace(m_nonBlockingLoaders); |
1626 visitor->trace(m_documentResources); | 1648 visitor->trace(m_documentResources); |
1627 visitor->trace(m_preloads); | 1649 visitor->trace(m_preloads); |
1628 visitor->trace(m_resourceTimingInfoMap); | 1650 visitor->trace(m_resourceTimingInfoMap); |
1629 } | 1651 } |
1630 | 1652 |
1631 } // namespace blink | 1653 } // namespace blink |
OLD | NEW |