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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 169 |
163 // A manually set priority acts as a floor. This is used to ensure that sync
hronous requests | 170 // A manually set priority acts as a floor. This is used to ensure that sync
hronous requests |
164 // are always given the highest possible priority, as well as to ensure that
there isn't priority | 171 // are always given the highest possible priority, as well as to ensure that
there isn't priority |
165 // churn if images move in and out of the viewport, or is displayed more tha
n once, both in and out | 172 // churn if images move in and out of the viewport, or is displayed more tha
n once, both in and out |
166 // of the viewport. | 173 // of the viewport. |
167 return std::max(context().modifyPriorityForExperiments(priority), request.re
sourceRequest().priority()); | 174 return std::max(context().modifyPriorityForExperiments(priority), request.re
sourceRequest().priority()); |
168 } | 175 } |
169 | 176 |
170 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) | 177 static void populateResourceTiming(ResourceTimingInfo* info, Resource* resource) |
171 { | 178 { |
172 info->setInitialRequest(resource->resourceRequest()); | 179 KURL initialURL = resource->response().redirectResponses().isEmpty() |
| 180 ? resource->resourceRequest().url() |
| 181 : resource->response().redirectResponses()[0].url(); |
| 182 info->setInitialURL(initialURL); |
173 info->setFinalResponse(resource->response()); | 183 info->setFinalResponse(resource->response()); |
174 } | 184 } |
175 | 185 |
176 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re
source::Type type) | 186 static WebURLRequest::RequestContext requestContextFromType(bool isMainFrame, Re
source::Type type) |
177 { | 187 { |
178 switch (type) { | 188 switch (type) { |
179 case Resource::MainResource: | 189 case Resource::MainResource: |
180 if (!isMainFrame) | 190 if (!isMainFrame) |
181 return WebURLRequest::RequestContextIframe; | 191 return WebURLRequest::RequestContextIframe; |
182 // FIXME: Change this to a context frame type (once we introduce them):
http://fetch.spec.whatwg.org/#concept-request-context-frame-type | 192 // FIXME: Change this to a context frame type (once we introduce them):
http://fetch.spec.whatwg.org/#concept-request-context-frame-type |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 return resource; | 611 return resource; |
602 } | 612 } |
603 | 613 |
604 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) | 614 void ResourceFetcher::storeResourceTimingInitiatorInformation(Resource* resource
) |
605 { | 615 { |
606 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; | 616 const AtomicString& fetchInitiator = resource->options().initiatorInfo.name; |
607 if (fetchInitiator == FetchInitiatorTypeNames::internal) | 617 if (fetchInitiator == FetchInitiatorTypeNames::internal) |
608 return; | 618 return; |
609 | 619 |
610 bool isMainResource = resource->getType() == Resource::MainResource; | 620 bool isMainResource = resource->getType() == Resource::MainResource; |
611 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI
nitiator, monotonicallyIncreasingTime(), isMainResource); | 621 |
| 622 // The request can already be fetched in a previous navigation. Thus |
| 623 // startTime must be set accordingly. |
| 624 double startTime = resource->resourceRequest().navigationStartTime() |
| 625 ? resource->resourceRequest().navigationStartTime() |
| 626 : monotonicallyIncreasingTime(); |
| 627 |
| 628 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(fetchI
nitiator, startTime, isMainResource); |
612 | 629 |
613 if (resource->isCacheValidator()) { | 630 if (resource->isCacheValidator()) { |
614 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF
ield(HTTPNames::Timing_Allow_Origin); | 631 const AtomicString& timingAllowOrigin = resource->response().httpHeaderF
ield(HTTPNames::Timing_Allow_Origin); |
615 if (!timingAllowOrigin.isEmpty()) | 632 if (!timingAllowOrigin.isEmpty()) |
616 info->setOriginalTimingAllowOrigin(timingAllowOrigin); | 633 info->setOriginalTimingAllowOrigin(timingAllowOrigin); |
617 } | 634 } |
618 | 635 |
619 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge
t())) | 636 if (!isMainResource || context().updateTimingInfoForIFrameNavigation(info.ge
t())) |
620 m_resourceTimingInfoMap.add(resource, std::move(info)); | 637 m_resourceTimingInfoMap.add(resource, std::move(info)); |
621 } | 638 } |
(...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 | 941 // When loading a multipart resource, make the loader non-block when |
925 // finishing loading the first part. | 942 // finishing loading the first part. |
926 if (finishReason == DidFinishFirstPartInMultipart) | 943 if (finishReason == DidFinishFirstPartInMultipart) |
927 moveResourceLoaderToNonBlocking(resource->loader()); | 944 moveResourceLoaderToNonBlocking(resource->loader()); |
928 else | 945 else |
929 removeResourceLoader(resource->loader()); | 946 removeResourceLoader(resource->loader()); |
930 DCHECK(!m_loaders.contains(resource->loader())); | 947 DCHECK(!m_loaders.contains(resource->loader())); |
931 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s.contains(resource->loader())); | 948 DCHECK(finishReason == DidFinishFirstPartInMultipart || !m_nonBlockingLoader
s.contains(resource->loader())); |
932 | 949 |
933 if (std::unique_ptr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(
resource)) { | 950 if (std::unique_ptr<ResourceTimingInfo> info = m_resourceTimingInfoMap.take(
resource)) { |
| 951 |
| 952 // Store redirect responses that were packed inside the final response. |
| 953 const Vector<ResourceResponse>& responses = resource->response().redirec
tResponses(); |
| 954 for (size_t i = 0; i < responses.size(); ++i) { |
| 955 const KURL& newURL = i + 1 < responses.size() ? KURL(responses[i + 1
].url()) : resource->resourceRequest().url(); |
| 956 bool crossOrigin = IsCrossOrigin(responses[i].url(), newURL); |
| 957 info->addRedirect(responses[i], crossOrigin); |
| 958 } |
| 959 |
934 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { | 960 if (resource->response().isHTTP() && resource->response().httpStatusCode
() < 400) { |
935 populateResourceTiming(info.get(), resource); | 961 populateResourceTiming(info.get(), resource); |
936 info->setLoadFinishTime(finishTime); | 962 info->setLoadFinishTime(finishTime); |
937 // encodedDataLength == -1 means "not available". | 963 // encodedDataLength == -1 means "not available". |
938 // TODO(ricea): Find cases where it is not available but the | 964 // TODO(ricea): Find cases where it is not available but the |
939 // PerformanceResourceTiming spec requires it to be available and | 965 // PerformanceResourceTiming spec requires it to be available and |
940 // fix them. | 966 // fix them. |
941 info->addFinalTransferSize(encodedDataLength == -1 ? 0 : encodedData
Length); | 967 info->addFinalTransferSize(encodedDataLength == -1 ? 0 : encodedData
Length); |
942 if (resource->options().requestInitiatorContext == DocumentContext) | 968 if (resource->options().requestInitiatorContext == DocumentContext) |
943 context().addResourceTiming(*info); | 969 context().addResourceTiming(*info); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 bool ResourceFetcher::defersLoading() const | 1101 bool ResourceFetcher::defersLoading() const |
1076 { | 1102 { |
1077 return context().defersLoading(); | 1103 return context().defersLoading(); |
1078 } | 1104 } |
1079 | 1105 |
1080 static bool isManualRedirectFetchRequest(const ResourceRequest& request) | 1106 static bool isManualRedirectFetchRequest(const ResourceRequest& request) |
1081 { | 1107 { |
1082 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual
&& request.requestContext() == WebURLRequest::RequestContextFetch; | 1108 return request.fetchRedirectMode() == WebURLRequest::FetchRedirectModeManual
&& request.requestContext() == WebURLRequest::RequestContextFetch; |
1083 } | 1109 } |
1084 | 1110 |
1085 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne
wRequest, const ResourceResponse& redirectResponse, int64_t encodedDataLength) | 1111 bool ResourceFetcher::willFollowRedirect(Resource* resource, ResourceRequest& ne
wRequest, const ResourceResponse& redirectResponse) |
1086 { | 1112 { |
1087 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { | 1113 if (!isManualRedirectFetchRequest(resource->resourceRequest())) { |
1088 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur
l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO
riginRestrictionForType)) | 1114 if (!context().canRequest(resource->getType(), newRequest, newRequest.ur
l(), resource->options(), resource->isUnusedPreload(), FetchRequest::UseDefaultO
riginRestrictionForType)) |
1089 return false; | 1115 return false; |
1090 if (resource->options().corsEnabled == IsCORSEnabled) { | 1116 if (resource->options().corsEnabled == IsCORSEnabled) { |
1091 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr
igin; | 1117 RefPtr<SecurityOrigin> sourceOrigin = resource->options().securityOr
igin; |
1092 if (!sourceOrigin.get()) | 1118 if (!sourceOrigin.get()) |
1093 sourceOrigin = context().getSecurityOrigin(); | 1119 sourceOrigin = context().getSecurityOrigin(); |
1094 | 1120 |
1095 String errorMessage; | 1121 String errorMessage; |
1096 StoredCredentials withCredentials = resource->lastResourceRequest().
allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; | 1122 StoredCredentials withCredentials = resource->lastResourceRequest().
allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials; |
1097 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque
st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage)
) { | 1123 if (!CrossOriginAccessControl::handleRedirect(sourceOrigin, newReque
st, redirectResponse, withCredentials, resource->mutableOptions(), errorMessage)
) { |
1098 resource->setCORSFailed(); | 1124 resource->setCORSFailed(); |
1099 context().addConsoleMessage(errorMessage); | 1125 context().addConsoleMessage(errorMessage); |
1100 return false; | 1126 return false; |
1101 } | 1127 } |
1102 } | 1128 } |
1103 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe
quest.url())) | 1129 if (resource->getType() == Resource::Image && shouldDeferImageLoad(newRe
quest.url())) |
1104 return false; | 1130 return false; |
1105 } | 1131 } |
1106 | 1132 |
1107 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); | 1133 ResourceTimingInfoMap::iterator it = m_resourceTimingInfoMap.find(resource); |
1108 if (it != m_resourceTimingInfoMap.end()) { | 1134 if (it != m_resourceTimingInfoMap.end()) { |
1109 RefPtr<SecurityOrigin> originalSecurityOrigin = SecurityOrigin::create(r
edirectResponse.url()); | 1135 bool crossOrigin = IsCrossOrigin(redirectResponse.url(), newRequest.url(
)); |
1110 RefPtr<SecurityOrigin> redirectedSecurityOrigin = SecurityOrigin::create
(newRequest.url()); | 1136 it->value->addRedirect(redirectResponse, crossOrigin); |
1111 bool crossOrigin = !redirectedSecurityOrigin->isSameSchemeHostPort(origi
nalSecurityOrigin.get()); | |
1112 it->value->addRedirect(redirectResponse, encodedDataLength, crossOrigin)
; | |
1113 } | 1137 } |
1114 newRequest.setAllowStoredCredentials(resource->options().allowCredentials ==
AllowStoredCredentials); | 1138 newRequest.setAllowStoredCredentials(resource->options().allowCredentials ==
AllowStoredCredentials); |
1115 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour
ce->options()); | 1139 willSendRequest(resource->identifier(), newRequest, redirectResponse, resour
ce->options()); |
1116 return true; | 1140 return true; |
1117 } | 1141 } |
1118 | 1142 |
1119 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio
ns& options) | 1143 void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest&
newRequest, const ResourceResponse& redirectResponse, const ResourceLoaderOptio
ns& options) |
1120 { | 1144 { |
1121 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse,
options.initiatorInfo); | 1145 context().dispatchWillSendRequest(identifier, newRequest, redirectResponse,
options.initiatorInfo); |
1122 } | 1146 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 visitor->trace(m_context); | 1338 visitor->trace(m_context); |
1315 visitor->trace(m_archive); | 1339 visitor->trace(m_archive); |
1316 visitor->trace(m_loaders); | 1340 visitor->trace(m_loaders); |
1317 visitor->trace(m_nonBlockingLoaders); | 1341 visitor->trace(m_nonBlockingLoaders); |
1318 visitor->trace(m_documentResources); | 1342 visitor->trace(m_documentResources); |
1319 visitor->trace(m_preloads); | 1343 visitor->trace(m_preloads); |
1320 visitor->trace(m_resourceTimingInfoMap); | 1344 visitor->trace(m_resourceTimingInfoMap); |
1321 } | 1345 } |
1322 | 1346 |
1323 } // namespace blink | 1347 } // namespace blink |
OLD | NEW |