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 12 matching lines...) Expand all Loading... | |
| 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 <wtf/Assertions.h> | 33 #include "core/dom/DOMImplementation.h" |
| 34 #include <wtf/MemoryInstrumentationHashMap.h> | |
| 35 #include <wtf/MemoryInstrumentationHashSet.h> | |
| 36 #include <wtf/MemoryInstrumentationVector.h> | |
| 37 #include <wtf/text/CString.h> | |
| 38 #include <wtf/text/WTFString.h> | |
| 39 #include <wtf/unicode/Unicode.h> | |
| 40 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 41 #include "core/dom/DocumentParser.h" | 35 #include "core/dom/DocumentParser.h" |
| 42 #include "core/dom/Event.h" | 36 #include "core/dom/Event.h" |
| 43 #include "core/dom/WebCoreMemoryInstrumentation.h" | 37 #include "core/dom/WebCoreMemoryInstrumentation.h" |
| 44 #include "core/history/HistoryItem.h" | 38 #include "core/history/HistoryItem.h" |
| 45 #include "core/html/HTMLFormElement.h" | 39 #include "core/html/HTMLFormElement.h" |
| 46 #include "core/html/HTMLFrameOwnerElement.h" | 40 #include "core/html/HTMLFrameOwnerElement.h" |
| 47 #include "core/inspector/InspectorInstrumentation.h" | 41 #include "core/inspector/InspectorInstrumentation.h" |
| 48 #include "core/loader/DocumentWriter.h" | 42 #include "core/loader/DocumentWriter.h" |
| 49 #include "core/loader/FormState.h" | 43 #include "core/loader/FormState.h" |
| 50 #include "core/loader/FrameLoader.h" | 44 #include "core/loader/FrameLoader.h" |
| 51 #include "core/loader/FrameLoaderClient.h" | 45 #include "core/loader/FrameLoaderClient.h" |
| 52 #include "core/loader/ResourceLoader.h" | 46 #include "core/loader/ResourceLoader.h" |
| 47 #include "core/loader/SinkDocument.h" | |
| 53 #include "core/loader/TextResourceDecoder.h" | 48 #include "core/loader/TextResourceDecoder.h" |
| 54 #include "core/loader/UniqueIdentifier.h" | 49 #include "core/loader/UniqueIdentifier.h" |
| 55 #include "core/loader/appcache/ApplicationCacheHost.h" | 50 #include "core/loader/appcache/ApplicationCacheHost.h" |
| 56 #include "core/loader/archive/ArchiveResourceCollection.h" | 51 #include "core/loader/archive/ArchiveResourceCollection.h" |
| 57 #include "core/loader/archive/MHTMLArchive.h" | 52 #include "core/loader/archive/MHTMLArchive.h" |
| 58 #include "core/loader/cache/CachedResourceLoader.h" | 53 #include "core/loader/cache/CachedResourceLoader.h" |
| 59 #include "core/loader/cache/CachedResourceRequestInitiators.h" | 54 #include "core/loader/cache/CachedResourceRequestInitiators.h" |
| 60 #include "core/loader/cache/MemoryCache.h" | 55 #include "core/loader/cache/MemoryCache.h" |
| 61 #include "core/page/DOMWindow.h" | 56 #include "core/page/DOMWindow.h" |
| 62 #include "core/page/Frame.h" | 57 #include "core/page/Frame.h" |
| 63 #include "core/page/FrameTree.h" | 58 #include "core/page/FrameTree.h" |
| 64 #include "core/page/Page.h" | 59 #include "core/page/Page.h" |
| 65 #include "core/page/Settings.h" | 60 #include "core/page/Settings.h" |
| 66 #include "core/platform/Logging.h" | 61 #include "core/platform/Logging.h" |
| 67 #include "weborigin/SchemeRegistry.h" | 62 #include "weborigin/SchemeRegistry.h" |
| 68 #include "weborigin/SecurityPolicy.h" | 63 #include "weborigin/SecurityPolicy.h" |
| 64 #include "wtf/Assertions.h" | |
| 65 #include "wtf/MemoryInstrumentationHashMap.h" | |
| 66 #include "wtf/MemoryInstrumentationHashSet.h" | |
| 67 #include "wtf/MemoryInstrumentationVector.h" | |
| 68 #include "wtf/text/CString.h" | |
| 69 #include "wtf/text/WTFString.h" | |
| 70 #include "wtf/unicode/Unicode.h" | |
| 69 | 71 |
| 70 namespace WebCore { | 72 namespace WebCore { |
| 71 | 73 |
| 72 static void cancelAll(const ResourceLoaderSet& loaders) | 74 static void cancelAll(const ResourceLoaderSet& loaders) |
| 73 { | 75 { |
| 74 Vector<RefPtr<ResourceLoader> > loadersCopy; | 76 Vector<RefPtr<ResourceLoader> > loadersCopy; |
| 75 copyToVector(loaders, loadersCopy); | 77 copyToVector(loaders, loadersCopy); |
| 76 size_t size = loadersCopy.size(); | 78 size_t size = loadersCopy.size(); |
| 77 for (size_t i = 0; i < size; ++i) | 79 for (size_t i = 0; i < size; ++i) |
| 78 loadersCopy[i]->cancel(); | 80 loadersCopy[i]->cancel(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 89 | 91 |
| 90 static bool isArchiveMIMEType(const String& mimeType) | 92 static bool isArchiveMIMEType(const String& mimeType) |
| 91 { | 93 { |
| 92 return mimeType == "multipart/related"; | 94 return mimeType == "multipart/related"; |
| 93 } | 95 } |
| 94 | 96 |
| 95 DocumentLoader::DocumentLoader(const ResourceRequest& req, const SubstituteData& substituteData) | 97 DocumentLoader::DocumentLoader(const ResourceRequest& req, const SubstituteData& substituteData) |
| 96 : m_deferMainResourceDataLoad(true) | 98 : m_deferMainResourceDataLoad(true) |
| 97 , m_frame(0) | 99 , m_frame(0) |
| 98 , m_cachedResourceLoader(CachedResourceLoader::create(this)) | 100 , m_cachedResourceLoader(CachedResourceLoader::create(this)) |
| 99 , m_writer(m_frame) | |
| 100 , m_originalRequest(req) | 101 , m_originalRequest(req) |
| 101 , m_substituteData(substituteData) | 102 , m_substituteData(substituteData) |
| 102 , m_originalRequestCopy(req) | 103 , m_originalRequestCopy(req) |
| 103 , m_request(req) | 104 , m_request(req) |
| 104 , m_committed(false) | 105 , m_committed(false) |
| 105 , m_isStopping(false) | 106 , m_isStopping(false) |
| 106 , m_gotFirstByte(false) | |
| 107 , m_isClientRedirect(false) | 107 , m_isClientRedirect(false) |
| 108 , m_wasOnloadHandled(false) | 108 , m_wasOnloadHandled(false) |
| 109 , m_loadingMainResource(false) | 109 , m_loadingMainResource(false) |
| 110 , m_timeOfLastDataReceived(0.0) | 110 , m_timeOfLastDataReceived(0.0) |
| 111 , m_identifierForLoadWithoutResourceLoader(0) | 111 , m_identifierForLoadWithoutResourceLoader(0) |
| 112 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow) | 112 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow) |
| 113 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this))) | 113 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this))) |
| 114 { | 114 { |
| 115 } | 115 } |
| 116 | 116 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 stopLoadingSubresources(); | 291 stopLoadingSubresources(); |
| 292 | 292 |
| 293 m_isStopping = false; | 293 m_isStopping = false; |
| 294 } | 294 } |
| 295 | 295 |
| 296 void DocumentLoader::commitIfReady() | 296 void DocumentLoader::commitIfReady() |
| 297 { | 297 { |
| 298 if (!m_committed) { | 298 if (!m_committed) { |
| 299 m_committed = true; | 299 m_committed = true; |
| 300 frameLoader()->commitProvisionalLoad(); | 300 frameLoader()->commitProvisionalLoad(); |
| 301 m_writer.setMIMEType(m_response.mimeType()); | |
| 302 } | 301 } |
| 303 } | 302 } |
| 304 | 303 |
| 305 bool DocumentLoader::isLoading() const | 304 bool DocumentLoader::isLoading() const |
| 306 { | 305 { |
| 307 if (document() && document()->hasActiveParser()) | 306 if (document() && document()->hasActiveParser()) |
| 308 return true; | 307 return true; |
| 309 | 308 |
| 310 return isLoadingMainResource() || !m_resourceLoaders.isEmpty(); | 309 return isLoadingMainResource() || !m_resourceLoaders.isEmpty(); |
| 311 } | 310 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 337 if (!responseEndTime) | 336 if (!responseEndTime) |
| 338 responseEndTime = m_timeOfLastDataReceived; | 337 responseEndTime = m_timeOfLastDataReceived; |
| 339 if (!responseEndTime) | 338 if (!responseEndTime) |
| 340 responseEndTime = monotonicallyIncreasingTime(); | 339 responseEndTime = monotonicallyIncreasingTime(); |
| 341 timing()->setResponseEnd(responseEndTime); | 340 timing()->setResponseEnd(responseEndTime); |
| 342 | 341 |
| 343 commitIfReady(); | 342 commitIfReady(); |
| 344 if (!frameLoader()) | 343 if (!frameLoader()) |
| 345 return; | 344 return; |
| 346 | 345 |
| 347 if (!maybeCreateArchive()) { | 346 if (isArchiveMIMEType(m_response.mimeType())) { |
| 347 createArchive(); | |
| 348 } else { | |
| 348 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that | 349 // If this is an empty document, it will not have actually been created yet. Commit dummy data so that |
| 349 // DocumentWriter::begin() gets called and creates the Document. | 350 // DocumentWriter::begin() gets called and creates the Document. |
| 350 if (!m_gotFirstByte) | 351 if (!m_writer) |
| 351 commitData(0, 0); | 352 commitData(0, 0); |
| 353 | |
| 352 frameLoader()->client()->finishedLoading(this); | 354 frameLoader()->client()->finishedLoading(this); |
| 353 } | 355 } |
| 354 | 356 |
| 355 m_writer.end(); | 357 endWriting(m_writer.get()); |
| 358 | |
| 356 if (!m_mainDocumentError.isNull()) | 359 if (!m_mainDocumentError.isNull()) |
| 357 return; | 360 return; |
| 358 clearMainResourceLoader(); | 361 clearMainResourceLoader(); |
| 359 if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument()) | 362 if (!frameLoader()->stateMachine()->creatingInitialEmptyDocument()) |
| 360 frameLoader()->checkLoadComplete(); | 363 frameLoader()->checkLoadComplete(); |
| 361 | 364 |
| 362 // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache | 365 // If the document specified an application cache manifest, it violates the author's intent if we store it in the memory cache |
| 363 // and deny the appcache the chance to intercept it in the future, so remove from the memory cache. | 366 // and deny the appcache the chance to intercept it in the future, so remove from the memory cache. |
| 364 if (m_frame) { | 367 if (m_frame) { |
| 365 if (m_mainResource && m_frame->document()->hasManifest()) | 368 if (m_mainResource && m_frame->document()->hasManifest()) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 return frameLoader()->client()->interruptedForPolicyChangeError(request()); | 625 return frameLoader()->client()->interruptedForPolicyChangeError(request()); |
| 623 } | 626 } |
| 624 | 627 |
| 625 void DocumentLoader::stopLoadingForPolicyChange() | 628 void DocumentLoader::stopLoadingForPolicyChange() |
| 626 { | 629 { |
| 627 ResourceError error = interruptedForPolicyChangeError(); | 630 ResourceError error = interruptedForPolicyChangeError(); |
| 628 error.setIsCancellation(true); | 631 error.setIsCancellation(true); |
| 629 cancelMainResourceLoad(error); | 632 cancelMainResourceLoad(error); |
| 630 } | 633 } |
| 631 | 634 |
| 635 void DocumentLoader::ensureWriter() | |
| 636 { | |
| 637 ensureWriter(m_response.mimeType()); | |
| 638 } | |
| 639 | |
| 640 void DocumentLoader::ensureWriter(const String& mimeType) | |
| 641 { | |
| 642 if (m_writer) | |
| 643 return; | |
|
abarth-chromium
2013/06/26 03:04:08
Should we ASSERT that the mimeTypes match?
Hajime Morrita
2013/06/26 04:24:39
We should. Will do.
| |
| 644 | |
| 645 String encoding = overrideEncoding().isNull() ? response().textEncodingName( ).impl() : overrideEncoding(); | |
| 646 bool userChosen = !overrideEncoding().isNull(); | |
| 647 m_writer = createWriterFor(m_frame, 0, documentURL(), mimeType, encoding, fa lse, true); | |
| 648 m_writer->setDocumentWasLoadedAsPartOfNavigation(); | |
| 649 | |
| 650 if (frameLoader()->stateMachine()->creatingInitialEmptyDocument()) | |
| 651 return; | |
| 652 | |
| 653 // Call receivedFirstData() exactly once per load. | |
| 654 frameLoader()->receivedFirstData(); | |
| 655 } | |
| 656 | |
| 632 void DocumentLoader::commitData(const char* bytes, size_t length) | 657 void DocumentLoader::commitData(const char* bytes, size_t length) |
| 633 { | 658 { |
| 634 if (!m_gotFirstByte) { | 659 ensureWriter(); |
| 635 m_gotFirstByte = true; | |
| 636 m_writer.begin(documentURL(), false); | |
| 637 m_writer.setDocumentWasLoadedAsPartOfNavigation(); | |
| 638 | |
| 639 if (frameLoader()->stateMachine()->creatingInitialEmptyDocument()) | |
| 640 return; | |
| 641 | |
| 642 // The origin is the MHTML file, we need to set the base URL to the docu ment encoded in the MHTML so | |
| 643 // relative URLs are resolved properly. | |
| 644 if (m_archive) | |
| 645 m_frame->document()->setBaseURLOverride(m_archive->mainResource()->u rl()); | |
| 646 | |
| 647 // Call receivedFirstData() exactly once per load. | |
| 648 frameLoader()->receivedFirstData(); | |
| 649 | |
| 650 bool userChosen = true; | |
| 651 String encoding = overrideEncoding(); | |
| 652 if (encoding.isNull()) { | |
| 653 userChosen = false; | |
| 654 encoding = response().textEncodingName(); | |
| 655 } | |
| 656 m_writer.setEncoding(encoding, userChosen); | |
| 657 } | |
| 658 ASSERT(m_frame->document()->parsing()); | 660 ASSERT(m_frame->document()->parsing()); |
| 659 m_writer.addData(bytes, length); | 661 m_writer->addData(bytes, length); |
| 660 } | 662 } |
| 661 | 663 |
| 662 void DocumentLoader::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 664 void DocumentLoader::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 663 { | 665 { |
| 664 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Loader); | 666 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::Loader); |
| 665 info.addMember(m_frame, "frame"); | 667 info.addMember(m_frame, "frame"); |
| 666 info.addMember(m_cachedResourceLoader, "cachedResourceLoader"); | 668 info.addMember(m_cachedResourceLoader, "cachedResourceLoader"); |
| 667 info.addMember(m_mainResource, "mainResource"); | 669 info.addMember(m_mainResource, "mainResource"); |
| 668 info.addMember(m_resourceLoaders, "resourceLoaders"); | 670 info.addMember(m_resourceLoaders, "resourceLoaders"); |
| 669 info.addMember(m_multipartResourceLoaders, "multipartResourceLoaders"); | 671 info.addMember(m_multipartResourceLoaders, "multipartResourceLoaders"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 // See https://bugs.webkit.org/show_bug.cgi?id=110937 | 706 // See https://bugs.webkit.org/show_bug.cgi?id=110937 |
| 705 // ASSERT(this == frameLoader()->activeDocumentLoader()) | 707 // ASSERT(this == frameLoader()->activeDocumentLoader()) |
| 706 m_frame->document()->domWindow()->finishedLoading(); | 708 m_frame->document()->domWindow()->finishedLoading(); |
| 707 } | 709 } |
| 708 | 710 |
| 709 void DocumentLoader::setFrame(Frame* frame) | 711 void DocumentLoader::setFrame(Frame* frame) |
| 710 { | 712 { |
| 711 if (m_frame == frame) | 713 if (m_frame == frame) |
| 712 return; | 714 return; |
| 713 ASSERT(frame && !m_frame); | 715 ASSERT(frame && !m_frame); |
| 716 ASSERT(!m_writer); | |
| 714 m_frame = frame; | 717 m_frame = frame; |
| 715 m_writer.setFrame(frame); | |
| 716 } | 718 } |
| 717 | 719 |
| 718 void DocumentLoader::detachFromFrame() | 720 void DocumentLoader::detachFromFrame() |
| 719 { | 721 { |
| 720 ASSERT(m_frame); | 722 ASSERT(m_frame); |
| 721 RefPtr<Frame> protectFrame(m_frame); | 723 RefPtr<Frame> protectFrame(m_frame); |
| 722 RefPtr<DocumentLoader> protectLoader(this); | 724 RefPtr<DocumentLoader> protectLoader(this); |
| 723 | 725 |
| 724 // It never makes sense to have a document loader that is detached from its | 726 // It never makes sense to have a document loader that is detached from its |
| 725 // frame have any loads active, so go ahead and kill all the loads. | 727 // frame have any loads active, so go ahead and kill all the loads. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 756 if (m_cachedResourceLoader->requestCount()) | 758 if (m_cachedResourceLoader->requestCount()) |
| 757 return true; | 759 return true; |
| 758 if (doc->processingLoadEvent()) | 760 if (doc->processingLoadEvent()) |
| 759 return true; | 761 return true; |
| 760 if (doc->hasActiveParser()) | 762 if (doc->hasActiveParser()) |
| 761 return true; | 763 return true; |
| 762 } | 764 } |
| 763 return frameLoader()->subframeIsLoading(); | 765 return frameLoader()->subframeIsLoading(); |
| 764 } | 766 } |
| 765 | 767 |
| 766 bool DocumentLoader::maybeCreateArchive() | 768 void DocumentLoader::createArchive() |
| 767 { | 769 { |
| 768 // Give the archive machinery a crack at this document. If the MIME type is not an archive type, it will return 0. | |
| 769 if (!isArchiveMIMEType(m_response.mimeType())) | |
| 770 return false; | |
| 771 | |
| 772 m_archive = MHTMLArchive::create(m_response.url(), mainResourceData().get()) ; | 770 m_archive = MHTMLArchive::create(m_response.url(), mainResourceData().get()) ; |
| 773 ASSERT(m_archive); | 771 ASSERT(m_archive); |
| 774 | 772 |
| 775 addAllArchiveResources(m_archive.get()); | 773 addAllArchiveResources(m_archive.get()); |
| 776 ArchiveResource* mainResource = m_archive->mainResource(); | 774 ArchiveResource* mainResource = m_archive->mainResource(); |
| 777 m_writer.setMIMEType(mainResource->mimeType()); | 775 |
| 778 | 776 ensureWriter(mainResource->mimeType()); |
| 779 ASSERT(m_frame->document()); | 777 |
| 778 // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so | |
| 779 // relative URLs are resolved properly. | |
| 780 m_frame->document()->setBaseURLOverride(m_archive->mainResource()->url()); | |
| 781 | |
| 780 commitData(mainResource->data()->data(), mainResource->data()->size()); | 782 commitData(mainResource->data()->data(), mainResource->data()->size()); |
| 781 return true; | |
| 782 } | 783 } |
| 783 | 784 |
| 784 void DocumentLoader::addAllArchiveResources(MHTMLArchive* archive) | 785 void DocumentLoader::addAllArchiveResources(MHTMLArchive* archive) |
| 785 { | 786 { |
| 786 ASSERT(archive); | 787 ASSERT(archive); |
| 787 if (!m_archiveResourceCollection) | 788 if (!m_archiveResourceCollection) |
| 788 m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection); | 789 m_archiveResourceCollection = adoptPtr(new ArchiveResourceCollection); |
| 789 m_archiveResourceCollection->addAllResources(archive); | 790 m_archiveResourceCollection->addAllResources(archive); |
| 790 } | 791 } |
| 791 | 792 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 void DocumentLoader::stopLoadingSubresources() | 895 void DocumentLoader::stopLoadingSubresources() |
| 895 { | 896 { |
| 896 cancelAll(m_resourceLoaders); | 897 cancelAll(m_resourceLoaders); |
| 897 } | 898 } |
| 898 | 899 |
| 899 void DocumentLoader::addResourceLoader(ResourceLoader* loader) | 900 void DocumentLoader::addResourceLoader(ResourceLoader* loader) |
| 900 { | 901 { |
| 901 // The main resource's underlying ResourceLoader will ask to be added here. | 902 // The main resource's underlying ResourceLoader will ask to be added here. |
| 902 // It is much simpler to handle special casing of main resource loads if we don't | 903 // It is much simpler to handle special casing of main resource loads if we don't |
| 903 // let it be added. In the main resource load case, mainResourceLoader() | 904 // let it be added. In the main resource load case, mainResourceLoader() |
| 904 // will still be null at this point, but m_gotFirstByte should be false here if and only | 905 // will still be null at this point, but document() should be null here if a nd only |
|
abarth-chromium
2013/06/26 03:04:08
null -> zero
Hajime Morrita
2013/06/26 04:24:39
Done.
| |
| 905 // if we are just starting the main resource load. | 906 // if we are just starting the main resource load. |
| 906 if (!m_gotFirstByte) | 907 if (!document()) |
| 907 return; | 908 return; |
| 908 ASSERT(!m_resourceLoaders.contains(loader)); | 909 ASSERT(!m_resourceLoaders.contains(loader)); |
| 909 ASSERT(!mainResourceLoader() || mainResourceLoader() != loader); | 910 ASSERT(!mainResourceLoader() || mainResourceLoader() != loader); |
| 910 m_resourceLoaders.add(loader); | 911 m_resourceLoaders.add(loader); |
| 911 } | 912 } |
| 912 | 913 |
| 913 void DocumentLoader::removeResourceLoader(ResourceLoader* loader) | 914 void DocumentLoader::removeResourceLoader(ResourceLoader* loader) |
| 914 { | 915 { |
| 915 if (!m_resourceLoaders.contains(loader)) | 916 if (!m_resourceLoaders.contains(loader)) |
| 916 return; | 917 return; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1012 } | 1013 } |
| 1013 | 1014 |
| 1014 void DocumentLoader::handledOnloadEvents() | 1015 void DocumentLoader::handledOnloadEvents() |
| 1015 { | 1016 { |
| 1016 m_wasOnloadHandled = true; | 1017 m_wasOnloadHandled = true; |
| 1017 applicationCacheHost()->stopDeferringEvents(); | 1018 applicationCacheHost()->stopDeferringEvents(); |
| 1018 } | 1019 } |
| 1019 | 1020 |
| 1020 DocumentWriter* DocumentLoader::beginWriting(const String& mimeType, const Strin g& encoding, const KURL& url) | 1021 DocumentWriter* DocumentLoader::beginWriting(const String& mimeType, const Strin g& encoding, const KURL& url) |
| 1021 { | 1022 { |
| 1022 m_writer.setMIMEType(mimeType); | 1023 m_writer = createWriterFor(m_frame, 0, url, mimeType, encoding, false, true) ; |
| 1023 m_writer.setEncoding(encoding, false); | 1024 return m_writer.get(); |
| 1024 m_writer.begin(url); | 1025 } |
| 1025 return &m_writer; | 1026 |
| 1027 void DocumentLoader::endWriting(DocumentWriter* writer) | |
| 1028 { | |
| 1029 ASSERT_UNUSED(writer, m_writer == writer); | |
| 1030 m_writer->end(); | |
| 1031 m_writer.clear(); | |
| 1032 } | |
| 1033 | |
| 1034 | |
| 1035 PassOwnPtr<DocumentWriter> DocumentLoader::createWriterFor(Frame* frame, const D ocument* ownerDocument, const KURL& url, const String& mimeType, const String& e ncoding, bool userChosen, bool dispatch) | |
| 1036 { | |
| 1037 // Create a new document before clearing the frame, because it may need to | |
| 1038 // inherit an aliased security context. | |
| 1039 RefPtr<Document> document = DOMImplementation::createDocument(mimeType, fram e, url, frame->inViewSourceMode()); | |
| 1040 if (document->isPluginDocument() && document->isSandboxed(SandboxPlugins)) | |
| 1041 document = SinkDocument::create(frame, url); | |
| 1042 bool shouldReuseDefaultView = frame->loader()->stateMachine()->isDisplayingI nitialEmptyDocument() && frame->document()->isSecureTransitionTo(url); | |
| 1043 | |
| 1044 RefPtr<DOMWindow> originalDOMWindow; | |
| 1045 if (shouldReuseDefaultView) | |
| 1046 originalDOMWindow = frame->domWindow(); | |
| 1047 frame->loader()->clear(!shouldReuseDefaultView, !shouldReuseDefaultView); | |
| 1048 | |
| 1049 if (!shouldReuseDefaultView) { | |
| 1050 frame->setDOMWindow(DOMWindow::create(frame)); | |
| 1051 } else { | |
| 1052 // Note that the old Document is still attached to the DOMWindow; the | |
| 1053 // setDocument() call below will detach the old Document. | |
| 1054 ASSERT(originalDOMWindow); | |
| 1055 frame->setDOMWindow(originalDOMWindow); | |
| 1056 } | |
| 1057 | |
| 1058 frame->loader()->setOutgoingReferrer(url); | |
| 1059 frame->domWindow()->setDocument(document); | |
| 1060 | |
| 1061 if (ownerDocument) { | |
| 1062 document->setCookieURL(ownerDocument->cookieURL()); | |
| 1063 document->setSecurityOrigin(ownerDocument->securityOrigin()); | |
| 1064 } | |
| 1065 | |
| 1066 frame->loader()->didBeginDocument(dispatch); | |
| 1067 | |
| 1068 return DocumentWriter::create(document.get(), mimeType, encoding, userChosen ); | |
| 1026 } | 1069 } |
| 1027 | 1070 |
| 1028 String DocumentLoader::mimeType() const | 1071 String DocumentLoader::mimeType() const |
| 1029 { | 1072 { |
| 1030 return m_writer.mimeType(); | 1073 return m_writer ? m_writer->mimeType() : m_response.mimeType().impl(); |
|
abarth-chromium
2013/06/26 03:04:08
impl() ?
Hajime Morrita
2013/06/26 04:24:39
I shouldn't have used the ternary operator :-|
| |
| 1031 } | 1074 } |
| 1032 | 1075 |
| 1076 // This is only called by ScriptController::executeScriptIfJavaScriptURL | |
| 1077 // and always contains the result of evaluating a javascript: url. | |
| 1078 // This is the <iframe src="javascript:'html'"> case. | |
| 1033 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) | 1079 void DocumentLoader::replaceDocument(const String& source, Document* ownerDocume nt) |
| 1034 { | 1080 { |
| 1035 m_writer.replaceDocument(source, ownerDocument); | 1081 m_writer = createWriterFor(m_frame, ownerDocument, m_frame->document()->url( ), "", "", false, true); |
| 1082 if (!source.isNull()) | |
| 1083 m_writer->appendReplacingData(source); | |
| 1084 endWriting(m_writer.get()); | |
| 1036 } | 1085 } |
| 1037 | 1086 |
| 1038 } // namespace WebCore | 1087 } // namespace WebCore |
| OLD | NEW |