DOMApplicationCache.cpp [plain text]
#include "config.h"
#include "DOMApplicationCache.h"
#include "ApplicationCacheHost.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "FrameLoader.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(DOMApplicationCache);
DOMApplicationCache::DOMApplicationCache(DOMWindow& window)
: DOMWindowProperty(&window)
{
if (auto* host = applicationCacheHost())
host->setDOMApplicationCache(this);
}
ApplicationCacheHost* DOMApplicationCache::applicationCacheHost() const
{
auto* frame = this->frame();
if (!frame)
return nullptr;
auto* documentLoader = frame->loader().documentLoader();
if (!documentLoader)
return nullptr;
return &documentLoader->applicationCacheHost();
}
unsigned short DOMApplicationCache::status() const
{
auto* host = applicationCacheHost();
if (!host)
return ApplicationCacheHost::UNCACHED;
return host->status();
}
ExceptionOr<void> DOMApplicationCache::update()
{
auto* host = applicationCacheHost();
if (!host || !host->update())
return Exception { InvalidStateError };
return { };
}
ExceptionOr<void> DOMApplicationCache::swapCache()
{
auto* host = applicationCacheHost();
if (!host || !host->swapCache())
return Exception { InvalidStateError };
return { };
}
void DOMApplicationCache::abort()
{
if (auto* host = applicationCacheHost())
host->abort();
}
ScriptExecutionContext* DOMApplicationCache::scriptExecutionContext() const
{
auto* frame = this->frame();
if (!frame)
return nullptr;
return frame->document();
}
}