| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ | 88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ |
| 89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ | 89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ |
| 90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ | 90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ |
| 91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ | 91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ |
| 92 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ | 92 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ |
| 93 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ | 93 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ |
| 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) { |
| 99 RefPtr<SecurityOrigin> originA = SecurityOrigin::create(a); |
| 100 RefPtr<SecurityOrigin> originB = SecurityOrigin::create(b); |
| 101 return !originB->isSameSchemeHostPort(originA.get()); |
| 102 } |
| 103 |
| 98 } // namespace | 104 } // namespace |
| 99 | 105 |
| 100 static void RecordSriResourceIntegrityMismatchEvent( | 106 static void RecordSriResourceIntegrityMismatchEvent( |
| 101 SriResourceIntegrityMismatchEvent event) { | 107 SriResourceIntegrityMismatchEvent event) { |
| 102 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 108 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 103 EnumerationHistogram, integrityHistogram, | 109 EnumerationHistogram, integrityHistogram, |
| 104 new EnumerationHistogram("sri.resource_integrity_mismatch_event", | 110 new EnumerationHistogram("sri.resource_integrity_mismatch_event", |
| 105 SriResourceIntegrityMismatchEventCount)); | 111 SriResourceIntegrityMismatchEventCount)); |
| 106 integrityHistogram.count(event); | 112 integrityHistogram.count(event); |
| 107 } | 113 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // synchronous requests are always given the highest possible priority, as | 182 // synchronous requests are always given the highest possible priority, as |
| 177 // well as to ensure that there isn't priority churn if images move in and out | 183 // well as to ensure that there isn't priority churn if images move in and out |
| 178 // of the viewport, or is displayed more than once, both in and out of the | 184 // of the viewport, or is displayed more than once, both in and out of the |
| 179 // viewport. | 185 // viewport. |
| 180 return std::max(context().modifyPriorityForExperiments(priority), | 186 return std::max(context().modifyPriorityForExperiments(priority), |
| 181 request.resourceRequest().priority()); | 187 request.resourceRequest().priority()); |
| 182 } | 188 } |
| 183 | 189 |
| 184 static void populateResourceTiming(ResourceTimingInfo* info, | 190 static void populateResourceTiming(ResourceTimingInfo* info, |
| 185 Resource* resource) { | 191 Resource* resource) { |
| 186 info->setInitialRequest(resource->resourceRequest()); | 192 KURL initialURL = resource->response().redirectResponses().isEmpty() |
| 193 ? resource->resourceRequest().url() |
| 194 : resource->response().redirectResponses()[0].url(); |
| 195 info->setInitialURL(initialURL); |
| 187 info->setFinalResponse(resource->response()); | 196 info->setFinalResponse(resource->response()); |
| 188 } | 197 } |
| 189 | 198 |
| 190 static WebURLRequest::RequestContext requestContextFromType( | 199 static WebURLRequest::RequestContext requestContextFromType( |
| 191 bool isMainFrame, | 200 bool isMainFrame, |
| 192 Resource::Type type) { | 201 Resource::Type type) { |
| 193 switch (type) { | 202 switch (type) { |
| 194 case Resource::MainResource: | 203 case Resource::MainResource: |
| 195 if (!isMainFrame) | 204 if (!isMainFrame) |
| 196 return WebURLRequest::RequestContextIframe; | 205 return WebURLRequest::RequestContextIframe; |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return resource; | 724 return resource; |
| 716 } | 725 } |
| 717 | 726 |
| 718 void ResourceFetcher::storeResourceTimingInitiatorInformation( | 727 void ResourceFetcher::storeResourceTimingInitiatorInformation( |
| 719 Resource* resource) { | 728 Resource* resource) { |
| 720 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; | 729 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
| 721 if (fetchInitiator == FetchInitiatorTypeNames::internal) | 730 if (fetchInitiator == FetchInitiatorTypeNames::internal) |
| 722 return; | 731 return; |
| 723 | 732 |
| 724 bool isMainResource = resource->getType() == Resource::MainResource; | 733 bool isMainResource = resource->getType() == Resource::MainResource; |
| 725 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create( | 734 |
| 726 fetchInitiator, monotonicallyIncreasingTime(), isMainResource); | 735 // The request can already be fetched in a previous navigation. Thus |
| 736 // startTime must be set accordingly. |
| 737 double startTime = resource->resourceRequest().navigationStartTime() |
| 738 ? resource->resourceRequest().navigationStartTime() |
| 739 : monotonicallyIncreasingTime(); |
| 740 |
| 741 std::unique_ptr<ResourceTimingInfo> info = |
| 742 ResourceTimingInfo::create(fetchInitiator, startTime, isMainResource); |
| 727 | 743 |
| 728 if (resource->isCacheValidator()) { | 744 if (resource->isCacheValidator()) { |
| 729 const AtomicString& timingAllowOrigin = | 745 const AtomicString& timingAllowOrigin = |
| 730 resource->response().httpHeaderField(HTTPNames::Timing_Allow_Origin); | 746 resource->response().httpHeaderField(HTTPNames::Timing_Allow_Origin); |
| 731 if (!timingAllowOrigin.isEmpty()) | 747 if (!timingAllowOrigin.isEmpty()) |
| 732 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 748 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
| 733 } | 749 } |
| 734 | 750 |
| 735 if (!isMainResource || | 751 if (!isMainResource || |
| 736 context().updateTimingInfoForIFrameNavigation(info.get())) | 752 context().updateTimingInfoForIFrameNavigation(info.get())) |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 if (finishReason == DidFinishFirstPartInMultipart) | 1107 if (finishReason == DidFinishFirstPartInMultipart) |
| 1092 moveResourceLoaderToNonBlocking(resource->loader()); | 1108 moveResourceLoaderToNonBlocking(resource->loader()); |
| 1093 else | 1109 else |
| 1094 removeResourceLoader(resource->loader()); | 1110 removeResourceLoader(resource->loader()); |
| 1095 DCHECK(!m_loaders.contains(resource->loader())); | 1111 DCHECK(!m_loaders.contains(resource->loader())); |
| 1096 DCHECK(finishReason == DidFinishFirstPartInMultipart || | 1112 DCHECK(finishReason == DidFinishFirstPartInMultipart || |
| 1097 !m_nonBlockingLoaders.contains(resource->loader())); | 1113 !m_nonBlockingLoaders.contains(resource->loader())); |
| 1098 | 1114 |
| 1099 if (std::unique_ptr<ResourceTimingInfo> info = | 1115 if (std::unique_ptr<ResourceTimingInfo> info = |
| 1100 m_resourceTimingInfoMap.take(resource)) { | 1116 m_resourceTimingInfoMap.take(resource)) { |
| 1117 // Store redirect responses that were packed inside the final response. |
| 1118 const Vector<ResourceResponse>& responses = |
| 1119 resource->response().redirectResponses(); |
| 1120 for (size_t i = 0; i < responses.size(); ++i) { |
| 1121 const KURL& newURL = i + 1 < responses.size() |
| 1122 ? KURL(responses[i + 1].url()) |
| 1123 : resource->resourceRequest().url(); |
| 1124 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); |
| 1125 info->addRedirect(responses[i], crossOrigin); |
| 1126 } |
| 1127 |
| 1101 if (resource->response().isHTTP() && | 1128 if (resource->response().isHTTP() && |
| 1102 resource->response().httpStatusCode() < 400) { | 1129 resource->response().httpStatusCode() < 400) { |
| 1103 populateResourceTiming(info.get(), resource); | 1130 populateResourceTiming(info.get(), resource); |
| 1104 info->setLoadFinishTime(finishTime); | 1131 info->setLoadFinishTime(finishTime); |
| 1105 // encodedDataLength == -1 means "not available". | 1132 // encodedDataLength == -1 means "not available". |
| 1106 // TODO(ricea): Find cases where it is not available but the | 1133 // TODO(ricea): Find cases where it is not available but the |
| 1107 // PerformanceResourceTiming spec requires it to be available and fix | 1134 // PerformanceResourceTiming spec requires it to be available and fix |
| 1108 // them. | 1135 // them. |
| 1109 info->addFinalTransferSize(encodedDataLength == -1 ? 0 | 1136 info->addFinalTransferSize(encodedDataLength == -1 ? 0 |
| 1110 : encodedDataLength); | 1137 : encodedDataLength); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 | 1314 |
| 1288 static bool isManualRedirectFetchRequest(const ResourceRequest& request) { | 1315 static bool isManualRedirectFetchRequest(const ResourceRequest& request) { |
| 1289 return request.fetchRedirectMode() == | 1316 return request.fetchRedirectMode() == |
| 1290 WebURLRequest::FetchRedirectModeManual && | 1317 WebURLRequest::FetchRedirectModeManual && |
| 1291 request.requestContext() == WebURLRequest::RequestContextFetch; | 1318 request.requestContext() == WebURLRequest::RequestContextFetch; |
| 1292 } | 1319 } |
| 1293 | 1320 |
| 1294 bool ResourceFetcher::willFollowRedirect( | 1321 bool ResourceFetcher::willFollowRedirect( |
| 1295 Resource* resource, | 1322 Resource* resource, |
| 1296 ResourceRequest& newRequest, | 1323 ResourceRequest& newRequest, |
| 1297 const ResourceResponse& redirectResponse, | 1324 const ResourceResponse& redirectResponse) { |
| 1298 int64_t encodedDataLength) { | |
| 1299 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { | 1325 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { |
| 1300 if (!context().canRequest(resource->getType(), newRequest, newRequest.url(), | 1326 if (!context().canRequest(resource->getType(), newRequest, newRequest.url(), |
| 1301 resource->options(), resource->isUnusedPreload(), | 1327 resource->options(), resource->isUnusedPreload(), |
| 1302 FetchRequest::UseDefaultOriginRestrictionForType)) | 1328 FetchRequest::UseDefaultOriginRestrictionForType)) |
| 1303 return false; | 1329 return false; |
| 1304 if (resource->options().corsEnabled == IsCORSEnabled) { | 1330 if (resource->options().corsEnabled == IsCORSEnabled) { |
| 1305 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOrigin; | 1331 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOrigin; |
| 1306 if (!sourceOrigin.get()) | 1332 if (!sourceOrigin.get()) |
| 1307 sourceOrigin = context().getSecurityOrigin(); | 1333 sourceOrigin = context().getSecurityOrigin(); |
| 1308 | 1334 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1319 return false; | 1345 return false; |
| 1320 } | 1346 } |
| 1321 } | 1347 } |
| 1322 if (resource->getType() == Resource::Image && | 1348 if (resource->getType() == Resource::Image && |
| 1323 shouldDeferImageLoad(newRequest.url())) | 1349 shouldDeferImageLoad(newRequest.url())) |
| 1324 return false; | 1350 return false; |
| 1325 } | 1351 } |
| 1326 | 1352 |
| 1327 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1353 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
| 1328 if (it != m_resourceTimingInfoMap.end()) { | 1354 if (it != m_resourceTimingInfoMap.end()) { |
| 1329 RefPtr<SecurityOrigin> originalSecurityOrigin = | 1355 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url()); |
| 1330 SecurityOrigin::create(redirectResponse.url()); | 1356 it->value->addRedirect(redirectResponse, crossOrigin); |
| 1331 RefPtr<SecurityOrigin> redirectedSecurityOrigin = | |
| 1332 SecurityOrigin::create(newRequest.url()); | |
| 1333 bool crossOrigin = !redirectedSecurityOrigin->isSameSchemeHostPort( | |
| 1334 originalSecurityOrigin.get()); | |
| 1335 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin); | |
| 1336 } | 1357 } |
| 1337 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == | 1358 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == |
| 1338 AllowStoredCredentials); | 1359 AllowStoredCredentials); |
| 1339 willSendRequest(resource->identifier(), newRequest, redirectResponse, | 1360 willSendRequest(resource->identifier(), newRequest, redirectResponse, |
| 1340 resource->options()); | 1361 resource->options()); |
| 1341 return true; | 1362 return true; |
| 1342 } | 1363 } |
| 1343 | 1364 |
| 1344 void ResourceFetcher::willSendRequest(unsigned long identifier, | 1365 void ResourceFetcher::willSendRequest(unsigned long identifier, |
| 1345 ResourceRequest& newRequest, | 1366 ResourceRequest& newRequest, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 visitor->trace(m_context); | 1592 visitor->trace(m_context); |
| 1572 visitor->trace(m_archive); | 1593 visitor->trace(m_archive); |
| 1573 visitor->trace(m_loaders); | 1594 visitor->trace(m_loaders); |
| 1574 visitor->trace(m_nonBlockingLoaders); | 1595 visitor->trace(m_nonBlockingLoaders); |
| 1575 visitor->trace(m_documentResources); | 1596 visitor->trace(m_documentResources); |
| 1576 visitor->trace(m_preloads); | 1597 visitor->trace(m_preloads); |
| 1577 visitor->trace(m_resourceTimingInfoMap); | 1598 visitor->trace(m_resourceTimingInfoMap); |
| 1578 } | 1599 } |
| 1579 | 1600 |
| 1580 } // namespace blink | 1601 } // namespace blink |
| OLD | NEW |