StorageInfoChromium.cpp [plain text]
#include "config.h"
#include "StorageInfo.h"
#if ENABLE(QUOTA)
#include "DOMCoreException.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "ScriptExecutionContext.h"
#include "StorageInfoErrorCallback.h"
#include "StorageInfoQuotaCallback.h"
#include "StorageInfoUsageCallback.h"
#include "WebFrameClient.h"
#include "WebFrameImpl.h"
#include "WebStorageQuotaCallbacksImpl.h"
#include "WebStorageQuotaType.h"
using namespace WebKit;
namespace WebCore {
namespace {
void fireStorageInfoErrorCallback(PassRefPtr<StorageInfoErrorCallback> errorCallback, ExceptionCode ec)
{
if (!errorCallback)
return;
ExceptionCodeDescription description(ec);
errorCallback->handleEvent(DOMCoreException::create(description).get());
}
}
void StorageInfo::queryUsageAndQuota(ScriptExecutionContext* context, int storageType, PassRefPtr<StorageInfoUsageCallback> successCallback, PassRefPtr<StorageInfoErrorCallback> errorCallback)
{
ASSERT(context);
if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorageQuotaTypePersistent) {
fireStorageInfoErrorCallback(errorCallback, NOT_SUPPORTED_ERR);
return;
}
if (context->isDocument()) {
Document* document = static_cast<Document*>(context);
WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
webFrame->client()->queryStorageUsageAndQuota(webFrame, static_cast<WebStorageQuotaType>(storageType), new WebStorageQuotaCallbacksImpl(successCallback, errorCallback));
} else {
fireStorageInfoErrorCallback(errorCallback, NOT_SUPPORTED_ERR);
}
}
void StorageInfo::requestQuota(ScriptExecutionContext* context, int storageType, unsigned long long newQuotaInBytes, PassRefPtr<StorageInfoQuotaCallback> successCallback, PassRefPtr<StorageInfoErrorCallback> errorCallback)
{
ASSERT(context);
if (storageType != WebStorageQuotaTypeTemporary && storageType != WebStorageQuotaTypePersistent) {
fireStorageInfoErrorCallback(errorCallback, NOT_SUPPORTED_ERR);
return;
}
if (context->isDocument()) {
Document* document = static_cast<Document*>(context);
WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
webFrame->client()->requestStorageQuota(webFrame, static_cast<WebStorageQuotaType>(storageType), newQuotaInBytes, new WebStorageQuotaCallbacksImpl(successCallback, errorCallback));
} else {
fireStorageInfoErrorCallback(errorCallback, NOT_SUPPORTED_ERR);
}
}
}
#endif // ENABLE(QUOTA)