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
diff --git a/WebCore/loader/MainResourceLoader.cpp b/WebCore/loader/MainResourceLoader.cpp
index 39e5b90..159aaa1 100644
--- a/WebCore/loader/MainResourceLoader.cpp
+++ b/WebCore/loader/MainResourceLoader.cpp
@@ -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::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 @@
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 @@
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)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
- if (!error.isCancellation()) {
- 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()->maybeLoadFallbackForMainError(request(), error))
+ return;
#endif
// There is a bug in CFNetwork where callbacks can be dispatched even when loads are deferred.
@@ -495,27 +478,15 @@
m_substituteData = substituteData;
+ ResourceRequest request(r);
+
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
- // Check if this request should be loaded from the application cache
- if (!m_substituteData.isValid() && frameLoader()->frame()->settings() && frameLoader()->frame()->settings()->offlineWebApplicationCacheEnabled()) {
- ASSERT(!m_applicationCache);
-
- m_applicationCache = ApplicationCacheGroup::cacheForMainRequest(r, m_documentLoader.get());
-
- if (m_applicationCache) {
- // Get the resource from the application cache. By definition, cacheForMainRequest() returns a cache that contains the resource.
- ApplicationCacheResource* resource = m_applicationCache->resourceForRequest(r);
- m_substituteData = SubstituteData(resource->data(),
- resource->response().mimeType(),
- resource->response().textEncodingName(), KURL());
- }
- }
+ documentLoader()->applicationCacheHost()->maybeLoadMainResource(request, m_substituteData);
#endif
- ResourceRequest request(r);
bool defer = defersLoading();
if (defer) {
- bool shouldLoadEmpty = shouldLoadAsEmptyDocument(r.url());
+ bool shouldLoadEmpty = shouldLoadAsEmptyDocument(request.url());
if (shouldLoadEmpty)
defer = false;
}