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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ | 84 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, MainResource) \ |
85 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ | 85 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Manifest) \ |
86 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ | 86 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Media) \ |
87 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ | 87 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Raw) \ |
88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ | 88 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, Script) \ |
89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ | 89 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, SVGDocument) \ |
90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ | 90 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, TextTrack) \ |
91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ | 91 DEFINE_SINGLE_RESOURCE_HISTOGRAM(prefix, XSLStyleSheet) \ |
92 } | 92 } |
93 | 93 |
| 94 bool IsCrossOrigin(const KURL& a, const KURL& b) |
| 95 { |
| 96 RefPtr<SecurityOrigin> originA = SecurityOrigin::create(a); |
| 97 RefPtr<SecurityOrigin> originB = SecurityOrigin::create(b); |
| 98 return !originB->isSameSchemeHostPort(originA.get()); |
| 99 } |
| 100 |
94 } // namespace | 101 } // namespace |
95 | 102 |
96 static void RecordSriResourceIntegrityMismatchEvent(SriResourceIntegrityMismatch
Event event) | 103 static void RecordSriResourceIntegrityMismatchEvent(SriResourceIntegrityMismatch
Event event) |
97 { | 104 { |
98 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, integrityHistogram, ne
w EnumerationHistogram("sri.resource_integrity_mismatch_event", SriResourceInteg
rityMismatchEventCount)); | 105 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, integrityHistogram, ne
w EnumerationHistogram("sri.resource_integrity_mismatch_event", SriResourceInteg
rityMismatchEventCount)); |
99 integrityHistogram.count(event); | 106 integrityHistogram.count(event); |
100 } | 107 } |
101 | 108 |
102 static ResourceLoadPriority typeToPriority(Resource::Type type) | 109 static ResourceLoadPriority typeToPriority(Resource::Type type) |
103 { | 110 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 170 |
164 // A manually set priority acts as a floor. This is used to ensure that sync
hronous requests | 171 // A manually set priority acts as a floor. This is used to ensure that sync
hronous requests |
165 // are always given the highest possible priority, as well as to ensure that
there isn't priority | 172 // are always given the highest possible priority, as well as to ensure that
there isn't priority |
166 // churn if images move in and out of the viewport, or is displayed more tha
n once, both in and out | 173 // churn if images move in and out of the viewport, or is displayed more tha
n once, both in and out |
167 // of the viewport. | 174 // of the viewport. |
168 return std::max(context().modifyPriorityForExperiments(priority), request.re
sourceRequest().priority()); | 175 return std::max(context().modifyPriorityForExperiments(priority), request.re
sourceRequest().priority()); |
169 } | 176 } |
170 | 177 |
171 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) | 178 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) |
172 { | 179 { |
173 info->setInitialRequest(resource->resourceRequest()); | 180 KURL initialURL = resource->response().redirectResponses().isEmpty() |
| 181 ? resource->resourceRequest().url() |
| 182 : resource->response().redirectResponses()[0].url(); |
| 183 info->setInitialURL(initialURL); |
174 info->setFinalResponse(resource->response()); | 184 info->setFinalResponse(resource->response()); |
175 } | 185 } |
176 | 186 |
177 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re
source::Type type) | 187 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re
source::Type type) |
178 { | 188 { |
179 switch (type) { | 189 switch (type) { |
180 case Resource::MainResource: | 190 case Resource::MainResource: |
181 if (!isMainFrame) | 191 if (!isMainFrame) |
182 return WebURLRequest::RequestContextIframe; | 192 return WebURLRequest::RequestContextIframe; |
183 // FIXME: Change this to a context frame type (once we introduce them):
http://fetch.spec.whatwg.org/#concept-request-context-frame-type | 193 // FIXME: Change this to a context frame type (once we introduce them):
http://fetch.spec.whatwg.org/#concept-request-context-frame-type |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return resource; | 614 return resource; |
605 } | 615 } |
606 | 616 |
607 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 617 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
608 { | 618 { |
609 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; | 619 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
610 if (fetchInitiator == FetchInitiatorTypeNames::internal) | 620 if (fetchInitiator == FetchInitiatorTypeNames::internal) |
611 return; | 621 return; |
612 | 622 |
613 bool isMainResource = resource->getType() == Resource::MainResource; | 623 bool isMainResource = resource->getType() == Resource::MainResource; |
614 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI
nitiator, monotonicallyIncreasingTime(), isMainResource); | 624 |
| 625 // The request can already be fetched in a previous navigation. Thus |
| 626 // startTime must be set accordingly. |
| 627 double startTime = resource->resourceRequest().navigationStartTime() |
| 628 ? resource->resourceRequest().navigationStartTime() |
| 629 : monotonicallyIncreasingTime(); |
| 630 |
| 631 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI
nitiator, startTime, isMainResource); |
615 | 632 |
616 if (resource->isCacheValidator()) { | 633 if (resource->isCacheValidator()) { |
617 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF
ield(HTTPNames::Timing_Allow_Origin); | 634 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF
ield(HTTPNames::Timing_Allow_Origin); |
618 if (!timingAllowOrigin.isEmpty()) | 635 if (!timingAllowOrigin.isEmpty()) |
619 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 636 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
620 } | 637 } |
621 | 638 |
622 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge
t())) | 639 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge
t())) |
623 m_resourceTimingInfoMap.add(resource, std::move(info)); | 640 m_resourceTimingInfoMap.add(resource, std::move(info)); |
624 } | 641 } |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 // When loading a multipart resource, make the loader non-block when | 953 // When loading a multipart resource, make the loader non-block when |
937 // finishing loading the first part. | 954 // finishing loading the first part. |
938 if (finishReason == DidFinishFirstPartInMultipart) | 955 if (finishReason == DidFinishFirstPartInMultipart) |
939 moveResourceLoaderToNonBlocking(resource->loader()); | 956 moveResourceLoaderToNonBlocking(resource->loader()); |
940 else | 957 else |
941 removeResourceLoader(resource->loader()); | 958 removeResourceLoader(resource->loader()); |
942 DCHECK(!m_loaders.contains(resource->loader())); | 959 DCHECK(!m_loaders.contains(resource->loader())); |
943 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s.contains(resource->loader())); | 960 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s.contains(resource->loader())); |
944 | 961 |
945 if (std::unique_ptr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(
resource)) { | 962 if (std::unique_ptr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(
resource)) { |
| 963 |
| 964 // Store redirect responses that were packed inside the final response. |
| 965 const Vector<ResourceResponse>& responses = resource->response().redirec
tResponses(); |
| 966 for (size_t i = 0; i < responses.size(); ++i) { |
| 967 const KURL& newURL = i + 1 < responses.size() ? KURL(responses[i + 1
].url()) : resource->resourceRequest().url(); |
| 968 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); |
| 969 info->addRedirect(responses[i], crossOrigin); |
| 970 } |
| 971 |
946 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { | 972 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { |
947 populateResourceTiming(info.get(), resource); | 973 populateResourceTiming(info.get(), resource); |
948 info->setLoadFinishTime(finishTime); | 974 info->setLoadFinishTime(finishTime); |
949 // encodedDataLength == -1 means "not available". | 975 // encodedDataLength == -1 means "not available". |
950 // TODO(ricea): Find cases where it is not available but the | 976 // TODO(ricea): Find cases where it is not available but the |
951 // PerformanceResourceTiming spec requires it to be available and | 977 // PerformanceResourceTiming spec requires it to be available and |
952 // fix them. | 978 // fix them. |
953 info->addFinalTransferSize(encodedDataLength == -1 ? 0 : encodedData
Length); | 979 info->addFinalTransferSize(encodedDataLength == -1 ? 0 : encodedData
Length); |
954 if (resource->options().requestInitiatorContext == DocumentContext) | 980 if (resource->options().requestInitiatorContext == DocumentContext) |
955 context().addResourceTiming(*info); | 981 context().addResourceTiming(*info); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 bool ResourceFetcher::defersLoading() const | 1124 bool ResourceFetcher::defersLoading() const |
1099 { | 1125 { |
1100 return context().defersLoading(); | 1126 return context().defersLoading(); |
1101 } | 1127 } |
1102 | 1128 |
1103 static bool isManualRedirectFetchRequest(const ResourceRequest& request) | 1129 static bool isManualRedirectFetchRequest(const ResourceRequest& request) |
1104 { | 1130 { |
1105 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual
&& request.requestContext() == WebURLRequest::RequestContextFetch; | 1131 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual
&& request.requestContext() == WebURLRequest::RequestContextFetch; |
1106 } | 1132 } |
1107 | 1133 |
1108 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne
wRequest, const ResourceResponse& redirectResponse, int64_t encodedDataLength) | 1134 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne
wRequest, const ResourceResponse& redirectResponse) |
1109 { | 1135 { |
1110 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { | 1136 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { |
1111 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur
l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO
riginRestrictionForType)) | 1137 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur
l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO
riginRestrictionForType)) |
1112 return false; | 1138 return false; |
1113 if (resource->options().corsEnabled == IsCORSEnabled) { | 1139 if (resource->options().corsEnabled == IsCORSEnabled) { |
1114 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr
igin; | 1140 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr
igin; |
1115 if (!sourceOrigin.get()) | 1141 if (!sourceOrigin.get()) |
1116 sourceOrigin = context().getSecurityOrigin(); | 1142 sourceOrigin = context().getSecurityOrigin(); |
1117 | 1143 |
1118 String errorMessage; | 1144 String errorMessage; |
1119 StoredCredentials withCredentials = resource->lastResourceRequest().
allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; | 1145 StoredCredentials withCredentials = resource->lastResourceRequest().
allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; |
1120 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque
st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage)
) { | 1146 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque
st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage)
) { |
1121 resource->setCORSFailed(); | 1147 resource->setCORSFailed(); |
1122 context().addConsoleMessage(errorMessage); | 1148 context().addConsoleMessage(errorMessage); |
1123 return false; | 1149 return false; |
1124 } | 1150 } |
1125 } | 1151 } |
1126 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe
quest.url())) | 1152 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe
quest.url())) |
1127 return false; | 1153 return false; |
1128 } | 1154 } |
1129 | 1155 |
1130 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1156 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
1131 if (it != m_resourceTimingInfoMap.end()) { | 1157 if (it != m_resourceTimingInfoMap.end()) { |
1132 RefPtr<SecurityOrigin> originalSecurityOrigin = SecurityOrigin::create(r
edirectResponse.url()); | 1158 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url(
)); |
1133 RefPtr<SecurityOrigin> redirectedSecurityOrigin = SecurityOrigin::create
(newRequest.url()); | 1159 it->value->addRedirect(redirectResponse, crossOrigin); |
1134 bool crossOrigin = !redirectedSecurityOrigin->isSameSchemeHostPort(origi
nalSecurityOrigin.get()); | |
1135 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin)
; | |
1136 } | 1160 } |
1137 newRequest.setAllowStoredCredentials(resource->options().allowCredentials ==
AllowStoredCredentials); | 1161 newRequest.setAllowStoredCredentials(resource->options().allowCredentials ==
AllowStoredCredentials); |
1138 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour
ce->options()); | 1162 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour
ce->options()); |
1139 return true; | 1163 return true; |
1140 } | 1164 } |
1141 | 1165 |
1142 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio
ns& options) | 1166 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio
ns& options) |
1143 { | 1167 { |
1144 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse,
options.initiatorInfo); | 1168 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse,
options.initiatorInfo); |
1145 } | 1169 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 visitor->trace(m_context); | 1361 visitor->trace(m_context); |
1338 visitor->trace(m_archive); | 1362 visitor->trace(m_archive); |
1339 visitor->trace(m_loaders); | 1363 visitor->trace(m_loaders); |
1340 visitor->trace(m_nonBlockingLoaders); | 1364 visitor->trace(m_nonBlockingLoaders); |
1341 visitor->trace(m_documentResources); | 1365 visitor->trace(m_documentResources); |
1342 visitor->trace(m_preloads); | 1366 visitor->trace(m_preloads); |
1343 visitor->trace(m_resourceTimingInfoMap); | 1367 visitor->trace(m_resourceTimingInfoMap); |
1344 } | 1368 } |
1345 | 1369 |
1346 } // namespace blink | 1370 } // namespace blink |
OLD | NEW |