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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ | 94 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ |
95 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ | 95 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ |
96 } | 96 } |
97 | 97 |
98 bool IsCrossOrigin(const KURL& a, const KURL& b) { | 98 bool IsCrossOrigin(const KURL& a, const KURL& b) { |
99 RefPtr<SecurityOrigin> originA = SecurityOrigin::create(a); | 99 RefPtr<SecurityOrigin> originA = SecurityOrigin::create(a); |
100 RefPtr<SecurityOrigin> originB = SecurityOrigin::create(b); | 100 RefPtr<SecurityOrigin> originB = SecurityOrigin::create(b); |
101 return !originB->isSameSchemeHostPort(originA.get()); | 101 return !originB->isSameSchemeHostPort(originA.get()); |
102 } | 102 } |
103 | 103 |
| 104 void mayActivateCacheAwareLoading(ResourceRequest& request) { |
| 105 switch (request.getCachePolicy()) { |
| 106 case WebCachePolicy::BypassingCache: |
| 107 case WebCachePolicy::ReturnCacheDataDontLoad: |
| 108 return; |
| 109 case WebCachePolicy::UseProtocolCachePolicy: |
| 110 case WebCachePolicy::ValidatingCacheData: |
| 111 case WebCachePolicy::ReturnCacheDataElseLoad: |
| 112 break; |
| 113 } |
| 114 request.activateCacheAwareLoading(); |
| 115 } |
| 116 |
104 } // namespace | 117 } // namespace |
105 | 118 |
106 static void RecordSriResourceIntegrityMismatchEvent( | 119 static void RecordSriResourceIntegrityMismatchEvent( |
107 SriResourceIntegrityMismatchEvent event) { | 120 SriResourceIntegrityMismatchEvent event) { |
108 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 121 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
109 EnumerationHistogram, integrityHistogram, | 122 EnumerationHistogram, integrityHistogram, |
110 new EnumerationHistogram("sri.resource_integrity_mismatch_event", | 123 new EnumerationHistogram("sri.resource_integrity_mismatch_event", |
111 SriResourceIntegrityMismatchEventCount)); | 124 SriResourceIntegrityMismatchEventCount)); |
112 integrityHistogram.count(event); | 125 integrityHistogram.count(event); |
113 } | 126 } |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 FetchRequest& request, | 728 FetchRequest& request, |
716 const String& charset, | 729 const String& charset, |
717 const ResourceFactory& factory) { | 730 const ResourceFactory& factory) { |
718 const String cacheIdentifier = getCacheIdentifier(); | 731 const String cacheIdentifier = getCacheIdentifier(); |
719 DCHECK(!memoryCache()->resourceForURL(request.resourceRequest().url(), | 732 DCHECK(!memoryCache()->resourceForURL(request.resourceRequest().url(), |
720 cacheIdentifier)); | 733 cacheIdentifier)); |
721 | 734 |
722 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " | 735 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " |
723 << request.resourceRequest().url().elidedString(); | 736 << request.resourceRequest().url().elidedString(); |
724 | 737 |
| 738 if (request.isCacheAwareLoadingEnabled()) |
| 739 mayActivateCacheAwareLoading(request.mutableResourceRequest()); |
| 740 |
725 Resource* resource = | 741 Resource* resource = |
726 factory.create(request.resourceRequest(), request.options(), charset); | 742 factory.create(request.resourceRequest(), request.options(), charset); |
727 resource->setLinkPreload(request.isLinkPreload()); | 743 resource->setLinkPreload(request.isLinkPreload()); |
728 if (request.forPreload()) { | 744 if (request.forPreload()) { |
729 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); | 745 resource->setPreloadDiscoveryTime(request.preloadDiscoveryTime()); |
730 } | 746 } |
731 resource->setCacheIdentifier(cacheIdentifier); | 747 resource->setCacheIdentifier(cacheIdentifier); |
732 | 748 |
733 // Don't add main resource to cache to prevent reuse. | 749 // Don't add main resource to cache to prevent reuse. |
734 if (factory.type() != Resource::MainResource) | 750 if (factory.type() != Resource::MainResource) |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 return m_archive ? m_archive->mainResource() : nullptr; | 1122 return m_archive ? m_archive->mainResource() : nullptr; |
1107 } | 1123 } |
1108 | 1124 |
1109 void ResourceFetcher::didFinishLoading(Resource* resource, | 1125 void ResourceFetcher::didFinishLoading(Resource* resource, |
1110 double finishTime, | 1126 double finishTime, |
1111 int64_t encodedDataLength, | 1127 int64_t encodedDataLength, |
1112 DidFinishLoadingReason finishReason) { | 1128 DidFinishLoadingReason finishReason) { |
1113 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1129 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); |
1114 DCHECK(resource); | 1130 DCHECK(resource); |
1115 | 1131 |
| 1132 if (resource->resourceRequest().isCacheAwareLoadingActivated()) |
| 1133 resource->deactivateCacheAwareLoading(); |
| 1134 |
1116 // When loading a multipart resource, make the loader non-block when finishing | 1135 // When loading a multipart resource, make the loader non-block when finishing |
1117 // loading the first part. | 1136 // loading the first part. |
1118 if (finishReason == DidFinishFirstPartInMultipart) | 1137 if (finishReason == DidFinishFirstPartInMultipart) |
1119 moveResourceLoaderToNonBlocking(resource->loader()); | 1138 moveResourceLoaderToNonBlocking(resource->loader()); |
1120 else | 1139 else |
1121 removeResourceLoader(resource->loader()); | 1140 removeResourceLoader(resource->loader()); |
1122 DCHECK(!m_loaders.contains(resource->loader())); | 1141 DCHECK(!m_loaders.contains(resource->loader())); |
1123 DCHECK(finishReason == DidFinishFirstPartInMultipart || | 1142 DCHECK(finishReason == DidFinishFirstPartInMultipart || |
1124 !m_nonBlockingLoaders.contains(resource->loader())); | 1143 !m_nonBlockingLoaders.contains(resource->loader())); |
1125 | 1144 |
(...skipping 27 matching lines...) Expand all Loading... |
1153 } | 1172 } |
1154 context().dispatchDidFinishLoading(resource->identifier(), finishTime, | 1173 context().dispatchDidFinishLoading(resource->identifier(), finishTime, |
1155 encodedDataLength); | 1174 encodedDataLength); |
1156 if (finishReason == DidFinishLoading) | 1175 if (finishReason == DidFinishLoading) |
1157 resource->finish(finishTime); | 1176 resource->finish(finishTime); |
1158 context().didLoadResource(resource); | 1177 context().didLoadResource(resource); |
1159 } | 1178 } |
1160 | 1179 |
1161 void ResourceFetcher::didFailLoading(Resource* resource, | 1180 void ResourceFetcher::didFailLoading(Resource* resource, |
1162 const ResourceError& error) { | 1181 const ResourceError& error) { |
| 1182 if (resource->resourceRequest().isCacheAwareLoadingActivated() && |
| 1183 error.isCacheMiss()) { |
| 1184 resource->deactivateCacheAwareLoading(); |
| 1185 resource->willReloadAfterDiskCacheMiss(); |
| 1186 resource->loader()->start(resource->resourceRequest(), |
| 1187 context().loadingTaskRunner(), |
| 1188 context().defersLoading()); |
| 1189 return; |
| 1190 } |
| 1191 |
1163 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1192 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); |
1164 removeResourceLoader(resource->loader()); | 1193 removeResourceLoader(resource->loader()); |
1165 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); | 1194 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); |
1166 bool isInternalRequest = resource->options().initiatorInfo.name == | 1195 bool isInternalRequest = resource->options().initiatorInfo.name == |
1167 FetchInitiatorTypeNames::internal; | 1196 FetchInitiatorTypeNames::internal; |
1168 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 1197 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
1169 resource->error(error); | 1198 resource->error(error); |
1170 context().didLoadResource(resource); | 1199 context().didLoadResource(resource); |
1171 } | 1200 } |
1172 | 1201 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 resource->options()); | 1295 resource->options()); |
1267 | 1296 |
1268 // Resource requests from suborigins should not be intercepted by the service | 1297 // Resource requests from suborigins should not be intercepted by the service |
1269 // worker of the physical origin. This has the effect that, for now, | 1298 // worker of the physical origin. This has the effect that, for now, |
1270 // suborigins do not work with service workers. See | 1299 // suborigins do not work with service workers. See |
1271 // https://w3c.github.io/webappsec-suborigins/. | 1300 // https://w3c.github.io/webappsec-suborigins/. |
1272 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); | 1301 SecurityOrigin* sourceOrigin = context().getSecurityOrigin(); |
1273 if (sourceOrigin && sourceOrigin->hasSuborigin()) | 1302 if (sourceOrigin && sourceOrigin->hasSuborigin()) |
1274 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); | 1303 request.setSkipServiceWorker(WebURLRequest::SkipServiceWorker::All); |
1275 | 1304 |
| 1305 // TODO(632580): Workaround to persist cache-aware state, remove after fixed. |
| 1306 resource->setResourceRequest(request); |
| 1307 |
1276 ResourceLoader* loader = ResourceLoader::create(this, resource); | 1308 ResourceLoader* loader = ResourceLoader::create(this, resource); |
1277 if (resource->shouldBlockLoadEvent()) | 1309 if (resource->shouldBlockLoadEvent()) |
1278 m_loaders.add(loader); | 1310 m_loaders.add(loader); |
1279 else | 1311 else |
1280 m_nonBlockingLoaders.add(loader); | 1312 m_nonBlockingLoaders.add(loader); |
1281 | 1313 |
1282 storeResourceTimingInitiatorInformation(resource); | 1314 storeResourceTimingInitiatorInformation(resource); |
1283 resource->setFetcherSecurityOrigin(sourceOrigin); | 1315 resource->setFetcherSecurityOrigin(sourceOrigin); |
1284 loader->start(request, context().loadingTaskRunner(), | 1316 loader->start(request, context().loadingTaskRunner(), |
1285 context().defersLoading()); | 1317 context().defersLoading()); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 visitor->trace(m_context); | 1635 visitor->trace(m_context); |
1604 visitor->trace(m_archive); | 1636 visitor->trace(m_archive); |
1605 visitor->trace(m_loaders); | 1637 visitor->trace(m_loaders); |
1606 visitor->trace(m_nonBlockingLoaders); | 1638 visitor->trace(m_nonBlockingLoaders); |
1607 visitor->trace(m_documentResources); | 1639 visitor->trace(m_documentResources); |
1608 visitor->trace(m_preloads); | 1640 visitor->trace(m_preloads); |
1609 visitor->trace(m_resourceTimingInfoMap); | 1641 visitor->trace(m_resourceTimingInfoMap); |
1610 } | 1642 } |
1611 | 1643 |
1612 } // namespace blink | 1644 } // namespace blink |
OLD | NEW |