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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 DEFINE_RESOURCE_HISTOGRAM("Dead."); | 456 DEFINE_RESOURCE_HISTOGRAM("Dead."); |
457 } | 457 } |
458 } | 458 } |
459 | 459 |
460 ResourceFetcher::PrepareRequestResult ResourceFetcher::prepareRequest( | 460 ResourceFetcher::PrepareRequestResult ResourceFetcher::prepareRequest( |
461 FetchRequest& request, | 461 FetchRequest& request, |
462 const ResourceFactory& factory, | 462 const ResourceFactory& factory, |
463 const SubstituteData& substituteData, | 463 const SubstituteData& substituteData, |
464 unsigned long identifier, | 464 unsigned long identifier, |
465 ResourceRequestBlockedReason& blockedReason) { | 465 ResourceRequestBlockedReason& blockedReason) { |
466 ResourceRequest& resourceRequest = request.mutableResourceRequest(); | |
467 | 466 |
468 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || | 467 DCHECK(request.options().synchronousPolicy == RequestAsynchronously || |
469 factory.type() == Resource::Raw || | 468 factory.type() == Resource::Raw || |
470 factory.type() == Resource::XSLStyleSheet); | 469 factory.type() == Resource::XSLStyleSheet); |
471 | 470 |
472 context().populateResourceRequest( | 471 context().populateResourceRequest( |
473 factory.type(), request.clientHintsPreferences(), | 472 factory.type(), request.clientHintsPreferences(), |
474 request.getResourceWidth(), resourceRequest); | 473 request.getResourceWidth(), request.mutableResourceRequest()); |
475 | 474 |
476 if (!request.url().isValid()) | 475 if (!request.url().isValid()) |
477 return Abort; | 476 return Abort; |
478 | 477 |
479 resourceRequest.setPriority(computeLoadPriority( | 478 request.mutableResourceRequest().setPriority(computeLoadPriority( |
480 factory.type(), request.resourceRequest(), ResourcePriority::NotVisible, | 479 factory.type(), request.resourceRequest(), ResourcePriority::NotVisible, |
481 request.defer(), request.isSpeculativePreload())); | 480 request.defer(), request.isSpeculativePreload())); |
482 initializeResourceRequest(resourceRequest, factory.type(), request.defer()); | 481 initializeResourceRequest(request.mutableResourceRequest(), factory.type(), |
483 network_instrumentation::resourcePrioritySet(identifier, | 482 request.defer()); |
484 resourceRequest.priority()); | 483 network_instrumentation::resourcePrioritySet( |
| 484 identifier, request.resourceRequest().priority()); |
485 | 485 |
486 blockedReason = context().canRequest( | 486 blockedReason = context().canRequest( |
487 factory.type(), resourceRequest, | 487 factory.type(), request.resourceRequest(), |
488 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), | 488 MemoryCache::removeFragmentIdentifierIfNeeded(request.url()), |
489 request.options(), | 489 request.options(), |
490 /* Don't send security violation reports for speculative preloads */ | 490 /* Don't send security violation reports for speculative preloads */ |
491 request.isSpeculativePreload() | 491 request.isSpeculativePreload() |
492 ? SecurityViolationReportingPolicy::SuppressReporting | 492 ? SecurityViolationReportingPolicy::SuppressReporting |
493 : SecurityViolationReportingPolicy::Report, | 493 : SecurityViolationReportingPolicy::Report, |
494 request.getOriginRestriction()); | 494 request.getOriginRestriction()); |
495 if (blockedReason != ResourceRequestBlockedReason::None) { | 495 if (blockedReason != ResourceRequestBlockedReason::None) { |
496 DCHECK(!substituteData.forceSynchronousLoad()); | 496 DCHECK(!substituteData.forceSynchronousLoad()); |
497 return Block; | 497 return Block; |
498 } | 498 } |
499 | 499 |
500 context().willStartLoadingResource( | 500 context().willStartLoadingResource( |
501 identifier, resourceRequest, factory.type(), | 501 identifier, request.mutableResourceRequest(), factory.type(), |
502 request.options().initiatorInfo.name, | 502 request.options().initiatorInfo.name, |
503 (request.isSpeculativePreload() | 503 (request.isSpeculativePreload() |
504 ? FetchContext::V8ActivityLoggingPolicy::SuppressLogging | 504 ? FetchContext::V8ActivityLoggingPolicy::SuppressLogging |
505 : FetchContext::V8ActivityLoggingPolicy::Log)); | 505 : FetchContext::V8ActivityLoggingPolicy::Log)); |
506 if (!request.url().isValid()) | 506 if (!request.url().isValid()) |
507 return Abort; | 507 return Abort; |
508 | 508 |
509 resourceRequest.setAllowStoredCredentials( | 509 request.mutableResourceRequest().setAllowStoredCredentials( |
510 request.options().allowCredentials == AllowStoredCredentials); | 510 request.options().allowCredentials == AllowStoredCredentials); |
511 return Continue; | 511 return Continue; |
512 } | 512 } |
513 | 513 |
514 Resource* ResourceFetcher::requestResource( | 514 Resource* ResourceFetcher::requestResource( |
515 FetchRequest& request, | 515 FetchRequest& request, |
516 const ResourceFactory& factory, | 516 const ResourceFactory& factory, |
517 const SubstituteData& substituteData) { | 517 const SubstituteData& substituteData) { |
518 unsigned long identifier = createUniqueIdentifier(); | 518 unsigned long identifier = createUniqueIdentifier(); |
519 ResourceRequest& resourceRequest = request.mutableResourceRequest(); | |
520 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( | 519 network_instrumentation::ScopedResourceLoadTracker scopedResourceLoadTracker( |
521 identifier, resourceRequest); | 520 identifier, request.resourceRequest()); |
522 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); | 521 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Blink.Fetch.RequestResourceTime"); |
523 // TODO(dproy): Remove this. http://crbug.com/659666 | 522 // TODO(dproy): Remove this. http://crbug.com/659666 |
524 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", | 523 TRACE_EVENT1("blink", "ResourceFetcher::requestResource", "url", |
525 urlForTraceEvent(request.url())); | 524 urlForTraceEvent(request.url())); |
526 | 525 |
527 Resource* resource = nullptr; | 526 Resource* resource = nullptr; |
528 ResourceRequestBlockedReason blockedReason = | 527 ResourceRequestBlockedReason blockedReason = |
529 ResourceRequestBlockedReason::None; | 528 ResourceRequestBlockedReason::None; |
530 | 529 |
531 PrepareRequestResult result = prepareRequest(request, factory, substituteData, | 530 PrepareRequestResult result = prepareRequest(request, factory, substituteData, |
532 identifier, blockedReason); | 531 identifier, blockedReason); |
533 if (result == Abort) | 532 if (result == Abort) |
534 return nullptr; | 533 return nullptr; |
535 if (result == Block) | 534 if (result == Block) |
536 return resourceForBlockedRequest(request, factory, blockedReason); | 535 return resourceForBlockedRequest(request, factory, blockedReason); |
537 | 536 |
538 bool isDataUrl = resourceRequest.url().protocolIsData(); | 537 bool isDataUrl = request.url().protocolIsData(); |
539 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; | 538 bool isStaticData = isDataUrl || substituteData.isValid() || m_archive; |
540 if (isStaticData) { | 539 if (isStaticData) { |
541 resource = resourceForStaticData(request, factory, substituteData); | 540 resource = resourceForStaticData(request, factory, substituteData); |
542 // Abort the request if the archive doesn't contain the resource, except in | 541 // Abort the request if the archive doesn't contain the resource, except in |
543 // the case of data URLs which might have resources such as fonts that need | 542 // the case of data URLs which might have resources such as fonts that need |
544 // to be decoded only on demand. These data URLs are allowed to be | 543 // to be decoded only on demand. These data URLs are allowed to be |
545 // processed using the normal ResourceFetcher machinery. | 544 // processed using the normal ResourceFetcher machinery. |
546 if (!resource && !isDataUrl && m_archive) | 545 if (!resource && !isDataUrl && m_archive) |
547 return nullptr; | 546 return nullptr; |
548 } | 547 } |
(...skipping 14 matching lines...) Expand all Loading... |
563 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); | 562 updateMemoryCacheStats(resource, policy, request, factory, isStaticData); |
564 | 563 |
565 switch (policy) { | 564 switch (policy) { |
566 case Reload: | 565 case Reload: |
567 memoryCache()->remove(resource); | 566 memoryCache()->remove(resource); |
568 // Fall through | 567 // Fall through |
569 case Load: | 568 case Load: |
570 resource = createResourceForLoading(request, request.charset(), factory); | 569 resource = createResourceForLoading(request, request.charset(), factory); |
571 break; | 570 break; |
572 case Revalidate: | 571 case Revalidate: |
573 initializeRevalidation(resourceRequest, resource); | 572 initializeRevalidation(request.mutableResourceRequest(), resource); |
574 break; | 573 break; |
575 case Use: | 574 case Use: |
576 if (resource->isLinkPreload() && !request.isLinkPreload()) | 575 if (resource->isLinkPreload() && !request.isLinkPreload()) |
577 resource->setLinkPreload(false); | 576 resource->setLinkPreload(false); |
578 break; | 577 break; |
579 } | 578 } |
580 if (!resource) | 579 if (!resource) |
581 return nullptr; | 580 return nullptr; |
582 | 581 |
583 // TODO(yoav): turn to a DCHECK. See https://crbug.com/690632 | 582 // TODO(yoav): turn to a DCHECK. See https://crbug.com/690632 |
584 CHECK_EQ(resource->getType(), factory.type()); | 583 CHECK_EQ(resource->getType(), factory.type()); |
585 | 584 |
586 if (!resource->isAlive()) | 585 if (!resource->isAlive()) |
587 m_deadStatsRecorder.update(policy); | 586 m_deadStatsRecorder.update(policy); |
588 | 587 |
589 if (policy != Use) | 588 if (policy != Use) |
590 resource->setIdentifier(identifier); | 589 resource->setIdentifier(identifier); |
591 | 590 |
592 // TODO(yoav): It is not clear why preloads are exempt from this check. Can we | 591 // TODO(yoav): It is not clear why preloads are exempt from this check. Can we |
593 // remove the exemption? | 592 // remove the exemption? |
594 if (!request.isSpeculativePreload() || policy != Use) { | 593 if (!request.isSpeculativePreload() || policy != Use) { |
595 // When issuing another request for a resource that is already in-flight | 594 // When issuing another request for a resource that is already in-flight |
596 // make sure to not demote the priority of the in-flight request. If the new | 595 // make sure to not demote the priority of the in-flight request. If the new |
597 // request isn't at the same priority as the in-flight request, only allow | 596 // request isn't at the same priority as the in-flight request, only allow |
598 // promotions. This can happen when a visible image's priority is increased | 597 // promotions. This can happen when a visible image's priority is increased |
599 // and then another reference to the image is parsed (which would be at a | 598 // and then another reference to the image is parsed (which would be at a |
600 // lower priority). | 599 // lower priority). |
601 if (resourceRequest.priority() > resource->resourceRequest().priority()) | 600 if (request.resourceRequest().priority() > |
602 resource->didChangePriority(resourceRequest.priority(), 0); | 601 resource->resourceRequest().priority()) |
| 602 resource->didChangePriority(request.resourceRequest().priority(), 0); |
603 // TODO(yoav): I'd expect the stated scenario to not go here, as its policy | 603 // TODO(yoav): I'd expect the stated scenario to not go here, as its policy |
604 // would be Use. | 604 // would be Use. |
605 } | 605 } |
606 | 606 |
607 // If only the fragment identifiers differ, it is the same resource. | 607 // If only the fragment identifiers differ, it is the same resource. |
608 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); | 608 DCHECK(equalIgnoringFragmentIdentifier(resource->url(), request.url())); |
609 requestLoadStarted( | 609 requestLoadStarted( |
610 identifier, resource, request, | 610 identifier, resource, request, |
611 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, | 611 policy == Use ? ResourceLoadingFromCache : ResourceLoadingFromNetwork, |
612 isStaticData); | 612 isStaticData); |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 visitor->trace(m_context); | 1544 visitor->trace(m_context); |
1545 visitor->trace(m_archive); | 1545 visitor->trace(m_archive); |
1546 visitor->trace(m_loaders); | 1546 visitor->trace(m_loaders); |
1547 visitor->trace(m_nonBlockingLoaders); | 1547 visitor->trace(m_nonBlockingLoaders); |
1548 visitor->trace(m_documentResources); | 1548 visitor->trace(m_documentResources); |
1549 visitor->trace(m_preloads); | 1549 visitor->trace(m_preloads); |
1550 visitor->trace(m_resourceTimingInfoMap); | 1550 visitor->trace(m_resourceTimingInfoMap); |
1551 } | 1551 } |
1552 | 1552 |
1553 } // namespace blink | 1553 } // namespace blink |
OLD | NEW |