ApplicationCacheGroup.h [plain text]
#pragma once
#include "ApplicationCacheResourceLoader.h"
#include "DOMApplicationCache.h"
#include "URL.h"
#include <wtf/Noncopyable.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class ApplicationCache;
class ApplicationCacheResource;
class ApplicationCacheStorage;
class Document;
class DocumentLoader;
class Frame;
class SecurityOrigin;
enum ApplicationCacheUpdateOption {
ApplicationCacheUpdateWithBrowsingContext,
ApplicationCacheUpdateWithoutBrowsingContext
};
class ApplicationCacheGroup {
WTF_MAKE_NONCOPYABLE(ApplicationCacheGroup);
WTF_MAKE_FAST_ALLOCATED;
public:
explicit ApplicationCacheGroup(Ref<ApplicationCacheStorage>&&, const URL& manifestURL);
virtual ~ApplicationCacheGroup();
enum UpdateStatus { Idle, Checking, Downloading };
static ApplicationCache* cacheForMainRequest(const ResourceRequest&, DocumentLoader*);
static ApplicationCache* fallbackCacheForMainRequest(const ResourceRequest&, DocumentLoader*);
static void selectCache(Frame&, const URL& manifestURL);
static void selectCacheWithoutManifestURL(Frame&);
ApplicationCacheStorage& storage() { return m_storage; }
const URL& manifestURL() const { return m_manifestURL; }
const SecurityOrigin& origin() const { return m_origin.get(); }
UpdateStatus updateStatus() const { return m_updateStatus; }
void setUpdateStatus(UpdateStatus status);
void setStorageID(unsigned storageID) { m_storageID = storageID; }
unsigned storageID() const { return m_storageID; }
void clearStorageID();
void update(Frame&, ApplicationCacheUpdateOption); void cacheDestroyed(ApplicationCache&);
void abort(Frame&);
bool cacheIsComplete(ApplicationCache& cache) { return m_caches.contains(&cache); }
void stopLoadingInFrame(Frame&);
ApplicationCache* newestCache() const { return m_newestCache.get(); }
void setNewestCache(Ref<ApplicationCache>&&);
void makeObsolete();
bool isObsolete() const { return m_isObsolete; }
void finishedLoadingMainResource(DocumentLoader&);
void failedLoadingMainResource(DocumentLoader&);
void disassociateDocumentLoader(DocumentLoader&);
private:
static void postListenerTask(const AtomicString& eventType, const HashSet<DocumentLoader*>& set) { postListenerTask(eventType, 0, 0, set); }
static void postListenerTask(const AtomicString& eventType, DocumentLoader& loader) { postListenerTask(eventType, 0, 0, loader); }
static void postListenerTask(const AtomicString& eventType, int progressTotal, int progressDone, const HashSet<DocumentLoader*>&);
static void postListenerTask(const AtomicString& eventType, int progressTotal, int progressDone, DocumentLoader&);
void scheduleReachedMaxAppCacheSizeCallback();
void didFinishLoadingManifest();
void didFailLoadingManifest(ApplicationCacheResourceLoader::Error);
void didFailLoadingEntry(ApplicationCacheResourceLoader::Error, const URL&, unsigned type);
void didFinishLoadingEntry(const URL&);
void didReachMaxAppCacheSize();
void didReachOriginQuota(int64_t totalSpaceNeeded);
void startLoadingEntry();
void deliverDelayedMainResources();
void checkIfLoadIsComplete();
void cacheUpdateFailed();
void recalculateAvailableSpaceInQuota();
void manifestNotFound();
void addEntry(const String&, unsigned type);
void associateDocumentLoaderWithCache(DocumentLoader*, ApplicationCache*);
void stopLoading();
ResourceRequest createRequest(URL&&, ApplicationCacheResource*);
Ref<ApplicationCacheStorage> m_storage;
URL m_manifestURL;
Ref<SecurityOrigin> m_origin;
UpdateStatus m_updateStatus { Idle };
RefPtr<ApplicationCache> m_newestCache;
HashSet<ApplicationCache*> m_caches;
RefPtr<ApplicationCache> m_cacheBeingUpdated;
HashSet<DocumentLoader*> m_pendingMasterResourceLoaders;
int m_downloadingPendingMasterResourceLoadersCount { 0 };
HashSet<DocumentLoader*> m_associatedDocumentLoaders;
HashMap<String, unsigned> m_pendingEntries;
int m_progressTotal { 0 };
int m_progressDone { 0 };
Frame* m_frame { nullptr };
unsigned m_storageID { 0 };
bool m_isObsolete { false };
enum CompletionType {
None,
NoUpdate,
Failure,
Completed
};
CompletionType m_completionType { None };
bool m_calledReachedMaxAppCacheSize { false };
RefPtr<ApplicationCacheResource> m_currentResource;
RefPtr<ApplicationCacheResourceLoader> m_entryLoader;
unsigned long m_currentResourceIdentifier;
RefPtr<ApplicationCacheResource> m_manifestResource;
RefPtr<ApplicationCacheResourceLoader> m_manifestLoader;
int64_t m_availableSpaceInQuota;
bool m_originQuotaExceededPreviously { false };
friend class ChromeClientCallbackTimer;
};
}