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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ | 85 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ |
86 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ | 86 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ |
87 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ | 87 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ |
88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ | 88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ |
89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ | 89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ |
90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ | 90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ |
91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ | 91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ |
92 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ | 92 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ |
93 } | 93 } |
94 | 94 |
95 bool IsCrossOrigin(const KURL& a, const KURL& b) | |
96 { | |
97 RefPtr<SecurityOrigin> originA = SecurityOrigin::create(a); | |
98 RefPtr<SecurityOrigin> originB = SecurityOrigin::create(b); | |
99 return !originB->isSameSchemeHostPort(originA.get()); | |
100 } | |
101 | |
95 } // namespace | 102 } // namespace |
96 | 103 |
97 static void RecordSriResourceIntegrityMismatchEvent(SriResourceIntegrityMismatch Event event) | 104 static void RecordSriResourceIntegrityMismatchEvent(SriResourceIntegrityMismatch Event event) |
98 { | 105 { |
99 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, integrityHistogram, ne w EnumerationHistogram("sri.resource_integrity_mismatch_event", SriResourceInteg rityMismatchEventCount)); | 106 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, integrityHistogram, ne w EnumerationHistogram("sri.resource_integrity_mismatch_event", SriResourceInteg rityMismatchEventCount)); |
100 integrityHistogram.count(event); | 107 integrityHistogram.count(event); |
101 } | 108 } |
102 | 109 |
103 static ResourceLoadPriority typeToPriority(Resource::Type type) | 110 static ResourceLoadPriority typeToPriority(Resource::Type type) |
104 { | 111 { |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 return resource; | 608 return resource; |
602 } | 609 } |
603 | 610 |
604 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) | 611 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource ) |
605 { | 612 { |
606 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; | 613 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
607 if (fetchInitiator == FetchInitiatorTypeNames::internal) | 614 if (fetchInitiator == FetchInitiatorTypeNames::internal) |
608 return; | 615 return; |
609 | 616 |
610 bool isMainResource = resource->getType() == Resource::MainResource; | 617 bool isMainResource = resource->getType() == Resource::MainResource; |
611 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI nitiator, monotonicallyIncreasingTime(), isMainResource); | 618 double startTime = monotonicallyIncreasingTime(); |
619 | |
620 // The request can already be fetched in a previous navigation. Thus | |
621 // startTime must be set accordingly. | |
622 if (resource->resourceRequest().previousNavigationStart()) | |
623 startTime = resource->resourceRequest().previousNavigationStart(); | |
624 | |
625 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI nitiator, startTime, isMainResource); | |
612 | 626 |
613 if (resource->isCacheValidator()) { | 627 if (resource->isCacheValidator()) { |
614 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield(HTTPNames::Timing_Allow_Origin); | 628 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF ield(HTTPNames::Timing_Allow_Origin); |
615 if (!timingAllowOrigin.isEmpty()) | 629 if (!timingAllowOrigin.isEmpty()) |
616 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 630 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
617 } | 631 } |
618 | 632 |
619 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge t())) | 633 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge t())) |
620 m_resourceTimingInfoMap.add(resource, std::move(info)); | 634 m_resourceTimingInfoMap.add(resource, std::move(info)); |
621 } | 635 } |
622 | 636 |
637 void ResourceFetcher::storeResourceTimingPreviousRedirects(Resource* resource) | |
638 { | |
639 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | |
640 if (it == m_resourceTimingInfoMap.end()) | |
641 return; | |
642 | |
643 const WebVector<WebURLResponse>& responses = resource->resourceRequest().pre viousResponses(); | |
644 for (size_t i = 0; i < responses.size(); ++i) { | |
645 const ResourceResponse& response = responses[i].toResourceResponse(); | |
646 const KURL& newURL = i + 1 < responses.size() ? KURL(responses[i + 1].ur l()) : resource->resourceRequest().url(); | |
647 // long long encodedDataLength = response.resourceLoadInfo()->encodedDat aLength; | |
648 long long encodedDataLength = 0; | |
arthursonzogni
2016/09/06 10:00:48
Oops, I didn't see that I forgot to transmit the e
| |
649 bool crossOrigin = IsCrossOrigin(response.url(), newURL); | |
650 it->value->addRedirect(response, encodedDataLength, crossOrigin); | |
651 } | |
652 } | |
653 | |
623 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const | 654 ResourceFetcher::RevalidationPolicy ResourceFetcher::determineRevalidationPolicy (Resource::Type type, const FetchRequest& fetchRequest, Resource* existingResour ce, bool isStaticData) const |
624 { | 655 { |
625 const ResourceRequest& request = fetchRequest.resourceRequest(); | 656 const ResourceRequest& request = fetchRequest.resourceRequest(); |
626 | 657 |
627 if (!existingResource) | 658 if (!existingResource) |
628 return Load; | 659 return Load; |
629 | 660 |
630 // Checks if the resource has an explicit policy about integrity metadata. | 661 // Checks if the resource has an explicit policy about integrity metadata. |
631 // Currently only applies to ScriptResources. | 662 // Currently only applies to ScriptResources. |
632 // | 663 // |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 ResourceRequest request(resource->resourceRequest()); | 1064 ResourceRequest request(resource->resourceRequest()); |
1034 willSendRequest(resource->identifier(), request, ResourceResponse(), resourc e->options()); | 1065 willSendRequest(resource->identifier(), request, ResourceResponse(), resourc e->options()); |
1035 | 1066 |
1036 ResourceLoader* loader = ResourceLoader::create(this, resource); | 1067 ResourceLoader* loader = ResourceLoader::create(this, resource); |
1037 if (resource->shouldBlockLoadEvent()) | 1068 if (resource->shouldBlockLoadEvent()) |
1038 m_loaders.add(loader); | 1069 m_loaders.add(loader); |
1039 else | 1070 else |
1040 m_nonBlockingLoaders.add(loader); | 1071 m_nonBlockingLoaders.add(loader); |
1041 | 1072 |
1042 storeResourceTimingInitiatorInformation(resource); | 1073 storeResourceTimingInitiatorInformation(resource); |
1074 storeResourceTimingPreviousRedirects(resource); | |
1043 resource->setFetcherSecurityOrigin(context().getSecurityOrigin()); | 1075 resource->setFetcherSecurityOrigin(context().getSecurityOrigin()); |
1044 loader->start(request, context().loadingTaskRunner(), context().defersLoadin g()); | 1076 loader->start(request, context().loadingTaskRunner(), context().defersLoadin g()); |
1045 return true; | 1077 return true; |
1046 } | 1078 } |
1047 | 1079 |
1048 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) | 1080 void ResourceFetcher::removeResourceLoader(ResourceLoader* loader) |
1049 { | 1081 { |
1050 if (m_loaders.contains(loader)) | 1082 if (m_loaders.contains(loader)) |
1051 m_loaders.remove(loader); | 1083 m_loaders.remove(loader); |
1052 else if (m_nonBlockingLoaders.contains(loader)) | 1084 else if (m_nonBlockingLoaders.contains(loader)) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 context().addConsoleMessage(errorMessage); | 1131 context().addConsoleMessage(errorMessage); |
1100 return false; | 1132 return false; |
1101 } | 1133 } |
1102 } | 1134 } |
1103 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url())) | 1135 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url())) |
1104 return false; | 1136 return false; |
1105 } | 1137 } |
1106 | 1138 |
1107 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1139 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
1108 if (it != m_resourceTimingInfoMap.end()) { | 1140 if (it != m_resourceTimingInfoMap.end()) { |
1109 RefPtr<SecurityOrigin> originalSecurityOrigin = SecurityOrigin::create(r edirectResponse.url()); | 1141 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url( )); |
1110 RefPtr<SecurityOrigin> redirectedSecurityOrigin = SecurityOrigin::create (newRequest.url()); | |
1111 bool crossOrigin = !redirectedSecurityOrigin->isSameSchemeHostPort(origi nalSecurityOrigin.get()); | |
1112 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin) ; | 1142 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin) ; |
1113 } | 1143 } |
1114 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == AllowStoredCredentials); | 1144 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == AllowStoredCredentials); |
1115 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour ce->options()); | 1145 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour ce->options()); |
1116 return true; | 1146 return true; |
1117 } | 1147 } |
1118 | 1148 |
1119 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio ns& options) | 1149 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio ns& options) |
1120 { | 1150 { |
1121 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse, options.initiatorInfo); | 1151 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse, options.initiatorInfo); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 visitor->trace(m_context); | 1344 visitor->trace(m_context); |
1315 visitor->trace(m_archive); | 1345 visitor->trace(m_archive); |
1316 visitor->trace(m_loaders); | 1346 visitor->trace(m_loaders); |
1317 visitor->trace(m_nonBlockingLoaders); | 1347 visitor->trace(m_nonBlockingLoaders); |
1318 visitor->trace(m_documentResources); | 1348 visitor->trace(m_documentResources); |
1319 visitor->trace(m_preloads); | 1349 visitor->trace(m_preloads); |
1320 visitor->trace(m_resourceTimingInfoMap); | 1350 visitor->trace(m_resourceTimingInfoMap); |
1321 } | 1351 } |
1322 | 1352 |
1323 } // namespace blink | 1353 } // namespace blink |
OLD | NEW |