ApplicationCacheHost.h [plain text]
#pragma once
#include <wtf/Deque.h>
#include <wtf/URL.h>
#include <wtf/Vector.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
class ApplicationCache;
class ApplicationCacheGroup;
class ApplicationCacheResource;
class ApplicationCacheStorage;
class DOMApplicationCache;
class DocumentLoader;
class Frame;
class ResourceError;
class ResourceLoader;
class ResourceRequest;
class ResourceResponse;
class SharedBuffer;
class SubstituteData;
class ApplicationCacheHost {
WTF_MAKE_NONCOPYABLE(ApplicationCacheHost); WTF_MAKE_FAST_ALLOCATED;
public:
enum Status {
UNCACHED = 0,
IDLE = 1,
CHECKING = 2,
DOWNLOADING = 3,
UPDATEREADY = 4,
OBSOLETE = 5
};
struct CacheInfo {
URL manifest;
double creationTime;
double updateTime;
long long size;
};
struct ResourceInfo {
URL resource;
bool isMaster;
bool isManifest;
bool isFallback;
bool isForeign;
bool isExplicit;
long long size;
};
explicit ApplicationCacheHost(DocumentLoader&);
~ApplicationCacheHost();
static URL createFileURL(const String&);
void selectCacheWithoutManifest();
void selectCacheWithManifest(const URL& manifestURL);
bool canLoadMainResource(const ResourceRequest&);
void maybeLoadMainResource(const ResourceRequest&, SubstituteData&);
void maybeLoadMainResourceForRedirect(const ResourceRequest&, SubstituteData&);
bool maybeLoadFallbackForMainResponse(const ResourceRequest&, const ResourceResponse&);
void mainResourceDataReceived(const char* data, int length, long long encodedDataLength, bool allAtOnce);
void finishedLoadingMainResource();
void failedLoadingMainResource();
WEBCORE_EXPORT bool maybeLoadResource(ResourceLoader&, const ResourceRequest&, const URL& originalURL);
WEBCORE_EXPORT bool maybeLoadFallbackForRedirect(ResourceLoader*, ResourceRequest&, const ResourceResponse&);
WEBCORE_EXPORT bool maybeLoadFallbackForResponse(ResourceLoader*, const ResourceResponse&);
WEBCORE_EXPORT bool maybeLoadFallbackForError(ResourceLoader*, const ResourceError&);
bool maybeLoadSynchronously(ResourceRequest&, ResourceError&, ResourceResponse&, RefPtr<SharedBuffer>&);
void maybeLoadFallbackSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, RefPtr<SharedBuffer>&);
bool canCacheInBackForwardCache();
Status status() const;
bool update();
bool swapCache();
void abort();
void setDOMApplicationCache(DOMApplicationCache*);
void notifyDOMApplicationCache(const AtomString& eventType, int progressTotal, int progressDone);
void stopLoadingInFrame(Frame&);
void stopDeferringEvents();
Vector<ResourceInfo> resourceList();
CacheInfo applicationCacheInfo();
bool shouldLoadResourceFromApplicationCache(const ResourceRequest&, ApplicationCacheResource*&);
bool getApplicationCacheFallbackResource(const ResourceRequest&, ApplicationCacheResource*&, ApplicationCache* = nullptr);
private:
friend class ApplicationCacheGroup;
struct DeferredEvent {
AtomString eventType;
int progressTotal;
int progressDone;
};
bool isApplicationCacheEnabled();
bool isApplicationCacheBlockedForRequest(const ResourceRequest&);
void dispatchDOMEvent(const AtomString& eventType, int progressTotal, int progressDone);
bool scheduleLoadFallbackResourceFromApplicationCache(ResourceLoader*, ApplicationCache* = nullptr);
void setCandidateApplicationCacheGroup(ApplicationCacheGroup*);
ApplicationCacheGroup* candidateApplicationCacheGroup() const;
void setApplicationCache(RefPtr<ApplicationCache>&&);
ApplicationCache* applicationCache() const { return m_applicationCache.get(); }
ApplicationCache* mainResourceApplicationCache() const { return m_mainResourceApplicationCache.get(); }
bool maybeLoadFallbackForMainError(const ResourceRequest&, const ResourceError&);
WeakPtr<DOMApplicationCache> m_domApplicationCache;
DocumentLoader& m_documentLoader;
bool m_defersEvents { true }; Vector<DeferredEvent> m_deferredEvents;
RefPtr<ApplicationCache> m_applicationCache;
WeakPtr<ApplicationCacheGroup> m_candidateApplicationCacheGroup;
RefPtr<ApplicationCache> m_mainResourceApplicationCache;
};
}