summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/webdatabase/DatabaseContext.cpp')
-rw-r--r--Source/WebCore/Modules/webdatabase/DatabaseContext.cpp130
1 files changed, 49 insertions, 81 deletions
diff --git a/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp b/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
index 752e29e48..3dcb56034 100644
--- a/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
+++ b/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
@@ -11,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -28,12 +28,9 @@
#include "config.h"
#include "DatabaseContext.h"
-#if ENABLE(SQL_DATABASE)
-
#include "Chrome.h"
#include "ChromeClient.h"
#include "Database.h"
-#include "DatabaseBackendContext.h"
#include "DatabaseManager.h"
#include "DatabaseTask.h"
#include "DatabaseThread.h"
@@ -42,7 +39,7 @@
#include "SchemeRegistry.h"
#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
-#include "Settings.h"
+#include "SecurityOriginData.h"
namespace WebCore {
@@ -97,54 +94,32 @@ namespace WebCore {
// DatabaseContext will outlive both regardless of which of the 2 destructs first.
-DatabaseContext::DatabaseContext(ScriptExecutionContext* context)
- : ActiveDOMObject(context)
- , m_hasOpenDatabases(false)
- , m_isRegistered(true) // will register on construction below.
- , m_hasRequestedTermination(false)
-#if PLATFORM(IOS)
- , m_paused(false)
-#endif //PLATFORM(IOS)
+DatabaseContext::DatabaseContext(ScriptExecutionContext& context)
+ : ActiveDOMObject(&context)
{
// ActiveDOMObject expects this to be called to set internal flags.
suspendIfNeeded();
- context->setDatabaseContext(this);
-
- // For debug accounting only. We must do this before we register the
- // instance. The assertions assume this.
- DatabaseManager::manager().didConstructDatabaseContext();
-
- DatabaseManager::manager().registerDatabaseContext(this);
+ ASSERT(!context.databaseContext());
+ context.setDatabaseContext(this);
}
DatabaseContext::~DatabaseContext()
{
stopDatabases();
ASSERT(!m_databaseThread || m_databaseThread->terminationRequested());
-
- // For debug accounting only. We must call this last. The assertions assume
- // this.
- DatabaseManager::manager().didDestructDatabaseContext();
+ ASSERT(!scriptExecutionContext() || !scriptExecutionContext()->databaseContext());
}
-// This is called if the associated ScriptExecutionContext is destructing while
+// This is called if the associated ScriptExecutionContext is destroyed while
// we're still associated with it. That's our cue to disassociate and shutdown.
-// To do this, we stop the database and let everything shutdown naturally
-// because the database closing process may still make use of this context.
+// To do this, we stop the database and let everything shut down naturally
+// because the database closing process might still make use of this context.
// It is not safe to just delete the context here.
void DatabaseContext::contextDestroyed()
{
+ ActiveDOMObject::contextDestroyed();
stopDatabases();
-
- // Normally, willDestroyActiveDOMObject() is called in ~ActiveDOMObject().
- // However, we're here because the destructor hasn't been called, and the
- // ScriptExecutionContext we're associated with is about to be destructed.
- // So, go ahead an unregister self from the ActiveDOMObject list, and
- // set m_scriptExecutionContext to 0 so that ~ActiveDOMObject() doesn't
- // try to do so again.
- m_scriptExecutionContext->willDestroyActiveDOMObject(this);
- m_scriptExecutionContext = 0;
}
// stop() is from stopActiveDOMObjects() which indicates that the owner Frame
@@ -155,18 +130,17 @@ void DatabaseContext::stop()
stopDatabases();
}
-PassRefPtr<DatabaseBackendContext> DatabaseContext::backend()
+bool DatabaseContext::canSuspendForDocumentSuspension() const
{
- DatabaseBackendContext* backend = static_cast<DatabaseBackendContext*>(this);
- return backend;
+ if (!hasOpenDatabases() || !m_databaseThread)
+ return true;
+
+ return !m_databaseThread->hasPendingDatabaseActivity();
}
DatabaseThread* DatabaseContext::databaseThread()
{
if (!m_databaseThread && !m_hasOpenDatabases) {
-#if PLATFORM(IOS)
- MutexLocker lock(m_databaseThreadMutex);
-#endif //PLATFORM(IOS)
// It's OK to ask for the m_databaseThread after we've requested
// termination because we're still using it to execute the closing
// of the database. However, it is NOT OK to create a new thread
@@ -177,33 +151,16 @@ DatabaseThread* DatabaseContext::databaseThread()
// because in that case we already had a database thread and terminated it and should not create another.
m_databaseThread = DatabaseThread::create();
if (!m_databaseThread->start())
- m_databaseThread = 0;
-#if PLATFORM(IOS)
- if (m_databaseThread)
- m_databaseThread->setPaused(m_paused);
-#endif //PLATFORM(IOS)
+ m_databaseThread = nullptr;
}
return m_databaseThread.get();
}
-#if PLATFORM(IOS)
-void DatabaseContext::setPaused(bool paused)
-{
- MutexLocker lock(m_databaseThreadMutex);
-
- m_paused = paused;
- if (m_databaseThread)
- m_databaseThread->setPaused(m_paused);
-}
-#endif // PLATFORM(IOS)
-
-bool DatabaseContext::stopDatabases(DatabaseTaskSynchronizer* cleanupSync)
+bool DatabaseContext::stopDatabases(DatabaseTaskSynchronizer* synchronizer)
{
- if (m_isRegistered) {
- DatabaseManager::manager().unregisterDatabaseContext(this);
- m_isRegistered = false;
- }
+ // FIXME: What guarantees this is never called after the script execution context is null?
+ ASSERT(scriptExecutionContext());
// Though we initiate termination of the DatabaseThread here in
// stopDatabases(), we can't clear the m_databaseThread ref till we get to
@@ -214,20 +171,26 @@ bool DatabaseContext::stopDatabases(DatabaseTaskSynchronizer* cleanupSync)
// why our ref count is 0 then and we're destructing). Then, the
// m_databaseThread RefPtr destructor will deref and delete the
// DatabaseThread.
-
- if (m_databaseThread && !m_hasRequestedTermination) {
- m_databaseThread->requestTermination(cleanupSync);
+ bool result = m_databaseThread && !m_hasRequestedTermination;
+ if (result) {
+ m_databaseThread->requestTermination(synchronizer);
m_hasRequestedTermination = true;
- return true;
}
- return false;
+
+ auto& context = *scriptExecutionContext();
+ if (context.databaseContext()) {
+ ASSERT(context.databaseContext() == this);
+ context.setDatabaseContext(nullptr);
+ }
+
+ return result;
}
bool DatabaseContext::allowDatabaseAccess() const
{
- if (m_scriptExecutionContext->isDocument()) {
- Document* document = toDocument(m_scriptExecutionContext);
- if (!document->page() || (document->page()->settings().privateBrowsingEnabled() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol())))
+ if (is<Document>(*m_scriptExecutionContext)) {
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ if (!document.page() || (document.page()->usesEphemeralSession() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document.securityOrigin().protocol())))
return false;
return true;
}
@@ -238,18 +201,23 @@ bool DatabaseContext::allowDatabaseAccess() const
void DatabaseContext::databaseExceededQuota(const String& name, DatabaseDetails details)
{
- if (m_scriptExecutionContext->isDocument()) {
- Document* document = toDocument(m_scriptExecutionContext);
- if (Page* page = document->page())
- page->chrome().client().exceededDatabaseQuota(document->frame(), name, details);
+ if (is<Document>(*m_scriptExecutionContext)) {
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ if (Page* page = document.page())
+ page->chrome().client().exceededDatabaseQuota(*document.frame(), name, details);
return;
}
ASSERT(m_scriptExecutionContext->isWorkerGlobalScope());
- // FIXME: This needs a real implementation; this is a temporary solution for testing.
- const unsigned long long defaultQuota = 5 * 1024 * 1024;
- DatabaseManager::manager().setQuota(m_scriptExecutionContext->securityOrigin(), defaultQuota);
}
-} // namespace WebCore
+SecurityOriginData DatabaseContext::securityOrigin() const
+{
+ return SecurityOriginData::fromSecurityOrigin(*m_scriptExecutionContext->securityOrigin());
+}
+
+bool DatabaseContext::isContextThread() const
+{
+ return m_scriptExecutionContext->isContextThread();
+}
-#endif // ENABLE(SQL_DATABASE)
+} // namespace WebCore