Commit 6042aeab authored by darin@chromium.org's avatar darin@chromium.org

2009-07-30 Michael Nordman <michaeln@google.com>

        Reviewed by Darin Fisher.

        https://bugs.webkit.org/show_bug.cgi?id=27821

        ApplicationCacheHost refactoring.
        
        1) Better encapsulate the interfaces between webcore common code
        and the appcache system within a new class ApplicationCacheHost.

        2) Use that interface throughout the loader system, replacing inline appcache logic.

        3) Implement the interface in terms of webcore's appcache system.

        4) Add the new files to various makefiles.

        5) Implement protocolHostAndPortAreEqual() in KURLGoogle.cpp

        No new features, no new tests. The existing layout tests all pass.

        * GNUmakefile.am:
        * WebCore.base.exp:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        * html/HTMLHtmlElement.cpp:
        (WebCore::HTMLHtmlElement::insertedIntoDocument):
        * loader/DocumentLoader.cpp:
        (WebCore::DocumentLoader::DocumentLoader):
        (WebCore::DocumentLoader::~DocumentLoader):
        (WebCore::DocumentLoader::mainReceivedError):
        (WebCore::DocumentLoader::detachFromFrame):
        (WebCore::DocumentLoader::setPrimaryLoadComplete):
        * loader/DocumentLoader.h:
        (WebCore::DocumentLoader::applicationCacheHost):
        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::canCachePageContainingThisFrame):
        (WebCore::FrameLoader::logCanCacheFrameDecision):
        (WebCore::FrameLoader::loadResourceSynchronously):
        * loader/MainResourceLoader.cpp:
        (WebCore::MainResourceLoader::didReceiveResponse):
        (WebCore::MainResourceLoader::didReceiveData):
        (WebCore::MainResourceLoader::didFinishLoading):
        (WebCore::MainResourceLoader::didFail):
        (WebCore::MainResourceLoader::load):
        * loader/MainResourceLoader.h:
        * loader/ResourceLoader.cpp:
        (WebCore::ResourceLoader::load):
        (WebCore::ResourceLoader::willSendRequest):
        (WebCore::ResourceLoader::didReceiveResponse):
        (WebCore::ResourceLoader::didFail):
        * loader/ResourceLoader.h:
        * loader/appcache/ApplicationCacheGroup.cpp:
        (WebCore::ApplicationCacheGroup::selectCache):
        (WebCore::ApplicationCacheGroup::selectCacheWithoutManifestURL):
        (WebCore::ApplicationCacheGroup::finishedLoadingMainResource):
        (WebCore::ApplicationCacheGroup::failedLoadingMainResource):
        (WebCore::ApplicationCacheGroup::disassociateDocumentLoader):
        (WebCore::ApplicationCacheGroup::update):
        (WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
        (WebCore::ApplicationCacheGroup::manifestNotFound):
        (WebCore::ApplicationCacheGroup::checkIfLoadIsComplete):
        (WebCore::ApplicationCacheGroup::startLoadingEntry):
        (WebCore::ApplicationCacheGroup::associateDocumentLoaderWithCache):
        (WebCore::CallCacheListenerTask::create):
        (WebCore::CallCacheListenerTask::performTask):
        (WebCore::CallCacheListenerTask::CallCacheListenerTask):
        (WebCore::ApplicationCacheGroup::postListenerTask):
        * loader/appcache/ApplicationCacheGroup.h:
        * loader/appcache/ApplicationCacheHost.cpp: Added.
        * loader/appcache/ApplicationCacheHost.h: Added.
        * loader/appcache/ApplicationCacheStorage.cpp:
        (WebCore::ApplicationCacheStorage::transferApplicationCache):
        * loader/appcache/ApplicationCacheStorage.h:
        * loader/appcache/DOMApplicationCache.cpp:
        (WebCore::DOMApplicationCache::DOMApplicationCache):
        (WebCore::DOMApplicationCache::disconnectFrame):
        (WebCore::DOMApplicationCache::applicationCacheHost):
        (WebCore::DOMApplicationCache::status):
        (WebCore::DOMApplicationCache::update):
        (WebCore::DOMApplicationCache::swapCache):
        (WebCore::DOMApplicationCache::addEventListener):
        (WebCore::DOMApplicationCache::removeEventListener):
        (WebCore::DOMApplicationCache::dispatchEvent):
        (WebCore::DOMApplicationCache::callListener):
        (WebCore::DOMApplicationCache::toEventName):
        (WebCore::DOMApplicationCache::toEventType):
        * loader/appcache/DOMApplicationCache.h:
        (WebCore::DOMApplicationCache::):
        (WebCore::DOMApplicationCache::setAttributeEventListener):
        (WebCore::DOMApplicationCache::getAttributeEventListener):
        (WebCore::DOMApplicationCache::clearAttributeEventListener):
        (WebCore::DOMApplicationCache::callEventListener):
        (WebCore::DOMApplicationCache::setOnchecking):
        (WebCore::DOMApplicationCache::onchecking):
        (WebCore::DOMApplicationCache::setOnerror):
        (WebCore::DOMApplicationCache::onerror):
        (WebCore::DOMApplicationCache::setOnnoupdate):
        (WebCore::DOMApplicationCache::onnoupdate):
        (WebCore::DOMApplicationCache::setOndownloading):
        (WebCore::DOMApplicationCache::ondownloading):
        (WebCore::DOMApplicationCache::setOnprogress):
        (WebCore::DOMApplicationCache::onprogress):
        (WebCore::DOMApplicationCache::setOnupdateready):
        (WebCore::DOMApplicationCache::onupdateready):
        (WebCore::DOMApplicationCache::setOncached):
        (WebCore::DOMApplicationCache::oncached):
        (WebCore::DOMApplicationCache::setOnobsolete):
        (WebCore::DOMApplicationCache::onobsolete):
        (WebCore::DOMApplicationCache::~DOMApplicationCache):
        * platform/KURLGoogle.cpp:
        (WebCore::protocolHostAndPortAreEqual):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8a7ad686
2009-07-30 Michael Nordman <michaeln@google.com>
Reviewed by Darin Fisher.
https://bugs.webkit.org/show_bug.cgi?id=27821
ApplicationCacheHost refactoring.
1) Better encapsulate the interfaces between webcore common code
and the appcache system within a new class ApplicationCacheHost.
2) Use that interface throughout the loader system, replacing inline appcache logic.
3) Implement the interface in terms of webcore's appcache system.
4) Add the new files to various makefiles.
5) Implement protocolHostAndPortAreEqual() in KURLGoogle.cpp
No new features, no new tests. The existing layout tests all pass.
* GNUmakefile.am:
* WebCore.base.exp:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* WebCoreSources.bkl:
* html/HTMLHtmlElement.cpp:
(WebCore::HTMLHtmlElement::insertedIntoDocument):
* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::DocumentLoader):
(WebCore::DocumentLoader::~DocumentLoader):
(WebCore::DocumentLoader::mainReceivedError):
(WebCore::DocumentLoader::detachFromFrame):
(WebCore::DocumentLoader::setPrimaryLoadComplete):
* loader/DocumentLoader.h:
(WebCore::DocumentLoader::applicationCacheHost):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::canCachePageContainingThisFrame):
(WebCore::FrameLoader::logCanCacheFrameDecision):
(WebCore::FrameLoader::loadResourceSynchronously):
* loader/MainResourceLoader.cpp:
(WebCore::MainResourceLoader::didReceiveResponse):
(WebCore::MainResourceLoader::didReceiveData):
(WebCore::MainResourceLoader::didFinishLoading):
(WebCore::MainResourceLoader::didFail):
(WebCore::MainResourceLoader::load):
* loader/MainResourceLoader.h:
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::load):
(WebCore::ResourceLoader::willSendRequest):
(WebCore::ResourceLoader::didReceiveResponse):
(WebCore::ResourceLoader::didFail):
* loader/ResourceLoader.h:
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::selectCache):
(WebCore::ApplicationCacheGroup::selectCacheWithoutManifestURL):
(WebCore::ApplicationCacheGroup::finishedLoadingMainResource):
(WebCore::ApplicationCacheGroup::failedLoadingMainResource):
(WebCore::ApplicationCacheGroup::disassociateDocumentLoader):
(WebCore::ApplicationCacheGroup::update):
(WebCore::ApplicationCacheGroup::didFinishLoadingManifest):
(WebCore::ApplicationCacheGroup::manifestNotFound):
(WebCore::ApplicationCacheGroup::checkIfLoadIsComplete):
(WebCore::ApplicationCacheGroup::startLoadingEntry):
(WebCore::ApplicationCacheGroup::associateDocumentLoaderWithCache):
(WebCore::CallCacheListenerTask::create):
(WebCore::CallCacheListenerTask::performTask):
(WebCore::CallCacheListenerTask::CallCacheListenerTask):
(WebCore::ApplicationCacheGroup::postListenerTask):
* loader/appcache/ApplicationCacheGroup.h:
* loader/appcache/ApplicationCacheHost.cpp: Added.
* loader/appcache/ApplicationCacheHost.h: Added.
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::transferApplicationCache):
* loader/appcache/ApplicationCacheStorage.h:
* loader/appcache/DOMApplicationCache.cpp:
(WebCore::DOMApplicationCache::DOMApplicationCache):
(WebCore::DOMApplicationCache::disconnectFrame):
(WebCore::DOMApplicationCache::applicationCacheHost):
(WebCore::DOMApplicationCache::status):
(WebCore::DOMApplicationCache::update):
(WebCore::DOMApplicationCache::swapCache):
(WebCore::DOMApplicationCache::addEventListener):
(WebCore::DOMApplicationCache::removeEventListener):
(WebCore::DOMApplicationCache::dispatchEvent):
(WebCore::DOMApplicationCache::callListener):
(WebCore::DOMApplicationCache::toEventName):
(WebCore::DOMApplicationCache::toEventType):
* loader/appcache/DOMApplicationCache.h:
(WebCore::DOMApplicationCache::):
(WebCore::DOMApplicationCache::setAttributeEventListener):
(WebCore::DOMApplicationCache::getAttributeEventListener):
(WebCore::DOMApplicationCache::clearAttributeEventListener):
(WebCore::DOMApplicationCache::callEventListener):
(WebCore::DOMApplicationCache::setOnchecking):
(WebCore::DOMApplicationCache::onchecking):
(WebCore::DOMApplicationCache::setOnerror):
(WebCore::DOMApplicationCache::onerror):
(WebCore::DOMApplicationCache::setOnnoupdate):
(WebCore::DOMApplicationCache::onnoupdate):
(WebCore::DOMApplicationCache::setOndownloading):
(WebCore::DOMApplicationCache::ondownloading):
(WebCore::DOMApplicationCache::setOnprogress):
(WebCore::DOMApplicationCache::onprogress):
(WebCore::DOMApplicationCache::setOnupdateready):
(WebCore::DOMApplicationCache::onupdateready):
(WebCore::DOMApplicationCache::setOncached):
(WebCore::DOMApplicationCache::oncached):
(WebCore::DOMApplicationCache::setOnobsolete):
(WebCore::DOMApplicationCache::onobsolete):
(WebCore::DOMApplicationCache::~DOMApplicationCache):
* platform/KURLGoogle.cpp:
(WebCore::protocolHostAndPortAreEqual):
2009-07-30 Chris Fleizach <cfleizach@apple.com>
Reviewed by Darin Adler.
......
......@@ -2006,6 +2006,8 @@ webcore_sources += \
WebCore/loader/appcache/ApplicationCache.h \
WebCore/loader/appcache/ApplicationCacheGroup.cpp \
WebCore/loader/appcache/ApplicationCacheGroup.h \
WebCore/loader/appcache/ApplicationCacheHost.cpp \
WebCore/loader/appcache/ApplicationCacheHost.h \
WebCore/loader/appcache/ApplicationCacheResource.cpp \
WebCore/loader/appcache/ApplicationCacheResource.h \
WebCore/loader/appcache/ApplicationCacheStorage.cpp \
......
......@@ -443,7 +443,7 @@ __ZN7WebCore22applicationIsAppleMailEv
__ZN7WebCore22createFragmentFromTextEPNS_5RangeERKNS_6StringE
__ZN7WebCore22externalRepresentationEPNS_12RenderObjectE
__ZN7WebCore23ApplicationCacheStorage14setMaximumSizeEx
__ZN7WebCore23ApplicationCacheStorage16storeCopyOfCacheERKNS_6StringEPNS_16ApplicationCacheE
__ZN7WebCore23ApplicationCacheStorage24transferApplicationCacheERKNS_6StringEPNS_20ApplicationCacheHostE
__ZN7WebCore23ApplicationCacheStorage17setCacheDirectoryERKNS_6StringE
__ZN7WebCore23ApplicationCacheStorage18vacuumDatabaseFileEv
__ZN7WebCore23ApplicationCacheStorage5emptyEv
......
......@@ -1425,6 +1425,8 @@
'loader/appcache/ApplicationCache.h',
'loader/appcache/ApplicationCacheGroup.cpp',
'loader/appcache/ApplicationCacheGroup.h',
'loader/appcache/ApplicationCacheHost.cpp',
'loader/appcache/ApplicationCacheHost.h',
'loader/appcache/ApplicationCacheResource.cpp',
'loader/appcache/ApplicationCacheResource.h',
'loader/appcache/ApplicationCacheStorage.cpp',
......
......@@ -1513,6 +1513,7 @@ HEADERS += \
inspector/JavaScriptProfile.h \
inspector/JavaScriptProfileNode.h \
loader/appcache/ApplicationCacheGroup.h \
loader/appcache/ApplicationCacheHost.h \
loader/appcache/ApplicationCache.h \
loader/appcache/ApplicationCacheResource.h \
loader/appcache/ApplicationCacheStorage.h \
......@@ -3033,6 +3034,7 @@ IDL_BINDINGS += \
SOURCES += \
loader/appcache/ApplicationCache.cpp \
loader/appcache/ApplicationCacheGroup.cpp \
loader/appcache/ApplicationCacheHost.cpp \
loader/appcache/ApplicationCacheStorage.cpp \
loader/appcache/ApplicationCacheResource.cpp \
loader/appcache/DOMApplicationCache.cpp \
......
......@@ -17295,6 +17295,14 @@
RelativePath="..\loader\appcache\ApplicationCacheGroup.h"
>
</File>
<File
RelativePath="..\loader\appcache\ApplicationCacheHost.cpp"
>
</File>
<File
RelativePath="..\loader\appcache\ApplicationCacheHost.h"
>
</File>
<File
RelativePath="..\loader\appcache\ApplicationCacheResource.cpp"
>
......
......@@ -352,7 +352,7 @@
1A8F6BC00DB55CDC001DB794 /* ApplicationCacheResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A8F6BB50DB55CDC001DB794 /* ApplicationCacheResource.cpp */; };
1A8F6BC10DB55CDC001DB794 /* ApplicationCacheResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BB60DB55CDC001DB794 /* ApplicationCacheResource.h */; };
1A8F6BC20DB55CDC001DB794 /* DOMApplicationCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A8F6BB70DB55CDC001DB794 /* DOMApplicationCache.cpp */; };
1A8F6BC30DB55CDC001DB794 /* DOMApplicationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BB80DB55CDC001DB794 /* DOMApplicationCache.h */; };
1A8F6BC30DB55CDC001DB794 /* DOMApplicationCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BB80DB55CDC001DB794 /* DOMApplicationCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
1A8F6BC50DB55CDC001DB794 /* ManifestParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A8F6BBA0DB55CDC001DB794 /* ManifestParser.cpp */; };
1A8F6BC60DB55CDC001DB794 /* ManifestParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F6BBB0DB55CDC001DB794 /* ManifestParser.h */; };
1A98956B0AA78F80005EF5EF /* KURLCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */; };
......@@ -524,6 +524,8 @@
1CF6BE140E9BB4670025E1CD /* ObjCNodeFilterCondition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CF6BE120E9BB4670025E1CD /* ObjCNodeFilterCondition.mm */; };
1CF6BE150E9BB4670025E1CD /* ObjCNodeFilterCondition.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CF6BE130E9BB4670025E1CD /* ObjCNodeFilterCondition.h */; };
1CFAE3230A6D6A3F0032593D /* libobjc.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CFAE3220A6D6A3F0032593D /* libobjc.dylib */; };
24F54EAC101FE914000AE741 /* ApplicationCacheHost.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */; };
24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */ = {isa = PBXBuildFile; fileRef = 24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */; settings = {ATTRIBUTES = (Private, ); }; };
29A812260FBB9C1D00510293 /* AccessibilityRenderObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A812080FBB9C1D00510293 /* AccessibilityRenderObject.cpp */; };
29A812270FBB9C1D00510293 /* AccessibilityTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A812090FBB9C1D00510293 /* AccessibilityTable.cpp */; };
29A812280FBB9C1D00510293 /* AccessibilityARIAGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A8120A0FBB9C1D00510293 /* AccessibilityARIAGrid.cpp */; };
......@@ -5487,6 +5489,8 @@
1CF6BE120E9BB4670025E1CD /* ObjCNodeFilterCondition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ObjCNodeFilterCondition.mm; sourceTree = "<group>"; };
1CF6BE130E9BB4670025E1CD /* ObjCNodeFilterCondition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjCNodeFilterCondition.h; sourceTree = "<group>"; };
1CFAE3220A6D6A3F0032593D /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = "<absolute>"; };
24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationCacheHost.cpp; sourceTree = "<group>"; };
24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationCacheHost.h; sourceTree = "<group>"; };
29A812080FBB9C1D00510293 /* AccessibilityRenderObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityRenderObject.cpp; sourceTree = "<group>"; };
29A812090FBB9C1D00510293 /* AccessibilityTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityTable.cpp; sourceTree = "<group>"; };
29A8120A0FBB9C1D00510293 /* AccessibilityARIAGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityARIAGrid.cpp; sourceTree = "<group>"; };
......@@ -9708,6 +9712,8 @@
1A8F6BB00DB55CDC001DB794 /* appcache */ = {
isa = PBXGroup;
children = (
24F54EAA101FE914000AE741 /* ApplicationCacheHost.cpp */,
24F54EAB101FE914000AE741 /* ApplicationCacheHost.h */,
1A8F6BB10DB55CDC001DB794 /* ApplicationCache.cpp */,
1A8F6BB20DB55CDC001DB794 /* ApplicationCache.h */,
1A8F6BB30DB55CDC001DB794 /* ApplicationCacheGroup.cpp */,
......@@ -17062,6 +17068,7 @@
CE54FD381016D9A6008B44C8 /* ScriptSourceProvider.h in Headers */,
7A74ECBB101839A600BF939E /* InspectorBackend.h in Headers */,
7A1E88F6101CC384000C4DF5 /* ScriptArray.h in Headers */,
24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */,
41A3D58F101C152D00316D07 /* DedicatedWorkerThread.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -19104,6 +19111,7 @@
7A74ECBA101839A600BF939E /* InspectorBackend.cpp in Sources */,
7A74ECBD101839DA00BF939E /* JSInspectorBackendCustom.cpp in Sources */,
7A1E88F5101CC384000C4DF5 /* ScriptArray.cpp in Sources */,
24F54EAC101FE914000AE741 /* ApplicationCacheHost.cpp in Sources */,
41A3D58E101C152D00316D07 /* DedicatedWorkerThread.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -676,6 +676,7 @@ This file contains the list of files needed to build WebCore.
<set append="1" var="WEBCORE_SOURCES_LOADER">
loader/appcache/ApplicationCache.cpp
loader/appcache/ApplicationCacheGroup.cpp
loader/appcache/ApplicationCacheHost.cpp
loader/appcache/ApplicationCacheResource.cpp
loader/appcache/DOMApplicationCache.cpp
loader/appcache/ManifestParser.cpp
......
......@@ -23,8 +23,13 @@
#include "config.h"
#include "HTMLHtmlElement.h"
#include "ApplicationCacheGroup.h"
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
#include "ApplicationCacheHost.h"
#endif
#include "Document.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "HTMLNames.h"
namespace WebCore {
......@@ -68,12 +73,16 @@ void HTMLHtmlElement::insertedIntoDocument()
if (!document()->frame())
return;
DocumentLoader* documentLoader = document()->frame()->loader()->documentLoader();
if (!documentLoader)
return;
// Check the manifest attribute
AtomicString manifest = getAttribute(manifestAttr);
if (manifest.isNull())
ApplicationCacheGroup::selectCacheWithoutManifestURL(document()->frame());
if (manifest.isEmpty())
documentLoader->applicationCacheHost()->selectCacheWithoutManifest();
else
ApplicationCacheGroup::selectCache(document()->frame(), document()->completeURL(manifest));
documentLoader->applicationCacheHost()->selectCacheWithManifest(document()->completeURL(manifest));
}
#endif
......
......@@ -29,11 +29,6 @@
#include "config.h"
#include "DocumentLoader.h"
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
#include "ApplicationCache.h"
#include "ApplicationCacheGroup.h"
#include "ApplicationCacheResource.h"
#endif
#include "ArchiveFactory.h"
#include "ArchiveResourceCollection.h"
#include "CachedPage.h"
......@@ -153,7 +148,7 @@ DocumentLoader::DocumentLoader(const ResourceRequest& req, const SubstituteData&
, m_substituteResourceDeliveryTimer(this, &DocumentLoader::substituteResourceDeliveryTimerFired)
, m_didCreateGlobalHistoryEntry(false)
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
, m_candidateApplicationCacheGroup(0)
, m_applicationCacheHost(this)
#endif
{
}
......@@ -168,13 +163,6 @@ FrameLoader* DocumentLoader::frameLoader() const
DocumentLoader::~DocumentLoader()
{
ASSERT(!m_frame || frameLoader()->activeDocumentLoader() != this || !frameLoader()->isLoading());
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
if (m_applicationCache)
m_applicationCache->group()->disassociateDocumentLoader(this);
else if (m_candidateApplicationCacheGroup)
m_candidateApplicationCacheGroup->disassociateDocumentLoader(this);
#endif
}
PassRefPtr<SharedBuffer> DocumentLoader::mainResourceData() const
......@@ -258,14 +246,7 @@ void DocumentLoader::mainReceivedError(const ResourceError& error, bool isComple
ASSERT(!error.isNull());
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
ApplicationCacheGroup* group = m_candidateApplicationCacheGroup;
if (!group && m_applicationCache) {
ASSERT(!mainResourceApplicationCache()); // If the main resource were loaded from a cache, it wouldn't fail.
group = m_applicationCache->group();
}
if (group)
group->failedLoadingMainResource(this);
m_applicationCacheHost.failedLoadingMainResource();
#endif
if (!frameLoader())
......@@ -430,6 +411,9 @@ void DocumentLoader::attachToFrame()
void DocumentLoader::detachFromFrame()
{
ASSERT(m_frame);
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
m_applicationCacheHost.setDOMApplicationCache(0);
#endif
m_frame = 0;
}
......@@ -451,9 +435,6 @@ void DocumentLoader::setPrimaryLoadComplete(bool flag)
if (flag) {
if (m_mainResourceLoader) {
m_mainResourceData = m_mainResourceLoader->resourceData();
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
m_mainResourceApplicationCache = m_mainResourceLoader->applicationCache();
#endif
m_mainResourceLoader = 0;
}
......@@ -847,113 +828,4 @@ void DocumentLoader::iconLoadDecisionAvailable()
m_frame->loader()->iconLoadDecisionAvailable();
}
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
void DocumentLoader::setCandidateApplicationCacheGroup(ApplicationCacheGroup* group)
{
ASSERT(!m_applicationCache);
m_candidateApplicationCacheGroup = group;
}
void DocumentLoader::setApplicationCache(PassRefPtr<ApplicationCache> applicationCache)
{
if (m_candidateApplicationCacheGroup) {
ASSERT(!m_applicationCache);
m_candidateApplicationCacheGroup = 0;
}
m_applicationCache = applicationCache;
}
ApplicationCache* DocumentLoader::mainResourceApplicationCache() const
{
if (m_mainResourceApplicationCache)
return m_mainResourceApplicationCache.get();
if (m_mainResourceLoader)
return m_mainResourceLoader->applicationCache();
return 0;
}
bool DocumentLoader::shouldLoadResourceFromApplicationCache(const ResourceRequest& request, ApplicationCacheResource*& resource)
{
ApplicationCache* cache = applicationCache();
if (!cache || !cache->isComplete())
return false;
// If the resource is not a HTTP/HTTPS GET, then abort
if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request))
return false;
// If the resource's URL is an master entry, the manifest, an explicit entry, or a fallback entry
// in the application cache, then get the resource from the cache (instead of fetching it).
resource = cache->resourceForURL(request.url());
// Resources that match fallback namespaces or online whitelist entries are fetched from the network,
// unless they are also cached.
if (!resource && (cache->urlMatchesFallbackNamespace(request.url()) || cache->isURLInOnlineWhitelist(request.url())))
return false;
// Resources that are not present in the manifest will always fail to load (at least, after the
// cache has been primed the first time), making the testing of offline applications simpler.
return true;
}
bool DocumentLoader::getApplicationCacheFallbackResource(const ResourceRequest& request, ApplicationCacheResource*& resource, ApplicationCache* cache)
{
if (!cache) {
cache = applicationCache();
if (!cache)
return false;
}
if (!cache->isComplete())
return false;
// If the resource is not a HTTP/HTTPS GET, then abort
if (!ApplicationCache::requestIsHTTPOrHTTPSGet(request))
return false;
KURL fallbackURL;
if (!cache->urlMatchesFallbackNamespace(request.url(), &fallbackURL))
return false;
resource = cache->resourceForURL(fallbackURL);
ASSERT(resource);
return true;
}
bool DocumentLoader::scheduleApplicationCacheLoad(ResourceLoader* loader, const ResourceRequest& request, const KURL& originalURL)
{
if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled())
return false;
if (request.url() != originalURL)
return false;
ApplicationCacheResource* resource;
if (!shouldLoadResourceFromApplicationCache(request, resource))
return false;
m_pendingSubstituteResources.set(loader, resource);
deliverSubstituteResourcesAfterDelay();
return true;
}
bool DocumentLoader::scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader* loader, const ResourceRequest& request, ApplicationCache* cache)
{
if (!frameLoader()->frame()->settings() || !frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled())
return false;
ApplicationCacheResource* resource;
if (!getApplicationCacheFallbackResource(request, resource, cache))
return false;
m_pendingSubstituteResources.set(loader, resource);
deliverSubstituteResourcesAfterDelay();
return true;
}
#endif // ENABLE(OFFLINE_WEB_APPLICATIONS)
}
......@@ -29,6 +29,10 @@
#ifndef DocumentLoader_h
#define DocumentLoader_h
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
#include "ApplicationCacheHost.h"
#endif
#include "NavigationAction.h"
#include "ResourceError.h"
#include "ResourceRequest.h"
......@@ -38,9 +42,6 @@
namespace WebCore {
class ApplicationCache;
class ApplicationCacheGroup;
class ApplicationCacheResource;
class Archive;
class ArchiveResource;
class ArchiveResourceCollection;
......@@ -207,18 +208,7 @@ namespace WebCore {
void takeMemoryCacheLoadsForClientNotification(Vector<String>& loads);
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
bool scheduleApplicationCacheLoad(ResourceLoader*, const ResourceRequest&, const KURL& originalURL);
bool scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader*, const ResourceRequest&, ApplicationCache* = 0);
bool shouldLoadResourceFromApplicationCache(const ResourceRequest&, ApplicationCacheResource*&);
bool getApplicationCacheFallbackResource(const ResourceRequest&, ApplicationCacheResource*&, ApplicationCache* = 0);
void setCandidateApplicationCacheGroup(ApplicationCacheGroup* group);
ApplicationCacheGroup* candidateApplicationCacheGroup() const { return m_candidateApplicationCacheGroup; }
void setApplicationCache(PassRefPtr<ApplicationCache> applicationCache);
ApplicationCache* applicationCache() const { return m_applicationCache.get(); }
ApplicationCache* mainResourceApplicationCache() const;
ApplicationCacheHost* applicationCacheHost() { return &m_applicationCacheHost; }
#endif
protected:
......@@ -306,16 +296,9 @@ namespace WebCore {
String m_clientRedirectSourceForHistory;
bool m_didCreateGlobalHistoryEntry;
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
// The application cache that the document loader is associated with (if any).
RefPtr<ApplicationCache> m_applicationCache;
// Before an application cache has finished loading, this will be the candidate application
// group that the document loader is associated with.
ApplicationCacheGroup* m_candidateApplicationCacheGroup;
// Once the main resource has finished loading, this is the application cache it was loaded from (if any).
RefPtr<ApplicationCache> m_mainResourceApplicationCache;
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
friend class ApplicationCacheHost; // for substitute resource delivery
ApplicationCacheHost m_applicationCacheHost;
#endif
};
......
......@@ -95,8 +95,7 @@
#include <wtf/StdLibExtras.h>
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
#include "ApplicationCache.h"
#include "ApplicationCacheResource.h"
#include "ApplicationCacheHost.h"
#endif
#if ENABLE(SVG)
......@@ -1816,8 +1815,7 @@ bool FrameLoader::canCachePageContainingThisFrame()
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
// FIXME: We should investigating caching frames that have an associated
// application cache. <rdar://problem/5917899> tracks that work.
&& !m_documentLoader->applicationCache()
&& !m_documentLoader->candidateApplicationCacheGroup()
&& m_documentLoader->applicationCacheHost()->canCacheInPageCache()
#endif
#if ENABLE(WML)
&& !frameContainsWMLContent(m_frame)
......@@ -1967,10 +1965,8 @@ bool FrameLoader::logCanCacheFrameDecision(int indentLevel)
if (!m_frame->document()->canSuspendActiveDOMObjects())
{ PCLOG(" -The document cannot suspect its active DOM Objects"); cannotCache = true; }
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
if (m_documentLoader->applicationCache())
{ PCLOG(" -The DocumentLoader has an active application cache"); cannotCache = true; }
if (m_documentLoader->candidateApplicationCacheGroup())
{ PCLOG(" -The DocumentLoader has a candidateApplicationCacheGroup"); cannotCache = true; }
if (!m_documentLoader->applicationCacheHost()->canCacheInPageCache())
{ PCLOG(" -The DocumentLoader uses an application cache"); cannotCache = true; }
#endif
if (!m_client->canCachePage())
{ PCLOG(" -The client says this frame cannot be cached"); cannotCache = true; }
......@@ -3681,30 +3677,11 @@ unsigned long FrameLoader::loadResourceSynchronously(const ResourceRequest& requ
ASSERT(!newRequest.isNull());
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
ApplicationCacheResource* resource;
if (documentLoader()->shouldLoadResourceFromApplicationCache(newRequest, resource)) {
if (resource) {
response = resource->response();
data.append(resource->data()->data(), resource->data()->size());
} else
error = cannotShowURLError(newRequest);
} else {
if (!documentLoader()->applicationCacheHost()->maybeLoadSynchronously(newRequest, error, response, data)) {
#endif
ResourceHandle::loadResourceSynchronously(newRequest, storedCredentials, error, response, data, m_frame);
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
// 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,
// 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
// corresponding to the matched namespace.
if ((!error.isNull() && !error.isCancellation())
|| response.httpStatusCode() / 100 == 4 || response.httpStatusCode() / 100 == 5
|| !protocolHostAndPortAreEqual(newRequest.url(), response.url())) {
if (documentLoader()->getApplicationCacheFallbackResource(newRequest, resource)) {
response = resource->response();
data.clear();
data.append(resource->data()->data(), resource->data()->size());
}
}
documentLoader()->applicationCacheHost()->maybeLoadFallbackSynchronously(newRequest, error, response, data);
}
#endif
}
......
......@@ -42,9 +42,7 @@
#include "Settings.h"
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
#include "ApplicationCache.h"
#include "ApplicationCacheGroup.h"
#include "ApplicationCacheResource.h"
#include "ApplicationCacheHost.h"
#endif
// FIXME: More that is in common with SubresourceLoader should move up into ResourceLoader.
......@@ -283,15 +281,8 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction policy)
void MainResourceLoader::didReceiveResponse(const ResourceResponse& r)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
if (r.httpStatusCode() / 100 == 4 || r.httpStatusCode() / 100 == 5) {
ASSERT(!m_applicationCache);
if (m_frame->settings() && m_frame->settings()->offlineWebApplicationCacheEnabled()) {
m_applicationCache = ApplicationCacheGroup::fallbackCacheForMainRequest(request(), documentLoader());
if (scheduleLoadFallbackResourceFromApplicationCache(m_applicationCache.get()))
return;
}
}
if (documentLoader()->applicationCacheHost()->maybeLoadFallbackForMainResponse(request(), r))
return;
#endif
HTTPHeaderMap::const_iterator it = r.httpHeaderFields().find(AtomicString("x-frame-options"));
......@@ -353,6 +344,10 @@ void MainResourceLoader::didReceiveData(const char* data, int length, long long
ASSERT(!defersLoading());
#endif
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
documentLoader()->applicationCacheHost()->mainResourceDataReceived(data, length, lengthReceived, allAtOnce);
#endif
// The additional processing can do anything including possibly removing the last
// reference to this object; one example of this is 3266216.
RefPtr<MainResourceLoader> protect(this);
......@@ -380,27 +375,15 @@ void MainResourceLoader::didFinishLoading()
ResourceLoader::didFinishLoading();
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
ApplicationCacheGroup* group = dl->candidateApplicationCacheGroup();
if (!group && dl->applicationCache() && !dl->mainResourceApplicationCache())
group = dl->applicationCache()->group();
if (group)
group->finishedLoadingMainResource(dl.get());
dl->applicationCacheHost()->finishedLoadingMainResource();
#endif
}
void MainResourceLoader::didFail(const ResourceError& error)