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

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

Issue 15697017: Move subresource archive loading out of ResourceLoader (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 , m_substituteData(substituteData) 96 , m_substituteData(substituteData)
97 , m_originalRequestCopy(req) 97 , m_originalRequestCopy(req)
98 , m_request(req) 98 , m_request(req)
99 , m_originalSubstituteDataWasValid(substituteData.isValid()) 99 , m_originalSubstituteDataWasValid(substituteData.isValid())
100 , m_committed(false) 100 , m_committed(false)
101 , m_isStopping(false) 101 , m_isStopping(false)
102 , m_gotFirstByte(false) 102 , m_gotFirstByte(false)
103 , m_isClientRedirect(false) 103 , m_isClientRedirect(false)
104 , m_isLoadingMultipartContent(false) 104 , m_isLoadingMultipartContent(false)
105 , m_wasOnloadHandled(false) 105 , m_wasOnloadHandled(false)
106 , m_substituteResourceDeliveryTimer(this, &DocumentLoader::substituteResourc eDeliveryTimerFired)
107 , m_loadingMainResource(false) 106 , m_loadingMainResource(false)
108 , m_timeOfLastDataReceived(0.0) 107 , m_timeOfLastDataReceived(0.0)
109 , m_identifierForLoadWithoutResourceLoader(0) 108 , m_identifierForLoadWithoutResourceLoader(0)
110 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow) 109 , m_dataLoadTimer(this, &DocumentLoader::handleSubstituteDataLoadNow)
111 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this))) 110 , m_applicationCacheHost(adoptPtr(new ApplicationCacheHost(this)))
112 { 111 {
113 } 112 }
114 113
115 FrameLoader* DocumentLoader::frameLoader() const 114 FrameLoader* DocumentLoader::frameLoader() const
116 { 115 {
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 info.addMember(m_mainResource, "mainResource"); 682 info.addMember(m_mainResource, "mainResource");
684 info.addMember(m_resourceLoaders, "resourceLoaders"); 683 info.addMember(m_resourceLoaders, "resourceLoaders");
685 info.addMember(m_multipartResourceLoaders, "multipartResourceLoaders"); 684 info.addMember(m_multipartResourceLoaders, "multipartResourceLoaders");
686 info.addMember(m_substituteData, "substituteData"); 685 info.addMember(m_substituteData, "substituteData");
687 info.addMember(m_pageTitle.string(), "pageTitle.string()"); 686 info.addMember(m_pageTitle.string(), "pageTitle.string()");
688 info.addMember(m_overrideEncoding, "overrideEncoding"); 687 info.addMember(m_overrideEncoding, "overrideEncoding");
689 info.addMember(m_originalRequest, "originalRequest"); 688 info.addMember(m_originalRequest, "originalRequest");
690 info.addMember(m_originalRequestCopy, "originalRequestCopy"); 689 info.addMember(m_originalRequestCopy, "originalRequestCopy");
691 info.addMember(m_request, "request"); 690 info.addMember(m_request, "request");
692 info.addMember(m_response, "response"); 691 info.addMember(m_response, "response");
693 info.addMember(m_pendingSubstituteResources, "pendingSubstituteResources");
694 info.addMember(m_substituteResourceDeliveryTimer, "substituteResourceDeliver yTimer");
695 info.addMember(m_archiveResourceCollection, "archiveResourceCollection"); 692 info.addMember(m_archiveResourceCollection, "archiveResourceCollection");
696 info.addMember(m_archive, "archive"); 693 info.addMember(m_archive, "archive");
697 info.addMember(m_resourcesClientKnowsAbout, "resourcesClientKnowsAbout"); 694 info.addMember(m_resourcesClientKnowsAbout, "resourcesClientKnowsAbout");
698 info.addMember(m_resourcesLoadedFromMemoryCacheForClientNotification, "resou rcesLoadedFromMemoryCacheForClientNotification"); 695 info.addMember(m_resourcesLoadedFromMemoryCacheForClientNotification, "resou rcesLoadedFromMemoryCacheForClientNotification");
699 info.addMember(m_applicationCacheHost, "applicationCacheHost"); 696 info.addMember(m_applicationCacheHost, "applicationCacheHost");
700 } 697 }
701 698
702 void DocumentLoader::dataReceived(CachedResource* resource, const char* data, in t length) 699 void DocumentLoader::dataReceived(CachedResource* resource, const char* data, in t length)
703 { 700 {
704 ASSERT(data); 701 ASSERT(data);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 return; 829 return;
833 addAllArchiveResources(m_archive.get()); 830 addAllArchiveResources(m_archive.get());
834 831
835 ArchiveResource* mainResource = m_archive->mainResource(); 832 ArchiveResource* mainResource = m_archive->mainResource();
836 m_substituteData = SubstituteData(mainResource->data(), mainResource->mimeTy pe(), mainResource->textEncoding(), KURL()); 833 m_substituteData = SubstituteData(mainResource->data(), mainResource->mimeTy pe(), mainResource->textEncoding(), KURL());
837 } 834 }
838 835
839 void DocumentLoader::clearArchiveResources() 836 void DocumentLoader::clearArchiveResources()
840 { 837 {
841 m_archiveResourceCollection.clear(); 838 m_archiveResourceCollection.clear();
842 m_substituteResourceDeliveryTimer.stop();
843 } 839 }
844 840
845 ArchiveResource* DocumentLoader::archiveResourceForURL(const KURL& url) const 841 bool DocumentLoader::scheduleArchiveLoad(CachedResource* cachedResource, const R esourceRequest& request)
846 { 842 {
847 if (!m_archiveResourceCollection) 843 if (!m_archive)
848 return 0; 844 return false;
849
850 ArchiveResource* resource = m_archiveResourceCollection->archiveResourceForU RL(url);
851 845
852 return resource && !resource->shouldIgnoreWhenUnarchiving() ? resource : 0; 846 ASSERT(m_archiveResourceCollection);
853 } 847 ArchiveResource* archiveResource = m_archiveResourceCollection->archiveResou rceForURL(request.url());
848 ASSERT(archiveResource);
854 849
855 void DocumentLoader::deliverSubstituteResourcesAfterDelay() 850 cachedResource->setLoading(true);
856 { 851 SharedBuffer* data = archiveResource->data();
857 if (m_pendingSubstituteResources.isEmpty()) 852 cachedResource->responseReceived(archiveResource->response());
858 return; 853 cachedResource->appendData(data->data(), data->size());
859 ASSERT(m_frame && m_frame->page()); 854 cachedResource->finish();
Nate Chapin 2013/05/22 23:28:46 This "loads" the ArchiveResource by directly popul
abarth-chromium 2013/05/23 17:10:07 They're probably not needed.
860 if (m_frame->page()->defersLoading()) 855 return true;
861 return;
862 if (!m_substituteResourceDeliveryTimer.isActive())
863 m_substituteResourceDeliveryTimer.startOneShot(0);
864 }
865
866 void DocumentLoader::substituteResourceDeliveryTimerFired(Timer<DocumentLoader>* )
867 {
868 if (m_pendingSubstituteResources.isEmpty())
869 return;
870 ASSERT(m_frame && m_frame->page());
871 if (m_frame->page()->defersLoading())
872 return;
873
874 SubstituteResourceMap copy;
875 copy.swap(m_pendingSubstituteResources);
876
877 SubstituteResourceMap::const_iterator end = copy.end();
878 for (SubstituteResourceMap::const_iterator it = copy.begin(); it != end; ++i t) {
879 RefPtr<ResourceLoader> loader = it->key;
880 SubstituteResource* resource = it->value.get();
881
882 if (resource) {
883 SharedBuffer* data = resource->data();
884
885 loader->didReceiveResponse(0, resource->response());
886
887 // Calling ResourceLoader::didReceiveResponse can end up cancelling the load,
888 // so we need to check if the loader has reached its terminal state.
889 if (loader->reachedTerminalState())
890 return;
891
892 loader->didReceiveData(0, data->data(), data->size(), data->size());
893
894 // Calling ResourceLoader::didReceiveData can end up cancelling the load,
895 // so we need to check if the loader has reached its terminal state.
896 if (loader->reachedTerminalState())
897 return;
898
899 loader->didFinishLoading(0, 0);
900 } else {
901 // A null resource means that we should fail the load.
902 // FIXME: Maybe we should use another error here - something like "n ot in cache".
903 loader->didFail(0, loader->cannotShowURLError());
904 }
905 }
906 }
907
908 #ifndef NDEBUG
909 bool DocumentLoader::isSubstituteLoadPending(ResourceLoader* loader) const
910 {
911 return m_pendingSubstituteResources.contains(loader);
912 }
913 #endif
914
915 void DocumentLoader::cancelPendingSubstituteLoad(ResourceLoader* loader)
916 {
917 if (m_pendingSubstituteResources.isEmpty())
918 return;
919 m_pendingSubstituteResources.remove(loader);
920 if (m_pendingSubstituteResources.isEmpty())
921 m_substituteResourceDeliveryTimer.stop();
922 }
923
924 bool DocumentLoader::scheduleArchiveLoad(ResourceLoader* loader, const ResourceR equest& request)
925 {
926 if (ArchiveResource* resource = archiveResourceForURL(request.url())) {
927 m_pendingSubstituteResources.set(loader, resource);
928 deliverSubstituteResourcesAfterDelay();
929 return true;
930 }
931 return m_archive;
932 } 856 }
933 857
934 void DocumentLoader::setTitle(const StringWithDirection& title) 858 void DocumentLoader::setTitle(const StringWithDirection& title)
935 { 859 {
936 if (m_pageTitle == title) 860 if (m_pageTitle == title)
937 return; 861 return;
938 862
939 m_pageTitle = title; 863 m_pageTitle = title;
940 frameLoader()->didChangeTitle(this); 864 frameLoader()->didChangeTitle(this);
941 } 865 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 907
984 void DocumentLoader::setDefersLoading(bool defers) 908 void DocumentLoader::setDefersLoading(bool defers)
985 { 909 {
986 // Multiple frames may be loading the same main resource simultaneously. If deferral state changes, 910 // Multiple frames may be loading the same main resource simultaneously. If deferral state changes,
987 // each frame's DocumentLoader will try to send a setDefersLoading() to the same underlying ResourceLoader. Ensure only 911 // each frame's DocumentLoader will try to send a setDefersLoading() to the same underlying ResourceLoader. Ensure only
988 // the "owning" DocumentLoader does so, as setDefersLoading() is not resilie nt to setting the same value repeatedly. 912 // the "owning" DocumentLoader does so, as setDefersLoading() is not resilie nt to setting the same value repeatedly.
989 if (mainResourceLoader() && mainResourceLoader()->documentLoader() == this) 913 if (mainResourceLoader() && mainResourceLoader()->documentLoader() == this)
990 mainResourceLoader()->setDefersLoading(defers); 914 mainResourceLoader()->setDefersLoading(defers);
991 915
992 setAllDefersLoading(m_resourceLoaders, defers); 916 setAllDefersLoading(m_resourceLoaders, defers);
993 if (!defers)
994 deliverSubstituteResourcesAfterDelay();
995 } 917 }
996 918
997 void DocumentLoader::setMainResourceDataBufferingPolicy(DataBufferingPolicy data BufferingPolicy) 919 void DocumentLoader::setMainResourceDataBufferingPolicy(DataBufferingPolicy data BufferingPolicy)
998 { 920 {
999 if (m_mainResource) 921 if (m_mainResource)
1000 m_mainResource->setDataBufferingPolicy(dataBufferingPolicy); 922 m_mainResource->setDataBufferingPolicy(dataBufferingPolicy);
1001 } 923 }
1002 924
1003 void DocumentLoader::stopLoadingSubresources() 925 void DocumentLoader::stopLoadingSubresources()
1004 { 926 {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 commitLoad(resourceData->data(), resourceData->size()); 1063 commitLoad(resourceData->data(), resourceData->size());
1142 } 1064 }
1143 1065
1144 void DocumentLoader::handledOnloadEvents() 1066 void DocumentLoader::handledOnloadEvents()
1145 { 1067 {
1146 m_wasOnloadHandled = true; 1068 m_wasOnloadHandled = true;
1147 applicationCacheHost()->stopDeferringEvents(); 1069 applicationCacheHost()->stopDeferringEvents();
1148 } 1070 }
1149 1071
1150 } // namespace WebCore 1072 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698