Title: [109716] trunk/Source/WebCore
Revision
109716
Author
aba...@webkit.org
Date
2012-03-05 00:13:42 -0800 (Mon, 05 Mar 2012)

Log Message

allowDatabaseAccess and databaseExceededQuota should be part of DatabaseContext not ScriptExecutionContext
https://bugs.webkit.org/show_bug.cgi?id=80178

Reviewed by Eric Seidel.

These functions are only used by SQLDatabase, which means we can move
them to DatabaseContext, removing one more tendril of the SQLDatabase
code.

* dom/Document.cpp:
(WebCore):
* dom/Document.h:
(Document):
* dom/ScriptExecutionContext.h:
(ScriptExecutionContext):
* storage/DatabaseContext.cpp:
(WebCore::DatabaseContext::DatabaseContext):
(WebCore::DatabaseContext::from):
(WebCore::DatabaseContext::allowDatabaseAccess):
(WebCore):
(WebCore::DatabaseContext::databaseExceededQuota):
* storage/DatabaseContext.h:
(DatabaseContext):
* storage/DatabaseTracker.cpp:
(WebCore::DatabaseTracker::canEstablishDatabase):
* storage/SQLTransaction.cpp:
(WebCore::SQLTransaction::executeSQL):
* storage/SQLTransactionClient.cpp:
(WebCore::SQLTransactionClient::didExceedQuota):
* storage/SQLTransactionSync.cpp:
(WebCore::SQLTransactionSync::executeSQL):
* workers/WorkerContext.cpp:
(WebCore):
* workers/WorkerContext.h:
(WorkerContext):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (109715 => 109716)


--- trunk/Source/WebCore/ChangeLog	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/ChangeLog	2012-03-05 08:13:42 UTC (rev 109716)
@@ -1,3 +1,41 @@
+2012-03-05  Adam Barth  <aba...@webkit.org>
+
+        allowDatabaseAccess and databaseExceededQuota should be part of DatabaseContext not ScriptExecutionContext
+        https://bugs.webkit.org/show_bug.cgi?id=80178
+
+        Reviewed by Eric Seidel.
+
+        These functions are only used by SQLDatabase, which means we can move
+        them to DatabaseContext, removing one more tendril of the SQLDatabase
+        code.
+
+        * dom/Document.cpp:
+        (WebCore):
+        * dom/Document.h:
+        (Document):
+        * dom/ScriptExecutionContext.h:
+        (ScriptExecutionContext):
+        * storage/DatabaseContext.cpp:
+        (WebCore::DatabaseContext::DatabaseContext):
+        (WebCore::DatabaseContext::from):
+        (WebCore::DatabaseContext::allowDatabaseAccess):
+        (WebCore):
+        (WebCore::DatabaseContext::databaseExceededQuota):
+        * storage/DatabaseContext.h:
+        (DatabaseContext):
+        * storage/DatabaseTracker.cpp:
+        (WebCore::DatabaseTracker::canEstablishDatabase):
+        * storage/SQLTransaction.cpp:
+        (WebCore::SQLTransaction::executeSQL):
+        * storage/SQLTransactionClient.cpp:
+        (WebCore::SQLTransactionClient::didExceedQuota):
+        * storage/SQLTransactionSync.cpp:
+        (WebCore::SQLTransactionSync::executeSQL):
+        * workers/WorkerContext.cpp:
+        (WebCore):
+        * workers/WorkerContext.h:
+        (WorkerContext):
+
 2012-03-04  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r107551.

Modified: trunk/Source/WebCore/dom/Document.cpp (109715 => 109716)


--- trunk/Source/WebCore/dom/Document.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -4738,24 +4738,6 @@
     SecurityContext::setSecurityOrigin(origin);
 }
 
-#if ENABLE(SQL_DATABASE)
-
-bool Document::allowDatabaseAccess() const
-{
-    if (!page() || (page()->settings()->privateBrowsingEnabled() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(securityOrigin()->protocol())))
-        return false;
-    return true;
-}
-
-void Document::databaseExceededQuota(const String& name)
-{
-    Page* currentPage = page();
-    if (currentPage)
-        currentPage->chrome()->client()->exceededDatabaseQuota(document()->frame(), name);
-}
-
-#endif
-
 bool Document::isContextThread() const
 {
     return isMainThread();

Modified: trunk/Source/WebCore/dom/Document.h (109715 => 109716)


--- trunk/Source/WebCore/dom/Document.h	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/dom/Document.h	2012-03-05 08:13:42 UTC (rev 109716)
@@ -1028,11 +1028,6 @@
     bool processingLoadEvent() const { return m_processingLoadEvent; }
     bool loadEventFinished() const { return m_loadEventFinished; }
 
-#if ENABLE(SQL_DATABASE)
-    virtual bool allowDatabaseAccess() const;
-    virtual void databaseExceededQuota(const String& name);
-#endif
-
     virtual bool isContextThread() const;
     virtual bool isJSExecutionForbidden() const { return false; }
 

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (109715 => 109716)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2012-03-05 08:13:42 UTC (rev 109716)
@@ -70,10 +70,6 @@
     virtual bool isDocument() const { return false; }
     virtual bool isWorkerContext() const { return false; }
 
-#if ENABLE(SQL_DATABASE)
-    virtual bool allowDatabaseAccess() const = 0;
-    virtual void databaseExceededQuota(const String& name) = 0;
-#endif
     virtual bool isContextThread() const { return true; }
     virtual bool isJSExecutionForbidden() const = 0;
 

Modified: trunk/Source/WebCore/storage/DatabaseContext.cpp (109715 => 109716)


--- trunk/Source/WebCore/storage/DatabaseContext.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/storage/DatabaseContext.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -30,9 +30,17 @@
 
 #if ENABLE(SQL_DATABASE)
 
+#include "Chrome.h"
+#include "ChromeClient.h"
 #include "Database.h"
 #include "DatabaseTask.h"
 #include "DatabaseThread.h"
+#include "DatabaseTracker.h"
+#include "Document.h"
+#include "Page.h"
+#include "SchemeRegistry.h"
+#include "SecurityOrigin.h"
+#include "Settings.h"
 
 namespace WebCore {
 
@@ -41,8 +49,9 @@
     return static_cast<DatabaseContext*>(Supplement<ScriptExecutionContext>::from(context, "DatabaseContext"));
 }
 
-DatabaseContext::DatabaseContext()
-    : m_hasOpenDatabases(false)
+DatabaseContext::DatabaseContext(ScriptExecutionContext* context)
+    : m_scriptExecutionContext(context)
+    , m_hasOpenDatabases(false)
 {
 }
 
@@ -58,7 +67,7 @@
 {
     DatabaseContext* supplement = existingDatabaseContextFrom(context);
     if (!supplement) {
-        supplement = new DatabaseContext();
+        supplement = new DatabaseContext(context);
         provideTo(context, "DatabaseContext", adoptPtr(supplement));
         ASSERT(supplement == existingDatabaseContextFrom(context));
     }
@@ -100,6 +109,35 @@
         cleanupSync->taskCompleted();
 }
 
+bool DatabaseContext::allowDatabaseAccess() const
+{
+    if (m_scriptExecutionContext->isDocument()) {
+        Document* document = static_cast<Document*>(m_scriptExecutionContext);
+        if (!document->page() || (document->page()->settings()->privateBrowsingEnabled() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol())))
+            return false;
+        return true;
+    }
+    ASSERT(m_scriptExecutionContext->isWorkerContext());
+    // allowDatabaseAccess is not yet implemented for workers.
+    return true;
+}
+
+void DatabaseContext::databaseExceededQuota(const String& name)
+{
+    if (m_scriptExecutionContext->isDocument()) {
+        Document* document = static_cast<Document*>(m_scriptExecutionContext);
+        if (Page* page = document->page())
+            page->chrome()->client()->exceededDatabaseQuota(document->frame(), name);
+        return;
+    }
+    ASSERT(m_scriptExecutionContext->isWorkerContext());
+#if !PLATFORM(CHROMIUM)
+    // FIXME: This needs a real implementation; this is a temporary solution for testing.
+    const unsigned long long defaultQuota = 5 * 1024 * 1024;
+    DatabaseTracker::tracker().setQuota(m_scriptExecutionContext->securityOrigin(), defaultQuota);
+#endif
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(SQL_DATABASE)

Modified: trunk/Source/WebCore/storage/DatabaseContext.h (109715 => 109716)


--- trunk/Source/WebCore/storage/DatabaseContext.h	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/storage/DatabaseContext.h	2012-03-05 08:13:42 UTC (rev 109716)
@@ -53,9 +53,13 @@
     // When the database cleanup is done, cleanupSync will be signalled.
     static void stopDatabases(ScriptExecutionContext*, DatabaseTaskSynchronizer*);
 
+    bool allowDatabaseAccess() const;
+    void databaseExceededQuota(const String& name);
+
 private:
-    DatabaseContext();
+    explicit DatabaseContext(ScriptExecutionContext*);
 
+    ScriptExecutionContext* m_scriptExecutionContext;
     RefPtr<DatabaseThread> m_databaseThread;
     bool m_hasOpenDatabases; // This never changes back to false, even after the database thread is closed.
 };

Modified: trunk/Source/WebCore/storage/DatabaseTracker.cpp (109715 => 109716)


--- trunk/Source/WebCore/storage/DatabaseTracker.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/storage/DatabaseTracker.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -34,6 +34,7 @@
 #include "AbstractDatabase.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
+#include "DatabaseContext.h"
 #include "DatabaseThread.h"
 #include "DatabaseTrackerClient.h"
 #include "Logging.h"
@@ -175,7 +176,7 @@
         m_proposedDatabases.add(&details);
     }
     // Drop all locks before calling out; we don't know what they'll do.
-    context->databaseExceededQuota(name);
+    DatabaseContext::from(context)->databaseExceededQuota(name);
 
     MutexLocker lockDatabase(m_databaseGuard);
 

Modified: trunk/Source/WebCore/storage/SQLTransaction.cpp (109715 => 109716)


--- trunk/Source/WebCore/storage/SQLTransaction.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/storage/SQLTransaction.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -98,7 +98,7 @@
     }
 
     int permissions = DatabaseAuthorizer::ReadWriteMask;
-    if (!m_database->scriptExecutionContext()->allowDatabaseAccess())
+    if (!m_database->databaseContext()->allowDatabaseAccess())
         permissions |= DatabaseAuthorizer::NoAccessMask;
     else if (m_readOnly)
         permissions |= DatabaseAuthorizer::ReadOnlyMask;

Modified: trunk/Source/WebCore/storage/SQLTransactionClient.cpp (109715 => 109716)


--- trunk/Source/WebCore/storage/SQLTransactionClient.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/storage/SQLTransactionClient.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -34,6 +34,7 @@
 #if ENABLE(SQL_DATABASE)
 
 #include "AbstractDatabase.h"
+#include "DatabaseContext.h"
 #include "DatabaseTracker.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
@@ -55,7 +56,7 @@
 {
     ASSERT(database->scriptExecutionContext()->isContextThread());
     unsigned long long currentQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin());
-    database->scriptExecutionContext()->databaseExceededQuota(database->stringIdentifier());
+    database->databaseContext()->databaseExceededQuota(database->stringIdentifier());
     unsigned long long newQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin());
     return (newQuota > currentQuota);
 }

Modified: trunk/Source/WebCore/storage/SQLTransactionSync.cpp (109715 => 109716)


--- trunk/Source/WebCore/storage/SQLTransactionSync.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/storage/SQLTransactionSync.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -34,6 +34,7 @@
 #if ENABLE(SQL_DATABASE)
 
 #include "DatabaseAuthorizer.h"
+#include "DatabaseContext.h"
 #include "DatabaseSync.h"
 #include "PlatformString.h"
 #include "SQLException.h"
@@ -94,7 +95,7 @@
         return 0;
 
     int permissions = DatabaseAuthorizer::ReadWriteMask;
-    if (!m_database->scriptExecutionContext()->allowDatabaseAccess())
+    if (!m_database->databaseContext()->allowDatabaseAccess())
       permissions |= DatabaseAuthorizer::NoAccessMask;
     else if (m_readOnly)
       permissions |= DatabaseAuthorizer::ReadOnlyMask;

Modified: trunk/Source/WebCore/workers/WorkerContext.cpp (109715 => 109716)


--- trunk/Source/WebCore/workers/WorkerContext.cpp	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/workers/WorkerContext.cpp	2012-03-05 08:13:42 UTC (rev 109716)
@@ -319,15 +319,6 @@
     return Database::openDatabase(this, name, version, displayName, estimatedSize, creationCallback, ec);
 }
 
-void WorkerContext::databaseExceededQuota(const String&)
-{
-#if !PLATFORM(CHROMIUM)
-    // FIXME: This needs a real implementation; this is a temporary solution for testing.
-    const unsigned long long defaultQuota = 5 * 1024 * 1024;
-    DatabaseTracker::tracker().setQuota(securityOrigin(), defaultQuota);
-#endif
-}
-
 PassRefPtr<DatabaseSync> WorkerContext::openDatabaseSync(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
 {
     if (!securityOrigin()->canAccessDatabase() || !AbstractDatabase::isAvailable()) {

Modified: trunk/Source/WebCore/workers/WorkerContext.h (109715 => 109716)


--- trunk/Source/WebCore/workers/WorkerContext.h	2012-03-05 08:08:16 UTC (rev 109715)
+++ trunk/Source/WebCore/workers/WorkerContext.h	2012-03-05 08:13:42 UTC (rev 109716)
@@ -116,11 +116,6 @@
         // HTML 5 client-side database
         PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode&);
         PassRefPtr<DatabaseSync> openDatabaseSync(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode&);
-
-        // Not implemented yet.
-        virtual bool allowDatabaseAccess() const { return true; }
-        // Not implemented for real yet.
-        virtual void databaseExceededQuota(const String&);
 #endif
         virtual bool isContextThread() const;
         virtual bool isJSExecutionForbidden() const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to