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

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

Issue 17640007: Refactoring: Simplify DocumentWriter by reorganizing its lifetime. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Re-landing after fixing ASAN failure on set-parent-src-synchronously.xhtml. Created 7 years, 5 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 | Annotate | Revision Log
« 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 12 matching lines...) Expand all
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "core/loader/DocumentLoader.h" 31 #include "core/loader/DocumentLoader.h"
32 32
33 #include "core/dom/DOMImplementation.h"
33 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
34 #include "core/dom/DocumentParser.h" 35 #include "core/dom/DocumentParser.h"
35 #include "core/dom/Event.h" 36 #include "core/dom/Event.h"
36 #include "core/dom/WebCoreMemoryInstrumentation.h" 37 #include "core/dom/WebCoreMemoryInstrumentation.h"
37 #include "core/html/HTMLFrameOwnerElement.h" 38 #include "core/html/HTMLFrameOwnerElement.h"
38 #include "core/inspector/InspectorInstrumentation.h" 39 #include "core/inspector/InspectorInstrumentation.h"
39 #include "core/loader/DocumentWriter.h" 40 #include "core/loader/DocumentWriter.h"
40 #include "core/loader/FrameLoader.h" 41 #include "core/loader/FrameLoader.h"
41 #include "core/loader/FrameLoaderClient.h" 42 #include "core/loader/FrameLoaderClient.h"
42 #include "core/loader/ResourceLoader.h" 43 #include "core/loader/ResourceLoader.h"
44 #include "core/loader/SinkDocument.h"
43 #include "core/loader/TextResourceDecoder.h" 45 #include "core/loader/TextResourceDecoder.h"
44 #include "core/loader/UniqueIdentifier.h" 46 #include "core/loader/UniqueIdentifier.h"
45 #include "core/loader/appcache/ApplicationCacheHost.h" 47 #include "core/loader/appcache/ApplicationCacheHost.h"
46 #include "core/loader/archive/ArchiveResourceCollection.h" 48 #include "core/loader/archive/ArchiveResourceCollection.h"
47 #include "core/loader/archive/MHTMLArchive.h" 49 #include "core/loader/archive/MHTMLArchive.h"
48 #include "core/loader/cache/CachedResourceLoader.h" 50 #include "core/loader/cache/CachedResourceLoader.h"
49 #include "core/loader/cache/CachedResourceRequestInitiators.h" 51 #include "core/loader/cache/CachedResourceRequestInitiators.h"
50 #include "core/loader/cache/MemoryCache.h" 52 #include "core/loader/cache/MemoryCache.h"
51 #include "core/page/DOMWindow.h" 53 #include "core/page/DOMWindow.h"
52 #include "core/page/Frame.h" 54 #include "core/page/Frame.h"
53 #include "core/page/FrameTree.h" 55 #include "core/page/FrameTree.h"
54 #include "core/page/Page.h" 56 #include "core/page/Page.h"
55 #include "core/page/Settings.h" 57 #include "core/page/Settings.h"
58 #include "core/platform/Logging.h"
56 #include "weborigin/SchemeRegistry.h" 59 #include "weborigin/SchemeRegistry.h"
60 #include "weborigin/SecurityPolicy.h"
57 #include "wtf/Assertions.h" 61 #include "wtf/Assertions.h"
58 #include "wtf/MemoryInstrumentationHashMap.h" 62 #include "wtf/MemoryInstrumentationHashMap.h"
59 #include "wtf/MemoryInstrumentationHashSet.h" 63 #include "wtf/MemoryInstrumentationHashSet.h"
60 #include "wtf/MemoryInstrumentationVector.h" 64 #include "wtf/MemoryInstrumentationVector.h"
61 #include "wtf/text/WTFString.h" 65 #include "wtf/text/WTFString.h"
62 66
63 namespace WebCore { 67 namespace WebCore {
64 68
65 static void cancelAll(const ResourceLoaderSet& loaders) 69 static void cancelAll(const ResourceLoaderSet& loaders)
66 { 70 {
(...skipping 15 matching lines...) Expand all
82 86
83 static bool isArchiveMIMEType(const String& mimeType) 87 static bool isArchiveMIMEType(const String& mimeType)
84 { 88 {
85 return mimeType == "multipart/related"; 89 return mimeType == "multipart/related";
86 } 90 }
87 91
88 DocumentLoader::DocumentLoader(const ResourceRequest& req, const SubstituteData& substituteData) 92 DocumentLoader::DocumentLoader(const ResourceRequest& req, const SubstituteData& substituteData)
89 : m_deferMainResourceDataLoad(true) 93 : m_deferMainResourceDataLoad(true)
90 , m_frame(0) 94 , m_frame(0)
91 , m_cachedResourceLoader(CachedResourceLoader::create(this)) 95 , m_cachedResourceLoader(CachedResourceLoader::create(this))
92 , m_writer(m_frame)
93 , m_originalRequest(req) 96 , m_originalRequest(req)
94 , m_substituteData(substituteData) 97 , m_substituteData(substituteData)
95 , m_originalRequestCopy(req) 98 , m_originalRequestCopy(req)
96 , m_request(req) 99 , m_request(req)
97 , m_committed(false) 100 , m_committed(false)
98 , m_isStopping(false) 101 , m_isStopping(false)
99 , m_gotFirstByte(false)
100 , m_isClientRedirect(false) 102 , m_isClientRedirect(false)
101 , m_wasOnloadHandled(false) 103 , m_wasOnloadHandled(false)
102 , m_loadingMainResource(false) 104 , m_loadingMainResource(false)
103 , m_timeOfLastDataReceived(0.0) 105 , m_timeOfLastDataReceived(0.0)
104 , m_identifierForLoadWithoutResourceLoader(0) 106 , m_identifierForLoadWithoutResourceLoader(0)
105 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow) 107 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow)
106 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this))) 108 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this)))
107 { 109 {
108 } 110 }
109 111
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 stopLoadingSubresources(); 285 stopLoadingSubresources();
284 286
285 m_isStopping = false; 287 m_isStopping = false;
286 } 288 }
287 289
288 void DocumentLoader::commitIfReady() 290 void DocumentLoader::commitIfReady()
289 { 291 {
290 if (!m_committed) { 292 if (!m_committed) {
291 m_committed = true; 293 m_committed = true;
292 frameLoader()->commitProvisionalLoad(); 294 frameLoader()->commitProvisionalLoad();
293 m_writer.setMIMEType(m_response.mimeType());
294 } 295 }
295 } 296 }
296 297
297 bool DocumentLoader::isLoading() const 298 bool DocumentLoader::isLoading() const
298 { 299 {
299 if (document() && document()->hasActiveParser()) 300 if (document() && document()->hasActiveParser())
300 return true; 301 return true;
301 302
302 return isLoadingMainResource() || !m_resourceLoaders.isEmpty(); 303 return isLoadingMainResource() || !m_resourceLoaders.isEmpty();
303 } 304 }
(...skipping 25 matching lines...) Expand all
329 if (!responseEndTime) 330 if (!responseEndTime)
330 responseEndTime = m_timeOfLastDataReceived; 331 responseEndTime = m_timeOfLastDataReceived;
331 if (!responseEndTime) 332 if (!responseEndTime)
332 responseEndTime = monotonicallyIncreasingTime(); 333 responseEndTime = monotonicallyIncreasingTime();
333 timing()->setResponseEnd(responseEndTime); 334 timing()->setResponseEnd(responseEndTime);
334 335
335 commitIfReady(); 336 commitIfReady();
336 if (!frameLoader()) 337 if (!frameLoader())
337 return; 338 return;
338 339
339 if (!maybeCreateArchive()) { 340 if (isArchiveMIMEType(m_response.mimeType())) {
341 createArchive();
342 } else {
340 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that 343 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that
341 // DocumentWriter::begin() gets called and creates the Document. 344 // DocumentWriter::begin() gets called and creates the Document.
342 if (!m_gotFirstByte) 345 if (!m_writer)
343 commitData(0, 0); 346 commitData(0, 0);
344 } 347 }
345 348
346 m_writer.end(); 349 endWriting(m_writer.get());
350
347 if (!m_mainDocumentError.isNull()) 351 if (!m_mainDocumentError.isNull())
348 return; 352 return;
349 clearMainResourceLoader(); 353 clearMainResourceLoader();
350 if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument()) 354 if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument())
351 frameLoader()->checkLoadComplete(); 355 frameLoader()->checkLoadComplete();
352 356
353 // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache 357 // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache
354 // and deny the appcache the chance to intercept it in the future, so remove from the memory cache. 358 // and deny the appcache the chance to intercept it in the future, so remove from the memory cache.
355 if (m_frame) { 359 if (m_frame) {
356 if (m_mainResource && m_frame->document()->hasManifest()) 360 if (m_mainResource && m_frame->document()->hasManifest())
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 return frameLoader()->client()->interruptedForPolicyChangeError(request()); 601 return frameLoader()->client()->interruptedForPolicyChangeError(request());
598 } 602 }
599 603
600 void DocumentLoader::stopLoadingForPolicyChange() 604 void DocumentLoader::stopLoadingForPolicyChange()
601 { 605 {
602 ResourceError error = interruptedForPolicyChangeError(); 606 ResourceError error = interruptedForPolicyChangeError();
603 error.setIsCancellation(true); 607 error.setIsCancellation(true);
604 cancelMainResourceLoad(error); 608 cancelMainResourceLoad(error);
605 } 609 }
606 610
611 void DocumentLoader::ensureWriter()
612 {
613 ensureWriter(m_response.mimeType());
614 }
615
616 void DocumentLoader::ensureWriter(const String& mimeType, const KURL& overriding URL)
617 {
618 if (m_writer)
619 return;
620
621 String encoding = overrideEncoding().isNull() ? response().textEncodingName( ).impl() : overrideEncoding();
622 bool userChosen = !overrideEncoding().isNull();
623 m_writer = createWriterFor(m_frame, 0, documentURL(), mimeType, encoding, fa lse, false);
624 m_writer->setDocumentWasLoadedAsPartOfNavigation();
625
626 if (frameLoader()->stateMachine()->creatingInitialEmptyDocument())
627 return;
628
629 // This should be set before receivedFirstData().
630 if (!overridingURL.isEmpty())
631 m_frame->document()->setBaseURLOverride(overridingURL);
632
633 // Call receivedFirstData() exactly once per load.
634 frameLoader()->receivedFirstData();
635 }
636
607 void DocumentLoader::commitData(const char* bytes, size_t length) 637 void DocumentLoader::commitData(const char* bytes, size_t length)
608 { 638 {
609 if (!m_gotFirstByte) { 639 ensureWriter();
610 m_gotFirstByte = true;
611 m_writer.begin(documentURL(), false);
612 m_writer.setDocumentWasLoadedAsPartOfNavigation();
613
614 if (frameLoader()->stateMachine()->creatingInitialEmptyDocument())
615 return;
616
617 // The origin is the MHTML file, we need to set the base URL to the docu ment encoded in the MHTML so
618 // relative URLs are resolved properly.
619 if (m_archive)
620 m_frame->document()->setBaseURLOverride(m_archive->mainResource()->u rl());
621
622 // Call receivedFirstData() exactly once per load.
623 frameLoader()->receivedFirstData();
624
625 bool userChosen = true;
626 String encoding = overrideEncoding();
627 if (encoding.isNull()) {
628 userChosen = false;
629 encoding = response().textEncodingName();
630 }
631 m_writer.setEncoding(encoding, userChosen);
632 }
633 ASSERT(m_frame->document()->parsing()); 640 ASSERT(m_frame->document()->parsing());
634 m_writer.addData(bytes, length); 641 m_writer->addData(bytes, length);
635 } 642 }
636 643
637 void DocumentLoader::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 644 void DocumentLoader::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
638 { 645 {
639 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Loader); 646 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Loader);
640 info.addMember(m_frame, "frame"); 647 info.addMember(m_frame, "frame");
641 info.addMember(m_cachedResourceLoader, "cachedResourceLoader"); 648 info.addMember(m_cachedResourceLoader, "cachedResourceLoader");
642 info.addMember(m_mainResource, "mainResource"); 649 info.addMember(m_mainResource, "mainResource");
643 info.addMember(m_resourceLoaders, "resourceLoaders"); 650 info.addMember(m_resourceLoaders, "resourceLoaders");
644 info.addMember(m_multipartResourceLoaders, "multipartResourceLoaders"); 651 info.addMember(m_multipartResourceLoaders, "multipartResourceLoaders");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // See https://bugs.webkit.org/show_bug.cgi?id=110937 702 // See https://bugs.webkit.org/show_bug.cgi?id=110937
696 // ASSERT(this == frameLoader()->activeDocumentLoader()) 703 // ASSERT(this == frameLoader()->activeDocumentLoader())
697 m_frame->document()->domWindow()->finishedLoading(); 704 m_frame->document()->domWindow()->finishedLoading();
698 } 705 }
699 706
700 void DocumentLoader::setFrame(Frame* frame) 707 void DocumentLoader::setFrame(Frame* frame)
701 { 708 {
702 if (m_frame == frame) 709 if (m_frame == frame)
703 return; 710 return;
704 ASSERT(frame && !m_frame); 711 ASSERT(frame && !m_frame);
712 ASSERT(!m_writer);
705 m_frame = frame; 713 m_frame = frame;
706 m_writer.setFrame(frame);
707 } 714 }
708 715
709 void DocumentLoader::detachFromFrame() 716 void DocumentLoader::detachFromFrame()
710 { 717 {
711 ASSERT(m_frame); 718 ASSERT(m_frame);
712 RefPtr<Frame> protectFrame(m_frame); 719 RefPtr<Frame> protectFrame(m_frame);
713 RefPtr<DocumentLoader> protectLoader(this); 720 RefPtr<DocumentLoader> protectLoader(this);
714 721
715 // It never makes sense to have a document loader that is detached from its 722 // It never makes sense to have a document loader that is detached from its
716 // frame have any loads active, so go ahead and kill all the loads. 723 // frame have any loads active, so go ahead and kill all the loads.
(...skipping 30 matching lines...) Expand all
747 if (m_cachedResourceLoader->requestCount()) 754 if (m_cachedResourceLoader->requestCount())
748 return true; 755 return true;
749 if (doc->processingLoadEvent()) 756 if (doc->processingLoadEvent())
750 return true; 757 return true;
751 if (doc->hasActiveParser()) 758 if (doc->hasActiveParser())
752 return true; 759 return true;
753 } 760 }
754 return frameLoader()->subframeIsLoading(); 761 return frameLoader()->subframeIsLoading();
755 } 762 }
756 763
757 bool DocumentLoader::maybeCreateArchive() 764 void DocumentLoader::createArchive()
758 { 765 {
759 // Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0.
760 if (!isArchiveMIMEType(m_response.mimeType()))
761 return false;
762
763 m_archive = MHTMLArchive::create(m_response.url(), mainResourceData().get()) ; 766 m_archive = MHTMLArchive::create(m_response.url(), mainResourceData().get()) ;
764 ASSERT(m_archive); 767 ASSERT(m_archive);
765 768
766 addAllArchiveResources(m_archive.get()); 769 addAllArchiveResources(m_archive.get());
767 ArchiveResource* mainResource = m_archive->mainResource(); 770 ArchiveResource* mainResource = m_archive->mainResource();
768 m_writer.setMIMEType(mainResource->mimeType()); 771
769 772 // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
770 ASSERT(m_frame->document()); 773 // relative URLs are resolved properly.
774 ensureWriter(mainResource->mimeType(), m_archive->mainResource()->url());
775
771 commitData(mainResource->data()->data(), mainResource->data()->size()); 776 commitData(mainResource->data()->data(), mainResource->data()->size());
772 return true;
773 } 777 }
774 778
775 void DocumentLoader::addAllArchiveResources(MHTMLArchive* archive) 779 void DocumentLoader::addAllArchiveResources(MHTMLArchive* archive)
776 { 780 {
777 ASSERT(archive); 781 ASSERT(archive);
778 if (!m_archiveResourceCollection) 782 if (!m_archiveResourceCollection)
779 m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection); 783 m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection);
780 m_archiveResourceCollection->addAllResources(archive); 784 m_archiveResourceCollection->addAllResources(archive);
781 } 785 }
782 786
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 void DocumentLoader::stopLoadingSubresources() 889 void DocumentLoader::stopLoadingSubresources()
886 { 890 {
887 cancelAll(m_resourceLoaders); 891 cancelAll(m_resourceLoaders);
888 } 892 }
889 893
890 void DocumentLoader::addResourceLoader(ResourceLoader* loader) 894 void DocumentLoader::addResourceLoader(ResourceLoader* loader)
891 { 895 {
892 // The main resource's underlying ResourceLoader will ask to be added here. 896 // The main resource's underlying ResourceLoader will ask to be added here.
893 // It is much simpler to handle special casing of main resource loads if we don't 897 // It is much simpler to handle special casing of main resource loads if we don't
894 // let it be added. In the main resource load case, mainResourceLoader() 898 // let it be added. In the main resource load case, mainResourceLoader()
895 // will still be null at this point, but m_gotFirstByte should be false here if and only 899 // will still be null at this point, but document() should be zero here if a nd only
896 // if we are just starting the main resource load. 900 // if we are just starting the main resource load.
897 if (!m_gotFirstByte) 901 if (!document())
898 return; 902 return;
899 ASSERT(!m_resourceLoaders.contains(loader)); 903 ASSERT(!m_resourceLoaders.contains(loader));
900 ASSERT(!mainResourceLoader() || mainResourceLoader() != loader); 904 ASSERT(!mainResourceLoader() || mainResourceLoader() != loader);
901 m_resourceLoaders.add(loader); 905 m_resourceLoaders.add(loader);
902 } 906 }
903 907
904 void DocumentLoader::removeResourceLoader(ResourceLoader* loader) 908 void DocumentLoader::removeResourceLoader(ResourceLoader* loader)
905 { 909 {
906 if (!m_resourceLoaders.contains(loader)) 910 if (!m_resourceLoaders.contains(loader))
907 return; 911 return;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 } 1007 }
1004 1008
1005 void DocumentLoader::handledOnloadEvents() 1009 void DocumentLoader::handledOnloadEvents()
1006 { 1010 {
1007 m_wasOnloadHandled = true; 1011 m_wasOnloadHandled = true;
1008 applicationCacheHost()->stopDeferringEvents(); 1012 applicationCacheHost()->stopDeferringEvents();
1009 } 1013 }
1010 1014
1011 DocumentWriter* DocumentLoader::beginWriting(const String& mimeType, const Strin g& encoding, const KURL& url) 1015 DocumentWriter* DocumentLoader::beginWriting(const String& mimeType, const Strin g& encoding, const KURL& url)
1012 { 1016 {
1013 m_writer.setMIMEType(mimeType); 1017 m_writer = createWriterFor(m_frame, 0, url, mimeType, encoding, false, true) ;
1014 m_writer.setEncoding(encoding, false); 1018 return m_writer.get();
1015 m_writer.begin(url); 1019 }
1016 return &m_writer; 1020
1021 void DocumentLoader::endWriting(DocumentWriter* writer)
1022 {
1023 ASSERT_UNUSED(writer, m_writer == writer);
1024 m_writer->end();
1025 m_writer.clear();
1026 }
1027
1028
1029 PassRefPtr<DocumentWriter> DocumentLoader::createWriterFor(Frame* frame, const D ocument* ownerDocument, const KURL& url, const String& mimeType, const String& e ncoding, bool userChosen, bool dispatch)
1030 {
1031 // Create a new document before clearing the frame, because it may need to
1032 // inherit an aliased security context.
1033 RefPtr<Document> document = DOMImplementation::createDocument(mimeType, fram e, url, frame->inViewSourceMode());
1034 if (document->isPluginDocument() && document->isSandboxed(SandboxPlugins))
1035 document = SinkDocument::create(frame, url);
1036 bool shouldReuseDefaultView = frame->loader()->stateMachine()->isDisplayingI nitialEmptyDocument() && frame->document()->isSecureTransitionTo(url);
1037
1038 RefPtr<DOMWindow> originalDOMWindow;
1039 if (shouldReuseDefaultView)
1040 originalDOMWindow = frame->domWindow();
1041 frame->loader()->clear(!shouldReuseDefaultView, !shouldReuseDefaultView);
1042
1043 if (!shouldReuseDefaultView) {
1044 frame->setDOMWindow(DOMWindow::create(frame));
1045 } else {
1046 // Note that the old Document is still attached to the DOMWindow; the
1047 // setDocument() call below will detach the old Document.
1048 ASSERT(originalDOMWindow);
1049 frame->setDOMWindow(originalDOMWindow);
1050 }
1051
1052 frame->loader()->setOutgoingReferrer(url);
1053 frame->domWindow()->setDocument(document);
1054
1055 if (ownerDocument) {
1056 document->setCookieURL(ownerDocument->cookieURL());
1057 document->setSecurityOrigin(ownerDocument->securityOrigin());
1058 }
1059
1060 frame->loader()->didBeginDocument(dispatch);
1061
1062 return DocumentWriter::create(document.get(), mimeType, encoding, userChosen );
1017 } 1063 }
1018 1064
1019 String DocumentLoader::mimeType() const 1065 String DocumentLoader::mimeType() const
1020 { 1066 {
1021 return m_writer.mimeType(); 1067 if (m_writer)
1068 return m_writer->mimeType();
1069 return m_response.mimeType();
1022 } 1070 }
1023 1071
1072 // This is only called by ScriptController::executeScriptIfJavaScriptURL
1073 // and always contains the result of evaluating a javascript: url.
1074 // This is the <iframe src="javascript:'html'"> case.
1024 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) 1075 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt)
1025 { 1076 {
1026 m_writer.replaceDocument(source, ownerDocument); 1077 m_frame->loader()->stopAllLoaders();
1078 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), mimeType(), m_writer ? m_writer->encoding() : "", m_writer ? m_writer->encod ingWasChosenByUser() : false, true);
1079 if (!source.isNull())
1080 m_writer->appendReplacingData(source);
1081 endWriting(m_writer.get());
1027 } 1082 }
1028 1083
1029 } // namespace WebCore 1084 } // namespace WebCore
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