| Index: loader/appcache2/DOMApplicationCache.cpp
|
| ===================================================================
|
| --- loader/appcache2/DOMApplicationCache.cpp (revision 0)
|
| +++ loader/appcache2/DOMApplicationCache.cpp (working copy)
|
| @@ -26,12 +26,8 @@
|
| #include "config.h"
|
| #include "DOMApplicationCache.h"
|
|
|
| -#if ENABLE(OFFLINE_WEB_APPLICATIONS)
|
| +#if ENABLE(APPLICATION_CACHE)
|
|
|
| -#include "ApplicationCache.h"
|
| -#include "ApplicationCacheGroup.h"
|
| -#include "ApplicationCacheResource.h"
|
| -#include "DocumentLoader.h"
|
| #include "Event.h"
|
| #include "EventException.h"
|
| #include "EventListener.h"
|
| @@ -44,81 +40,40 @@
|
|
|
| DOMApplicationCache::DOMApplicationCache(Frame* frame)
|
| : m_frame(frame)
|
| + , m_appcacheFrontend(frame->loader()->appcacheFrontend())
|
| {
|
| + appcacheFrontend()->setDOMApplicationCache(this);
|
| }
|
|
|
| void DOMApplicationCache::disconnectFrame()
|
| {
|
| + appcacheFrontend()->setDOMApplicationCache(0);
|
| m_frame = 0;
|
| + m_appcacheFrontend = 0;
|
| }
|
|
|
| -ApplicationCache* DOMApplicationCache::associatedCache() const
|
| -{
|
| - if (!m_frame)
|
| - return 0;
|
| -
|
| - return m_frame->loader()->documentLoader()->applicationCache();
|
| -}
|
| -
|
| unsigned short DOMApplicationCache::status() const
|
| {
|
| - ApplicationCache* cache = associatedCache();
|
| - if (!cache)
|
| - return UNCACHED;
|
| -
|
| - switch (cache->group()->updateStatus()) {
|
| - case ApplicationCacheGroup::Checking:
|
| - return CHECKING;
|
| - case ApplicationCacheGroup::Downloading:
|
| - return DOWNLOADING;
|
| - case ApplicationCacheGroup::Idle: {
|
| - if (cache->group()->isObsolete())
|
| - return OBSOLETE;
|
| - if (cache != cache->group()->newestCache())
|
| - return UPDATEREADY;
|
| - return IDLE;
|
| - }
|
| - }
|
| -
|
| - ASSERT_NOT_REACHED();
|
| - return 0;
|
| + ApplicationCacheFrontend* cache = appcacheFrontend();
|
| + return cache ? cache->status() : APPCACHE_UNCACHED;
|
| }
|
|
|
| void DOMApplicationCache::update(ExceptionCode& ec)
|
| {
|
| - ApplicationCache* cache = associatedCache();
|
| + ApplicationCacheFrontend* cache = appcacheFrontend();
|
| if (!cache) {
|
| ec = INVALID_STATE_ERR;
|
| return;
|
| }
|
| -
|
| - cache->group()->update(m_frame, ApplicationCacheUpdateWithoutBrowsingContext);
|
| + cache->update();
|
| }
|
|
|
| bool DOMApplicationCache::swapCache()
|
| {
|
| - if (!m_frame)
|
| - return false;
|
| -
|
| - ApplicationCache* cache = m_frame->loader()->documentLoader()->applicationCache();
|
| + ApplicationCacheFrontend* cache = appcacheFrontend();
|
| if (!cache)
|
| return false;
|
| -
|
| - // If the group of application caches to which cache belongs has the lifecycle status obsolete, unassociate document from cache.
|
| - if (cache->group()->isObsolete()) {
|
| - cache->group()->disassociateDocumentLoader(m_frame->loader()->documentLoader());
|
| - return true;
|
| - }
|
| -
|
| - // If there is no newer cache, raise an INVALID_STATE_ERR exception.
|
| - ApplicationCache* newestCache = cache->group()->newestCache();
|
| - if (cache == newestCache)
|
| - return false;
|
| -
|
| - ASSERT(cache->group() == newestCache->group());
|
| - m_frame->loader()->documentLoader()->setApplicationCache(newestCache);
|
| -
|
| - return true;
|
| + return cache->swapCache();
|
| }
|
|
|
| void DOMApplicationCache::swapCache(ExceptionCode& ec)
|
| @@ -127,77 +82,18 @@
|
| ec = INVALID_STATE_ERR;
|
| }
|
|
|
| -PassRefPtr<DOMStringList> DOMApplicationCache::items()
|
| -{
|
| - Vector<String> result;
|
| - if (ApplicationCache* cache = associatedCache()) {
|
| - unsigned numEntries = cache->numDynamicEntries();
|
| - result.reserveInitialCapacity(numEntries);
|
| - for (unsigned i = 0; i < numEntries; ++i)
|
| - result.append(cache->dynamicEntry(i));
|
| - }
|
| - return StaticStringList::adopt(result);
|
| -}
|
| -
|
| -bool DOMApplicationCache::hasItem(const KURL& url, ExceptionCode& ec)
|
| -{
|
| - ApplicationCache* cache = associatedCache();
|
| - if (!cache) {
|
| - ec = INVALID_STATE_ERR;
|
| - return false;
|
| - }
|
| -
|
| - if (!url.isValid()) {
|
| - ec = SYNTAX_ERR;
|
| - return false;
|
| - }
|
| -
|
| - ApplicationCacheResource* resource = cache->resourceForURL(url.string());
|
| - return resource && (resource->type() & ApplicationCacheResource::Dynamic);
|
| -}
|
| -
|
| -void DOMApplicationCache::add(const KURL& url, ExceptionCode& ec)
|
| -{
|
| - ApplicationCache* cache = associatedCache();
|
| - if (!cache) {
|
| - ec = INVALID_STATE_ERR;
|
| - return;
|
| - }
|
| -
|
| - if (!url.isValid()) {
|
| - ec = SYNTAX_ERR;
|
| - return;
|
| - }
|
| -
|
| - if (!cache->addDynamicEntry(url)) {
|
| - // This should use the (currently not specified) security exceptions in HTML5 4.3.4
|
| - ec = SECURITY_ERR;
|
| - }
|
| -}
|
| -
|
| -void DOMApplicationCache::remove(const KURL& url, ExceptionCode& ec)
|
| -{
|
| - ApplicationCache* cache = associatedCache();
|
| - if (!cache) {
|
| - ec = INVALID_STATE_ERR;
|
| - return;
|
| - }
|
| -
|
| - cache->removeDynamicEntry(url);
|
| -}
|
| -
|
| ScriptExecutionContext* DOMApplicationCache::scriptExecutionContext() const
|
| {
|
| - return m_frame->document();
|
| + return m_frame ? m_frame->document() : 0;
|
| }
|
|
|
| -void DOMApplicationCache::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool)
|
| +void DOMApplicationCache::addEventListener(const AtomicString& eventName, PassRefPtr<EventListener> eventListener, bool)
|
| {
|
| - EventListenersMap::iterator iter = m_eventListeners.find(eventType);
|
| + EventListenersMap::iterator iter = m_eventListeners.find(eventName);
|
| if (iter == m_eventListeners.end()) {
|
| ListenerVector listeners;
|
| listeners.append(eventListener);
|
| - m_eventListeners.add(eventType, listeners);
|
| + m_eventListeners.add(eventName, listeners);
|
| } else {
|
| ListenerVector& listeners = iter->second;
|
| for (ListenerVector::iterator listenerIter = listeners.begin(); listenerIter != listeners.end(); ++listenerIter) {
|
| @@ -206,13 +102,13 @@
|
| }
|
|
|
| listeners.append(eventListener);
|
| - m_eventListeners.add(eventType, listeners);
|
| + m_eventListeners.add(eventName, listeners);
|
| }
|
| }
|
|
|
| -void DOMApplicationCache::removeEventListener(const AtomicString& eventType, EventListener* eventListener, bool)
|
| +void DOMApplicationCache::removeEventListener(const AtomicString& eventName, EventListener* eventListener, bool)
|
| {
|
| - EventListenersMap::iterator iter = m_eventListeners.find(eventType);
|
| + EventListenersMap::iterator iter = m_eventListeners.find(eventName);
|
| if (iter == m_eventListeners.end())
|
| return;
|
|
|
| @@ -231,7 +127,7 @@
|
| ec = EventException::UNSPECIFIED_EVENT_TYPE_ERR;
|
| return true;
|
| }
|
| -
|
| +
|
| ListenerVector listenersCopy = m_eventListeners.get(event->type());
|
| for (ListenerVector::const_iterator listenerIter = listenersCopy.begin(); listenerIter != listenersCopy.end(); ++listenerIter) {
|
| event->setTarget(this);
|
| @@ -258,46 +154,56 @@
|
| ASSERT(!ec);
|
| }
|
|
|
| -void DOMApplicationCache::callCheckingListener()
|
| +// static
|
| +const AtomicString& DOMApplicationCache::toEventName(ApplicationCacheEventType eventType)
|
| {
|
| - callListener(eventNames().checkingEvent, m_onCheckingListener.get());
|
| + switch (eventType) {
|
| + case APPCACHE_CHECKING_EVENT:
|
| + return eventNames().checkingEvent;
|
| + case APPCACHE_ERROR_EVENT:
|
| + return eventNames().errorEvent;
|
| + case APPCACHE_NOUPDATE_EVENT:
|
| + return eventNames().noupdateEvent;
|
| + case APPCACHE_DOWNLOADING_EVENT:
|
| + return eventNames().downloadingEvent;
|
| + case APPCACHE_PROGRESS_EVENT:
|
| + return eventNames().progressEvent;
|
| + case APPCACHE_UPDATEREADY_EVENT:
|
| + return eventNames().updatereadyEvent;
|
| + case APPCACHE_CACHED_EVENT:
|
| + return eventNames().cachedEvent;
|
| + case APPCACHE_OBSOLETE_EVENT:
|
| + return eventNames().obsoleteEvent;
|
| + }
|
| + ASSERT(false);
|
| + return eventNames().abortEvent;
|
| }
|
|
|
| -void DOMApplicationCache::callErrorListener()
|
| +// static
|
| +ApplicationCacheEventType DOMApplicationCache::toEventType(const AtomicString& eventName)
|
| {
|
| - callListener(eventNames().errorEvent, m_onErrorListener.get());
|
| + if (eventName == eventNames().checkingEvent)
|
| + return APPCACHE_CHECKING_EVENT;
|
| + if (eventName == eventNames().errorEvent)
|
| + return APPCACHE_ERROR_EVENT;
|
| + if (eventName == eventNames().noupdateEvent)
|
| + return APPCACHE_NOUPDATE_EVENT;
|
| + if (eventName == eventNames().downloadingEvent)
|
| + return APPCACHE_DOWNLOADING_EVENT;
|
| + if (eventName == eventNames().progressEvent)
|
| + return APPCACHE_PROGRESS_EVENT;
|
| + if (eventName == eventNames().updatereadyEvent)
|
| + return APPCACHE_UPDATEREADY_EVENT;
|
| + if (eventName == eventNames().cachedEvent)
|
| + return APPCACHE_CACHED_EVENT;
|
| + if (eventName == eventNames().obsoleteEvent)
|
| + return APPCACHE_OBSOLETE_EVENT;
|
| +
|
| + ASSERT(false);
|
| + return NUMBER_OF_APPCACHE_EVENT_TYPES;
|
| }
|
|
|
| -void DOMApplicationCache::callNoUpdateListener()
|
| -{
|
| - callListener(eventNames().noupdateEvent, m_onNoUpdateListener.get());
|
| -}
|
|
|
| -void DOMApplicationCache::callDownloadingListener()
|
| -{
|
| - callListener(eventNames().downloadingEvent, m_onDownloadingListener.get());
|
| -}
|
| -
|
| -void DOMApplicationCache::callProgressListener()
|
| -{
|
| - callListener(eventNames().progressEvent, m_onProgressListener.get());
|
| -}
|
| -
|
| -void DOMApplicationCache::callUpdateReadyListener()
|
| -{
|
| - callListener(eventNames().updatereadyEvent, m_onUpdateReadyListener.get());
|
| -}
|
| -
|
| -void DOMApplicationCache::callCachedListener()
|
| -{
|
| - callListener(eventNames().cachedEvent, m_onCachedListener.get());
|
| -}
|
| -
|
| -void DOMApplicationCache::callObsoleteListener()
|
| -{
|
| - callListener(eventNames().obsoleteEvent, m_onObsoleteListener.get());
|
| -}
|
| -
|
| } // namespace WebCore
|
|
|
| -#endif // ENABLE(OFFLINE_WEB_APPLICATIONS)
|
| +#endif // ENABLE(APPLICATION_CACHE)
|
|
|