ApplicationCacheGroup.h [plain text]
#ifndef ApplicationCacheGroup_h
#define ApplicationCacheGroup_h
#include "DOMApplicationCache.h"
#include "URL.h"
#include "ResourceHandleClient.h"
#include "SharedBuffer.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 Document;
class DocumentLoader;
class Frame;
class ResourceHandle;
class SecurityOrigin;
enum ApplicationCacheUpdateOption {
ApplicationCacheUpdateWithBrowsingContext,
ApplicationCacheUpdateWithoutBrowsingContext
};
class ApplicationCacheGroup : ResourceHandleClient {
WTF_MAKE_NONCOPYABLE(ApplicationCacheGroup); WTF_MAKE_FAST_ALLOCATED;
public:
ApplicationCacheGroup(const URL& manifestURL, bool isCopy = false);
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*);
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 cacheIsBeingUpdated(const ApplicationCache* cache) const { return cache == m_cacheBeingUpdated; }
void stopLoadingInFrame(Frame*);
ApplicationCache* newestCache() const { return m_newestCache.get(); }
void setNewestCache(PassRefPtr<ApplicationCache>);
void makeObsolete();
bool isObsolete() const { return m_isObsolete; }
void finishedLoadingMainResource(DocumentLoader*);
void failedLoadingMainResource(DocumentLoader*);
void disassociateDocumentLoader(DocumentLoader*);
bool isCopy() const { return m_isCopy; }
private:
static void postListenerTask(ApplicationCacheHost::EventID id, const HashSet<DocumentLoader*>& set) { postListenerTask(id, 0, 0, set); }
static void postListenerTask(ApplicationCacheHost::EventID id, DocumentLoader* loader) { postListenerTask(id, 0, 0, loader); }
static void postListenerTask(ApplicationCacheHost::EventID, int progressTotal, int progressDone, const HashSet<DocumentLoader*>&);
static void postListenerTask(ApplicationCacheHost::EventID, int progressTotal, int progressDone, DocumentLoader*);
void scheduleReachedMaxAppCacheSizeCallback();
PassRefPtr<ResourceHandle> createResourceHandle(const URL&, ApplicationCacheResource* newestCachedResource);
virtual bool shouldUseCredentialStorage(ResourceHandle*) override { return true; }
virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&) override;
virtual void didReceiveData(ResourceHandle*, const char*, unsigned length, int encodedDataLength) override;
virtual void didFinishLoading(ResourceHandle*, double finishTime) override;
virtual void didFail(ResourceHandle*, const ResourceError&) override;
void didReceiveManifestResponse(const ResourceResponse&);
void didReceiveManifestData(const char*, int);
void didFinishLoadingManifest();
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();
URL m_manifestURL;
RefPtr<SecurityOrigin> m_origin;
UpdateStatus m_updateStatus;
RefPtr<ApplicationCache> m_newestCache;
HashSet<ApplicationCache*> m_caches;
RefPtr<ApplicationCache> m_cacheBeingUpdated;
HashSet<DocumentLoader*> m_pendingMasterResourceLoaders;
int m_downloadingPendingMasterResourceLoadersCount;
HashSet<DocumentLoader*> m_associatedDocumentLoaders;
typedef HashMap<String, unsigned> EntryMap;
EntryMap m_pendingEntries;
int m_progressTotal;
int m_progressDone;
Frame* m_frame;
unsigned m_storageID;
bool m_isObsolete;
enum CompletionType {
None,
NoUpdate,
Failure,
Completed
};
CompletionType m_completionType;
bool m_isCopy;
bool m_calledReachedMaxAppCacheSize;
RefPtr<ResourceHandle> m_currentHandle;
RefPtr<ApplicationCacheResource> m_currentResource;
#if ENABLE(INSPECTOR)
unsigned long m_currentResourceIdentifier;
#endif
RefPtr<ApplicationCacheResource> m_manifestResource;
RefPtr<ResourceHandle> m_manifestHandle;
int64_t m_availableSpaceInQuota;
bool m_originQuotaExceededPreviously;
friend class ChromeClientCallbackTimer;
};
}
#endif // ApplicationCacheGroup_h