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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 if (resource && !resource->isAlive() && | 446 if (resource && !resource->isAlive() && |
447 (!m_preloads || !m_preloads->contains(resource))) { | 447 (!m_preloads || !m_preloads->contains(resource))) { |
448 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 448 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 Resource* ResourceFetcher::requestResource( | 452 Resource* ResourceFetcher::requestResource( |
453 FetchRequest& request, | 453 FetchRequest& request, |
454 const ResourceFactory& factory, | 454 const ResourceFactory& factory, |
455 const SubstituteData& substituteData) { | 455 const SubstituteData& substituteData) { |
| 456 ResourceRequest& resourceRequest = request.mutableResourceRequest(); |
| 457 |
456 unsigned long identifier = createUniqueIdentifier(); | 458 unsigned long identifier = createUniqueIdentifier(); |
457 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( | 459 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( |
458 identifier, request.resourceRequest()); | 460 identifier, resourceRequest); |
459 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); | 461 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); |
460 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || | 462 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || |
461 factory.type() == Resource::Raw || | 463 factory.type() == Resource::Raw || |
462 factory.type() == Resource::XSLStyleSheet); | 464 factory.type() == Resource::XSLStyleSheet); |
463 | 465 |
464 context().populateRequestData(request.mutableResourceRequest()); | 466 context().populateResourceRequest( |
465 context().modifyRequestForCSP(request.mutableResourceRequest()); | 467 factory.type(), request.clientHintsPreferences(), |
466 context().addClientHintsIfNecessary(request); | 468 request.getResourceWidth(), resourceRequest); |
467 context().addCSPHeaderIfNecessary(factory.type(), request); | |
468 | 469 |
469 // TODO(dproy): Remove this. http://crbug.com/659666 | 470 // TODO(dproy): Remove this. http://crbug.com/659666 |
470 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", | 471 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", |
471 urlForTraceEvent(request.url())); | 472 urlForTraceEvent(request.url())); |
472 | 473 |
473 if (!request.url().isValid()) | 474 if (!request.url().isValid()) |
474 return nullptr; | 475 return nullptr; |
475 | 476 |
476 request.mutableResourceRequest().setPriority(computeLoadPriority( | 477 resourceRequest.setPriority(computeLoadPriority( |
477 factory.type(), request, ResourcePriority::NotVisible)); | 478 factory.type(), request, ResourcePriority::NotVisible)); |
478 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), | 479 initializeResourceRequest(resourceRequest, factory.type(), request.defer()); |
479 request.defer()); | 480 network_instrumentation::resourcePrioritySet(identifier, |
480 network_instrumentation::resourcePrioritySet( | 481 resourceRequest.priority()); |
481 identifier, request.resourceRequest().priority()); | |
482 | 482 |
483 ResourceRequestBlockedReason blockedReason = context().canRequest( | 483 ResourceRequestBlockedReason blockedReason = context().canRequest( |
484 factory.type(), request.resourceRequest(), | 484 factory.type(), resourceRequest, |
485 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), | 485 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), |
486 request.options(), request.forPreload(), request.getOriginRestriction()); | 486 request.options(), request.forPreload(), request.getOriginRestriction()); |
487 if (blockedReason != ResourceRequestBlockedReason::None) { | 487 if (blockedReason != ResourceRequestBlockedReason::None) { |
488 DCHECK(!substituteData.forceSynchronousLoad()); | 488 DCHECK(!substituteData.forceSynchronousLoad()); |
489 return resourceForBlockedRequest(request, factory, blockedReason); | 489 return resourceForBlockedRequest(request, factory, blockedReason); |
490 } | 490 } |
491 | 491 |
492 context().willStartLoadingResource( | 492 context().willStartLoadingResource( |
493 identifier, request.mutableResourceRequest(), factory.type(), | 493 identifier, resourceRequest, factory.type(), |
494 request.options().initiatorInfo.name, request.forPreload()); | 494 request.options().initiatorInfo.name, request.forPreload()); |
495 if (!request.url().isValid()) | 495 if (!request.url().isValid()) |
496 return nullptr; | 496 return nullptr; |
497 | 497 |
498 bool isDataUrl = request.resourceRequest().url().protocolIsData(); | 498 bool isDataUrl = resourceRequest.url().protocolIsData(); |
499 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; | 499 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; |
500 Resource* resource(nullptr); | 500 Resource* resource(nullptr); |
501 if (isStaticData) { | 501 if (isStaticData) { |
502 resource = resourceForStaticData(request, factory, substituteData); | 502 resource = resourceForStaticData(request, factory, substituteData); |
503 // Abort the request if the archive doesn't contain the resource, except in | 503 // Abort the request if the archive doesn't contain the resource, except in |
504 // the case of data URLs which might have resources such as fonts that need | 504 // the case of data URLs which might have resources such as fonts that need |
505 // to be decoded only on demand. These data URLs are allowed to be | 505 // to be decoded only on demand. These data URLs are allowed to be |
506 // processed using the normal ResourceFetcher machinery. | 506 // processed using the normal ResourceFetcher machinery. |
507 if (!resource && !isDataUrl && m_archive) | 507 if (!resource && !isDataUrl && m_archive) |
508 return nullptr; | 508 return nullptr; |
509 } | 509 } |
510 if (!resource) { | 510 if (!resource) { |
511 resource = | 511 resource = |
512 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); | 512 memoryCache()->resourceForURL(request.url(), getCacheIdentifier()); |
513 } | 513 } |
514 | 514 |
515 // See if we can use an existing resource from the cache. If so, we need to | 515 // See if we can use an existing resource from the cache. If so, we need to |
516 // move it to be load blocking. | 516 // move it to be load blocking. |
517 moveCachedNonBlockingResourceToBlocking(resource, request); | 517 moveCachedNonBlockingResourceToBlocking(resource, request); |
518 | 518 |
519 const RevalidationPolicy policy = determineRevalidationPolicy( | 519 const RevalidationPolicy policy = determineRevalidationPolicy( |
520 factory.type(), request, resource, isStaticData); | 520 factory.type(), request, resource, isStaticData); |
521 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", | 521 TRACE_EVENT_INSTANT1("blink", "ResourceFetcher::determineRevalidationPolicy", |
522 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); | 522 TRACE_EVENT_SCOPE_THREAD, "revalidationPolicy", policy); |
523 | 523 |
524 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); | 524 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); |
525 | 525 |
526 request.mutableResourceRequest().setAllowStoredCredentials( | 526 resourceRequest.setAllowStoredCredentials( |
527 request.options().allowCredentials == AllowStoredCredentials); | 527 request.options().allowCredentials == AllowStoredCredentials); |
528 | 528 |
529 switch (policy) { | 529 switch (policy) { |
530 case Reload: | 530 case Reload: |
531 memoryCache()->remove(resource); | 531 memoryCache()->remove(resource); |
532 // Fall through | 532 // Fall through |
533 case Load: | 533 case Load: |
534 resource = createResourceForLoading(request, request.charset(), factory); | 534 resource = createResourceForLoading(request, request.charset(), factory); |
535 break; | 535 break; |
536 case Revalidate: | 536 case Revalidate: |
537 initializeRevalidation(request.mutableResourceRequest(), resource); | 537 initializeRevalidation(resourceRequest, resource); |
538 break; | 538 break; |
539 case Use: | 539 case Use: |
540 if (resource->isLinkPreload() && !request.isLinkPreload()) | 540 if (resource->isLinkPreload() && !request.isLinkPreload()) |
541 resource->setLinkPreload(false); | 541 resource->setLinkPreload(false); |
542 break; | 542 break; |
543 } | 543 } |
544 if (!resource) | 544 if (!resource) |
545 return nullptr; | 545 return nullptr; |
546 if (resource->getType() != factory.type()) { | 546 if (resource->getType() != factory.type()) { |
547 DCHECK(request.forPreload()); | 547 DCHECK(request.forPreload()); |
548 return nullptr; | 548 return nullptr; |
549 } | 549 } |
550 | 550 |
551 if (!resource->isAlive()) | 551 if (!resource->isAlive()) |
552 m_deadStatsRecorder.update(policy); | 552 m_deadStatsRecorder.update(policy); |
553 | 553 |
554 if (policy != Use) | 554 if (policy != Use) |
555 resource->setIdentifier(identifier); | 555 resource->setIdentifier(identifier); |
556 | 556 |
557 if (!request.forPreload() || policy != Use) { | 557 if (!request.forPreload() || policy != Use) { |
558 // When issuing another request for a resource that is already in-flight | 558 // When issuing another request for a resource that is already in-flight |
559 // make sure to not demote the priority of the in-flight request. If the new | 559 // make sure to not demote the priority of the in-flight request. If the new |
560 // request isn't at the same priority as the in-flight request, only allow | 560 // request isn't at the same priority as the in-flight request, only allow |
561 // promotions. This can happen when a visible image's priority is increased | 561 // promotions. This can happen when a visible image's priority is increased |
562 // and then another reference to the image is parsed (which would be at a | 562 // and then another reference to the image is parsed (which would be at a |
563 // lower priority). | 563 // lower priority). |
564 if (request.resourceRequest().priority() > | 564 if (resourceRequest.priority() > resource->resourceRequest().priority()) |
565 resource->resourceRequest().priority()) | 565 resource->didChangePriority(resourceRequest.priority(), 0); |
566 resource->didChangePriority(request.resourceRequest().priority(), 0); | |
567 } | 566 } |
568 | 567 |
569 // If only the fragment identifiers differ, it is the same resource. | 568 // If only the fragment identifiers differ, it is the same resource. |
570 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); | 569 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
571 requestLoadStarted( | 570 requestLoadStarted( |
572 identifier, resource, request, | 571 identifier, resource, request, |
573 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, | 572 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, |
574 isStaticData); | 573 isStaticData); |
575 m_documentResources.set( | 574 m_documentResources.set( |
576 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); | 575 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), resource); |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 visitor->trace(m_context); | 1501 visitor->trace(m_context); |
1503 visitor->trace(m_archive); | 1502 visitor->trace(m_archive); |
1504 visitor->trace(m_loaders); | 1503 visitor->trace(m_loaders); |
1505 visitor->trace(m_nonBlockingLoaders); | 1504 visitor->trace(m_nonBlockingLoaders); |
1506 visitor->trace(m_documentResources); | 1505 visitor->trace(m_documentResources); |
1507 visitor->trace(m_preloads); | 1506 visitor->trace(m_preloads); |
1508 visitor->trace(m_resourceTimingInfoMap); | 1507 visitor->trace(m_resourceTimingInfoMap); |
1509 } | 1508 } |
1510 | 1509 |
1511 } // namespace blink | 1510 } // namespace blink |
OLD | NEW |