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(); |
Nate Chapin
2016/09/08 18:41:13
Any reason not to use:
double startTime = resourc
arthursonzogni
2016/09/09 12:45:33
There is no particular reasons. I will update it.
| |
619 | |
620 // The request can already be fetched in a previous navigation. Thus | |
621 // startTime must be set accordingly. | |
622 if (resource->resourceRequest().navigationStartTime()) | |
623 startTime = resource->resourceRequest().navigationStartTime(); | |
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 } |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
924 // When loading a multipart resource, make the loader non-block when | 938 // When loading a multipart resource, make the loader non-block when |
925 // finishing loading the first part. | 939 // finishing loading the first part. |
926 if (finishReason == DidFinishFirstPartInMultipart) | 940 if (finishReason == DidFinishFirstPartInMultipart) |
927 moveResourceLoaderToNonBlocking(resource->loader()); | 941 moveResourceLoaderToNonBlocking(resource->loader()); |
928 else | 942 else |
929 removeResourceLoader(resource->loader()); | 943 removeResourceLoader(resource->loader()); |
930 DCHECK(!m_loaders.contains(resource->loader())); | 944 DCHECK(!m_loaders.contains(resource->loader())); |
931 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader s.contains(resource->loader())); | 945 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader s.contains(resource->loader())); |
932 | 946 |
933 if (std::unique_ptr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take( resource)) { | 947 if (std::unique_ptr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take( resource)) { |
948 | |
949 // Store redirect responses that were packed inside the final response. | |
950 const std::vector<ResourceResponse>& responses = resource->response().re directResponses(); | |
951 for (size_t i = 0; i < responses.size(); ++i) { | |
952 const KURL& newURL = i + 1 < responses.size() ? KURL(responses[i + 1 ].url()) : resource->resourceRequest().url(); | |
953 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); | |
954 info->addRedirect(responses[i], crossOrigin); | |
955 } | |
956 | |
934 if (resource->response().isHTTP() && resource->response().httpStatusCode () < 400) { | 957 if (resource->response().isHTTP() && resource->response().httpStatusCode () < 400) { |
935 populateResourceTiming(info.get(), resource); | 958 populateResourceTiming(info.get(), resource); |
936 info->setLoadFinishTime(finishTime); | 959 info->setLoadFinishTime(finishTime); |
937 // encodedDataLength == -1 means "not available". | 960 // encodedDataLength == -1 means "not available". |
938 // TODO(ricea): Find cases where it is not available but the | 961 // TODO(ricea): Find cases where it is not available but the |
939 // PerformanceResourceTiming spec requires it to be available and | 962 // PerformanceResourceTiming spec requires it to be available and |
940 // fix them. | 963 // fix them. |
941 info->addFinalTransferSize(encodedDataLength == -1 ? 0 : encodedData Length); | 964 info->addFinalTransferSize(encodedDataLength == -1 ? 0 : encodedData Length); |
942 if (resource->options().requestInitiatorContext == DocumentContext) | 965 if (resource->options().requestInitiatorContext == DocumentContext) |
943 context().addResourceTiming(*info); | 966 context().addResourceTiming(*info); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1075 bool ResourceFetcher::defersLoading() const | 1098 bool ResourceFetcher::defersLoading() const |
1076 { | 1099 { |
1077 return context().defersLoading(); | 1100 return context().defersLoading(); |
1078 } | 1101 } |
1079 | 1102 |
1080 static bool isManualRedirectFetchRequest(const ResourceRequest& request) | 1103 static bool isManualRedirectFetchRequest(const ResourceRequest& request) |
1081 { | 1104 { |
1082 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch; | 1105 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual && request.requestContext() == WebURLRequest::RequestContextFetch; |
1083 } | 1106 } |
1084 | 1107 |
1085 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne wRequest, const ResourceResponse& redirectResponse, int64_t encodedDataLength) | 1108 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne wRequest, const ResourceResponse& redirectResponse) |
1086 { | 1109 { |
1087 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { | 1110 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { |
1088 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO riginRestrictionForType)) | 1111 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO riginRestrictionForType)) |
1089 return false; | 1112 return false; |
1090 if (resource->options().corsEnabled == IsCORSEnabled) { | 1113 if (resource->options().corsEnabled == IsCORSEnabled) { |
1091 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr igin; | 1114 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr igin; |
1092 if (!sourceOrigin.get()) | 1115 if (!sourceOrigin.get()) |
1093 sourceOrigin = context().getSecurityOrigin(); | 1116 sourceOrigin = context().getSecurityOrigin(); |
1094 | 1117 |
1095 String errorMessage; | 1118 String errorMessage; |
1096 StoredCredentials withCredentials = resource->lastResourceRequest(). allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; | 1119 StoredCredentials withCredentials = resource->lastResourceRequest(). allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; |
1097 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage) ) { | 1120 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage) ) { |
1098 resource->setCORSFailed(); | 1121 resource->setCORSFailed(); |
1099 context().addConsoleMessage(errorMessage); | 1122 context().addConsoleMessage(errorMessage); |
1100 return false; | 1123 return false; |
1101 } | 1124 } |
1102 } | 1125 } |
1103 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url())) | 1126 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe quest.url())) |
1104 return false; | 1127 return false; |
1105 } | 1128 } |
1106 | 1129 |
1107 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1130 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
1108 if (it != m_resourceTimingInfoMap.end()) { | 1131 if (it != m_resourceTimingInfoMap.end()) { |
1109 RefPtr<SecurityOrigin> originalSecurityOrigin = SecurityOrigin::create(r edirectResponse.url()); | 1132 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url( )); |
1110 RefPtr<SecurityOrigin> redirectedSecurityOrigin = SecurityOrigin::create (newRequest.url()); | 1133 it->value->addRedirect(redirectResponse, crossOrigin); |
1111 bool crossOrigin = !redirectedSecurityOrigin->isSameSchemeHostPort(origi nalSecurityOrigin.get()); | |
1112 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin) ; | |
1113 } | 1134 } |
1114 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == AllowStoredCredentials); | 1135 newRequest.setAllowStoredCredentials(resource->options().allowCredentials == AllowStoredCredentials); |
1115 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour ce->options()); | 1136 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour ce->options()); |
1116 return true; | 1137 return true; |
1117 } | 1138 } |
1118 | 1139 |
1119 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio ns& options) | 1140 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio ns& options) |
1120 { | 1141 { |
1121 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse, options.initiatorInfo); | 1142 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse, options.initiatorInfo); |
1122 } | 1143 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 visitor->trace(m_context); | 1335 visitor->trace(m_context); |
1315 visitor->trace(m_archive); | 1336 visitor->trace(m_archive); |
1316 visitor->trace(m_loaders); | 1337 visitor->trace(m_loaders); |
1317 visitor->trace(m_nonBlockingLoaders); | 1338 visitor->trace(m_nonBlockingLoaders); |
1318 visitor->trace(m_documentResources); | 1339 visitor->trace(m_documentResources); |
1319 visitor->trace(m_preloads); | 1340 visitor->trace(m_preloads); |
1320 visitor->trace(m_resourceTimingInfoMap); | 1341 visitor->trace(m_resourceTimingInfoMap); |
1321 } | 1342 } |
1322 | 1343 |
1323 } // namespace blink | 1344 } // namespace blink |
OLD | NEW |