StorageNamespaceProvider.cpp [plain text]
#include "config.h"
#include "StorageNamespaceProvider.h"
#include "Document.h"
#include "SecurityOriginData.h"
#include "StorageArea.h"
#include "StorageNamespace.h"
namespace WebCore {
unsigned localStorageDatabaseQuotaInBytes = 5 * 1024 * 1024;
StorageNamespaceProvider::StorageNamespaceProvider()
{
}
StorageNamespaceProvider::~StorageNamespaceProvider()
{
ASSERT(m_pages.isEmpty());
}
void StorageNamespaceProvider::addPage(Page& page)
{
ASSERT(!m_pages.contains(&page));
m_pages.add(&page);
}
void StorageNamespaceProvider::removePage(Page& page)
{
ASSERT(m_pages.contains(&page));
m_pages.remove(&page);
}
RefPtr<StorageArea> StorageNamespaceProvider::localStorageArea(Document& document)
{
auto& storageNamespace = document.securityOrigin()->canAccessLocalStorage(document.topOrigin()) ? localStorageNamespace() : transientLocalStorageNamespace(*document.topOrigin());
return storageNamespace.storageArea(SecurityOriginData::fromSecurityOrigin(*document.securityOrigin()));
}
StorageNamespace& StorageNamespaceProvider::localStorageNamespace()
{
if (!m_localStorageNamespace)
m_localStorageNamespace = createLocalStorageNamespace(localStorageDatabaseQuotaInBytes);
return *m_localStorageNamespace;
}
StorageNamespace& StorageNamespaceProvider::transientLocalStorageNamespace(SecurityOrigin& securityOrigin)
{
auto& slot = m_transientLocalStorageMap.add(&securityOrigin, nullptr).iterator->value;
if (!slot)
slot = createTransientLocalStorageNamespace(securityOrigin, localStorageDatabaseQuotaInBytes);
return *slot;
}
}