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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (resource && !resource->isAlive() && | 495 if (resource && !resource->isAlive() && |
496 (!m_preloads || !m_preloads->contains(resource))) { | 496 (!m_preloads || !m_preloads->contains(resource))) { |
497 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 497 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 Resource* ResourceFetcher::requestResource( | 501 Resource* ResourceFetcher::requestResource( |
502 FetchRequest& request, | 502 FetchRequest& request, |
503 const ResourceFactory& factory, | 503 const ResourceFactory& factory, |
504 const SubstituteData& substituteData) { | 504 const SubstituteData& substituteData) { |
| 505 ResourceRequest& resourceRequest = request.mutableResourceRequest(); |
| 506 |
505 unsigned long identifier = createUniqueIdentifier(); | 507 unsigned long identifier = createUniqueIdentifier(); |
506 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( | 508 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( |
507 identifier, request.resourceRequest()); | 509 identifier, resourceRequest); |
508 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); | 510 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); |
509 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || | 511 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || |
510 factory.type() == Resource::Raw || | 512 factory.type() == Resource::Raw || |
511 factory.type() == Resource::XSLStyleSheet); | 513 factory.type() == Resource::XSLStyleSheet); |
512 | 514 |
513 context().populateRequestData(request.mutableResourceRequest()); | 515 context().populateResourceRequest( |
514 context().modifyRequestForCSP(request.mutableResourceRequest()); | 516 factory.type(), request.clientHintsPreferences(), |
515 context().addClientHintsIfNecessary(request); | 517 request.getResourceWidth(), resourceRequest); |
516 context().addCSPHeaderIfNecessary(factory.type(), request); | |
517 | 518 |
518 // TODO(dproy): Remove this. http://crbug.com/659666 | 519 // TODO(dproy): Remove this. http://crbug.com/659666 |
519 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", | 520 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", |
520 urlForTraceEvent(request.url())); | 521 urlForTraceEvent(request.url())); |
521 | 522 |
522 if (!request.url().isValid()) | 523 if (!request.url().isValid()) |
523 return nullptr; | 524 return nullptr; |
524 | 525 |
525 request.mutableResourceRequest().setPriority(computeLoadPriority( | 526 resourceRequest.setPriority(computeLoadPriority( |
526 factory.type(), request, ResourcePriority::NotVisible)); | 527 factory.type(), request, ResourcePriority::NotVisible)); |
527 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), | 528 initializeResourceRequest(resourceRequest, factory.type(), request.defer()); |
528 request.defer()); | 529 network_instrumentation::resourcePrioritySet(identifier, |
529 network_instrumentation::resourcePrioritySet( | 530 resourceRequest.priority()); |
530 identifier, request.resourceRequest().priority()); | |
531 | 531 |
532 ResourceRequestBlockedReason blockedReason = context().canRequest( | 532 ResourceRequestBlockedReason blockedReason = context().canRequest( |
533 factory.type(), request.resourceRequest(), | 533 factory.type(), resourceRequest, |
534 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), | 534 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), |
535 request.options(), request.forPreload(), request.getOriginRestriction()); | 535 request.options(), request.forPreload(), request.getOriginRestriction()); |
536 if (blockedReason != ResourceRequestBlockedReason::None) { | 536 if (blockedReason != ResourceRequestBlockedReason::None) { |
537 DCHECK(!substituteData.forceSynchronousLoad()); | 537 DCHECK(!substituteData.forceSynchronousLoad()); |
538 return resourceForBlockedRequest(request, factory, blockedReason); | 538 return resourceForBlockedRequest(request, factory, blockedReason); |
539 } | 539 } |
540 | 540 |
541 context().willStartLoadingResource( | 541 context().willStartLoadingResource(identifier, resourceRequest, |
542 identifier, request.mutableResourceRequest(), factory.type()); | 542 factory.type()); |
543 if (!request.url().isValid()) | 543 if (!request.url().isValid()) |
544 return nullptr; | 544 return nullptr; |
545 | 545 |
546 if (!request.forPreload()) { | 546 if (!request.forPreload()) { |
547 V8DOMActivityLogger* activityLogger = nullptr; | 547 V8DOMActivityLogger* activityLogger = nullptr; |
548 if (request.options().initiatorInfo.name == | 548 if (request.options().initiatorInfo.name == |
549 FetchInitiatorTypeNames::xmlhttprequest) { | 549 FetchInitiatorTypeNames::xmlhttprequest) { |
550 activityLogger = V8DOMActivityLogger::currentActivityLogger(); | 550 activityLogger = V8DOMActivityLogger::currentActivityLogger(); |
551 } else { | 551 } else { |
552 activityLogger = | 552 activityLogger = |
553 V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld(); | 553 V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld(); |
554 } | 554 } |
555 | 555 |
556 if (activityLogger) { | 556 if (activityLogger) { |
557 Vector<String> argv; | 557 Vector<String> argv; |
558 argv.append(Resource::resourceTypeToString( | 558 argv.append(Resource::resourceTypeToString( |
559 factory.type(), request.options().initiatorInfo)); | 559 factory.type(), request.options().initiatorInfo)); |
560 argv.append(request.url()); | 560 argv.append(request.url()); |
561 activityLogger->logEvent("blinkRequestResource", argv.size(), | 561 activityLogger->logEvent("blinkRequestResource", argv.size(), |
562 argv.data()); | 562 argv.data()); |
563 } | 563 } |
564 } | 564 } |
565 | 565 |
566 bool isDataUrl = request.resourceRequest().url().protocolIsData(); | 566 bool isDataUrl = resourceRequest.url().protocolIsData(); |
567 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; | 567 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; |
568 Resource* resource(nullptr); | 568 Resource* resource(nullptr); |
569 if (isStaticData) { | 569 if (isStaticData) { |
570 resource = resourceForStaticData(request, factory, substituteData); | 570 resource = resourceForStaticData(request, factory, substituteData); |
571 // Abort the request if the archive doesn't contain the resource, except in | 571 // Abort the request if the archive doesn't contain the resource, except in |
572 // the case of data URLs which might have resources such as fonts that need | 572 // the case of data URLs which might have resources such as fonts that need |
573 // to be decoded only on demand. These data URLs are allowed to be | 573 // to be decoded only on demand. These data URLs are allowed to be |
574 // processed using the normal ResourceFetcher machinery. | 574 // processed using the normal ResourceFetcher machinery. |
575 if (!resource && !isDataUrl && m_archive) | 575 if (!resource && !isDataUrl && m_archive) |
576 return nullptr; | 576 return nullptr; |
577 } | 577 } |
578 if (!resource) { | 578 if (!resource) { |
579 resource = | 579 resource = |
580 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); | 580 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); |
581 } | 581 } |
582 | 582 |
583 // See if we can use an existing resource from the cache. If so, we need to | 583 // See if we can use an existing resource from the cache. If so, we need to |
584 // move it to be load blocking. | 584 // move it to be load blocking. |
585 moveCachedNonBlockingResourceToBlocking(resource, request); | 585 moveCachedNonBlockingResourceToBlocking(resource, request); |
586 | 586 |
587 const RevalidationPolicy policy = determineRevalidationPolicy( | 587 const RevalidationPolicy policy = determineRevalidationPolicy( |
588 factory.type(), request, resource, isStaticData); | 588 factory.type(), request, resource, isStaticData); |
589 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", | 589 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", |
590 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); | 590 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); |
591 | 591 |
592 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); | 592 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); |
593 | 593 |
594 request.mutableResourceRequest().setAllowStoredCredentials( | 594 resourceRequest.setAllowStoredCredentials( |
595 request.options().allowCredentials == AllowStoredCredentials); | 595 request.options().allowCredentials == AllowStoredCredentials); |
596 | 596 |
597 switch (policy) { | 597 switch (policy) { |
598 case Reload: | 598 case Reload: |
599 memoryCache()->remove(resource); | 599 memoryCache()->remove(resource); |
600 // Fall through | 600 // Fall through |
601 case Load: | 601 case Load: |
602 resource = createResourceForLoading(request, request.charset(), factory); | 602 resource = createResourceForLoading(request, request.charset(), factory); |
603 break; | 603 break; |
604 case Revalidate: | 604 case Revalidate: |
605 initializeRevalidation(request.mutableResourceRequest(), resource); | 605 initializeRevalidation(resourceRequest, resource); |
606 break; | 606 break; |
607 case Use: | 607 case Use: |
608 if (resource->isLinkPreload() && !request.isLinkPreload()) | 608 if (resource->isLinkPreload() && !request.isLinkPreload()) |
609 resource->setLinkPreload(false); | 609 resource->setLinkPreload(false); |
610 break; | 610 break; |
611 } | 611 } |
612 if (!resource) | 612 if (!resource) |
613 return nullptr; | 613 return nullptr; |
614 if (resource->getType() != factory.type()) { | 614 if (resource->getType() != factory.type()) { |
615 DCHECK(request.forPreload()); | 615 DCHECK(request.forPreload()); |
616 return nullptr; | 616 return nullptr; |
617 } | 617 } |
618 | 618 |
619 if (!resource->isAlive()) | 619 if (!resource->isAlive()) |
620 m_deadStatsRecorder.update(policy); | 620 m_deadStatsRecorder.update(policy); |
621 | 621 |
622 if (policy != Use) | 622 if (policy != Use) |
623 resource->setIdentifier(identifier); | 623 resource->setIdentifier(identifier); |
624 | 624 |
625 if (!request.forPreload() || policy != Use) { | 625 if (!request.forPreload() || policy != Use) { |
626 // When issuing another request for a resource that is already in-flight | 626 // When issuing another request for a resource that is already in-flight |
627 // make sure to not demote the priority of the in-flight request. If the new | 627 // make sure to not demote the priority of the in-flight request. If the new |
628 // request isn't at the same priority as the in-flight request, only allow | 628 // request isn't at the same priority as the in-flight request, only allow |
629 // promotions. This can happen when a visible image's priority is increased | 629 // promotions. This can happen when a visible image's priority is increased |
630 // and then another reference to the image is parsed (which would be at a | 630 // and then another reference to the image is parsed (which would be at a |
631 // lower priority). | 631 // lower priority). |
632 if (request.resourceRequest().priority() > | 632 if (resourceRequest.priority() > resource->resourceRequest().priority()) |
633 resource->resourceRequest().priority()) | 633 resource->didChangePriority(resourceRequest.priority(), 0); |
634 resource->didChangePriority(request.resourceRequest().priority(), 0); | |
635 } | 634 } |
636 | 635 |
637 // If only the fragment identifiers differ, it is the same resource. | 636 // If only the fragment identifiers differ, it is the same resource. |
638 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); | 637 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
639 requestLoadStarted( | 638 requestLoadStarted( |
640 identifier, resource, request, | 639 identifier, resource, request, |
641 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, | 640 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, |
642 isStaticData); | 641 isStaticData); |
643 m_documentResources.set( | 642 m_documentResources.set( |
644 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); | 643 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 visitor->trace(m_context); | 1704 visitor->trace(m_context); |
1706 visitor->trace(m_archive); | 1705 visitor->trace(m_archive); |
1707 visitor->trace(m_loaders); | 1706 visitor->trace(m_loaders); |
1708 visitor->trace(m_nonBlockingLoaders); | 1707 visitor->trace(m_nonBlockingLoaders); |
1709 visitor->trace(m_documentResources); | 1708 visitor->trace(m_documentResources); |
1710 visitor->trace(m_preloads); | 1709 visitor->trace(m_preloads); |
1711 visitor->trace(m_resourceTimingInfoMap); | 1710 visitor->trace(m_resourceTimingInfoMap); |
1712 } | 1711 } |
1713 | 1712 |
1714 } // namespace blink | 1713 } // namespace blink |
OLD | NEW |