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

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

Issue 2795673002: Added UseCounter for clearing browsing context name on cross-origin name (Closed)
Patch Set: Rebase-update Created 3 years, 8 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) 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
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
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 inline bool shouldClearWindowName(
jochen (gone - plz use gerrit) 2017/04/03 15:24:26 nit. don't add inline
andypaicu 2017/04/04 07:23:39 Done. Also moved function into the DocumentLoader
1038 const LocalFrame& frame,
1039 SecurityOrigin* frameSecurityOrigin,
1040 const Document& newDocument)
1041 {
1042 if (!frameSecurityOrigin)
1043 return false;
1044 if (!frame.isMainFrame())
1045 return false;
1046 if (frame.loader().opener())
1047 return false;
1048
1049 return !newDocument.getSecurityOrigin()->isSameSchemeHostPort(frameSecurityOri gin);
1050 }
1051
1033 void DocumentLoader::installNewDocument( 1052 void DocumentLoader::installNewDocument(
1034 const DocumentInit& init, 1053 const DocumentInit& init,
1035 const AtomicString& mimeType, 1054 const AtomicString& mimeType,
1036 const AtomicString& encoding, 1055 const AtomicString& encoding,
1037 InstallNewDocumentReason reason, 1056 InstallNewDocumentReason reason,
1038 ParserSynchronizationPolicy parsingPolicy, 1057 ParserSynchronizationPolicy parsingPolicy,
1039 const KURL& overridingURL) { 1058 const KURL& overridingURL,
1059 SecurityOrigin* frameSecurityOrigin) {
1040 DCHECK_EQ(init.frame(), m_frame); 1060 DCHECK_EQ(init.frame(), m_frame);
1041 DCHECK(!m_frame->document() || !m_frame->document()->isActive()); 1061 DCHECK(!m_frame->document() || !m_frame->document()->isActive());
1042 DCHECK_EQ(m_frame->tree().childCount(), 0u); 1062 DCHECK_EQ(m_frame->tree().childCount(), 0u);
1043 1063
1044 if (!init.shouldReuseDefaultView()) 1064 if (!init.shouldReuseDefaultView())
1045 m_frame->setDOMWindow(LocalDOMWindow::create(*m_frame)); 1065 m_frame->setDOMWindow(LocalDOMWindow::create(*m_frame));
1046 1066
1047 Document* document = m_frame->domWindow()->installNewDocument(mimeType, init); 1067 Document* document = m_frame->domWindow()->installNewDocument(mimeType, init);
1068
1069 if (shouldClearWindowName(*m_frame, frameSecurityOrigin, *document)) {
1070 // TODO(andypaicu): decide if we can do this without breaking functionality
1071 // after we get user data. experimentalSetNullName will just record the fact
1072 // that the name would be nulled and if the name is accessed after we will f ire a UseCounter
1073 // This is what would be here if we decided to move forward with this:
1074 // m_frame->tree().setName(nullAtom);
1075 m_frame->tree().experimentalSetNulledName();
1076 }
1077
1048 m_frame->page()->chromeClient().installSupplements(*m_frame); 1078 m_frame->page()->chromeClient().installSupplements(*m_frame);
1049 if (!overridingURL.isEmpty()) 1079 if (!overridingURL.isEmpty())
1050 document->setBaseURLOverride(overridingURL); 1080 document->setBaseURLOverride(overridingURL);
1051 didInstallNewDocument(document); 1081 didInstallNewDocument(document);
1052 1082
1053 // This must be called before DocumentWriter is created, otherwise HTML parser 1083 // This must be called before DocumentWriter is created, otherwise HTML parser
1054 // will use stale values from HTMLParserOption. 1084 // will use stale values from HTMLParserOption.
1055 if (reason == InstallNewDocumentReason::kNavigation) 1085 if (reason == InstallNewDocumentReason::kNavigation)
1056 didCommitNavigation(); 1086 didCommitNavigation();
1057 1087
1058 m_writer = 1088 m_writer =
1059 DocumentWriter::create(document, parsingPolicy, mimeType, encoding); 1089 DocumentWriter::create(document, parsingPolicy, mimeType, encoding);
1060 1090
1061 // FeaturePolicy is reset in the browser process on commit, so this needs to 1091 // 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 1092 // be initialized and replicated to the browser process after commit messages
1063 // are sent in didCommitNavigation(). 1093 // are sent in didCommitNavigation().
1064 setFeaturePolicy(document, 1094 setFeaturePolicy(document,
1065 m_response.httpHeaderField(HTTPNames::Feature_Policy)); 1095 m_response.httpHeaderField(HTTPNames::Feature_Policy));
1096
1066 frameLoader().dispatchDidClearDocumentOfWindowObject(); 1097 frameLoader().dispatchDidClearDocumentOfWindowObject();
1067 } 1098 }
1068 1099
1069 const AtomicString& DocumentLoader::mimeType() const { 1100 const AtomicString& DocumentLoader::mimeType() const {
1070 if (m_writer) 1101 if (m_writer)
1071 return m_writer->mimeType(); 1102 return m_writer->mimeType();
1072 return m_response.mimeType(); 1103 return m_response.mimeType();
1073 } 1104 }
1074 1105
1075 // This is only called by 1106 // This is only called by
1076 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL() 1107 // FrameLoader::replaceDocumentWhileExecutingJavaScriptURL()
1077 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL( 1108 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(
1078 const DocumentInit& init, 1109 const DocumentInit& init,
1079 const String& source) { 1110 const String& source,
1111 SecurityOrigin* frameSecurityOrigin) {
1080 installNewDocument(init, mimeType(), 1112 installNewDocument(init, mimeType(),
1081 m_writer ? m_writer->encoding() : emptyAtom, 1113 m_writer ? m_writer->encoding() : emptyAtom,
1082 InstallNewDocumentReason::kJavascriptURL, 1114 InstallNewDocumentReason::kJavascriptURL,
1083 ForceSynchronousParsing, KURL()); 1115 ForceSynchronousParsing, KURL(), frameSecurityOrigin);
1084 if (!source.isNull()) 1116 if (!source.isNull())
1085 m_writer->appendReplacingData(source); 1117 m_writer->appendReplacingData(source);
1086 endWriting(); 1118 endWriting();
1087 } 1119 }
1088 1120
1089 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 1121 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
1090 1122
1091 } // namespace blink 1123 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/DocumentLoader.h ('k') | third_party/WebKit/Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698