Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(678)

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcher.cpp

Issue 2417173002: Loading: bulk style errors fix in core/fetch (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // http://crbug.com/52411 317 // http://crbug.com/52411
318 static const int kMaxValidatedURLsSize = 10000; 318 static const int kMaxValidatedURLsSize = 10000;
319 319
320 void ResourceFetcher::requestLoadStarted(unsigned long identifier, 320 void ResourceFetcher::requestLoadStarted(unsigned long identifier,
321 Resource* resource, 321 Resource* resource,
322 const FetchRequest& request, 322 const FetchRequest& request,
323 ResourceLoadStartType type, 323 ResourceLoadStartType type,
324 bool isStaticData) { 324 bool isStaticData) {
325 if (type == ResourceLoadingFromCache && 325 if (type == ResourceLoadingFromCache &&
326 resource->getStatus() == Resource::Cached && 326 resource->getStatus() == Resource::Cached &&
327 !m_validatedURLs.contains(resource->url())) 327 !m_validatedURLs.contains(resource->url())) {
328 context().dispatchDidLoadResourceFromMemoryCache( 328 context().dispatchDidLoadResourceFromMemoryCache(
329 identifier, resource, request.resourceRequest().frameType(), 329 identifier, resource, request.resourceRequest().frameType(),
330 request.resourceRequest().requestContext()); 330 request.resourceRequest().requestContext());
331 }
331 332
332 if (isStaticData) 333 if (isStaticData)
333 return; 334 return;
334 335
335 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() && 336 if (type == ResourceLoadingFromCache && !resource->stillNeedsLoad() &&
336 !m_validatedURLs.contains(request.resourceRequest().url())) { 337 !m_validatedURLs.contains(request.resourceRequest().url())) {
337 // Resources loaded from memory cache should be reported the first time 338 // Resources loaded from memory cache should be reported the first time
338 // they're used. 339 // they're used.
339 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create( 340 std::unique_ptr<ResourceTimingInfo> info = ResourceTimingInfo::create(
340 request.options().initiatorInfo.name, monotonicallyIncreasingTime(), 341 request.options().initiatorInfo.name, monotonicallyIncreasingTime(),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), 516 initializeResourceRequest(request.mutableResourceRequest(), factory.type(),
516 request.defer()); 517 request.defer());
517 context().willStartLoadingResource( 518 context().willStartLoadingResource(
518 identifier, request.mutableResourceRequest(), factory.type()); 519 identifier, request.mutableResourceRequest(), factory.type());
519 if (!request.url().isValid()) 520 if (!request.url().isValid())
520 return nullptr; 521 return nullptr;
521 522
522 if (!request.forPreload()) { 523 if (!request.forPreload()) {
523 V8DOMActivityLogger* activityLogger = nullptr; 524 V8DOMActivityLogger* activityLogger = nullptr;
524 if (request.options().initiatorInfo.name == 525 if (request.options().initiatorInfo.name ==
525 FetchInitiatorTypeNames::xmlhttprequest) 526 FetchInitiatorTypeNames::xmlhttprequest) {
526 activityLogger = V8DOMActivityLogger::currentActivityLogger(); 527 activityLogger = V8DOMActivityLogger::currentActivityLogger();
527 else 528 } else {
528 activityLogger = 529 activityLogger =
529 V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld(); 530 V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld();
531 }
530 532
531 if (activityLogger) { 533 if (activityLogger) {
532 Vector<String> argv; 534 Vector<String> argv;
533 argv.append(Resource::resourceTypeToString( 535 argv.append(Resource::resourceTypeToString(
534 factory.type(), request.options().initiatorInfo)); 536 factory.type(), request.options().initiatorInfo));
535 argv.append(request.url()); 537 argv.append(request.url());
536 activityLogger->logEvent("blinkRequestResource", argv.size(), 538 activityLogger->logEvent("blinkRequestResource", argv.size(),
537 argv.data()); 539 argv.data());
538 } 540 }
539 } 541 }
540 542
541 bool isDataUrl = request.resourceRequest().url().protocolIsData(); 543 bool isDataUrl = request.resourceRequest().url().protocolIsData();
542 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; 544 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive;
543 Resource* resource(nullptr); 545 Resource* resource(nullptr);
544 if (isStaticData) { 546 if (isStaticData) {
545 resource = resourceForStaticData(request, factory, substituteData); 547 resource = resourceForStaticData(request, factory, substituteData);
546 // Abort the request if the archive doesn't contain the resource, except in 548 // Abort the request if the archive doesn't contain the resource, except in
547 // the case of data URLs which might have resources such as fonts that need 549 // the case of data URLs which might have resources such as fonts that need
548 // to be decoded only on demand. These data URLs are allowed to be 550 // to be decoded only on demand. These data URLs are allowed to be
549 // processed using the normal ResourceFetcher machinery. 551 // processed using the normal ResourceFetcher machinery.
550 if (!resource && !isDataUrl && m_archive) 552 if (!resource && !isDataUrl && m_archive)
551 return nullptr; 553 return nullptr;
552 } 554 }
553 if (!resource) 555 if (!resource) {
554 resource = 556 resource =
555 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); 557 memoryCache()->resourceForURL(request.url(), getCacheIdentifier());
558 }
556 559
557 // See if we can use an existing resource from the cache. If so, we need to 560 // See if we can use an existing resource from the cache. If so, we need to
558 // move it to be load blocking. 561 // move it to be load blocking.
559 moveCachedNonBlockingResourceToBlocking(resource, request); 562 moveCachedNonBlockingResourceToBlocking(resource, request);
560 563
561 const RevalidationPolicy policy = determineRevalidationPolicy( 564 const RevalidationPolicy policy = determineRevalidationPolicy(
562 factory.type(), request, resource, isStaticData); 565 factory.type(), request, resource, isStaticData);
563 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", 566 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy",
564 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); 567 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy);
565 568
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 DCHECK(resource->canUseCacheValidator()); 684 DCHECK(resource->canUseCacheValidator());
682 DCHECK(!resource->isCacheValidator()); 685 DCHECK(!resource->isCacheValidator());
683 DCHECK(!context().isControlledByServiceWorker()); 686 DCHECK(!context().isControlledByServiceWorker());
684 687
685 const AtomicString& lastModified = 688 const AtomicString& lastModified =
686 resource->response().httpHeaderField(HTTPNames::Last_Modified); 689 resource->response().httpHeaderField(HTTPNames::Last_Modified);
687 const AtomicString& eTag = 690 const AtomicString& eTag =
688 resource->response().httpHeaderField(HTTPNames::ETag); 691 resource->response().httpHeaderField(HTTPNames::ETag);
689 if (!lastModified.isEmpty() || !eTag.isEmpty()) { 692 if (!lastModified.isEmpty() || !eTag.isEmpty()) {
690 DCHECK_NE(context().getCachePolicy(), CachePolicyReload); 693 DCHECK_NE(context().getCachePolicy(), CachePolicyReload);
691 if (context().getCachePolicy() == CachePolicyRevalidate) 694 if (context().getCachePolicy() == CachePolicyRevalidate) {
692 revalidatingRequest.setHTTPHeaderField(HTTPNames::Cache_Control, 695 revalidatingRequest.setHTTPHeaderField(HTTPNames::Cache_Control,
693 "max-age=0"); 696 "max-age=0");
697 }
694 } 698 }
695 if (!lastModified.isEmpty()) 699 if (!lastModified.isEmpty()) {
696 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_Modified_Since, 700 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_Modified_Since,
697 lastModified); 701 lastModified);
702 }
698 if (!eTag.isEmpty()) 703 if (!eTag.isEmpty())
699 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag); 704 revalidatingRequest.setHTTPHeaderField(HTTPNames::If_None_Match, eTag);
700 705
701 double stalenessLifetime = resource->stalenessLifetime(); 706 double stalenessLifetime = resource->stalenessLifetime();
702 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) { 707 if (std::isfinite(stalenessLifetime) && stalenessLifetime > 0) {
703 revalidatingRequest.setHTTPHeaderField( 708 revalidatingRequest.setHTTPHeaderField(
704 HTTPNames::Resource_Freshness, 709 HTTPNames::Resource_Freshness,
705 AtomicString(String::format( 710 AtomicString(String::format(
706 "max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf", 711 "max-age=%.0lf,stale-while-revalidate=%.0lf,age=%.0lf",
707 resource->freshnessLifetime(), stalenessLifetime, 712 resource->freshnessLifetime(), stalenessLifetime,
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 resource->loader()->didFail( 1218 resource->loader()->didFail(
1214 nullptr, ResourceError::cancelledDueToAccessCheckError(response.url())); 1219 nullptr, ResourceError::cancelledDueToAccessCheckError(response.url()));
1215 return; 1220 return;
1216 } 1221 }
1217 1222
1218 context().dispatchDidReceiveResponse( 1223 context().dispatchDidReceiveResponse(
1219 resource->identifier(), response, resource->resourceRequest().frameType(), 1224 resource->identifier(), response, resource->resourceRequest().frameType(),
1220 resource->resourceRequest().requestContext(), resource); 1225 resource->resourceRequest().requestContext(), resource);
1221 resource->responseReceived(response, std::move(handle)); 1226 resource->responseReceived(response, std::move(handle));
1222 if (resource->loader() && response.httpStatusCode() >= 400 && 1227 if (resource->loader() && response.httpStatusCode() >= 400 &&
1223 !resource->shouldIgnoreHTTPStatusCodeErrors()) 1228 !resource->shouldIgnoreHTTPStatusCodeErrors()) {
1224 resource->loader()->didFail(nullptr, 1229 resource->loader()->didFail(nullptr,
1225 ResourceError::cancelledError(response.url())); 1230 ResourceError::cancelledError(response.url()));
1231 }
1226 } 1232 }
1227 1233
1228 void ResourceFetcher::didReceiveData(const Resource* resource, 1234 void ResourceFetcher::didReceiveData(const Resource* resource,
1229 const char* data, 1235 const char* data,
1230 int dataLength, 1236 int dataLength,
1231 int encodedDataLength) { 1237 int encodedDataLength) {
1232 context().dispatchDidReceiveData(resource->identifier(), data, dataLength, 1238 context().dispatchDidReceiveData(resource->identifier(), data, dataLength,
1233 encodedDataLength); 1239 encodedDataLength);
1234 } 1240 }
1235 1241
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 visitor->trace(m_context); 1609 visitor->trace(m_context);
1604 visitor->trace(m_archive); 1610 visitor->trace(m_archive);
1605 visitor->trace(m_loaders); 1611 visitor->trace(m_loaders);
1606 visitor->trace(m_nonBlockingLoaders); 1612 visitor->trace(m_nonBlockingLoaders);
1607 visitor->trace(m_documentResources); 1613 visitor->trace(m_documentResources);
1608 visitor->trace(m_preloads); 1614 visitor->trace(m_preloads);
1609 visitor->trace(m_resourceTimingInfoMap); 1615 visitor->trace(m_resourceTimingInfoMap);
1610 } 1616 }
1611 1617
1612 } // namespace blink 1618 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698