Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 #include "core/dom/WeakIdentifierMap.h" | 34 #include "core/dom/WeakIdentifierMap.h" |
| 35 #include "core/events/Event.h" | 35 #include "core/events/Event.h" |
| 36 #include "core/frame/Deprecation.h" | 36 #include "core/frame/Deprecation.h" |
| 37 #include "core/frame/FrameHost.h" | 37 #include "core/frame/FrameHost.h" |
| 38 #include "core/frame/LocalDOMWindow.h" | 38 #include "core/frame/LocalDOMWindow.h" |
| 39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 40 #include "core/frame/LocalFrameClient.h" | 40 #include "core/frame/LocalFrameClient.h" |
| 41 #include "core/frame/Settings.h" | 41 #include "core/frame/Settings.h" |
| 42 #include "core/frame/csp/ContentSecurityPolicy.h" | 42 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 43 #include "core/html/HTMLFrameOwnerElement.h" | 43 #include "core/html/HTMLFrameOwnerElement.h" |
| 44 #include "core/html/parser/HTMLParserIdioms.h" | |
| 44 #include "core/html/parser/TextResourceDecoder.h" | 45 #include "core/html/parser/TextResourceDecoder.h" |
| 45 #include "core/inspector/ConsoleMessage.h" | 46 #include "core/inspector/ConsoleMessage.h" |
| 46 #include "core/inspector/InspectorInstrumentation.h" | 47 #include "core/inspector/InspectorInstrumentation.h" |
| 48 #include "core/inspector/InspectorTraceEvents.h" | |
| 47 #include "core/inspector/MainThreadDebugger.h" | 49 #include "core/inspector/MainThreadDebugger.h" |
| 48 #include "core/loader/FrameFetchContext.h" | 50 #include "core/loader/FrameFetchContext.h" |
| 49 #include "core/loader/FrameLoader.h" | 51 #include "core/loader/FrameLoader.h" |
| 50 #include "core/loader/LinkLoader.h" | 52 #include "core/loader/LinkLoader.h" |
| 51 #include "core/loader/NetworkHintsInterface.h" | 53 #include "core/loader/NetworkHintsInterface.h" |
| 52 #include "core/loader/ProgressTracker.h" | 54 #include "core/loader/ProgressTracker.h" |
| 53 #include "core/loader/SubresourceFilter.h" | 55 #include "core/loader/SubresourceFilter.h" |
| 54 #include "core/loader/appcache/ApplicationCacheHost.h" | 56 #include "core/loader/appcache/ApplicationCacheHost.h" |
| 55 #include "core/loader/resource/CSSStyleSheetResource.h" | 57 #include "core/loader/resource/CSSStyleSheetResource.h" |
| 56 #include "core/loader/resource/FontResource.h" | 58 #include "core/loader/resource/FontResource.h" |
| 57 #include "core/loader/resource/ImageResource.h" | 59 #include "core/loader/resource/ImageResource.h" |
| 58 #include "core/loader/resource/ScriptResource.h" | 60 #include "core/loader/resource/ScriptResource.h" |
| 61 #include "core/origin_trials/OriginTrialContext.h" | |
| 59 #include "core/page/FrameTree.h" | 62 #include "core/page/FrameTree.h" |
| 60 #include "core/page/Page.h" | 63 #include "core/page/Page.h" |
| 61 #include "platform/HTTPNames.h" | 64 #include "platform/HTTPNames.h" |
| 62 #include "platform/UserGestureIndicator.h" | 65 #include "platform/UserGestureIndicator.h" |
| 66 #include "platform/feature_policy/FeaturePolicy.h" | |
| 63 #include "platform/loader/fetch/FetchInitiatorTypeNames.h" | 67 #include "platform/loader/fetch/FetchInitiatorTypeNames.h" |
| 64 #include "platform/loader/fetch/FetchRequest.h" | 68 #include "platform/loader/fetch/FetchRequest.h" |
| 65 #include "platform/loader/fetch/FetchUtils.h" | 69 #include "platform/loader/fetch/FetchUtils.h" |
| 66 #include "platform/loader/fetch/MemoryCache.h" | 70 #include "platform/loader/fetch/MemoryCache.h" |
| 67 #include "platform/loader/fetch/ResourceFetcher.h" | 71 #include "platform/loader/fetch/ResourceFetcher.h" |
| 68 #include "platform/mhtml/ArchiveResource.h" | 72 #include "platform/mhtml/ArchiveResource.h" |
| 69 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" | 73 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" |
| 70 #include "platform/network/HTTPParsers.h" | 74 #include "platform/network/HTTPParsers.h" |
| 71 #include "platform/network/mime/MIMETypeRegistry.h" | 75 #include "platform/network/mime/MIMETypeRegistry.h" |
| 72 #include "platform/plugins/PluginData.h" | 76 #include "platform/plugins/PluginData.h" |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 DocumentInit init(owner, url(), m_frame); | 562 DocumentInit init(owner, url(), m_frame); |
| 559 init.withNewRegistrationContext(); | 563 init.withNewRegistrationContext(); |
| 560 m_frame->loader().clear(); | 564 m_frame->loader().clear(); |
| 561 DCHECK(m_frame->page()); | 565 DCHECK(m_frame->page()); |
| 562 | 566 |
| 563 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing; | 567 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing; |
| 564 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || | 568 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || |
| 565 !Document::threadedParsingEnabledForTesting()) | 569 !Document::threadedParsingEnabledForTesting()) |
| 566 parsingPolicy = ForceSynchronousParsing; | 570 parsingPolicy = ForceSynchronousParsing; |
| 567 | 571 |
| 568 m_writer = createWriterFor(init, mimeType, encoding, false, parsingPolicy, | 572 installNewDocument(init, mimeType, encoding, |
| 569 overridingURL); | 573 InstallNewDocumentReason::kNavigation, parsingPolicy, |
| 574 overridingURL); | |
| 570 m_writer->setDocumentWasLoadedAsPartOfNavigation(); | 575 m_writer->setDocumentWasLoadedAsPartOfNavigation(); |
| 571 m_frame->document()->maybeHandleHttpRefresh( | 576 m_frame->document()->maybeHandleHttpRefresh( |
| 572 m_response.httpHeaderField(HTTPNames::Refresh), | 577 m_response.httpHeaderField(HTTPNames::Refresh), |
| 573 Document::HttpRefreshFromHeader); | 578 Document::HttpRefreshFromHeader); |
| 574 } | 579 } |
| 575 | 580 |
| 576 void DocumentLoader::commitData(const char* bytes, size_t length) { | 581 void DocumentLoader::commitData(const char* bytes, size_t length) { |
| 577 DCHECK_EQ(m_state, Committed); | 582 DCHECK_EQ(m_state, Committed); |
| 578 ensureWriter(m_response.mimeType()); | 583 ensureWriter(m_response.mimeType()); |
| 579 | 584 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 m_request = m_mainResource->isLoading() ? m_mainResource->resourceRequest() | 775 m_request = m_mainResource->isLoading() ? m_mainResource->resourceRequest() |
| 771 : fetchRequest.resourceRequest(); | 776 : fetchRequest.resourceRequest(); |
| 772 m_mainResource->addClient(this); | 777 m_mainResource->addClient(this); |
| 773 } | 778 } |
| 774 | 779 |
| 775 void DocumentLoader::endWriting() { | 780 void DocumentLoader::endWriting() { |
| 776 m_writer->end(); | 781 m_writer->end(); |
| 777 m_writer.clear(); | 782 m_writer.clear(); |
| 778 } | 783 } |
| 779 | 784 |
| 780 DocumentWriter* DocumentLoader::createWriterFor( | 785 void DocumentLoader::didInstallNewDocument(Document* document) { |
| 786 document->setReadyState(Document::Loading); | |
| 787 document->initContentSecurityPolicy(m_contentSecurityPolicy.release()); | |
| 788 | |
| 789 frameLoader().didInstallNewDocument(); | |
| 790 | |
| 791 String suboriginHeader = m_response.httpHeaderField(HTTPNames::Suborigin); | |
| 792 if (!suboriginHeader.isNull()) { | |
| 793 Vector<String> messages; | |
| 794 Suborigin suborigin; | |
| 795 if (parseSuboriginHeader(suboriginHeader, &suborigin, messages)) | |
| 796 document->enforceSuborigin(suborigin); | |
| 797 | |
| 798 for (auto& message : messages) { | |
| 799 document->addConsoleMessage( | |
| 800 ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel, | |
| 801 "Error with Suborigin header: " + message)); | |
| 802 } | |
| 803 } | |
| 804 | |
| 805 document->clientHintsPreferences().updateFrom(m_clientHintsPreferences); | |
| 806 | |
| 807 // TODO(japhet): There's no reason to wait until commit to set these bits. | |
| 808 Settings* settings = document->settings(); | |
| 809 m_fetcher->setImagesEnabled(settings->getImagesEnabled()); | |
| 810 m_fetcher->setAutoLoadImages(settings->getLoadsImagesAutomatically()); | |
| 811 | |
| 812 const AtomicString& dnsPrefetchControl = | |
| 813 m_response.httpHeaderField(HTTPNames::X_DNS_Prefetch_Control); | |
| 814 if (!dnsPrefetchControl.isEmpty()) | |
| 815 document->parseDNSPrefetchControlHeader(dnsPrefetchControl); | |
| 816 | |
| 817 String headerContentLanguage = | |
| 818 m_response.httpHeaderField(HTTPNames::Content_Language); | |
| 819 if (!headerContentLanguage.isEmpty()) { | |
| 820 size_t commaIndex = headerContentLanguage.find(','); | |
| 821 // kNotFound == -1 == don't truncate | |
| 822 headerContentLanguage.truncate(commaIndex); | |
| 823 headerContentLanguage = | |
| 824 headerContentLanguage.stripWhiteSpace(isHTMLSpace<UChar>); | |
| 825 if (!headerContentLanguage.isEmpty()) | |
| 826 document->setContentLanguage(AtomicString(headerContentLanguage)); | |
| 827 } | |
| 828 | |
| 829 OriginTrialContext::addTokensFromHeader( | |
| 830 document, m_response.httpHeaderField(HTTPNames::Origin_Trial)); | |
| 831 String referrerPolicyHeader = | |
| 832 m_response.httpHeaderField(HTTPNames::Referrer_Policy); | |
| 833 if (!referrerPolicyHeader.isNull()) { | |
| 834 UseCounter::count(*document, UseCounter::ReferrerPolicyHeader); | |
| 835 document->parseAndSetReferrerPolicy(referrerPolicyHeader); | |
| 836 } | |
| 837 | |
| 838 localFrameClient().didCreateNewDocument(); | |
| 839 } | |
| 840 | |
| 841 void DocumentLoader::didCommitNavigation() { | |
| 842 if (frameLoader().stateMachine()->creatingInitialEmptyDocument()) | |
| 843 return; | |
| 844 frameLoader().receivedFirstData(); | |
| 845 | |
| 846 // didObserveLoadingBehavior() must be called after dispatchDidCommitLoad() is | |
| 847 // called for the metrics tracking logic to handle it properly. | |
| 848 if (m_serviceWorkerNetworkProvider && | |
| 849 m_serviceWorkerNetworkProvider->isControlledByServiceWorker()) { | |
| 850 localFrameClient().didObserveLoadingBehavior( | |
| 851 WebLoadingBehaviorServiceWorkerControlled); | |
| 852 } | |
| 853 | |
| 854 // Links with media values need more information (like viewport information). | |
| 855 // This happens after the first chunk is parsed in HTMLDocumentParser. | |
| 856 dispatchLinkHeaderPreloads(nullptr, LinkLoader::OnlyLoadNonMedia); | |
| 857 | |
| 858 TRACE_EVENT1("devtools.timeline", "CommitLoad", "data", | |
| 859 InspectorCommitLoadEvent::data(m_frame)); | |
| 860 probe::didCommitLoad(m_frame, this); | |
| 861 m_frame->page()->didCommitLoad(m_frame); | |
| 862 } | |
| 863 | |
| 864 void setFeaturePolicy(Document* document, const String& featurePolicyHeader) { | |
| 865 if (!RuntimeEnabledFeatures::featurePolicyEnabled()) | |
| 866 return; | |
| 867 LocalFrame* frame = document->frame(); | |
|
yhirano
2017/03/21 13:20:37
DCHECK_EQ(frame, m_frame);
Nate Chapin
2017/03/21 19:26:57
This is a static helper, so there is no m_frame he
| |
| 868 WebFeaturePolicy* parentFeaturePolicy = | |
| 869 frame->isMainFrame() | |
| 870 ? nullptr | |
| 871 : frame->tree().parent()->securityContext()->getFeaturePolicy(); | |
| 872 Vector<String> messages; | |
| 873 const WebParsedFeaturePolicy& parsedHeader = parseFeaturePolicy( | |
| 874 featurePolicyHeader, frame->securityContext()->getSecurityOrigin(), | |
| 875 &messages); | |
| 876 frame->securityContext()->initializeFeaturePolicy(parsedHeader, | |
| 877 parentFeaturePolicy); | |
| 878 for (auto& message : messages) { | |
| 879 document->addConsoleMessage( | |
| 880 ConsoleMessage::create(OtherMessageSource, ErrorMessageLevel, | |
| 881 "Error with Feature-Policy header: " + message)); | |
| 882 } | |
| 883 if (!parsedHeader.isEmpty()) | |
| 884 frame->client()->didSetFeaturePolicyHeader(parsedHeader); | |
| 885 } | |
| 886 | |
| 887 void DocumentLoader::installNewDocument( | |
| 781 const DocumentInit& init, | 888 const DocumentInit& init, |
| 782 const AtomicString& mimeType, | 889 const AtomicString& mimeType, |
| 783 const AtomicString& encoding, | 890 const AtomicString& encoding, |
| 784 bool dispatchWindowObjectAvailable, | 891 InstallNewDocumentReason reason, |
| 785 ParserSynchronizationPolicy parsingPolicy, | 892 ParserSynchronizationPolicy parsingPolicy, |
| 786 const KURL& overridingURL) { | 893 const KURL& overridingURL) { |
|
yhirano
2017/03/21 13:20:37
DCHECK_EQ(init.frame(), m_frame);
Nate Chapin
2017/03/21 19:26:58
Done.
| |
| 787 LocalFrame* frame = init.frame(); | 894 DCHECK(!m_frame->document() || !m_frame->document()->isActive()); |
| 788 | 895 DCHECK_EQ(m_frame->tree().childCount(), 0u); |
| 789 DCHECK(!frame->document() || !frame->document()->isActive()); | |
| 790 DCHECK_EQ(frame->tree().childCount(), 0u); | |
| 791 | 896 |
| 792 if (!init.shouldReuseDefaultView()) | 897 if (!init.shouldReuseDefaultView()) |
| 793 frame->setDOMWindow(LocalDOMWindow::create(*frame)); | 898 m_frame->setDOMWindow(LocalDOMWindow::create(*m_frame)); |
| 794 | 899 |
| 795 Document* document = frame->domWindow()->installNewDocument(mimeType, init); | 900 Document* document = m_frame->domWindow()->installNewDocument(mimeType, init); |
| 796 | 901 m_frame->page()->chromeClient().installSupplements(*m_frame); |
| 797 frame->page()->chromeClient().installSupplements(*frame); | |
| 798 | |
| 799 // This should be set before receivedFirstData(). | |
| 800 if (!overridingURL.isEmpty()) | 902 if (!overridingURL.isEmpty()) |
| 801 frame->document()->setBaseURLOverride(overridingURL); | 903 document->setBaseURLOverride(overridingURL); |
| 802 | 904 didInstallNewDocument(document); |
| 803 frame->loader().didInstallNewDocument(dispatchWindowObjectAvailable); | |
| 804 | 905 |
| 805 // This must be called before DocumentWriter is created, otherwise HTML parser | 906 // This must be called before DocumentWriter is created, otherwise HTML parser |
| 806 // will use stale values from HTMLParserOption. | 907 // will use stale values from HTMLParserOption. |
| 807 if (!dispatchWindowObjectAvailable) | 908 if (reason == InstallNewDocumentReason::kNavigation) |
| 808 frame->loader().receivedFirstData(); | 909 didCommitNavigation(); |
| 809 | 910 |
| 810 frame->loader().didBeginDocument(); | 911 m_writer = |
| 912 DocumentWriter::create(document, parsingPolicy, mimeType, encoding); | |
| 811 | 913 |
| 812 return DocumentWriter::create(document, parsingPolicy, mimeType, encoding); | 914 // FeaturePolicy is reset in the browser process on commit, so this needs to |
| 915 // be initialized and replicated to the browser process after commit messages | |
| 916 // are sent in didCommitNavigation(). | |
| 917 setFeaturePolicy(document, | |
| 918 m_response.httpHeaderField(HTTPNames::Feature_Policy)); | |
| 919 frameLoader().dispatchDidClearDocumentOfWindowObject(); | |
|
Nate Chapin
2017/03/17 23:33:18
This single caller appears to meet the requirement
| |
| 813 } | 920 } |
| 814 | 921 |
| 815 const AtomicString& DocumentLoader::mimeType() const { | 922 const AtomicString& DocumentLoader::mimeType() const { |
| 816 if (m_writer) | 923 if (m_writer) |
| 817 return m_writer->mimeType(); | 924 return m_writer->mimeType(); |
| 818 return m_response.mimeType(); | 925 return m_response.mimeType(); |
| 819 } | 926 } |
| 820 | 927 |
| 821 // This is only called by | 928 // This is only called by |
| 822 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL() | 929 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL() |
| 823 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL( | 930 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL( |
| 824 const DocumentInit& init, | 931 const DocumentInit& init, |
| 825 const String& source) { | 932 const String& source) { |
| 826 m_writer = createWriterFor(init, mimeType(), | 933 installNewDocument(init, mimeType(), |
| 827 m_writer ? m_writer->encoding() : emptyAtom, true, | 934 m_writer ? m_writer->encoding() : emptyAtom, |
| 828 ForceSynchronousParsing); | 935 InstallNewDocumentReason::kJavascriptURL, |
| 936 ForceSynchronousParsing, KURL()); | |
| 829 if (!source.isNull()) | 937 if (!source.isNull()) |
| 830 m_writer->appendReplacingData(source); | 938 m_writer->appendReplacingData(source); |
| 831 endWriting(); | 939 endWriting(); |
| 832 } | 940 } |
| 833 | 941 |
| 834 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); | 942 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); |
| 835 | 943 |
| 836 } // namespace blink | 944 } // namespace blink |
| OLD | NEW |