WorkerGlobalScopeIndexedDatabase.cpp [plain text]
#include "config.h"
#if ENABLE(INDEXED_DATABASE_IN_WORKERS)
#include "WorkerGlobalScopeIndexedDatabase.h"
#include "IDBConnectionProxy.h"
#include "IDBFactory.h"
#include "IDBOpenDBRequest.h"
#include "ScriptExecutionContext.h"
#include "WorkerGlobalScope.h"
namespace WebCore {
WorkerGlobalScopeIndexedDatabase::WorkerGlobalScopeIndexedDatabase(WorkerGlobalScope&, IDBClient::IDBConnectionProxy& connectionProxy)
: m_connectionProxy(connectionProxy)
{
}
WorkerGlobalScopeIndexedDatabase::~WorkerGlobalScopeIndexedDatabase() = default;
const char* WorkerGlobalScopeIndexedDatabase::supplementName()
{
return "WorkerGlobalScopeIndexedDatabase";
}
WorkerGlobalScopeIndexedDatabase* WorkerGlobalScopeIndexedDatabase::from(WorkerGlobalScope& scope)
{
WorkerGlobalScopeIndexedDatabase* supplement = static_cast<WorkerGlobalScopeIndexedDatabase*>(Supplement<WorkerGlobalScope>::from(&scope, supplementName()));
if (!supplement) {
auto* connectionProxy = scope.idbConnectionProxy();
if (!connectionProxy)
return nullptr;
auto newSupplement = makeUnique<WorkerGlobalScopeIndexedDatabase>(scope, *connectionProxy);
supplement = newSupplement.get();
provideTo(&scope, supplementName(), WTFMove(newSupplement));
}
return supplement;
}
IDBFactory* WorkerGlobalScopeIndexedDatabase::indexedDB(WorkerGlobalScope& scope)
{
auto* scopeIDB = from(scope);
return scopeIDB ? scopeIDB->indexedDB() : nullptr;
}
IDBFactory* WorkerGlobalScopeIndexedDatabase::indexedDB()
{
if (!m_idbFactory)
m_idbFactory = IDBFactory::create(m_connectionProxy.get());
return m_idbFactory.get();
}
}
#endif // ENABLE(INDEXED_DATABASE_IN_WORKERS)