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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 setHistoryItemStateForCommit(frameLoader().documentLoader()->historyItem(), | 662 setHistoryItemStateForCommit(frameLoader().documentLoader()->historyItem(), |
| 663 m_loadType, | 663 m_loadType, |
| 664 HistoryNavigationType::kDifferentDocument); | 664 HistoryNavigationType::kDifferentDocument); |
| 665 } | 665 } |
| 666 | 666 |
| 667 DCHECK_EQ(m_state, Provisional); | 667 DCHECK_EQ(m_state, Provisional); |
| 668 frameLoader().commitProvisionalLoad(); | 668 frameLoader().commitProvisionalLoad(); |
| 669 if (!m_frame) | 669 if (!m_frame) |
| 670 return; | 670 return; |
| 671 | 671 |
| 672 SecurityOrigin* frameSecurityOrigin = nullptr; | |
| 673 if (m_frame->document()) | |
| 674 frameSecurityOrigin = m_frame->document()->getSecurityOrigin(); | |
| 675 | |
| 672 const AtomicString& encoding = response().textEncodingName(); | 676 const AtomicString& encoding = response().textEncodingName(); |
| 673 | 677 |
| 674 // Prepare a DocumentInit before clearing the frame, because it may need to | 678 // Prepare a DocumentInit before clearing the frame, because it may need to |
| 675 // inherit an aliased security context. | 679 // inherit an aliased security context. |
| 676 Document* owner = nullptr; | 680 Document* owner = nullptr; |
| 677 // TODO(dcheng): This differs from the behavior of both IE and Firefox: the | 681 // TODO(dcheng): This differs from the behavior of both IE and Firefox: the |
| 678 // origin is inherited from the document that loaded the URL. | 682 // origin is inherited from the document that loaded the URL. |
| 679 if (shouldInheritSecurityOriginFromOwner(url())) { | 683 if (shouldInheritSecurityOriginFromOwner(url())) { |
| 680 Frame* ownerFrame = m_frame->tree().parent(); | 684 Frame* ownerFrame = m_frame->tree().parent(); |
| 681 if (!ownerFrame) | 685 if (!ownerFrame) |
| 682 ownerFrame = m_frame->loader().opener(); | 686 ownerFrame = m_frame->loader().opener(); |
| 683 if (ownerFrame && ownerFrame->isLocalFrame()) | 687 if (ownerFrame && ownerFrame->isLocalFrame()) |
| 684 owner = toLocalFrame(ownerFrame)->document(); | 688 owner = toLocalFrame(ownerFrame)->document(); |
| 685 } | 689 } |
| 686 DocumentInit init(owner, url(), m_frame); | 690 DocumentInit init(owner, url(), m_frame); |
| 687 init.withNewRegistrationContext(); | 691 init.withNewRegistrationContext(); |
| 688 m_frame->loader().clear(); | 692 m_frame->loader().clear(); |
| 689 DCHECK(m_frame->page()); | 693 DCHECK(m_frame->page()); |
| 690 | 694 |
| 691 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing; | 695 ParserSynchronizationPolicy parsingPolicy = AllowAsynchronousParsing; |
| 692 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || | 696 if ((m_substituteData.isValid() && m_substituteData.forceSynchronousLoad()) || |
| 693 !Document::threadedParsingEnabledForTesting()) | 697 !Document::threadedParsingEnabledForTesting()) |
| 694 parsingPolicy = ForceSynchronousParsing; | 698 parsingPolicy = ForceSynchronousParsing; |
| 695 | 699 |
| 696 installNewDocument(init, mimeType, encoding, | 700 installNewDocument(init, mimeType, encoding, |
| 697 InstallNewDocumentReason::kNavigation, parsingPolicy, | 701 InstallNewDocumentReason::kNavigation, parsingPolicy, |
| 698 overridingURL); | 702 overridingURL, frameSecurityOrigin); |
| 699 m_writer->setDocumentWasLoadedAsPartOfNavigation(); | 703 m_writer->setDocumentWasLoadedAsPartOfNavigation(); |
| 700 m_frame->document()->maybeHandleHttpRefresh( | 704 m_frame->document()->maybeHandleHttpRefresh( |
| 701 m_response.httpHeaderField(HTTPNames::Refresh), | 705 m_response.httpHeaderField(HTTPNames::Refresh), |
| 702 Document::HttpRefreshFromHeader); | 706 Document::HttpRefreshFromHeader); |
| 703 } | 707 } |
| 704 | 708 |
| 705 void DocumentLoader::commitData(const char* bytes, size_t length) { | 709 void DocumentLoader::commitData(const char* bytes, size_t length) { |
| 706 ensureWriter(m_response.mimeType()); | 710 ensureWriter(m_response.mimeType()); |
| 707 DCHECK_GE(m_state, Committed); | 711 DCHECK_GE(m_state, Committed); |
| 708 | 712 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 | 1027 |
| 1024 for (auto& message : messages) { | 1028 for (auto& message : messages) { |
| 1025 document->addConsoleMessage( | 1029 document->addConsoleMessage( |
| 1026 ConsoleMessage::create(OtherMessageSource, ErrorMessageLevel, | 1030 ConsoleMessage::create(OtherMessageSource, ErrorMessageLevel, |
| 1027 "Error with Feature-Policy header: " + message)); | 1031 "Error with Feature-Policy header: " + message)); |
| 1028 } | 1032 } |
| 1029 if (!parsedHeader.isEmpty()) | 1033 if (!parsedHeader.isEmpty()) |
| 1030 frame->client()->didSetFeaturePolicyHeader(parsedHeader); | 1034 frame->client()->didSetFeaturePolicyHeader(parsedHeader); |
| 1031 } | 1035 } |
| 1032 | 1036 |
| 1037 // static | |
| 1038 bool DocumentLoader::shouldClearWindowName( | |
| 1039 const LocalFrame& frame, | |
| 1040 SecurityOrigin* frameSecurityOrigin, | |
| 1041 const Document& newDocument) | |
| 1042 { | |
| 1043 if (!frameSecurityOrigin) | |
| 1044 return false; | |
| 1045 if (!frame.isMainFrame()) | |
| 1046 return false; | |
| 1047 if (frame.loader().opener()) | |
| 1048 return false; | |
| 1049 | |
| 1050 return !newDocument.getSecurityOrigin()->isSameSchemeHostPort(frameSecurityOri gin); | |
| 1051 } | |
| 1052 | |
| 1033 void DocumentLoader::installNewDocument( | 1053 void DocumentLoader::installNewDocument( |
| 1034 const DocumentInit& init, | 1054 const DocumentInit& init, |
| 1035 const AtomicString& mimeType, | 1055 const AtomicString& mimeType, |
| 1036 const AtomicString& encoding, | 1056 const AtomicString& encoding, |
| 1037 InstallNewDocumentReason reason, | 1057 InstallNewDocumentReason reason, |
| 1038 ParserSynchronizationPolicy parsingPolicy, | 1058 ParserSynchronizationPolicy parsingPolicy, |
| 1039 const KURL& overridingURL) { | 1059 const KURL& overridingURL, |
| 1060 SecurityOrigin* frameSecurityOrigin) { | |
| 1040 DCHECK_EQ(init.frame(), m_frame); | 1061 DCHECK_EQ(init.frame(), m_frame); |
| 1041 DCHECK(!m_frame->document() || !m_frame->document()->isActive()); | 1062 DCHECK(!m_frame->document() || !m_frame->document()->isActive()); |
| 1042 DCHECK_EQ(m_frame->tree().childCount(), 0u); | 1063 DCHECK_EQ(m_frame->tree().childCount(), 0u); |
| 1043 | 1064 |
| 1044 if (!init.shouldReuseDefaultView()) | 1065 if (!init.shouldReuseDefaultView()) |
| 1045 m_frame->setDOMWindow(LocalDOMWindow::create(*m_frame)); | 1066 m_frame->setDOMWindow(LocalDOMWindow::create(*m_frame)); |
| 1046 | 1067 |
| 1047 Document* document = m_frame->domWindow()->installNewDocument(mimeType, init); | 1068 Document* document = m_frame->domWindow()->installNewDocument(mimeType, init); |
| 1069 | |
| 1070 if (shouldClearWindowName(*m_frame, frameSecurityOrigin, *document)) { | |
|
dcheng
2017/04/04 07:53:21
Can we just check this in LocalDOMWindow::installN
dcheng
2017/04/04 07:57:59
Ah never mind, that doesn't work because we may ha
dcheng
2017/04/04 07:59:39
Actually we can avoid plumbing around frameSecurit
| |
| 1071 // TODO(andypaicu): decide if we can do this without breaking functionality | |
|
Mike West
2017/04/04 12:12:01
Nit: double-space after "decide"
Nit: Capital "D"
| |
| 1072 // after we get user data. experimentalSetNullName will just record the fact | |
| 1073 // that the name would be nulled and if the name is accessed after we will f ire a UseCounter | |
| 1074 // This is what would be here if we decided to move forward with this: | |
| 1075 // m_frame->tree().setName(nullAtom); | |
| 1076 m_frame->tree().experimentalSetNulledName(); | |
| 1077 } | |
| 1078 | |
| 1048 m_frame->page()->chromeClient().installSupplements(*m_frame); | 1079 m_frame->page()->chromeClient().installSupplements(*m_frame); |
| 1049 if (!overridingURL.isEmpty()) | 1080 if (!overridingURL.isEmpty()) |
| 1050 document->setBaseURLOverride(overridingURL); | 1081 document->setBaseURLOverride(overridingURL); |
| 1051 didInstallNewDocument(document); | 1082 didInstallNewDocument(document); |
| 1052 | 1083 |
| 1053 // This must be called before DocumentWriter is created, otherwise HTML parser | 1084 // This must be called before DocumentWriter is created, otherwise HTML parser |
| 1054 // will use stale values from HTMLParserOption. | 1085 // will use stale values from HTMLParserOption. |
| 1055 if (reason == InstallNewDocumentReason::kNavigation) | 1086 if (reason == InstallNewDocumentReason::kNavigation) |
| 1056 didCommitNavigation(); | 1087 didCommitNavigation(); |
| 1057 | 1088 |
| 1058 m_writer = | 1089 m_writer = |
| 1059 DocumentWriter::create(document, parsingPolicy, mimeType, encoding); | 1090 DocumentWriter::create(document, parsingPolicy, mimeType, encoding); |
| 1060 | 1091 |
| 1061 // FeaturePolicy is reset in the browser process on commit, so this needs to | 1092 // FeaturePolicy is reset in the browser process on commit, so this needs to |
| 1062 // be initialized and replicated to the browser process after commit messages | 1093 // be initialized and replicated to the browser process after commit messages |
| 1063 // are sent in didCommitNavigation(). | 1094 // are sent in didCommitNavigation(). |
| 1064 setFeaturePolicy(document, | 1095 setFeaturePolicy(document, |
| 1065 m_response.httpHeaderField(HTTPNames::Feature_Policy)); | 1096 m_response.httpHeaderField(HTTPNames::Feature_Policy)); |
| 1097 | |
| 1066 frameLoader().dispatchDidClearDocumentOfWindowObject(); | 1098 frameLoader().dispatchDidClearDocumentOfWindowObject(); |
| 1067 } | 1099 } |
| 1068 | 1100 |
| 1069 const AtomicString& DocumentLoader::mimeType() const { | 1101 const AtomicString& DocumentLoader::mimeType() const { |
| 1070 if (m_writer) | 1102 if (m_writer) |
| 1071 return m_writer->mimeType(); | 1103 return m_writer->mimeType(); |
| 1072 return m_response.mimeType(); | 1104 return m_response.mimeType(); |
| 1073 } | 1105 } |
| 1074 | 1106 |
| 1075 // This is only called by | 1107 // This is only called by |
| 1076 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL() | 1108 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL() |
| 1077 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL( | 1109 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL( |
| 1078 const DocumentInit& init, | 1110 const DocumentInit& init, |
| 1079 const String& source) { | 1111 const String& source, |
| 1112 SecurityOrigin* frameSecurityOrigin) { | |
| 1080 installNewDocument(init, mimeType(), | 1113 installNewDocument(init, mimeType(), |
| 1081 m_writer ? m_writer->encoding() : emptyAtom, | 1114 m_writer ? m_writer->encoding() : emptyAtom, |
| 1082 InstallNewDocumentReason::kJavascriptURL, | 1115 InstallNewDocumentReason::kJavascriptURL, |
| 1083 ForceSynchronousParsing, KURL()); | 1116 ForceSynchronousParsing, KURL(), frameSecurityOrigin); |
| 1084 if (!source.isNull()) | 1117 if (!source.isNull()) |
| 1085 m_writer->appendReplacingData(source); | 1118 m_writer->appendReplacingData(source); |
| 1086 endWriting(); | 1119 endWriting(); |
| 1087 } | 1120 } |
| 1088 | 1121 |
| 1089 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); | 1122 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); |
| 1090 | 1123 |
| 1091 } // namespace blink | 1124 } // namespace blink |
| OLD | NEW |