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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 mainResourceLoader()->attachThreadedDataReceiver(threadedDataReceiver); | 769 mainResourceLoader()->attachThreadedDataReceiver(threadedDataReceiver); |
770 } | 770 } |
771 | 771 |
772 void DocumentLoader::endWriting(DocumentWriter* writer) | 772 void DocumentLoader::endWriting(DocumentWriter* writer) |
773 { | 773 { |
774 ASSERT_UNUSED(writer, m_writer == writer); | 774 ASSERT_UNUSED(writer, m_writer == writer); |
775 m_writer->end(); | 775 m_writer->end(); |
776 m_writer.clear(); | 776 m_writer.clear(); |
777 } | 777 } |
778 | 778 |
779 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(LocalFram e* frame, const Document* ownerDocument, const KURL& url, const AtomicString& mi meType, const AtomicString& encoding, bool dispatch) | 779 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(LocalFram e* frame, const Document* ownerDocument, const KURL& url, const AtomicString& mi meType, const AtomicString& encoding, bool dispatch) |
dglazkov
2014/08/26 17:22:43
Just thinking outloud: since now there are two cre
| |
780 { | 780 { |
781 // Create a new document before clearing the frame, because it may need to | 781 // Prepare a DocumentInit before clearing the frame, because it may need to |
782 // inherit an aliased security context. | 782 // inherit an aliased security context. |
783 DocumentInit init(url, frame); | 783 DocumentInit init(url, frame); |
784 init.withNewRegistrationContext(); | 784 init.withNewRegistrationContext(); |
785 frame->loader().clear(); | |
786 ASSERT(frame->page()); | |
787 return createWriterFor(ownerDocument, init, mimeType, encoding, dispatch); | |
788 } | |
785 | 789 |
786 // In some rare cases, we'll re-used a LocalDOMWindow for a new Document. Fo r example, | 790 PassRefPtrWillBeRawPtr<DocumentWriter> DocumentLoader::createWriterFor(const Doc ument* ownerDocument, const DocumentInit& init, const AtomicString& mimeType, co nst AtomicString& encoding, bool dispatch) |
787 // when a script calls window.open("..."), the browser gives JavaScript a wi ndow | 791 { |
788 // synchronously but kicks off the load in the window asynchronously. Web si tes | 792 LocalFrame* frame = init.frame(); |
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 | 793 |
797 if (frame->document()) | 794 if (frame->document()) |
798 frame->document()->prepareForDestruction(); | 795 frame->document()->prepareForDestruction(); |
799 | 796 |
800 if (!shouldReuseDefaultView) | 797 if (!init.shouldReuseDefaultView()) |
801 frame->setDOMWindow(LocalDOMWindow::create(*frame)); | 798 frame->setDOMWindow(LocalDOMWindow::create(*frame)); |
802 | 799 |
803 RefPtrWillBeRawPtr<Document> document = frame->domWindow()->installNewDocume nt(mimeType, init); | 800 RefPtrWillBeRawPtr<Document> document = frame->domWindow()->installNewDocume nt(mimeType, init); |
804 if (ownerDocument) { | 801 if (ownerDocument) { |
805 document->setCookieURL(ownerDocument->cookieURL()); | 802 document->setCookieURL(ownerDocument->cookieURL()); |
806 document->setSecurityOrigin(ownerDocument->securityOrigin()); | 803 document->setSecurityOrigin(ownerDocument->securityOrigin()); |
807 if (ownerDocument->isTransitionDocument()) | 804 if (ownerDocument->isTransitionDocument()) |
808 document->setIsTransitionDocument(); | 805 document->setIsTransitionDocument(); |
809 } | 806 } |
810 | 807 |
811 frame->loader().didBeginDocument(dispatch); | 808 frame->loader().didBeginDocument(dispatch); |
812 | 809 |
813 return DocumentWriter::create(document.get(), mimeType, encoding); | 810 return DocumentWriter::create(document.get(), mimeType, encoding); |
814 } | 811 } |
815 | 812 |
816 const AtomicString& DocumentLoader::mimeType() const | 813 const AtomicString& DocumentLoader::mimeType() const |
817 { | 814 { |
818 if (m_writer) | 815 if (m_writer) |
819 return m_writer->mimeType(); | 816 return m_writer->mimeType(); |
820 return m_response.mimeType(); | 817 return m_response.mimeType(); |
821 } | 818 } |
822 | 819 |
823 void DocumentLoader::setUserChosenEncoding(const String& charset) | 820 void DocumentLoader::setUserChosenEncoding(const String& charset) |
824 { | 821 { |
825 if (m_writer) | 822 if (m_writer) |
826 m_writer->setUserChosenEncoding(charset); | 823 m_writer->setUserChosenEncoding(charset); |
827 } | 824 } |
828 | 825 |
829 // This is only called by ScriptController::executeScriptIfJavaScriptURL | 826 // This is only called by FrameLoader::replaceDocumentWhileExecutingJavaScriptUR L() |
830 // and always contains the result of evaluating a javascript: url. | 827 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 { | 828 { |
834 m_frame->loader().stopAllLoaders(); | 829 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()) | 830 if (!source.isNull()) |
837 m_writer->appendReplacingData(source); | 831 m_writer->appendReplacingData(source); |
838 endWriting(m_writer.get()); | 832 endWriting(m_writer.get()); |
839 } | 833 } |
840 | 834 |
841 } // namespace blink | 835 } // namespace blink |
OLD | NEW |