Changeset 46609 in webkit
- Timestamp:
- Jul 30, 2009 4:08:33 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r46606 r46609 1 2009-07-30 Michael Nordman <michaeln@google.com> 2 3 Reviewed by Darin Fisher. 4 5 https://bugs.webkit.org/show_bug.cgi?id=27821 6 7 ApplicationCacheHost refactoring. 8 9 1) Better encapsulate the interfaces between webcore common code 10 and the appcache system within a new class ApplicationCacheHost. 11 12 2) Use that interface throughout the loader system, replacing inline appcache logic. 13 14 3) Implement the interface in terms of webcore's appcache system. 15 16 4) Add the new files to various makefiles. 17 18 5) Implement protocolHostAndPortAreEqual() in KURLGoogle.cpp 19 20 No new features, no new tests. The existing layout tests all pass. 21 22 * GNUmakefile.am: 23 * WebCore.base.exp: 24 * WebCore.gypi: 25 * WebCore.pro: 26 * WebCore.vcproj/WebCore.vcproj: 27 * WebCore.xcodeproj/project.pbxproj: 28 * WebCoreSources.bkl: 29 * html/HTMLHtmlElement.cpp: 30 (WebCore::HTMLHtmlElement::insertedIntoDocument): 31 * loader/DocumentLoader.cpp: 32 (WebCore::DocumentLoader::DocumentLoader): 33 (WebCore::DocumentLoader::~DocumentLoader): 34 (WebCore::DocumentLoader::mainReceivedError): 35 (WebCore::DocumentLoader::detachFromFrame): 36 (WebCore::DocumentLoader::setPrimaryLoadComplete): 37 * loader/DocumentLoader.h: 38 (WebCore::DocumentLoader::applicationCacheHost): 39 * loader/FrameLoader.cpp: 40 (WebCore::FrameLoader::canCachePageContainingThisFrame): 41 (WebCore::FrameLoader::logCanCacheFrameDecision): 42 (WebCore::FrameLoader::loadResourceSynchronously): 43 * loader/MainResourceLoader.cpp: 44 (WebCore::MainResourceLoader::didReceiveResponse): 45 (WebCore::MainResourceLoader::didReceiveData): 46 (WebCore::MainResourceLoader::didFinishLoading): 47 (WebCore::MainResourceLoader::didFail): 48 (WebCore::MainResourceLoader::load): 49 * loader/MainResourceLoader.h: 50 * loader/ResourceLoader.cpp: 51 (WebCore::ResourceLoader::load): 52 (WebCore::ResourceLoader::willSendRequest): 53 (WebCore::ResourceLoader::didReceiveResponse): 54 (WebCore::ResourceLoader::didFail): 55 * loader/ResourceLoader.h: 56 * loader/appcache/ApplicationCacheGroup.cpp: 57 (WebCore::ApplicationCacheGroup::selectCache): 58 (WebCore::ApplicationCacheGroup::selectCacheWithoutManifestURL): 59 (WebCore::ApplicationCacheGroup::finishedLoadingMainResource): 60 (WebCore::ApplicationCacheGroup::failedLoadingMainResource): 61 (WebCore::ApplicationCacheGroup::disassociateDocumentLoader): 62 (WebCore::ApplicationCacheGroup::update): 63 (WebCore::ApplicationCacheGroup::didFinishLoadingManifest): 64 (WebCore::ApplicationCacheGroup::manifestNotFound): 65 (WebCore::ApplicationCacheGroup::checkIfLoadIsComplete): 66 (WebCore::ApplicationCacheGroup::startLoadingEntry): 67 (WebCore::ApplicationCacheGroup::associateDocumentLoaderWithCache): 68 (WebCore::CallCacheListenerTask::create): 69 (WebCore::CallCacheListenerTask::performTask): 70 (WebCore::CallCacheListenerTask::CallCacheListenerTask): 71 (WebCore::ApplicationCacheGroup::postListenerTask): 72 * loader/appcache/ApplicationCacheGroup.h: 73 * loader/appcache/ApplicationCacheHost.cpp: Added. 74 * loader/appcache/ApplicationCacheHost.h: Added. 75 * loader/appcache/ApplicationCacheStorage.cpp: 76 (WebCore::ApplicationCacheStorage::transferApplicationCache): 77 * loader/appcache/ApplicationCacheStorage.h: 78 * loader/appcache/DOMApplicationCache.cpp: 79 (WebCore::DOMApplicationCache::DOMApplicationCache): 80 (WebCore::DOMApplicationCache::disconnectFrame): 81 (WebCore::DOMApplicationCache::applicationCacheHost): 82 (WebCore::DOMApplicationCache::status): 83 (WebCore::DOMApplicationCache::update): 84 (WebCore::DOMApplicationCache::swapCache): 85 (WebCore::DOMApplicationCache::addEventListener): 86 (WebCore::DOMApplicationCache::removeEventListener): 87 (WebCore::DOMApplicationCache::dispatchEvent): 88 (WebCore::DOMApplicationCache::callListener): 89 (WebCore::DOMApplicationCache::toEventName): 90 (WebCore::DOMApplicationCache::toEventType): 91 * loader/appcache/DOMApplicationCache.h: 92 (WebCore::DOMApplicationCache::): 93 (WebCore::DOMApplicationCache::setAttributeEventListener): 94 (WebCore::DOMApplicationCache::getAttributeEventListener): 95 (WebCore::DOMApplicationCache::clearAttributeEventListener): 96 (WebCore::DOMApplicationCache::callEventListener): 97 (WebCore::DOMApplicationCache::setOnchecking): 98 (WebCore::DOMApplicationCache::onchecking): 99 (WebCore::DOMApplicationCache::setOnerror): 100 (WebCore::DOMApplicationCache::onerror): 101 (WebCore::DOMApplicationCache::setOnnoupdate): 102 (WebCore::DOMApplicationCache::onnoupdate): 103 (WebCore::DOMApplicationCache::setOndownloading): 104 (WebCore::DOMApplicationCache::ondownloading): 105 (WebCore::DOMApplicationCache::setOnprogress): 106 (WebCore::DOMApplicationCache::onprogress): 107 (WebCore::DOMApplicationCache::setOnupdateready): 108 (WebCore::DOMApplicationCache::onupdateready): 109 (WebCore::DOMApplicationCache::setOncached): 110 (WebCore::DOMApplicationCache::oncached): 111 (WebCore::DOMApplicationCache::setOnobsolete): 112 (WebCore::DOMApplicationCache::onobsolete): 113 (WebCore::DOMApplicationCache::~DOMApplicationCache): 114 * platform/KURLGoogle.cpp: 115 (WebCore::protocolHostAndPortAreEqual): 116 1 117 2009-07-30 Chris Fleizach <cfleizach@apple.com> 2 118 -
trunk/WebCore/GNUmakefile.am
r46509 r46609 2007 2007 WebCore/loader/appcache/ApplicationCacheGroup.cpp \ 2008 2008 WebCore/loader/appcache/ApplicationCacheGroup.h \ 2009 WebCore/loader/appcache/ApplicationCacheHost.cpp \ 2010 WebCore/loader/appcache/ApplicationCacheHost.h \ 2009 2011 WebCore/loader/appcache/ApplicationCacheResource.cpp \ 2010 2012 WebCore/loader/appcache/ApplicationCacheResource.h \ -
trunk/WebCore/WebCore.base.exp
r46449 r46609 444 444 __ZN7WebCore22externalRepresentationEPNS_12RenderObjectE 445 445 __ZN7WebCore23ApplicationCacheStorage14setMaximumSizeEx 446 __ZN7WebCore23ApplicationCacheStorage 16storeCopyOfCacheERKNS_6StringEPNS_16ApplicationCacheE446 __ZN7WebCore23ApplicationCacheStorage24transferApplicationCacheERKNS_6StringEPNS_20ApplicationCacheHostE 447 447 __ZN7WebCore23ApplicationCacheStorage17setCacheDirectoryERKNS_6StringE 448 448 __ZN7WebCore23ApplicationCacheStorage18vacuumDatabaseFileEv -
trunk/WebCore/WebCore.gypi
r46529 r46609 1426 1426 'loader/appcache/ApplicationCacheGroup.cpp', 1427 1427 'loader/appcache/ApplicationCacheGroup.h', 1428 'loader/appcache/ApplicationCacheHost.cpp', 1429 'loader/appcache/ApplicationCacheHost.h', 1428 1430 'loader/appcache/ApplicationCacheResource.cpp', 1429 1431 'loader/appcache/ApplicationCacheResource.h', -
trunk/WebCore/WebCore.pro
r46522 r46609 1514 1514 inspector/JavaScriptProfileNode.h \ 1515 1515 loader/appcache/ApplicationCacheGroup.h \ 1516 loader/appcache/ApplicationCacheHost.h \ 1516 1517 loader/appcache/ApplicationCache.h \ 1517 1518 loader/appcache/ApplicationCacheResource.h \ … … 3034 3035 loader/appcache/ApplicationCache.cpp \ 3035 3036 loader/appcache/ApplicationCacheGroup.cpp \ 3037 loader/appcache/ApplicationCacheHost.cpp \ 3036 3038 loader/appcache/ApplicationCacheStorage.cpp \ 3037 3039 loader/appcache/ApplicationCacheResource.cpp \ -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r46507 r46609 17294 17294 <File 17295 17295 RelativePath="..\loader\appcache\ApplicationCacheGroup.h" 17296 > 17297 </File> 17298 <File 17299 RelativePath="..\loader\appcache\ApplicationCacheHost.cpp" 17300 > 17301 </File> 17302 <File 17303 RelativePath="..\loader\appcache\ApplicationCacheHost.h" 17296 17304 > 17297 17305 </File> -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r46507 r46609 353 353 1A8F6BC10DB55CDC001DB794 /* ApplicationCacheResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BB60DB55CDC001DB794 /* ApplicationCacheResource.h */; }; 354 354 1A8F6BC20DB55CDC001DB794 /* DOMApplicationCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A8F6BB70DB55CDC001DB794 /* DOMApplicationCache.cpp */; }; 355 1A8F6BC30DB55CDC001DB794 /* DOMApplicationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BB80DB55CDC001DB794 /* DOMApplicationCache.h */; };355 1A8F6BC30DB55CDC001DB794 /* DOMApplicationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BB80DB55CDC001DB794 /* DOMApplicationCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 356 356 1A8F6BC50DB55CDC001DB794 /* ManifestParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A8F6BBA0DB55CDC001DB794 /* ManifestParser.cpp */; }; 357 357 1A8F6BC60DB55CDC001DB794 /* ManifestParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BBB0DB55CDC001DB794 /* ManifestParser.h */; }; … … 525 525 1CF6BE150E9BB4670025E1CD /* ObjCNodeFilterCondition.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CF6BE130E9BB4670025E1CD /* ObjCNodeFilterCondition.h */; }; 526 526 1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */; }; 527 24F54EAC101FE914000AE741 /* ApplicationCacheHost.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */; }; 528 24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */ = {isa = PBXBuildFile; fileRef = 24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */; settings = {ATTRIBUTES = (Private, ); }; }; 527 529 29A812260FBB9C1D00510293 /* AccessibilityRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A812080FBB9C1D00510293 /* AccessibilityRenderObject.cpp */; }; 528 530 29A812270FBB9C1D00510293 /* AccessibilityTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A812090FBB9C1D00510293 /* AccessibilityTable.cpp */; }; … … 5488 5490 1CF6BE130E9BB4670025E1CD /* ObjCNodeFilterCondition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCNodeFilterCondition.h; sourceTree = "<group>"; }; 5489 5491 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; }; 5492 24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationCacheHost.cpp; sourceTree = "<group>"; }; 5493 24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationCacheHost.h; sourceTree = "<group>"; }; 5490 5494 29A812080FBB9C1D00510293 /* AccessibilityRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityRenderObject.cpp; sourceTree = "<group>"; }; 5491 5495 29A812090FBB9C1D00510293 /* AccessibilityTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityTable.cpp; sourceTree = "<group>"; }; … … 9709 9713 isa = PBXGroup; 9710 9714 children = ( 9715 24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */, 9716 24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */, 9711 9717 1A8F6BB10DB55CDC001DB794 /* ApplicationCache.cpp */, 9712 9718 1A8F6BB20DB55CDC001DB794 /* ApplicationCache.h */, … … 17063 17069 7A74ECBB101839A600BF939E /* InspectorBackend.h in Headers */, 17064 17070 7A1E88F6101CC384000C4DF5 /* ScriptArray.h in Headers */, 17071 24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */, 17065 17072 41A3D58F101C152D00316D07 /* DedicatedWorkerThread.h in Headers */, 17066 17073 ); … … 19105 19112 7A74ECBD101839DA00BF939E /* JSInspectorBackendCustom.cpp in Sources */, 19106 19113 7A1E88F5101CC384000C4DF5 /* ScriptArray.cpp in Sources */, 19114 24F54EAC101FE914000AE741 /* ApplicationCacheHost.cpp in Sources */, 19107 19115 41A3D58E101C152D00316D07 /* DedicatedWorkerThread.cpp in Sources */, 19108 19116 ); -
trunk/WebCore/WebCoreSources.bkl
r46490 r46609 677 677 loader/appcache/ApplicationCache.cpp 678 678 loader/appcache/ApplicationCacheGroup.cpp 679 loader/appcache/ApplicationCacheHost.cpp 679 680 loader/appcache/ApplicationCacheResource.cpp 680 681 loader/appcache/DOMApplicationCache.cpp -
trunk/WebCore/html/HTMLHtmlElement.cpp
r43215 r46609 24 24 #include "HTMLHtmlElement.h" 25 25 26 #include "ApplicationCacheGroup.h" 26 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 27 #include "ApplicationCacheHost.h" 28 #endif 29 27 30 #include "Document.h" 31 #include "DocumentLoader.h" 32 #include "Frame.h" 28 33 #include "HTMLNames.h" 29 34 … … 69 74 return; 70 75 76 DocumentLoader* documentLoader = document()->frame()->loader()->documentLoader(); 77 if (!documentLoader) 78 return; 79 71 80 // Check the manifest attribute 72 81 AtomicString manifest = getAttribute(manifestAttr); 73 if (manifest.is Null())74 ApplicationCacheGroup::selectCacheWithoutManifestURL(document()->frame());82 if (manifest.isEmpty()) 83 documentLoader->applicationCacheHost()->selectCacheWithoutManifest(); 75 84 else 76 ApplicationCacheGroup::selectCache(document()->frame(),document()->completeURL(manifest));85 documentLoader->applicationCacheHost()->selectCacheWithManifest(document()->completeURL(manifest)); 77 86 } 78 87 #endif -
trunk/WebCore/loader/DocumentLoader.cpp
r44943 r46609 30 30 #include "DocumentLoader.h" 31 31 32 #if ENABLE(OFFLINE_WEB_APPLICATIONS)33 #include "ApplicationCache.h"34 #include "ApplicationCacheGroup.h"35 #include "ApplicationCacheResource.h"36 #endif37 32 #include "ArchiveFactory.h" 38 33 #include "ArchiveResourceCollection.h" … … 154 149 , m_didCreateGlobalHistoryEntry(false) 155 150 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 156 , m_ candidateApplicationCacheGroup(0)151 , m_applicationCacheHost(this) 157 152 #endif 158 153 { … … 169 164 { 170 165 ASSERT(!m_frame || frameLoader()->activeDocumentLoader() != this || !frameLoader()->isLoading()); 171 172 #if ENABLE(OFFLINE_WEB_APPLICATIONS)173 if (m_applicationCache)174 m_applicationCache->group()->disassociateDocumentLoader(this);175 else if (m_candidateApplicationCacheGroup)176 m_candidateApplicationCacheGroup->disassociateDocumentLoader(this);177 #endif178 166 } 179 167 … … 259 247 260 248 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 261 ApplicationCacheGroup* group = m_candidateApplicationCacheGroup; 262 if (!group && m_applicationCache) { 263 ASSERT(!mainResourceApplicationCache()); // If the main resource were loaded from a cache, it wouldn't fail. 264 group = m_applicationCache->group(); 265 } 266 267 if (group) 268 group->failedLoadingMainResource(this); 249 m_applicationCacheHost.failedLoadingMainResource(); 269 250 #endif 270 251 … … 431 412 { 432 413 ASSERT(m_frame); 414 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 415 m_applicationCacheHost.setDOMApplicationCache(0); 416 #endif 433 417 m_frame = 0; 434 418 } … … 452 436 if (m_mainResourceLoader) { 453 437 m_mainResourceData = m_mainResourceLoader->resourceData(); 454 #if ENABLE(OFFLINE_WEB_APPLICATIONS)455 m_mainResourceApplicationCache = m_mainResourceLoader->applicationCache();456 #endif457 438 m_mainResourceLoader = 0; 458 439 } … … 848 829 } 849 830 850 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 851 void DocumentLoader::setCandidateApplicationCacheGroup(ApplicationCacheGroup* group) 852 { 853 ASSERT(!m_applicationCache); 854 m_candidateApplicationCacheGroup = group; 855 } 856 857 void DocumentLoader::setApplicationCache(PassRefPtr<ApplicationCache> applicationCache) 858 { 859 if (m_candidateApplicationCacheGroup) { 860 ASSERT(!m_applicationCache); 861 m_candidateApplicationCacheGroup = 0; 862 } 863 864 m_applicationCache = applicationCache; 865 } 866 867 ApplicationCache* DocumentLoader::mainResourceApplicationCache() const 868 { 869 if (m_mainResourceApplicationCache) 870 return m_mainResourceApplicationCache.get(); 871 if (m_mainResourceLoader) 872 return m_mainResourceLoader->applicationCache(); 873 return 0; 874 } 875 876 bool DocumentLoader::shouldLoadResourceFromApplicationCache(const ResourceRequest& request, ApplicationCacheResource*& resource) 877 { 878 ApplicationCache* cache = applicationCache(); 879 if (!cache || !cache->isComplete()) 880 return false; 881 882 // If the resource is not a HTTP/HTTPS GET, then abort 883 if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request)) 884 return false; 885 886 // If the resource's URL is an master entry, the manifest, an explicit entry, or a fallback entry 887 // in the application cache, then get the resource from the cache (instead of fetching it). 888 resource = cache->resourceForURL(request.url()); 889 890 // Resources that match fallback namespaces or online whitelist entries are fetched from the network, 891 // unless they are also cached. 892 if (!resource && (cache->urlMatchesFallbackNamespace(request.url()) || cache->isURLInOnlineWhitelist(request.url()))) 893 return false; 894 895 // Resources that are not present in the manifest will always fail to load (at least, after the 896 // cache has been primed the first time), making the testing of offline applications simpler. 897 return true; 898 } 899 900 bool DocumentLoader::getApplicationCacheFallbackResource(const ResourceRequest& request, ApplicationCacheResource*& resource, ApplicationCache* cache) 901 { 902 if (!cache) { 903 cache = applicationCache(); 904 if (!cache) 905 return false; 906 } 907 if (!cache->isComplete()) 908 return false; 909 910 // If the resource is not a HTTP/HTTPS GET, then abort 911 if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request)) 912 return false; 913 914 KURL fallbackURL; 915 if (!cache->urlMatchesFallbackNamespace(request.url(), &fallbackURL)) 916 return false; 917 918 resource = cache->resourceForURL(fallbackURL); 919 ASSERT(resource); 920 921 return true; 922 } 923 924 bool DocumentLoader::scheduleApplicationCacheLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL) 925 { 926 if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) 927 return false; 928 929 if (request.url() != originalURL) 930 return false; 931 932 ApplicationCacheResource* resource; 933 if (!shouldLoadResourceFromApplicationCache(request, resource)) 934 return false; 935 936 m_pendingSubstituteResources.set(loader, resource); 937 deliverSubstituteResourcesAfterDelay(); 938 939 return true; 940 } 941 942 bool DocumentLoader::scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader* loader, const ResourceRequest& request, ApplicationCache* cache) 943 { 944 if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) 945 return false; 946 947 ApplicationCacheResource* resource; 948 if (!getApplicationCacheFallbackResource(request, resource, cache)) 949 return false; 950 951 m_pendingSubstituteResources.set(loader, resource); 952 deliverSubstituteResourcesAfterDelay(); 953 954 return true; 955 } 956 957 #endif // ENABLE(OFFLINE_WEB_APPLICATIONS) 958 959 } 831 } -
trunk/WebCore/loader/DocumentLoader.h
r44468 r46609 30 30 #define DocumentLoader_h 31 31 32 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 33 #include "ApplicationCacheHost.h" 34 #endif 35 32 36 #include "NavigationAction.h" 33 37 #include "ResourceError.h" … … 39 43 namespace WebCore { 40 44 41 class ApplicationCache;42 class ApplicationCacheGroup;43 class ApplicationCacheResource;44 45 class Archive; 45 46 class ArchiveResource; … … 208 209 209 210 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 210 bool scheduleApplicationCacheLoad(ResourceLoader*, const ResourceRequest&, const KURL& originalURL); 211 bool scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader*, const ResourceRequest&, ApplicationCache* = 0); 212 bool shouldLoadResourceFromApplicationCache(const ResourceRequest&, ApplicationCacheResource*&); 213 bool getApplicationCacheFallbackResource(const ResourceRequest&, ApplicationCacheResource*&, ApplicationCache* = 0); 214 215 void setCandidateApplicationCacheGroup(ApplicationCacheGroup* group); 216 ApplicationCacheGroup* candidateApplicationCacheGroup() const { return m_candidateApplicationCacheGroup; } 217 218 void setApplicationCache(PassRefPtr<ApplicationCache> applicationCache); 219 ApplicationCache* applicationCache() const { return m_applicationCache.get(); } 220 221 ApplicationCache* mainResourceApplicationCache() const; 211 ApplicationCacheHost* applicationCacheHost() { return &m_applicationCacheHost; } 222 212 #endif 223 213 … … 307 297 bool m_didCreateGlobalHistoryEntry; 308 298 309 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 310 // The application cache that the document loader is associated with (if any). 311 RefPtr<ApplicationCache> m_applicationCache; 312 313 // Before an application cache has finished loading, this will be the candidate application 314 // group that the document loader is associated with. 315 ApplicationCacheGroup* m_candidateApplicationCacheGroup; 316 317 // Once the main resource has finished loading, this is the application cache it was loaded from (if any). 318 RefPtr<ApplicationCache> m_mainResourceApplicationCache; 299 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 300 friend class ApplicationCacheHost; // for substitute resource delivery 301 ApplicationCacheHost m_applicationCacheHost; 319 302 #endif 320 303 }; -
trunk/WebCore/loader/FrameLoader.cpp
r46592 r46609 96 96 97 97 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 98 #include "ApplicationCache.h" 99 #include "ApplicationCacheResource.h" 98 #include "ApplicationCacheHost.h" 100 99 #endif 101 100 … … 1817 1816 // FIXME: We should investigating caching frames that have an associated 1818 1817 // application cache. <rdar://problem/5917899> tracks that work. 1819 && !m_documentLoader->applicationCache() 1820 && !m_documentLoader->candidateApplicationCacheGroup() 1818 && m_documentLoader->applicationCacheHost()->canCacheInPageCache() 1821 1819 #endif 1822 1820 #if ENABLE(WML) … … 1968 1966 { PCLOG(" -The document cannot suspect its active DOM Objects"); cannotCache = true; } 1969 1967 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 1970 if (m_documentLoader->applicationCache()) 1971 { PCLOG(" -The DocumentLoader has an active application cache"); cannotCache = true; } 1972 if (m_documentLoader->candidateApplicationCacheGroup()) 1973 { PCLOG(" -The DocumentLoader has a candidateApplicationCacheGroup"); cannotCache = true; } 1968 if (!m_documentLoader->applicationCacheHost()->canCacheInPageCache()) 1969 { PCLOG(" -The DocumentLoader uses an application cache"); cannotCache = true; } 1974 1970 #endif 1975 1971 if (!m_client->canCachePage()) … … 3682 3678 3683 3679 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 3684 ApplicationCacheResource* resource; 3685 if (documentLoader()->shouldLoadResourceFromApplicationCache(newRequest, resource)) { 3686 if (resource) { 3687 response = resource->response(); 3688 data.append(resource->data()->data(), resource->data()->size()); 3689 } else 3690 error = cannotShowURLError(newRequest); 3691 } else { 3680 if (!documentLoader()->applicationCacheHost()->maybeLoadSynchronously(newRequest, error, response, data)) { 3692 3681 #endif 3693 3682 ResourceHandle::loadResourceSynchronously(newRequest, storedCredentials, error, response, data, m_frame); 3694 3695 3683 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 3696 // If normal loading results in a redirect to a resource with another origin (indicative of a captive portal), or a 4xx or 5xx status code or equivalent, 3697 // or if there were network errors (but not if the user canceled the download), then instead get, from the cache, the resource of the fallback entry 3698 // corresponding to the matched namespace. 3699 if ((!error.isNull() && !error.isCancellation()) 3700 || response.httpStatusCode() / 100 == 4 || response.httpStatusCode() / 100 == 5 3701 || !protocolHostAndPortAreEqual(newRequest.url(), response.url())) { 3702 if (documentLoader()->getApplicationCacheFallbackResource(newRequest, resource)) { 3703 response = resource->response(); 3704 data.clear(); 3705 data.append(resource->data()->data(), resource->data()->size()); 3706 } 3707 } 3684 documentLoader()->applicationCacheHost()->maybeLoadFallbackSynchronously(newRequest, error, response, data); 3708 3685 } 3709 3686 #endif -
trunk/WebCore/loader/MainResourceLoader.cpp
r44047 r46609 43 43 44 44 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 45 #include "ApplicationCache.h" 46 #include "ApplicationCacheGroup.h" 47 #include "ApplicationCacheResource.h" 45 #include "ApplicationCacheHost.h" 48 46 #endif 49 47 … … 284 282 { 285 283 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 286 if (r.httpStatusCode() / 100 == 4 || r.httpStatusCode() / 100 == 5) { 287 ASSERT(!m_applicationCache); 288 if (m_frame->settings() && m_frame->settings()->offlineWebApplicationCacheEnabled()) { 289 m_applicationCache = ApplicationCacheGroup::fallbackCacheForMainRequest(request(), documentLoader()); 290 291 if (scheduleLoadFallbackResourceFromApplicationCache(m_applicationCache.get())) 292 return; 293 } 294 } 284 if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainResponse(request(), r)) 285 return; 295 286 #endif 296 287 … … 354 345 #endif 355 346 347 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 348 documentLoader()->applicationCacheHost()->mainResourceDataReceived(data, length, lengthReceived, allAtOnce); 349 #endif 350 356 351 // The additional processing can do anything including possibly removing the last 357 352 // reference to this object; one example of this is 3266216. … … 381 376 382 377 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 383 ApplicationCacheGroup* group = dl->candidateApplicationCacheGroup(); 384 if (!group && dl->applicationCache() && !dl->mainResourceApplicationCache()) 385 group = dl->applicationCache()->group(); 386 387 if (group) 388 group->finishedLoadingMainResource(dl.get()); 378 dl->applicationCacheHost()->finishedLoadingMainResource(); 389 379 #endif 390 380 } … … 393 383 { 394 384 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 395 if (!error.isCancellation()) { 396 ASSERT(!m_applicationCache); 397 if (m_frame->settings() && m_frame->settings()->offlineWebApplicationCacheEnabled()) { 398 m_applicationCache = ApplicationCacheGroup::fallbackCacheForMainRequest(request(), documentLoader()); 399 400 if (scheduleLoadFallbackResourceFromApplicationCache(m_applicationCache.get())) 401 return; 402 } 403 } 385 if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainError(request(), error)) 386 return; 404 387 #endif 405 388 … … 496 479 m_substituteData = substituteData; 497 480 481 ResourceRequest request(r); 482 498 483 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 499 // Check if this request should be loaded from the application cache 500 if (!m_substituteData.isValid() && frameLoader()->frame()->settings() && frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) { 501 ASSERT(!m_applicationCache); 502 503 m_applicationCache = ApplicationCacheGroup::cacheForMainRequest(r, m_documentLoader.get()); 504 505 if (m_applicationCache) { 506 // Get the resource from the application cache. By definition, cacheForMainRequest() returns a cache that contains the resource. 507 ApplicationCacheResource* resource = m_applicationCache->resourceForRequest(r); 508 m_substituteData = SubstituteData(resource->data(), 509 resource->response().mimeType(), 510 resource->response().textEncodingName(), KURL()); 511 } 512 } 513 #endif 514 515 ResourceRequest request(r); 484 documentLoader()->applicationCacheHost()->maybeLoadMainResource(request, m_substituteData); 485 #endif 486 516 487 bool defer = defersLoading(); 517 488 if (defer) { 518 bool shouldLoadEmpty = shouldLoadAsEmptyDocument(r .url());489 bool shouldLoadEmpty = shouldLoadAsEmptyDocument(request.url()); 519 490 if (shouldLoadEmpty) 520 491 defer = false; -
trunk/WebCore/loader/MainResourceLoader.h
r41845 r46609 40 40 namespace WebCore { 41 41 42 #if ENABLE(OFFLINE_WEB_APPLICATIONS)43 class ApplicationCache;44 #endif45 42 class FormState; 46 43 struct ResourceRequest; … … 71 68 72 69 bool isLoadingMultipartContent() const { return m_loadingMultipartContent; } 73 74 #if ENABLE(OFFLINE_WEB_APPLICATIONS)75 ApplicationCache* applicationCache() const { return m_applicationCache.get(); }76 #endif77 70 78 71 private: … … 106 99 MainResourceLoaderTimer m_dataLoadTimer; 107 100 108 #if ENABLE(OFFLINE_WEB_APPLICATIONS)109 // The application cache that the main resource was loaded from (if any).110 RefPtr<ApplicationCache> m_applicationCache;111 #endif112 113 101 bool m_loadingMultipartContent; 114 102 bool m_waitingForContentPolicy; -
trunk/WebCore/loader/ResourceLoader.cpp
r39962 r46609 31 31 #include "ResourceLoader.h" 32 32 33 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 34 #include "ApplicationCacheHost.h" 35 #endif 33 36 #include "DocumentLoader.h" 34 37 #include "Frame.h" … … 120 123 121 124 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 122 if (m_documentLoader-> scheduleApplicationCacheLoad(this, clientRequest, r.url()))125 if (m_documentLoader->applicationCacheHost()->maybeLoadResource(this, clientRequest, r.url())) 123 126 return true; 124 127 #endif … … 191 194 } 192 195 193 #if ENABLE(OFFLINE_WEB_APPLICATIONS)194 bool ResourceLoader::scheduleLoadFallbackResourceFromApplicationCache(ApplicationCache* cache)195 {196 if (documentLoader()->scheduleLoadFallbackResourceFromApplicationCache(this, m_request, cache)) {197 handle()->cancel();198 return true;199 }200 return false;201 }202 #endif203 204 196 void ResourceLoader::willSendRequest(ResourceRequest& request, const ResourceResponse& redirectResponse) 205 197 { … … 383 375 { 384 376 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 385 if (!redirectResponse.isNull() && !protocolHostAndPortAreEqual(request.url(), redirectResponse.url())) { 386 if (scheduleLoadFallbackResourceFromApplicationCache()) 387 return; 388 } 377 if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForRedirect(this, request, redirectResponse)) 378 return; 389 379 #endif 390 380 willSendRequest(request, redirectResponse); … … 399 389 { 400 390 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 401 if (response.httpStatusCode() / 100 == 4 || response.httpStatusCode() / 100 == 5) { 402 if (scheduleLoadFallbackResourceFromApplicationCache()) 403 return; 404 } 391 if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForResponse(this, response)) 392 return; 405 393 #endif 406 394 didReceiveResponse(response); … … 420 408 { 421 409 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 422 if (!error.isCancellation()) { 423 if (documentLoader()->scheduleLoadFallbackResourceFromApplicationCache(this, m_request)) 424 return; 425 } 410 if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForError(this, error)) 411 return; 426 412 #endif 427 413 didFail(error); -
trunk/WebCore/loader/ResourceLoader.h
r41773 r46609 41 41 namespace WebCore { 42 42 43 class ApplicationCache ;43 class ApplicationCacheHost; 44 44 class DocumentLoader; 45 45 class Frame; … … 120 120 121 121 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 122 bool scheduleLoadFallbackResourceFromApplicationCache(ApplicationCache* = 0);122 friend class ApplicationCacheHost; // for access to request() 123 123 #endif 124 124 … … 134 134 RefPtr<Frame> m_frame; 135 135 RefPtr<DocumentLoader> m_documentLoader; 136 ResourceResponse m_response; 136 ResourceResponse m_response; 137 137 138 138 private: … … 140 140 RefPtr<SharedBuffer> m_resourceData; 141 141 142 unsigned long m_identifier; 142 unsigned long m_identifier; 143 143 144 144 bool m_reachedTerminalState; -
trunk/WebCore/loader/appcache/ApplicationCacheGroup.cpp
r46344 r46609 30 30 31 31 #include "ApplicationCache.h" 32 #include "ApplicationCacheHost.h" 32 33 #include "ApplicationCacheResource.h" 33 34 #include "ApplicationCacheStorage.h" … … 127 128 128 129 DocumentLoader* documentLoader = frame->loader()->documentLoader(); 129 ASSERT(!documentLoader->applicationCache ());130 ASSERT(!documentLoader->applicationCacheHost()->applicationCache()); 130 131 131 132 if (passedManifestURL.isNull()) { … … 138 139 manifestURL.removeRef(); 139 140 140 ApplicationCache* mainResourceCache = documentLoader-> mainResourceApplicationCache();141 ApplicationCache* mainResourceCache = documentLoader->applicationCacheHost()->mainResourceApplicationCache(); 141 142 142 143 if (mainResourceCache) { … … 176 177 // Don't change anything on disk if private browsing is enabled. 177 178 if (!frame->settings() || frame->settings()->privateBrowsingEnabled()) { 178 postListenerTask( &DOMApplicationCache::callCheckingListener, documentLoader);179 postListenerTask( &DOMApplicationCache::callErrorListener, documentLoader);179 postListenerTask(DOMApplicationCache::CHECKING_EVENT, documentLoader); 180 postListenerTask(DOMApplicationCache::ERROR_EVENT, documentLoader); 180 181 return; 181 182 } … … 183 184 ApplicationCacheGroup* group = cacheStorage().findOrCreateCacheGroup(manifestURL); 184 185 185 documentLoader-> setCandidateApplicationCacheGroup(group);186 documentLoader->applicationCacheHost()->setCandidateApplicationCacheGroup(group); 186 187 group->m_pendingMasterResourceLoaders.add(documentLoader); 187 188 group->m_downloadingPendingMasterResourceLoadersCount++; … … 197 198 198 199 DocumentLoader* documentLoader = frame->loader()->documentLoader(); 199 ASSERT(!documentLoader->applicationCache ());200 201 ApplicationCache* mainResourceCache = documentLoader-> mainResourceApplicationCache();200 ASSERT(!documentLoader->applicationCacheHost()->applicationCache()); 201 202 ApplicationCache* mainResourceCache = documentLoader->applicationCacheHost()->mainResourceApplicationCache(); 202 203 203 204 if (mainResourceCache) { … … 236 237 // (its main resource was not cached yet, so it is likely that the application changed significantly server-side). 237 238 ASSERT(!m_cacheBeingUpdated); // Already cleared out by stopLoading(). 238 loader-> setApplicationCache(0); // Will unset candidate, too.239 loader->applicationCacheHost()->setApplicationCache(0); // Will unset candidate, too. 239 240 m_associatedDocumentLoaders.remove(loader); 240 postListenerTask( &DOMApplicationCache::callErrorListener, loader);241 postListenerTask(DOMApplicationCache::ERROR_EVENT, loader); 241 242 break; 242 243 case Completed: … … 272 273 // The manifest didn't change, and we have a relevant cache - but the main resource download failed mid-way, so it cannot be stored to the cache, 273 274 // and the loader does not get associated to it. If there are other main resources being downloaded for this cache group, they may still succeed. 274 postListenerTask( &DOMApplicationCache::callErrorListener, loader);275 postListenerTask(DOMApplicationCache::ERROR_EVENT, loader); 275 276 276 277 break; … … 278 279 // Cache update failed, too. 279 280 ASSERT(!m_cacheBeingUpdated); // Already cleared out by stopLoading(). 280 ASSERT(!loader->applicationCache () || loader->applicationCache() == m_cacheBeingUpdated);281 282 loader-> setApplicationCache(0); // Will unset candidate, too.281 ASSERT(!loader->applicationCacheHost()->applicationCache() || loader->applicationCacheHost()->applicationCache() == m_cacheBeingUpdated); 282 283 loader->applicationCacheHost()->setApplicationCache(0); // Will unset candidate, too. 283 284 m_associatedDocumentLoaders.remove(loader); 284 postListenerTask( &DOMApplicationCache::callErrorListener, loader);285 postListenerTask(DOMApplicationCache::ERROR_EVENT, loader); 285 286 break; 286 287 case Completed: … … 288 289 // so it cannot be stored to the cache. If there are other main resources being downloaded for this cache group, they may still succeed. 289 290 ASSERT(m_associatedDocumentLoaders.contains(loader)); 290 ASSERT(loader->applicationCache () == m_cacheBeingUpdated);291 ASSERT(!loader-> candidateApplicationCacheGroup());291 ASSERT(loader->applicationCacheHost()->applicationCache() == m_cacheBeingUpdated); 292 ASSERT(!loader->applicationCacheHost()->candidateApplicationCacheGroup()); 292 293 m_associatedDocumentLoaders.remove(loader); 293 loader-> setApplicationCache(0);294 295 postListenerTask( &DOMApplicationCache::callErrorListener, loader);294 loader->applicationCacheHost()->setApplicationCache(0); 295 296 postListenerTask(DOMApplicationCache::ERROR_EVENT, loader); 296 297 297 298 break; … … 333 334 m_pendingMasterResourceLoaders.remove(loader); 334 335 335 loader-> setApplicationCache(0); // Will set candidate to 0, too.336 loader->applicationCacheHost()->setApplicationCache(0); // Will set candidate to 0, too. 336 337 337 338 if (!m_associatedDocumentLoaders.isEmpty() || !m_pendingMasterResourceLoaders.isEmpty()) … … 389 390 if (m_updateStatus == Checking || m_updateStatus == Downloading) { 390 391 if (updateOption == ApplicationCacheUpdateWithBrowsingContext) { 391 postListenerTask( &DOMApplicationCache::callCheckingListener, frame->loader()->documentLoader());392 postListenerTask(DOMApplicationCache::CHECKING_EVENT, frame->loader()->documentLoader()); 392 393 if (m_updateStatus == Downloading) 393 postListenerTask( &DOMApplicationCache::callDownloadingListener, frame->loader()->documentLoader());394 postListenerTask(DOMApplicationCache::DOWNLOADING_EVENT, frame->loader()->documentLoader()); 394 395 } 395 396 return; … … 401 402 ASSERT(m_pendingEntries.isEmpty()); 402 403 ASSERT(!m_cacheBeingUpdated); 403 postListenerTask( &DOMApplicationCache::callCheckingListener, frame->loader()->documentLoader());404 postListenerTask( &DOMApplicationCache::callNoUpdateListener, frame->loader()->documentLoader());404 postListenerTask(DOMApplicationCache::CHECKING_EVENT, frame->loader()->documentLoader()); 405 postListenerTask(DOMApplicationCache::NOUPDATE_EVENT, frame->loader()->documentLoader()); 405 406 return; 406 407 } … … 411 412 m_updateStatus = Checking; 412 413 413 postListenerTask( &DOMApplicationCache::callCheckingListener, m_associatedDocumentLoaders);414 postListenerTask(DOMApplicationCache::CHECKING_EVENT, m_associatedDocumentLoaders); 414 415 if (!m_newestCache) { 415 416 ASSERT(updateOption == ApplicationCacheUpdateWithBrowsingContext); 416 postListenerTask( &DOMApplicationCache::callCheckingListener, frame->loader()->documentLoader());417 postListenerTask(DOMApplicationCache::CHECKING_EVENT, frame->loader()->documentLoader()); 417 418 } 418 419 … … 649 650 m_updateStatus = Downloading; 650 651 651 postListenerTask( &DOMApplicationCache::callDownloadingListener, m_associatedDocumentLoaders);652 postListenerTask(DOMApplicationCache::DOWNLOADING_EVENT, m_associatedDocumentLoaders); 652 653 653 654 ASSERT(m_pendingEntries.isEmpty()); … … 699 700 makeObsolete(); 700 701 701 postListenerTask( &DOMApplicationCache::callObsoleteListener, m_associatedDocumentLoaders);702 postListenerTask( &DOMApplicationCache::callErrorListener, m_pendingMasterResourceLoaders);702 postListenerTask(DOMApplicationCache::OBSOLETE_EVENT, m_associatedDocumentLoaders); 703 postListenerTask(DOMApplicationCache::ERROR_EVENT, m_pendingMasterResourceLoaders); 703 704 704 705 stopLoading(); … … 710 711 HashSet<DocumentLoader*>::iterator it = m_pendingMasterResourceLoaders.begin(); 711 712 712 ASSERT((*it)-> candidateApplicationCacheGroup() == this);713 ASSERT(!(*it)->applicationCache ());714 (*it)-> setCandidateApplicationCacheGroup(0);713 ASSERT((*it)->applicationCacheHost()->candidateApplicationCacheGroup() == this); 714 ASSERT(!(*it)->applicationCacheHost()->applicationCache()); 715 (*it)->applicationCacheHost()->setCandidateApplicationCacheGroup(0); 715 716 m_pendingMasterResourceLoaders.remove(it); 716 717 } … … 748 749 cacheStorage().storeNewestCache(this); 749 750 750 postListenerTask( &DOMApplicationCache::callNoUpdateListener, m_associatedDocumentLoaders);751 postListenerTask(DOMApplicationCache::NOUPDATE_EVENT, m_associatedDocumentLoaders); 751 752 break; 752 753 case Failure: 753 754 ASSERT(!m_cacheBeingUpdated); 754 postListenerTask( &DOMApplicationCache::callErrorListener, m_associatedDocumentLoaders);755 postListenerTask(DOMApplicationCache::ERROR_EVENT, m_associatedDocumentLoaders); 755 756 if (m_caches.isEmpty()) { 756 757 ASSERT(m_associatedDocumentLoaders.isEmpty()); … … 781 782 cacheStorage().remove(oldNewestCache.get()); 782 783 // Fire the success events. 783 postListenerTask(isUpgradeAttempt ? &DOMApplicationCache::callUpdateReadyListener : &DOMApplicationCache::callCachedListener, m_associatedDocumentLoaders);784 postListenerTask(isUpgradeAttempt ? DOMApplicationCache::UPDATEREADY_EVENT : DOMApplicationCache::CACHED_EVENT, m_associatedDocumentLoaders); 784 785 } else { 785 786 if (cacheStorage().isMaximumSizeReached() && !m_calledReachedMaxAppCacheSize) { … … 801 802 // Fire the error events to all pending master entries, as well any other cache hosts 802 803 // currently associated with a cache in this group. 803 postListenerTask( &DOMApplicationCache::callErrorListener, m_associatedDocumentLoaders);804 postListenerTask(DOMApplicationCache::ERROR_EVENT, m_associatedDocumentLoaders); 804 805 // Disassociate the pending master entries from the failed new cache. Note that 805 806 // all other loaders in the m_associatedDocumentLoaders are still associated with … … 847 848 EntryMap::const_iterator it = m_pendingEntries.begin(); 848 849 849 postListenerTask( &DOMApplicationCache::callProgressListener, m_associatedDocumentLoaders);850 postListenerTask(DOMApplicationCache::PROGRESS_EVENT, m_associatedDocumentLoaders); 850 851 851 852 ASSERT(!m_currentHandle); … … 911 912 ASSERT(!m_isObsolete); 912 913 913 loader-> setApplicationCache(cache);914 loader->applicationCacheHost()->setApplicationCache(cache); 914 915 915 916 ASSERT(!m_associatedDocumentLoaders.contains(loader)); … … 945 946 946 947 class CallCacheListenerTask : public ScriptExecutionContext::Task { 947 typedef void (DOMApplicationCache::*ListenerFunction)();948 948 public: 949 static PassRefPtr<CallCacheListenerTask> create( ListenerFunction listenerFunction)949 static PassRefPtr<CallCacheListenerTask> create(PassRefPtr<DocumentLoader> loader, DOMApplicationCache::EventType eventType) 950 950 { 951 return adoptRef(new CallCacheListenerTask(l istenerFunction));951 return adoptRef(new CallCacheListenerTask(loader, eventType)); 952 952 } 953 953 954 954 virtual void performTask(ScriptExecutionContext* context) 955 955 { 956 ASSERT(context->isDocument()); 957 if (DOMWindow* window = static_cast<Document*>(context)->domWindow()) { 958 if (DOMApplicationCache* domCache = window->optionalApplicationCache()) 959 (domCache->*m_listenerFunction)(); 960 } 956 957 ASSERT_UNUSED(context, context->isDocument()); 958 Frame* frame = m_documentLoader->frame(); 959 if (!frame) 960 return; 961 962 ASSERT(frame->loader()->documentLoader() == m_documentLoader.get()); 963 964 m_documentLoader->applicationCacheHost()->notifyEventListener(m_eventType); 961 965 } 962 966 963 967 private: 964 CallCacheListenerTask(ListenerFunction listenerFunction) 965 : m_listenerFunction(listenerFunction) 968 CallCacheListenerTask(PassRefPtr<DocumentLoader> loader, DOMApplicationCache::EventType eventType) 969 : m_documentLoader(loader) 970 , m_eventType(eventType) 966 971 { 967 972 } 968 973 969 ListenerFunction m_listenerFunction; 974 RefPtr<DocumentLoader> m_documentLoader; 975 DOMApplicationCache::EventType m_eventType; 970 976 }; 971 977 972 void ApplicationCacheGroup::postListenerTask( ListenerFunction listenerFunction, const HashSet<DocumentLoader*>& loaderSet)978 void ApplicationCacheGroup::postListenerTask(DOMApplicationCache::EventType eventType, const HashSet<DocumentLoader*>& loaderSet) 973 979 { 974 980 HashSet<DocumentLoader*>::const_iterator loaderSetEnd = loaderSet.end(); 975 981 for (HashSet<DocumentLoader*>::const_iterator iter = loaderSet.begin(); iter != loaderSetEnd; ++iter) 976 postListenerTask( listenerFunction, *iter);977 } 978 979 void ApplicationCacheGroup::postListenerTask( ListenerFunction listenerFunction, DocumentLoader* loader)982 postListenerTask(eventType, *iter); 983 } 984 985 void ApplicationCacheGroup::postListenerTask(DOMApplicationCache::EventType eventType, DocumentLoader* loader) 980 986 { 981 987 Frame* frame = loader->frame(); … … 985 991 ASSERT(frame->loader()->documentLoader() == loader); 986 992 987 frame->document()->postTask(CallCacheListenerTask::create(l istenerFunction));993 frame->document()->postTask(CallCacheListenerTask::create(loader, eventType)); 988 994 } 989 995 -
trunk/WebCore/loader/appcache/ApplicationCacheGroup.h
r46344 r46609 33 33 #include <wtf/HashSet.h> 34 34 35 #include "DOMApplicationCache.h" 35 36 #include "KURL.h" 36 37 #include "PlatformString.h" … … 43 44 class ApplicationCache; 44 45 class ApplicationCacheResource; 45 class DOMApplicationCache;46 46 class Document; 47 47 class DocumentLoader; … … 93 93 private: 94 94 typedef void (DOMApplicationCache::*ListenerFunction)(); 95 static void postListenerTask(ListenerFunction, const HashSet<DocumentLoader*>&); 96 static void postListenerTask(ListenerFunction, const Vector<RefPtr<DocumentLoader> >& loaders); 97 static void postListenerTask(ListenerFunction, DocumentLoader*); 95 static void postListenerTask(DOMApplicationCache::EventType, const HashSet<DocumentLoader*>&); 96 static void postListenerTask(DOMApplicationCache::EventType, DocumentLoader*); 98 97 void scheduleReachedMaxAppCacheSizeCallback(); 99 98 -
trunk/WebCore/loader/appcache/ApplicationCacheStorage.cpp
r46353 r46609 30 30 31 31 #include "ApplicationCache.h" 32 #include "ApplicationCacheHost.h" 32 33 #include "ApplicationCacheGroup.h" 33 34 #include "ApplicationCacheResource.h" … … 938 939 } 939 940 941 bool ApplicationCacheStorage::transferApplicationCache(const String& cacheDirectory, ApplicationCacheHost* cacheHost) 942 { 943 ApplicationCache* cache = cacheHost->applicationCache(); 944 if (!cache) 945 return true; 946 return ApplicationCacheStorage::storeCopyOfCache(cacheDirectory, cache); 947 } 948 940 949 bool ApplicationCacheStorage::storeCopyOfCache(const String& cacheDirectory, ApplicationCache* cache) 941 950 { -
trunk/WebCore/loader/appcache/ApplicationCacheStorage.h
r46344 r46609 38 38 39 39 class ApplicationCache; 40 class ApplicationCacheHost; 40 41 class ApplicationCacheGroup; 41 42 class ApplicationCacheResource; … … 70 71 void empty(); 71 72 73 static bool transferApplicationCache(const String& cacheDirectory, ApplicationCacheHost*); 72 74 static bool storeCopyOfCache(const String& cacheDirectory, ApplicationCache*); 73 75 -
trunk/WebCore/loader/appcache/DOMApplicationCache.cpp
r44943 r46609 29 29 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 30 30 31 #include "ApplicationCache.h" 32 #include "ApplicationCacheGroup.h" 33 #include "ApplicationCacheResource.h" 31 #include "ApplicationCacheHost.h" 34 32 #include "DocumentLoader.h" 35 33 #include "Event.h" … … 45 43 : m_frame(frame) 46 44 { 45 ASSERT(applicationCacheHost()); 46 applicationCacheHost()->setDOMApplicationCache(this); 47 47 } 48 48 49 49 void DOMApplicationCache::disconnectFrame() 50 50 { 51 ApplicationCacheHost* cacheHost = applicationCacheHost(); 52 if (cacheHost) 53 cacheHost->setDOMApplicationCache(0); 51 54 m_frame = 0; 52 55 } 53 56 54 ApplicationCache * DOMApplicationCache::associatedCache() const55 { 56 if (!m_frame )57 ApplicationCacheHost* DOMApplicationCache::applicationCacheHost() const 58 { 59 if (!m_frame || !m_frame->loader()->documentLoader()) 57 60 return 0; 58 59 return m_frame->loader()->documentLoader()->applicationCache(); 61 return m_frame->loader()->documentLoader()->applicationCacheHost(); 60 62 } 61 63 62 64 unsigned short DOMApplicationCache::status() const 63 65 { 64 ApplicationCache * cache = associatedCache();65 if (!cache )66 ApplicationCacheHost* cacheHost = applicationCacheHost(); 67 if (!cacheHost) 66 68 return UNCACHED; 67 68 switch (cache->group()->updateStatus()) { 69 case ApplicationCacheGroup::Checking: 70 return CHECKING; 71 case ApplicationCacheGroup::Downloading: 72 return DOWNLOADING; 73 case ApplicationCacheGroup::Idle: { 74 if (cache->group()->isObsolete()) 75 return OBSOLETE; 76 if (cache != cache->group()->newestCache()) 77 return UPDATEREADY; 78 return IDLE; 79 } 80 } 81 82 ASSERT_NOT_REACHED(); 83 return 0; 69 return cacheHost->status(); 84 70 } 85 71 86 72 void DOMApplicationCache::update(ExceptionCode& ec) 87 73 { 88 ApplicationCache * cache = associatedCache();89 if (!cache ) {74 ApplicationCacheHost* cacheHost = applicationCacheHost(); 75 if (!cacheHost || !cacheHost->update()) 90 76 ec = INVALID_STATE_ERR; 91 return;92 }93 94 cache->group()->update(m_frame, ApplicationCacheUpdateWithoutBrowsingContext);95 77 } 96 78 97 79 bool DOMApplicationCache::swapCache() 98 80 { 99 if (!m_frame) 81 ApplicationCacheHost* cacheHost = applicationCacheHost(); 82 if (!cacheHost) 100 83 return false; 101 102 ApplicationCache* cache = m_frame->loader()->documentLoader()->applicationCache(); 103 if (!cache) 104 return false; 105 106 // If the group of application caches to which cache belongs has the lifecycle status obsolete, unassociate document from cache. 107 if (cache->group()->isObsolete()) { 108 cache->group()->disassociateDocumentLoader(m_frame->loader()->documentLoader()); 109 return true; 110 } 111 112 // If there is no newer cache, raise an INVALID_STATE_ERR exception. 113 ApplicationCache* newestCache = cache->group()->newestCache(); 114 if (cache == newestCache) 115 return false; 116 117 ASSERT(cache->group() == newestCache->group()); 118 m_frame->loader()->documentLoader()->setApplicationCache(newestCache); 119 120 return true; 84 return cacheHost->swapCache(); 121 85 } 122 86 … … 132 96 } 133 97 134 void DOMApplicationCache::addEventListener(const AtomicString& event Type, PassRefPtr<EventListener> eventListener, bool)135 { 136 EventListenersMap::iterator iter = m_eventListeners.find(event Type);98 void DOMApplicationCache::addEventListener(const AtomicString& eventName, PassRefPtr<EventListener> eventListener, bool) 99 { 100 EventListenersMap::iterator iter = m_eventListeners.find(eventName); 137 101 if (iter == m_eventListeners.end()) { 138 102 ListenerVector listeners; 139 103 listeners.append(eventListener); 140 m_eventListeners.add(event Type, listeners);104 m_eventListeners.add(eventName, listeners); 141 105 } else { 142 106 ListenerVector& listeners = iter->second; … … 147 111 148 112 listeners.append(eventListener); 149 m_eventListeners.add(event Type, listeners);113 m_eventListeners.add(eventName, listeners); 150 114 } 151 115 } 152 116 153 void DOMApplicationCache::removeEventListener(const AtomicString& event Type, EventListener* eventListener, bool)154 { 155 EventListenersMap::iterator iter = m_eventListeners.find(event Type);117 void DOMApplicationCache::removeEventListener(const AtomicString& eventName, EventListener* eventListener, bool) 118 { 119 EventListenersMap::iterator iter = m_eventListeners.find(eventName); 156 120 if (iter == m_eventListeners.end()) 157 121 return; … … 172 136 return true; 173 137 } 174 138 175 139 ListenerVector listenersCopy = m_eventListeners.get(event->type()); 176 140 for (ListenerVector::const_iterator listenerIter = listenersCopy.begin(); listenerIter != listenersCopy.end(); ++listenerIter) { … … 183 147 } 184 148 185 void DOMApplicationCache::callListener(const AtomicString& event Type, EventListener* listener)149 void DOMApplicationCache::callListener(const AtomicString& eventName, EventListener* listener) 186 150 { 187 151 ASSERT(m_frame); 188 152 189 RefPtr<Event> event = Event::create(event Type, false, false);153 RefPtr<Event> event = Event::create(eventName, false, false); 190 154 if (listener) { 191 155 event->setTarget(this); … … 199 163 } 200 164 201 void DOMApplicationCache::callCheckingListener() 202 { 203 callListener(eventNames().checkingEvent, m_onCheckingListener.get()); 204 } 205 206 void DOMApplicationCache::callErrorListener() 207 { 208 callListener(eventNames().errorEvent, m_onErrorListener.get()); 209 } 210 211 void DOMApplicationCache::callNoUpdateListener() 212 { 213 callListener(eventNames().noupdateEvent, m_onNoUpdateListener.get()); 214 } 215 216 void DOMApplicationCache::callDownloadingListener() 217 { 218 callListener(eventNames().downloadingEvent, m_onDownloadingListener.get()); 219 } 220 221 void DOMApplicationCache::callProgressListener() 222 { 223 callListener(eventNames().progressEvent, m_onProgressListener.get()); 224 } 225 226 void DOMApplicationCache::callUpdateReadyListener() 227 { 228 callListener(eventNames().updatereadyEvent, m_onUpdateReadyListener.get()); 229 } 230 231 void DOMApplicationCache::callCachedListener() 232 { 233 callListener(eventNames().cachedEvent, m_onCachedListener.get()); 234 } 235 236 void DOMApplicationCache::callObsoleteListener() 237 { 238 callListener(eventNames().obsoleteEvent, m_onObsoleteListener.get()); 239 } 165 // static 166 const AtomicString& DOMApplicationCache::toEventName(EventType eventType) 167 { 168 switch (eventType) { 169 case CHECKING_EVENT: 170 return eventNames().checkingEvent; 171 case ERROR_EVENT: 172 return eventNames().errorEvent; 173 case NOUPDATE_EVENT: 174 return eventNames().noupdateEvent; 175 case DOWNLOADING_EVENT: 176 return eventNames().downloadingEvent; 177 case PROGRESS_EVENT: 178 return eventNames().progressEvent; 179 case UPDATEREADY_EVENT: 180 return eventNames().updatereadyEvent; 181 case CACHED_EVENT: 182 return eventNames().cachedEvent; 183 case OBSOLETE_EVENT: 184 return eventNames().obsoleteEvent; 185 } 186 ASSERT_NOT_REACHED(); 187 return eventNames().errorEvent; 188 } 189 190 // static 191 DOMApplicationCache::EventType DOMApplicationCache::toEventType(const AtomicString& eventName) 192 { 193 if (eventName == eventNames().checkingEvent) 194 return CHECKING_EVENT; 195 if (eventName == eventNames().errorEvent) 196 return ERROR_EVENT; 197 if (eventName == eventNames().noupdateEvent) 198 return NOUPDATE_EVENT; 199 if (eventName == eventNames().downloadingEvent) 200 return DOWNLOADING_EVENT; 201 if (eventName == eventNames().progressEvent) 202 return PROGRESS_EVENT; 203 if (eventName == eventNames().updatereadyEvent) 204 return UPDATEREADY_EVENT; 205 if (eventName == eventNames().cachedEvent) 206 return CACHED_EVENT; 207 if (eventName == eventNames().obsoleteEvent) 208 return OBSOLETE_EVENT; 209 210 ASSERT_NOT_REACHED(); 211 return ERROR_EVENT; 212 } 213 240 214 241 215 } // namespace WebCore -
trunk/WebCore/loader/appcache/DOMApplicationCache.h
r44943 r46609 39 39 namespace WebCore { 40 40 41 class ApplicationCache ;41 class ApplicationCacheHost; 42 42 class AtomicStringImpl; 43 43 class Frame; … … 48 48 public: 49 49 static PassRefPtr<DOMApplicationCache> create(Frame* frame) { return adoptRef(new DOMApplicationCache(frame)); } 50 ~DOMApplicationCache() { ASSERT(!m_frame); } 51 50 52 void disconnectFrame(); 51 53 … … 59 61 }; 60 62 63 enum EventType { 64 CHECKING_EVENT = 0, 65 ERROR_EVENT, 66 NOUPDATE_EVENT, 67 DOWNLOADING_EVENT, 68 PROGRESS_EVENT, 69 UPDATEREADY_EVENT, 70 CACHED_EVENT, 71 OBSOLETE_EVENT 72 }; 73 61 74 unsigned short status() const; 62 63 75 void update(ExceptionCode&); 64 76 void swapCache(ExceptionCode&); 65 66 virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture); 67 virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture); 77 78 // Event listener attributes by EventType 79 80 void setAttributeEventListener(EventType type, PassRefPtr<EventListener> eventListener) { m_attributeEventListeners[type] = eventListener; } 81 EventListener* getAttributeEventListener(EventType type) const { return m_attributeEventListeners[type].get(); } 82 void clearAttributeEventListener(EventType type) { m_attributeEventListeners[type] = 0; } 83 void callEventListener(EventType type) { callListener(toEventName(type), getAttributeEventListener(type)); } 84 85 // EventTarget impl 86 87 virtual void addEventListener(const AtomicString& eventName, PassRefPtr<EventListener>, bool useCapture); 88 virtual void removeEventListener(const AtomicString& eventName, EventListener*, bool useCapture); 68 89 virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); 69 70 90 typedef Vector<RefPtr<EventListener> > ListenerVector; 71 91 typedef HashMap<AtomicString, ListenerVector> EventListenersMap; … … 75 95 using RefCounted<DOMApplicationCache>::deref; 76 96 77 void setOnchecking(PassRefPtr<EventListener> eventListener) { m_onCheckingListener = eventListener; } 78 EventListener* onchecking() const { return m_onCheckingListener.get(); } 97 // Explicitly named attribute event listener helpers 79 98 80 void setOn error(PassRefPtr<EventListener> eventListener) { m_onErrorListener = eventListener; }81 EventListener* on error() const { return m_onErrorListener.get(); }99 void setOnchecking(PassRefPtr<EventListener> listener) { setAttributeEventListener(CHECKING_EVENT, listener); } 100 EventListener* onchecking() const { return getAttributeEventListener(CHECKING_EVENT); } 82 101 83 void setOn noupdate(PassRefPtr<EventListener> eventListener) { m_onNoUpdateListener = eventListener;}84 EventListener* on noupdate() const { return m_onNoUpdateListener.get(); }102 void setOnerror(PassRefPtr<EventListener> listener) { setAttributeEventListener(ERROR_EVENT, listener);} 103 EventListener* onerror() const { return getAttributeEventListener(ERROR_EVENT); } 85 104 86 void setOndownloading(PassRefPtr<EventListener> eventListener) { m_onDownloadingListener = eventListener; } 87 EventListener* ondownloading() const { return m_onDownloadingListener.get(); } 88 89 void setOnprogress(PassRefPtr<EventListener> eventListener) { m_onProgressListener = eventListener; } 90 EventListener* onprogress() const { return m_onProgressListener.get(); } 105 void setOnnoupdate(PassRefPtr<EventListener> listener) { setAttributeEventListener(NOUPDATE_EVENT, listener); } 106 EventListener* onnoupdate() const { return getAttributeEventListener(NOUPDATE_EVENT); } 91 107 92 void setOn updateready(PassRefPtr<EventListener> eventListener) { m_onUpdateReadyListener = eventListener; }93 EventListener* on updateready() const { return m_onUpdateReadyListener.get(); }108 void setOndownloading(PassRefPtr<EventListener> listener) { setAttributeEventListener(DOWNLOADING_EVENT, listener); } 109 EventListener* ondownloading() const { return getAttributeEventListener(DOWNLOADING_EVENT); } 94 110 95 void setOn cached(PassRefPtr<EventListener> eventListener) { m_onCachedListener = eventListener; }96 EventListener* on cached() const { return m_onCachedListener.get(); }111 void setOnprogress(PassRefPtr<EventListener> listener) { setAttributeEventListener(PROGRESS_EVENT, listener); } 112 EventListener* onprogress() const { return getAttributeEventListener(PROGRESS_EVENT); } 97 113 98 void setOnobsolete(PassRefPtr<EventListener> eventListener) { m_onObsoleteListener = eventListener; } 99 EventListener* onobsolete() const { return m_onObsoleteListener.get(); } 114 void setOnupdateready(PassRefPtr<EventListener> listener) { setAttributeEventListener(UPDATEREADY_EVENT, listener); } 115 EventListener* onupdateready() const { return getAttributeEventListener(UPDATEREADY_EVENT); } 116 117 void setOncached(PassRefPtr<EventListener> listener) { setAttributeEventListener(CACHED_EVENT, listener); } 118 EventListener* oncached() const { return getAttributeEventListener(CACHED_EVENT); } 119 120 void setOnobsolete(PassRefPtr<EventListener> listener) { setAttributeEventListener(OBSOLETE_EVENT, listener); } 121 EventListener* onobsolete() const { return getAttributeEventListener(OBSOLETE_EVENT); } 100 122 101 123 virtual ScriptExecutionContext* scriptExecutionContext() const; 102 124 DOMApplicationCache* toDOMApplicationCache() { return this; } 103 125 104 void callCheckingListener(); 105 void callErrorListener(); 106 void callNoUpdateListener(); 107 void callDownloadingListener(); 108 void callProgressListener(); 109 void callUpdateReadyListener(); 110 void callCachedListener(); 111 void callObsoleteListener(); 112 126 static const AtomicString& toEventName(EventType eventType); 127 static EventType toEventType(const AtomicString& eventName); 128 113 129 private: 114 130 DOMApplicationCache(Frame*); 115 void callListener(const AtomicString& eventType, EventListener*); 131 132 void callListener(const AtomicString& eventName, EventListener*); 116 133 117 134 virtual void refEventTarget() { ref(); } 118 135 virtual void derefEventTarget() { deref(); } 119 136 120 ApplicationCache * associatedCache() const;137 ApplicationCacheHost* applicationCacheHost() const; 121 138 bool swapCache(); 122 139 123 RefPtr<EventListener> m_onCheckingListener; 124 RefPtr<EventListener> m_onErrorListener; 125 RefPtr<EventListener> m_onNoUpdateListener; 126 RefPtr<EventListener> m_onDownloadingListener; 127 RefPtr<EventListener> m_onProgressListener; 128 RefPtr<EventListener> m_onUpdateReadyListener; 129 RefPtr<EventListener> m_onCachedListener; 130 RefPtr<EventListener> m_onObsoleteListener; 131 140 RefPtr<EventListener> m_attributeEventListeners[OBSOLETE_EVENT + 1]; 141 132 142 EventListenersMap m_eventListeners; 133 143 -
trunk/WebCore/platform/KURLGoogle.cpp
r43941 r46609 958 958 } 959 959 960 bool protocolHostAndPortAreEqual(const KURL& a, const KURL& b) 961 { 962 if (a.parsed().scheme.end() != b.parsed().scheme.end()) 963 return false; 964 965 int hostStartA = a.hostStart(); 966 int hostStartB = b.hostStart(); 967 if (a.hostEnd() - hostStartA != b.hostEnd() - hostStartB) 968 return false; 969 970 // Check the scheme 971 for (int i = 0; i < a.parsed().scheme.end(); ++i) 972 if (a.string()[i] != b.string()[i]) 973 return false; 974 975 // And the host 976 for (int i = hostStartA; i < static_cast<int>(a.hostEnd()); ++i) 977 if (a.string()[i] != b.string()[i]) 978 return false; 979 980 if (a.port() != b.port()) 981 return false; 982 983 return true; 984 } 985 960 986 } // namespace WebCore 961 987 -
trunk/WebKit/mac/ChangeLog
r46565 r46609 1 2009-07-30 Michael Nordman <michaeln@google.com> 2 3 Reviewed by Darin Fisher. 4 5 https://bugs.webkit.org/show_bug.cgi?id=27821 6 7 Mods to keep up with ApplicationCacheHost refactoring. 8 9 * WebView/WebDataSource.mm: 10 (-[WebDataSource _transferApplicationCache:]): 11 1 12 2009-07-29 David Kilzer <ddkilzer@apple.com> 2 13 -
trunk/WebKit/mac/WebView/WebDataSource.mm
r46384 r46609 199 199 if (!loader) 200 200 return NO; 201 202 ApplicationCache* cache = loader->applicationCache(); 203 if (!cache) 204 return YES; 205 201 206 202 NSString *cacheDir = [NSString _webkit_localCacheDirectoryWithBundleIdentifier:destinationBundleIdentifier]; 207 203 208 return ApplicationCacheStorage:: storeCopyOfCache(cacheDir, cache);204 return ApplicationCacheStorage::transferApplicationCache(cacheDir, loader->applicationCacheHost()); 209 205 } 210 206
Note: See TracChangeset
for help on using the changeset viewer.