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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 // Aims to count Resource only referenced from MemoryCache (i.e. what would be | 473 // Aims to count Resource only referenced from MemoryCache (i.e. what would be |
474 // dead if MemoryCache holds weak references to Resource). Currently we check | 474 // dead if MemoryCache holds weak references to Resource). Currently we check |
475 // references to Resource from ResourceClient and |m_preloads| only, because | 475 // references to Resource from ResourceClient and |m_preloads| only, because |
476 // they are major sources of references. | 476 // they are major sources of references. |
477 if (resource && !resource->isAlive() && | 477 if (resource && !resource->isAlive() && |
478 (!m_preloads || !m_preloads->contains(resource))) { | 478 (!m_preloads || !m_preloads->contains(resource))) { |
479 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 479 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 static void modifyRequestForPlaceholderImageRequest(FetchRequest& request, | |
484 Resource::Type type) { | |
485 if (request.placeholderImageRequestType() != FetchRequest::AllowPlaceholder) | |
486 return; | |
487 DCHECK_EQ(Resource::Image, type); | |
488 | |
489 if (!request.url().protocolIsInHTTPFamily() || | |
490 request.resourceRequest().httpMethod() != "GET" || | |
491 !request.resourceRequest().httpHeaderField("range").isNull()) { | |
492 request.setPlaceholderImageRequestType(FetchRequest::DisallowPlaceholder); | |
Nate Chapin
2016/10/18 18:23:17
Everything in this function should probably all be
sclittle
2016/10/18 23:53:03
Done.
| |
493 return; | |
494 } | |
495 | |
496 // Fetch the first few bytes of the image. This number is tuned to both (a) | |
497 // likely capture the entire image for small images and (b) likely contain | |
498 // the dimensions for larger images. | |
499 // TODO(sclittle): Calculate the optimal value for this number. | |
500 request.mutableResourceRequest().setHTTPHeaderField("range", "bytes=0-2047"); | |
501 | |
502 // TODO(sclittle): Indicate somehow (e.g. through a new request bit) to the | |
503 // embedder that it should return the full resource if the entire resource is | |
504 // fresh in the cache. | |
505 } | |
506 | |
483 Resource* ResourceFetcher::requestResource( | 507 Resource* ResourceFetcher::requestResource( |
484 FetchRequest& request, | 508 FetchRequest& request, |
485 const ResourceFactory& factory, | 509 const ResourceFactory& factory, |
486 const SubstituteData& substituteData) { | 510 const SubstituteData& substituteData) { |
487 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); | 511 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); |
488 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || | 512 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || |
489 factory.type() == Resource::Raw || | 513 factory.type() == Resource::Raw || |
490 factory.type() == Resource::XSLStyleSheet); | 514 factory.type() == Resource::XSLStyleSheet); |
491 | 515 |
492 context().populateRequestData(request.mutableResourceRequest()); | 516 context().populateRequestData(request.mutableResourceRequest()); |
(...skipping 16 matching lines...) Expand all Loading... | |
509 request.getOriginRestriction())) { | 533 request.getOriginRestriction())) { |
510 DCHECK(!substituteData.forceSynchronousLoad()); | 534 DCHECK(!substituteData.forceSynchronousLoad()); |
511 return resourceForBlockedRequest(request, factory); | 535 return resourceForBlockedRequest(request, factory); |
512 } | 536 } |
513 | 537 |
514 unsigned long identifier = createUniqueIdentifier(); | 538 unsigned long identifier = createUniqueIdentifier(); |
515 request.mutableResourceRequest().setPriority(computeLoadPriority( | 539 request.mutableResourceRequest().setPriority(computeLoadPriority( |
516 factory.type(), request, ResourcePriority::NotVisible)); | 540 factory.type(), request, ResourcePriority::NotVisible)); |
517 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), | 541 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), |
518 request.defer()); | 542 request.defer()); |
543 | |
544 modifyRequestForPlaceholderImageRequest(request, factory.type()); | |
545 | |
519 context().willStartLoadingResource( | 546 context().willStartLoadingResource( |
520 identifier, request.mutableResourceRequest(), factory.type()); | 547 identifier, request.mutableResourceRequest(), factory.type()); |
521 if (!request.url().isValid()) | 548 if (!request.url().isValid()) |
522 return nullptr; | 549 return nullptr; |
523 | 550 |
524 if (!request.forPreload()) { | 551 if (!request.forPreload()) { |
525 V8DOMActivityLogger* activityLogger = nullptr; | 552 V8DOMActivityLogger* activityLogger = nullptr; |
526 if (request.options().initiatorInfo.name == | 553 if (request.options().initiatorInfo.name == |
527 FetchInitiatorTypeNames::xmlhttprequest) { | 554 FetchInitiatorTypeNames::xmlhttprequest) { |
528 activityLogger = V8DOMActivityLogger::currentActivityLogger(); | 555 activityLogger = V8DOMActivityLogger::currentActivityLogger(); |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 if (resource->options().requestInitiatorContext == DocumentContext) | 1182 if (resource->options().requestInitiatorContext == DocumentContext) |
1156 context().addResourceTiming(*info); | 1183 context().addResourceTiming(*info); |
1157 resource->reportResourceTimingToClients(*info); | 1184 resource->reportResourceTimingToClients(*info); |
1158 } | 1185 } |
1159 } | 1186 } |
1160 context().dispatchDidFinishLoading(resource->identifier(), finishTime, | 1187 context().dispatchDidFinishLoading(resource->identifier(), finishTime, |
1161 encodedDataLength); | 1188 encodedDataLength); |
1162 if (finishReason == DidFinishLoading) | 1189 if (finishReason == DidFinishLoading) |
1163 resource->finish(finishTime); | 1190 resource->finish(finishTime); |
1164 context().didLoadResource(resource); | 1191 context().didLoadResource(resource); |
1192 | |
1193 if (resource->isImage() && | |
1194 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { | |
1195 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); | |
Nate Chapin
2016/10/18 18:23:17
I may have asked this in the design doc, but if I
sclittle
2016/10/18 23:53:03
I don't think the ordering here is important with
| |
1196 } | |
1165 } | 1197 } |
1166 | 1198 |
1167 void ResourceFetcher::didFailLoading(Resource* resource, | 1199 void ResourceFetcher::didFailLoading(Resource* resource, |
1168 const ResourceError& error) { | 1200 const ResourceError& error) { |
1169 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); | 1201 TRACE_EVENT_ASYNC_END0("blink.net", "Resource", resource->identifier()); |
1170 removeResourceLoader(resource->loader()); | 1202 removeResourceLoader(resource->loader()); |
1171 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); | 1203 m_resourceTimingInfoMap.take(const_cast<Resource*>(resource)); |
1172 bool isInternalRequest = resource->options().initiatorInfo.name == | 1204 bool isInternalRequest = resource->options().initiatorInfo.name == |
1173 FetchInitiatorTypeNames::internal; | 1205 FetchInitiatorTypeNames::internal; |
1174 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); | 1206 context().dispatchDidFail(resource->identifier(), error, isInternalRequest); |
1175 resource->error(error); | 1207 resource->error(error); |
1176 context().didLoadResource(resource); | 1208 context().didLoadResource(resource); |
1209 | |
1210 if (resource->isImage() && | |
1211 toImageResource(resource)->shouldReloadBrokenPlaceholder()) { | |
1212 toImageResource(resource)->reloadIfLoFiOrPlaceholder(this); | |
1213 } | |
1177 } | 1214 } |
1178 | 1215 |
1179 void ResourceFetcher::didReceiveResponse(Resource* resource, | 1216 void ResourceFetcher::didReceiveResponse(Resource* resource, |
1180 const ResourceResponse& response, | 1217 const ResourceResponse& response, |
1181 WebDataConsumerHandle* rawHandle) { | 1218 WebDataConsumerHandle* rawHandle) { |
1182 // |rawHandle|'s ownership is transferred to the callee. | 1219 // |rawHandle|'s ownership is transferred to the callee. |
1183 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); | 1220 std::unique_ptr<WebDataConsumerHandle> handle = wrapUnique(rawHandle); |
1184 | 1221 |
1185 if (response.wasFetchedViaServiceWorker()) { | 1222 if (response.wasFetchedViaServiceWorker()) { |
1186 if (resource->options().corsEnabled == IsCORSEnabled && | 1223 if (resource->options().corsEnabled == IsCORSEnabled && |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1414 resource->identifier(), resourceLoadPriority, | 1451 resource->identifier(), resourceLoadPriority, |
1415 resourcePriority.intraPriorityValue); | 1452 resourcePriority.intraPriorityValue); |
1416 } | 1453 } |
1417 } | 1454 } |
1418 | 1455 |
1419 void ResourceFetcher::reloadLoFiImages() { | 1456 void ResourceFetcher::reloadLoFiImages() { |
1420 for (const auto& documentResource : m_documentResources) { | 1457 for (const auto& documentResource : m_documentResources) { |
1421 Resource* resource = documentResource.value.get(); | 1458 Resource* resource = documentResource.value.get(); |
1422 if (resource && resource->isImage()) { | 1459 if (resource && resource->isImage()) { |
1423 ImageResource* imageResource = toImageResource(resource); | 1460 ImageResource* imageResource = toImageResource(resource); |
1424 imageResource->reloadIfLoFi(this); | 1461 imageResource->reloadIfLoFiOrPlaceholder(this); |
1425 } | 1462 } |
1426 } | 1463 } |
1427 } | 1464 } |
1428 | 1465 |
1429 void ResourceFetcher::logPreloadStats() { | 1466 void ResourceFetcher::logPreloadStats() { |
1430 if (!m_preloads) | 1467 if (!m_preloads) |
1431 return; | 1468 return; |
1432 unsigned scripts = 0; | 1469 unsigned scripts = 0; |
1433 unsigned scriptMisses = 0; | 1470 unsigned scriptMisses = 0; |
1434 unsigned stylesheets = 0; | 1471 unsigned stylesheets = 0; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1610 visitor->trace(m_context); | 1647 visitor->trace(m_context); |
1611 visitor->trace(m_archive); | 1648 visitor->trace(m_archive); |
1612 visitor->trace(m_loaders); | 1649 visitor->trace(m_loaders); |
1613 visitor->trace(m_nonBlockingLoaders); | 1650 visitor->trace(m_nonBlockingLoaders); |
1614 visitor->trace(m_documentResources); | 1651 visitor->trace(m_documentResources); |
1615 visitor->trace(m_preloads); | 1652 visitor->trace(m_preloads); |
1616 visitor->trace(m_resourceTimingInfoMap); | 1653 visitor->trace(m_resourceTimingInfoMap); |
1617 } | 1654 } |
1618 | 1655 |
1619 } // namespace blink | 1656 } // namespace blink |
OLD | NEW |