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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2676163002: Refactor the forPreload flag to mean speculative preload. (Closed)
Patch Set: Created 3 years, 10 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 value->setString("url", url.getString()); 564 value->setString("url", url.getString());
565 value->setInteger("priority", priority); 565 value->setInteger("priority", priority);
566 return value; 566 return value;
567 } 567 }
568 568
569 void FrameFetchContext::willStartLoadingResource( 569 void FrameFetchContext::willStartLoadingResource(
570 unsigned long identifier, 570 unsigned long identifier,
571 ResourceRequest& request, 571 ResourceRequest& request,
572 Resource::Type type, 572 Resource::Type type,
573 const AtomicString& fetchInitiatorName, 573 const AtomicString& fetchInitiatorName,
574 bool forPreload) { 574 bool suppressLogging) {
575 TRACE_EVENT_ASYNC_BEGIN1( 575 TRACE_EVENT_ASYNC_BEGIN1(
576 "blink.net", "Resource", identifier, "data", 576 "blink.net", "Resource", identifier, "data",
577 loadResourceTraceData(identifier, request.url(), request.priority())); 577 loadResourceTraceData(identifier, request.url(), request.priority()));
578 prepareRequest(request); 578 prepareRequest(request);
579 579
580 if (!m_documentLoader || m_documentLoader->fetcher()->archive() || 580 if (!m_documentLoader || m_documentLoader->fetcher()->archive() ||
581 !request.url().isValid()) 581 !request.url().isValid())
582 return; 582 return;
583 if (type == Resource::MainResource) { 583 if (type == Resource::MainResource) {
584 m_documentLoader->applicationCacheHost()->willStartLoadingMainResource( 584 m_documentLoader->applicationCacheHost()->willStartLoadingMainResource(
585 request); 585 request);
586 } else { 586 } else {
587 m_documentLoader->applicationCacheHost()->willStartLoadingResource(request); 587 m_documentLoader->applicationCacheHost()->willStartLoadingResource(request);
588 } 588 }
589 if (!forPreload) { 589 if (!suppressLogging) {
590 V8DOMActivityLogger* activityLogger = nullptr; 590 V8DOMActivityLogger* activityLogger = nullptr;
591 if (fetchInitiatorName == FetchInitiatorTypeNames::xmlhttprequest) { 591 if (fetchInitiatorName == FetchInitiatorTypeNames::xmlhttprequest) {
592 activityLogger = V8DOMActivityLogger::currentActivityLogger(); 592 activityLogger = V8DOMActivityLogger::currentActivityLogger();
593 } else { 593 } else {
594 activityLogger = 594 activityLogger =
595 V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld(); 595 V8DOMActivityLogger::currentActivityLoggerIfIsolatedWorld();
596 } 596 }
597 597
598 if (activityLogger) { 598 if (activityLogger) {
599 Vector<String> argv; 599 Vector<String> argv;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 645
646 frame()->document()->addConsoleMessage(ConsoleMessage::create( 646 frame()->document()->addConsoleMessage(ConsoleMessage::create(
647 SecurityMessageSource, ErrorMessageLevel, message)); 647 SecurityMessageSource, ErrorMessageLevel, message));
648 } 648 }
649 649
650 ResourceRequestBlockedReason FrameFetchContext::canRequest( 650 ResourceRequestBlockedReason FrameFetchContext::canRequest(
651 Resource::Type type, 651 Resource::Type type,
652 const ResourceRequest& resourceRequest, 652 const ResourceRequest& resourceRequest,
653 const KURL& url, 653 const KURL& url,
654 const ResourceLoaderOptions& options, 654 const ResourceLoaderOptions& options,
655 bool forPreload, 655 bool suppressReport,
656 FetchRequest::OriginRestriction originRestriction) const { 656 FetchRequest::OriginRestriction originRestriction) const {
657 ResourceRequestBlockedReason blockedReason = 657 ResourceRequestBlockedReason blockedReason =
658 canRequestInternal(type, resourceRequest, url, options, forPreload, 658 canRequestInternal(type, resourceRequest, url, options, suppressReport,
659 originRestriction, resourceRequest.redirectStatus()); 659 originRestriction, resourceRequest.redirectStatus());
660 if (blockedReason != ResourceRequestBlockedReason::None && !forPreload) { 660 if (blockedReason != ResourceRequestBlockedReason::None && !suppressReport) {
661 InspectorInstrumentation::didBlockRequest( 661 InspectorInstrumentation::didBlockRequest(
662 frame(), resourceRequest, masterDocumentLoader(), options.initiatorInfo, 662 frame(), resourceRequest, masterDocumentLoader(), options.initiatorInfo,
663 blockedReason); 663 blockedReason);
664 } 664 }
665 return blockedReason; 665 return blockedReason;
666 } 666 }
667 667
668 ResourceRequestBlockedReason FrameFetchContext::allowResponse( 668 ResourceRequestBlockedReason FrameFetchContext::allowResponse(
669 Resource::Type type, 669 Resource::Type type,
670 const ResourceRequest& resourceRequest, 670 const ResourceRequest& resourceRequest,
671 const KURL& url, 671 const KURL& url,
672 const ResourceLoaderOptions& options) const { 672 const ResourceLoaderOptions& options) const {
673 ResourceRequestBlockedReason blockedReason = 673 ResourceRequestBlockedReason blockedReason =
674 canRequestInternal(type, resourceRequest, url, options, false, 674 canRequestInternal(type, resourceRequest, url, options, false,
675 FetchRequest::UseDefaultOriginRestrictionForType, 675 FetchRequest::UseDefaultOriginRestrictionForType,
676 RedirectStatus::FollowedRedirect); 676 RedirectStatus::FollowedRedirect);
677 if (blockedReason != ResourceRequestBlockedReason::None) { 677 if (blockedReason != ResourceRequestBlockedReason::None) {
678 InspectorInstrumentation::didBlockRequest( 678 InspectorInstrumentation::didBlockRequest(
679 frame(), resourceRequest, masterDocumentLoader(), options.initiatorInfo, 679 frame(), resourceRequest, masterDocumentLoader(), options.initiatorInfo,
680 blockedReason); 680 blockedReason);
681 } 681 }
682 return blockedReason; 682 return blockedReason;
683 } 683 }
684 684
685 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal( 685 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal(
686 Resource::Type type, 686 Resource::Type type,
687 const ResourceRequest& resourceRequest, 687 const ResourceRequest& resourceRequest,
688 const KURL& url, 688 const KURL& url,
689 const ResourceLoaderOptions& options, 689 const ResourceLoaderOptions& options,
690 bool forPreload, 690 bool suppressReport,
691 FetchRequest::OriginRestriction originRestriction, 691 FetchRequest::OriginRestriction originRestriction,
692 ResourceRequest::RedirectStatus redirectStatus) const { 692 ResourceRequest::RedirectStatus redirectStatus) const {
693 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest)) 693 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest))
694 return ResourceRequestBlockedReason::Inspector; 694 return ResourceRequestBlockedReason::Inspector;
695 695
696 SecurityOrigin* securityOrigin = options.securityOrigin.get(); 696 SecurityOrigin* securityOrigin = options.securityOrigin.get();
697 if (!securityOrigin && m_document) 697 if (!securityOrigin && m_document)
698 securityOrigin = m_document->getSecurityOrigin(); 698 securityOrigin = m_document->getSecurityOrigin();
699 699
700 if (originRestriction != FetchRequest::NoOriginRestriction && 700 if (originRestriction != FetchRequest::NoOriginRestriction &&
701 securityOrigin && !securityOrigin->canDisplay(url)) { 701 securityOrigin && !securityOrigin->canDisplay(url)) {
702 if (!forPreload) 702 if (!suppressReport)
703 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString()); 703 FrameLoader::reportLocalLoadFailed(frame(), url.elidedString());
704 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::requestResource URL was not " 704 RESOURCE_LOADING_DVLOG(1) << "ResourceFetcher::requestResource URL was not "
705 "allowed by SecurityOrigin::canDisplay"; 705 "allowed by SecurityOrigin::canDisplay";
706 return ResourceRequestBlockedReason::Other; 706 return ResourceRequestBlockedReason::Other;
707 } 707 }
708 708
709 // Some types of resources can be loaded only from the same origin. Other 709 // Some types of resources can be loaded only from the same origin. Other
710 // types of resources, like Images, Scripts, and CSS, can be loaded from 710 // types of resources, like Images, Scripts, and CSS, can be loaded from
711 // any URL. 711 // any URL.
712 switch (type) { 712 switch (type) {
(...skipping 29 matching lines...) Expand all
742 742
743 // FIXME: Convert this to check the isolated world's Content Security Policy 743 // FIXME: Convert this to check the isolated world's Content Security Policy
744 // once webkit.org/b/104520 is solved. 744 // once webkit.org/b/104520 is solved.
745 bool shouldBypassMainWorldCSP = 745 bool shouldBypassMainWorldCSP =
746 frame()->script().shouldBypassMainWorldCSP() || 746 frame()->script().shouldBypassMainWorldCSP() ||
747 options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy; 747 options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy;
748 748
749 // Don't send CSP messages for preloads, we might never actually display those 749 // Don't send CSP messages for preloads, we might never actually display those
750 // items. 750 // items.
751 ContentSecurityPolicy::ReportingStatus cspReporting = 751 ContentSecurityPolicy::ReportingStatus cspReporting =
752 forPreload ? ContentSecurityPolicy::SuppressReport 752 suppressReport ? ContentSecurityPolicy::SuppressReport
753 : ContentSecurityPolicy::SendReport; 753 : ContentSecurityPolicy::SendReport;
754 754
755 if (m_document) { 755 if (m_document) {
756 DCHECK(m_document->contentSecurityPolicy()); 756 DCHECK(m_document->contentSecurityPolicy());
757 if (!shouldBypassMainWorldCSP && 757 if (!shouldBypassMainWorldCSP &&
758 !m_document->contentSecurityPolicy()->allowRequest( 758 !m_document->contentSecurityPolicy()->allowRequest(
759 resourceRequest.requestContext(), url, 759 resourceRequest.requestContext(), url,
760 options.contentSecurityPolicyNonce, options.integrityMetadata, 760 options.contentSecurityPolicyNonce, options.integrityMetadata,
761 options.parserDisposition, redirectStatus, cspReporting)) 761 options.parserDisposition, redirectStatus, cspReporting))
762 return ResourceRequestBlockedReason::CSP; 762 return ResourceRequestBlockedReason::CSP;
763 } 763 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 Deprecation::countDeprecation( 800 Deprecation::countDeprecation(
801 frame()->document(), 801 frame()->document(),
802 UseCounter::RequestedSubresourceWithEmbeddedCredentials); 802 UseCounter::RequestedSubresourceWithEmbeddedCredentials);
803 } 803 }
804 } 804 }
805 805
806 // Check for mixed content. We do this second-to-last so that when folks block 806 // Check for mixed content. We do this second-to-last so that when folks block
807 // mixed content with a CSP policy, they don't get a warning. They'll still 807 // mixed content with a CSP policy, they don't get a warning. They'll still
808 // get a warning in the console about CSP blocking the load. 808 // get a warning in the console about CSP blocking the load.
809 MixedContentChecker::ReportingStatus mixedContentReporting = 809 MixedContentChecker::ReportingStatus mixedContentReporting =
810 forPreload ? MixedContentChecker::SuppressReport 810 suppressReport ? MixedContentChecker::SuppressReport
811 : MixedContentChecker::SendReport; 811 : MixedContentChecker::SendReport;
812 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, 812 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url,
813 mixedContentReporting)) 813 mixedContentReporting))
814 return ResourceRequestBlockedReason::MixedContent; 814 return ResourceRequestBlockedReason::MixedContent;
815 815
816 // Let the client have the final say into whether or not the load should 816 // Let the client have the final say into whether or not the load should
817 // proceed. 817 // proceed.
818 DocumentLoader* documentLoader = masterDocumentLoader(); 818 DocumentLoader* documentLoader = masterDocumentLoader();
819 if (documentLoader && documentLoader->subresourceFilter() && 819 if (documentLoader && documentLoader->subresourceFilter() &&
820 type != Resource::MainResource && type != Resource::ImportResource && 820 type != Resource::MainResource && type != Resource::ImportResource &&
821 !documentLoader->subresourceFilter()->allowLoad( 821 !documentLoader->subresourceFilter()->allowLoad(
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 response); 1087 response);
1088 } 1088 }
1089 1089
1090 DEFINE_TRACE(FrameFetchContext) { 1090 DEFINE_TRACE(FrameFetchContext) {
1091 visitor->trace(m_document); 1091 visitor->trace(m_document);
1092 visitor->trace(m_documentLoader); 1092 visitor->trace(m_documentLoader);
1093 FetchContext::trace(visitor); 1093 FetchContext::trace(visitor);
1094 } 1094 }
1095 1095
1096 } // namespace blink 1096 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698