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

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

Issue 495743003: Add an extra guard to replaceDocument() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Landing Created 6 years, 3 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
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | Source/core/loader/DocumentWriter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 496 }
497 } 497 }
498 } 498 }
499 499
500 void DocumentLoader::ensureWriter(const AtomicString& mimeType, const KURL& over ridingURL) 500 void DocumentLoader::ensureWriter(const AtomicString& mimeType, const KURL& over ridingURL)
501 { 501 {
502 if (m_writer) 502 if (m_writer)
503 return; 503 return;
504 504
505 const AtomicString& encoding = overrideEncoding().isNull() ? response().text EncodingName() : overrideEncoding(); 505 const AtomicString& encoding = overrideEncoding().isNull() ? response().text EncodingName() : overrideEncoding();
506 m_writer = createWriterFor(m_frame, 0, url(), mimeType, encoding, false); 506
507 // Prepare a DocumentInit before clearing the frame, because it may need to
508 // inherit an aliased security context.
509 DocumentInit init(url(), m_frame);
510 init.withNewRegistrationContext();
511 m_frame->loader().clear();
512 ASSERT(m_frame->page());
513
514 m_writer = createWriterFor(0, init, mimeType, encoding, false);
507 m_writer->setDocumentWasLoadedAsPartOfNavigation(); 515 m_writer->setDocumentWasLoadedAsPartOfNavigation();
508 // This should be set before receivedFirstData(). 516 // This should be set before receivedFirstData().
509 if (!overridingURL.isEmpty()) 517 if (!overridingURL.isEmpty())
510 m_frame->document()->setBaseURLOverride(overridingURL); 518 m_frame->document()->setBaseURLOverride(overridingURL);
511 519
512 // Call receivedFirstData() exactly once per load. 520 // Call receivedFirstData() exactly once per load.
513 frameLoader()->receivedFirstData(); 521 frameLoader()->receivedFirstData();
514 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField("Refr esh"), Document::HttpRefreshFromHeader); 522 m_frame->document()->maybeHandleHttpRefresh(m_response.httpHeaderField("Refr esh"), Document::HttpRefreshFromHeader);
515 } 523 }
516 524
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 mainResourceLoader()->attachThreadedDataReceiver(threadedDataReceiver); 777 mainResourceLoader()->attachThreadedDataReceiver(threadedDataReceiver);
770 } 778 }
771 779
772 void DocumentLoader::endWriting(DocumentWriter* writer) 780 void DocumentLoader::endWriting(DocumentWriter* writer)
773 { 781 {
774 ASSERT_UNUSED(writer, m_writer == writer); 782 ASSERT_UNUSED(writer, m_writer == writer);
775 m_writer->end(); 783 m_writer->end();
776 m_writer.clear(); 784 m_writer.clear();
777 } 785 }
778 786
779 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(LocalFram e* frame, const Document* ownerDocument, const KURL& url, const AtomicString& mi meType, const AtomicString& encoding, bool dispatch) 787 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(const Doc ument* ownerDocument, const DocumentInit& init, const AtomicString& mimeType, co nst AtomicString& encoding, bool dispatch)
780 { 788 {
781 // Create a new document before clearing the frame, because it may need to 789 LocalFrame* frame = init.frame();
782 // inherit an aliased security context.
783 DocumentInit init(url, frame);
784 init.withNewRegistrationContext();
785
786 // In some rare cases, we'll re-used a LocalDOMWindow for a new Document. Fo r example,
787 // when a script calls window.open("..."), the browser gives JavaScript a wi ndow
788 // synchronously but kicks off the load in the window asynchronously. Web si tes
789 // expect that modifications that they make to the window object synchronous ly
790 // won't be blown away when the network load commits. To make that happen, w e
791 // "securely transition" the existing LocalDOMWindow to the Document that re sults from
792 // the network load. See also SecurityContext::isSecureTransitionTo.
793 bool shouldReuseDefaultView = frame->loader().stateMachine()->isDisplayingIn itialEmptyDocument() && frame->document()->isSecureTransitionTo(url);
794
795 frame->loader().clear();
796 790
797 if (frame->document()) 791 if (frame->document())
798 frame->document()->prepareForDestruction(); 792 frame->document()->prepareForDestruction();
799 793
800 if (!shouldReuseDefaultView) 794 if (!init.shouldReuseDefaultView())
801 frame->setDOMWindow(LocalDOMWindow::create(*frame)); 795 frame->setDOMWindow(LocalDOMWindow::create(*frame));
802 796
803 RefPtrWillBeRawPtr<Document> document = frame->domWindow()->installNewDocume nt(mimeType, init); 797 RefPtrWillBeRawPtr<Document> document = frame->domWindow()->installNewDocume nt(mimeType, init);
804 if (ownerDocument) { 798 if (ownerDocument) {
805 document->setCookieURL(ownerDocument->cookieURL()); 799 document->setCookieURL(ownerDocument->cookieURL());
806 document->setSecurityOrigin(ownerDocument->securityOrigin()); 800 document->setSecurityOrigin(ownerDocument->securityOrigin());
807 if (ownerDocument->isTransitionDocument()) 801 if (ownerDocument->isTransitionDocument())
808 document->setIsTransitionDocument(); 802 document->setIsTransitionDocument();
809 } 803 }
810 804
811 frame->loader().didBeginDocument(dispatch); 805 frame->loader().didBeginDocument(dispatch);
812 806
813 return DocumentWriter::create(document.get(), mimeType, encoding); 807 return DocumentWriter::create(document.get(), mimeType, encoding);
814 } 808 }
815 809
816 const AtomicString& DocumentLoader::mimeType() const 810 const AtomicString& DocumentLoader::mimeType() const
817 { 811 {
818 if (m_writer) 812 if (m_writer)
819 return m_writer->mimeType(); 813 return m_writer->mimeType();
820 return m_response.mimeType(); 814 return m_response.mimeType();
821 } 815 }
822 816
823 void DocumentLoader::setUserChosenEncoding(const String& charset) 817 void DocumentLoader::setUserChosenEncoding(const String& charset)
824 { 818 {
825 if (m_writer) 819 if (m_writer)
826 m_writer->setUserChosenEncoding(charset); 820 m_writer->setUserChosenEncoding(charset);
827 } 821 }
828 822
829 // This is only called by ScriptController::executeScriptIfJavaScriptURL 823 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L()
830 // and always contains the result of evaluating a javascript: url. 824 void DocumentLoader::replaceDocumentWhileExecutingJavaScriptURL(const DocumentIn it& init, const String& source, Document* ownerDocument)
831 // This is the <iframe src="javascript:'html'"> case.
832 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt)
833 { 825 {
834 m_frame->loader().stopAllLoaders(); 826 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true);
835 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : emptyAtom, true);
836 if (!source.isNull()) 827 if (!source.isNull())
837 m_writer->appendReplacingData(source); 828 m_writer->appendReplacingData(source);
838 endWriting(m_writer.get()); 829 endWriting(m_writer.get());
839 } 830 }
840 831
841 } // namespace blink 832 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.h ('k') | Source/core/loader/DocumentWriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698