DOMWindowIndexedDatabase.cpp [plain text]
#include "config.h"
#include "DOMWindowIndexedDatabase.h"
#if ENABLE(INDEXED_DATABASE)
#include "DOMWindow.h"
#include "DatabaseProvider.h"
#include "Document.h"
#include "IDBFactory.h"
#include "Page.h"
namespace WebCore {
DOMWindowIndexedDatabase::DOMWindowIndexedDatabase(DOMWindow* window)
: DOMWindowProperty(window)
{
}
DOMWindowIndexedDatabase::~DOMWindowIndexedDatabase() = default;
const char* DOMWindowIndexedDatabase::supplementName()
{
return "DOMWindowIndexedDatabase";
}
DOMWindowIndexedDatabase* DOMWindowIndexedDatabase::from(DOMWindow* window)
{
DOMWindowIndexedDatabase* supplement = static_cast<DOMWindowIndexedDatabase*>(Supplement<DOMWindow>::from(window, supplementName()));
if (!supplement) {
auto newSupplement = makeUnique<DOMWindowIndexedDatabase>(window);
supplement = newSupplement.get();
provideTo(window, supplementName(), WTFMove(newSupplement));
}
return supplement;
}
IDBFactory* DOMWindowIndexedDatabase::indexedDB(DOMWindow& window)
{
return from(&window)->indexedDB();
}
IDBFactory* DOMWindowIndexedDatabase::indexedDB()
{
auto* window = this->window();
if (!window)
return nullptr;
auto* document = window->document();
if (!document)
return nullptr;
auto* page = document->page();
if (!page)
return nullptr;
if (!window->isCurrentlyDisplayedInFrame())
return nullptr;
if (!m_idbFactory) {
auto* connectionProxy = document->idbConnectionProxy();
if (!connectionProxy)
return nullptr;
m_idbFactory = IDBFactory::create(*connectionProxy);
}
return m_idbFactory.get();
}
}
#endif // ENABLE(INDEXED_DATABASE)