summaryrefslogtreecommitdiff
path: root/Source/WebCore/storage/Storage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/storage/Storage.cpp')
-rw-r--r--Source/WebCore/storage/Storage.cpp111
1 files changed, 31 insertions, 80 deletions
diff --git a/Source/WebCore/storage/Storage.cpp b/Source/WebCore/storage/Storage.cpp
index c484b96aa..11f919a82 100644
--- a/Source/WebCore/storage/Storage.cpp
+++ b/Source/WebCore/storage/Storage.cpp
@@ -31,21 +31,21 @@
#include "Frame.h"
#include "Page.h"
#include "SchemeRegistry.h"
-#include "Settings.h"
+#include "SecurityOrigin.h"
#include "StorageArea.h"
-#include <wtf/PassRefPtr.h>
+#include "StorageType.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
-PassRefPtr<Storage> Storage::create(Frame* frame, PassRefPtr<StorageArea> storageArea)
+Ref<Storage> Storage::create(Frame* frame, RefPtr<StorageArea>&& storageArea)
{
- return adoptRef(new Storage(frame, storageArea));
+ return adoptRef(*new Storage(frame, WTFMove(storageArea)));
}
-Storage::Storage(Frame* frame, PassRefPtr<StorageArea> storageArea)
+Storage::Storage(Frame* frame, RefPtr<StorageArea>&& storageArea)
: DOMWindowProperty(frame)
- , m_storageArea(storageArea)
+ , m_storageArea(WTFMove(storageArea))
{
ASSERT(m_frame);
ASSERT(m_storageArea);
@@ -58,115 +58,66 @@ Storage::~Storage()
m_storageArea->decrementAccessCount();
}
-unsigned Storage::length(ExceptionCode& ec) const
+ExceptionOr<unsigned> Storage::length() const
{
- ec = 0;
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return 0;
- }
-
- if (isDisabledByPrivateBrowsing())
- return 0;
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
return m_storageArea->length();
}
-String Storage::key(unsigned index, ExceptionCode& ec) const
+ExceptionOr<String> Storage::key(unsigned index) const
{
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return String();
- }
-
- if (isDisabledByPrivateBrowsing())
- return String();
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
return m_storageArea->key(index);
}
-String Storage::getItem(const String& key, ExceptionCode& ec) const
+ExceptionOr<String> Storage::getItem(const String& key) const
{
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return String();
- }
-
- if (isDisabledByPrivateBrowsing())
- return String();
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
return m_storageArea->item(key);
}
-void Storage::setItem(const String& key, const String& value, ExceptionCode& ec)
+ExceptionOr<void> Storage::setItem(const String& key, const String& value)
{
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return;
- }
-
- if (isDisabledByPrivateBrowsing()) {
- ec = QUOTA_EXCEEDED_ERR;
- return;
- }
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
bool quotaException = false;
m_storageArea->setItem(m_frame, key, value, quotaException);
-
if (quotaException)
- ec = QUOTA_EXCEEDED_ERR;
+ return Exception { QUOTA_EXCEEDED_ERR };
+ return { };
}
-void Storage::removeItem(const String& key, ExceptionCode& ec)
+ExceptionOr<void> Storage::removeItem(const String& key)
{
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return;
- }
-
- if (isDisabledByPrivateBrowsing())
- return;
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
m_storageArea->removeItem(m_frame, key);
+ return { };
}
-void Storage::clear(ExceptionCode& ec)
+ExceptionOr<void> Storage::clear()
{
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return;
- }
-
- if (isDisabledByPrivateBrowsing())
- return;
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
m_storageArea->clear(m_frame);
+ return { };
}
-bool Storage::contains(const String& key, ExceptionCode& ec) const
+ExceptionOr<bool> Storage::contains(const String& key) const
{
- if (!m_storageArea->canAccessStorage(m_frame)) {
- ec = SECURITY_ERR;
- return false;
- }
-
- if (isDisabledByPrivateBrowsing())
- return false;
+ if (!m_storageArea->canAccessStorage(m_frame))
+ return Exception { SECURITY_ERR };
return m_storageArea->contains(key);
}
-bool Storage::isDisabledByPrivateBrowsing() const
-{
- if (!m_frame->page()->settings().privateBrowsingEnabled())
- return false;
-
- if (m_storageArea->storageType() == LocalStorage) {
- if (SchemeRegistry::allowsLocalStorageAccessInPrivateBrowsing(m_frame->document()->securityOrigin()->protocol()))
- return false;
- }
-
- return true;
-}
-
} // namespace WebCore