#include "config.h"
#include "Storage.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "Page.h"
#include "SchemeRegistry.h"
#include "SecurityOrigin.h"
#include "StorageArea.h"
#include "StorageType.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
Ref<Storage> Storage::create(Frame* frame, RefPtr<StorageArea>&& storageArea)
{
return adoptRef(*new Storage(frame, WTFMove(storageArea)));
}
Storage::Storage(Frame* frame, RefPtr<StorageArea>&& storageArea)
: DOMWindowProperty(frame)
, m_storageArea(WTFMove(storageArea))
{
ASSERT(m_frame);
ASSERT(m_storageArea);
m_storageArea->incrementAccessCount();
}
Storage::~Storage()
{
m_storageArea->decrementAccessCount();
}
ExceptionOr<unsigned> Storage::length() const
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
return m_storageArea->length();
}
ExceptionOr<String> Storage::key(unsigned index) const
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
return m_storageArea->key(index);
}
ExceptionOr<String> Storage::getItem(const String& key) const
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
return m_storageArea->item(key);
}
ExceptionOr<void> Storage::setItem(const String& key, const String& value)
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
bool quotaException = false;
m_storageArea->setItem(m_frame, key, value, quotaException);
if (quotaException)
return Exception { QUOTA_EXCEEDED_ERR };
return { };
}
ExceptionOr<void> Storage::removeItem(const String& key)
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
m_storageArea->removeItem(m_frame, key);
return { };
}
ExceptionOr<void> Storage::clear()
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
m_storageArea->clear(m_frame);
return { };
}
ExceptionOr<bool> Storage::contains(const String& key) const
{
if (!m_storageArea->canAccessStorage(m_frame))
return Exception { SECURITY_ERR };
return m_storageArea->contains(key);
}
bool Storage::isSupportedPropertyName(const String& propertyName) const
{
if (!m_storageArea->canAccessStorage(m_frame))
return false;
return m_storageArea->contains(propertyName);
}
}