Replace ExceptionCode with DatabaseError in the openDatabase() code path.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 01:05:04 +0000 (01:05 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 01:05:04 +0000 (01:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108724.

Reviewed by Alexey Proskuryakov.

Also made DatabaseBackend::performOpenAndVerify() a little more
straightforward and less repetitive.

No new tests.

* Modules/webdatabase/DOMWindowWebDatabase.cpp:
(WebCore::DOMWindowWebDatabase::openDatabase):
* Modules/webdatabase/Database.cpp:
(WebCore::Database::openAndVerifyVersion):
(WebCore::Database::performOpenAndVerify):
* Modules/webdatabase/Database.h:
(Database):
* Modules/webdatabase/DatabaseBackend.cpp:
(WebCore::DoneCreatingDatabaseOnExitCaller::DoneCreatingDatabaseOnExitCaller):
(WebCore::DoneCreatingDatabaseOnExitCaller::~DoneCreatingDatabaseOnExitCaller):
(DoneCreatingDatabaseOnExitCaller):
(WebCore::DoneCreatingDatabaseOnExitCaller::openSucceeded):
(WebCore::DatabaseBackend::performOpenAndVerify):
* Modules/webdatabase/DatabaseBackend.h:
* Modules/webdatabase/DatabaseManager.cpp:
(WebCore::DatabaseManager::openDatabase):
(WebCore::DatabaseManager::openDatabaseSync):
* Modules/webdatabase/DatabaseManager.h:
(DatabaseManager):
* Modules/webdatabase/DatabaseSync.cpp:
(WebCore::DatabaseSync::openAndVerifyVersion):
* Modules/webdatabase/DatabaseSync.h:
(DatabaseSync):
* Modules/webdatabase/DatabaseTask.cpp:
(WebCore::Database::DatabaseOpenTask::DatabaseOpenTask):
(WebCore::Database::DatabaseOpenTask::doPerformTask):
* Modules/webdatabase/DatabaseTask.h:
(WebCore::Database::DatabaseOpenTask::create):
(Database::DatabaseOpenTask):
* Modules/webdatabase/WorkerContextWebDatabase.cpp:
(WebCore::WorkerContextWebDatabase::openDatabase):
(WebCore::WorkerContextWebDatabase::openDatabaseSync):
* WebCore.gypi:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141668 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp
Source/WebCore/Modules/webdatabase/Database.cpp
Source/WebCore/Modules/webdatabase/Database.h
Source/WebCore/Modules/webdatabase/DatabaseBackend.cpp
Source/WebCore/Modules/webdatabase/DatabaseBackend.h
Source/WebCore/Modules/webdatabase/DatabaseManager.cpp
Source/WebCore/Modules/webdatabase/DatabaseManager.h
Source/WebCore/Modules/webdatabase/DatabaseSync.cpp
Source/WebCore/Modules/webdatabase/DatabaseSync.h
Source/WebCore/Modules/webdatabase/DatabaseTask.cpp
Source/WebCore/Modules/webdatabase/DatabaseTask.h
Source/WebCore/Modules/webdatabase/WorkerContextWebDatabase.cpp
Source/WebCore/WebCore.gypi

index 7f2189d..a2d1439 100644 (file)
@@ -1,3 +1,49 @@
+2013-02-01  Mark Lam  <mark.lam@apple.com>
+
+        Replace ExceptionCode with DatabaseError in the openDatabase() code path.
+        https://bugs.webkit.org/show_bug.cgi?id=108724.
+
+        Reviewed by Alexey Proskuryakov.
+
+        Also made DatabaseBackend::performOpenAndVerify() a little more
+        straightforward and less repetitive.
+
+        No new tests.
+
+        * Modules/webdatabase/DOMWindowWebDatabase.cpp:
+        (WebCore::DOMWindowWebDatabase::openDatabase):
+        * Modules/webdatabase/Database.cpp:
+        (WebCore::Database::openAndVerifyVersion):
+        (WebCore::Database::performOpenAndVerify):
+        * Modules/webdatabase/Database.h:
+        (Database):
+        * Modules/webdatabase/DatabaseBackend.cpp:
+        (WebCore::DoneCreatingDatabaseOnExitCaller::DoneCreatingDatabaseOnExitCaller):
+        (WebCore::DoneCreatingDatabaseOnExitCaller::~DoneCreatingDatabaseOnExitCaller):
+        (DoneCreatingDatabaseOnExitCaller):
+        (WebCore::DoneCreatingDatabaseOnExitCaller::openSucceeded):
+        (WebCore::DatabaseBackend::performOpenAndVerify):
+        * Modules/webdatabase/DatabaseBackend.h:
+        * Modules/webdatabase/DatabaseManager.cpp:
+        (WebCore::DatabaseManager::openDatabase):
+        (WebCore::DatabaseManager::openDatabaseSync):
+        * Modules/webdatabase/DatabaseManager.h:
+        (DatabaseManager):
+        * Modules/webdatabase/DatabaseSync.cpp:
+        (WebCore::DatabaseSync::openAndVerifyVersion):
+        * Modules/webdatabase/DatabaseSync.h:
+        (DatabaseSync):
+        * Modules/webdatabase/DatabaseTask.cpp:
+        (WebCore::Database::DatabaseOpenTask::DatabaseOpenTask):
+        (WebCore::Database::DatabaseOpenTask::doPerformTask):
+        * Modules/webdatabase/DatabaseTask.h:
+        (WebCore::Database::DatabaseOpenTask::create):
+        (Database::DatabaseOpenTask):
+        * Modules/webdatabase/WorkerContextWebDatabase.cpp:
+        (WebCore::WorkerContextWebDatabase::openDatabase):
+        (WebCore::WorkerContextWebDatabase::openDatabaseSync):
+        * WebCore.gypi:
+
 2013-02-01  Yongjun Zhang  <yongjun_zhang@apple.com>
 
         Document is never released if an image's src attribute is changed to a url blocked by content-security-policy.
index 53325e1..bde9539 100644 (file)
@@ -47,9 +47,13 @@ PassRefPtr<Database> DOMWindowWebDatabase::openDatabase(DOMWindow* window, const
 
     RefPtr<Database> database = 0;
     DatabaseManager& dbManager = DatabaseManager::manager();
+    DatabaseError error = DatabaseError::None;
     if (dbManager.isAvailable() && window->document()->securityOrigin()->canAccessDatabase(window->document()->topOrigin()))
-        database = dbManager.openDatabase(window->document(), name, version, displayName, estimatedSize, creationCallback, ec);
+        database = dbManager.openDatabase(window->document(), name, version, displayName, estimatedSize, creationCallback, error);
 
+    ASSERT(error == DatabaseError::None || error == DatabaseError::CannotOpenDatabase);
+    if (error == DatabaseError::CannotOpenDatabase)
+        ec = INVALID_STATE_ERR;
     if (!database && !ec)
         ec = SECURITY_ERR;
 
index 91352d8..47a0063 100644 (file)
@@ -121,7 +121,7 @@ String Database::version() const
     return DatabaseBackend::version();
 }
 
-bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, ExceptionCode& e, String& errorMessage)
+bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError& error, String& errorMessage)
 {
     DatabaseTaskSynchronizer synchronizer;
     if (!databaseContext()->databaseThread() || databaseContext()->databaseThread()->terminationRequested(&synchronizer))
@@ -131,7 +131,7 @@ bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, ExceptionCode&
     DatabaseTracker::tracker().prepareToOpenDatabase(this);
 #endif
     bool success = false;
-    OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInNewDatabase, &synchronizer, e, errorMessage, success);
+    OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInNewDatabase, &synchronizer, error, errorMessage, success);
     databaseContext()->databaseThread()->scheduleImmediateTask(task.release());
     synchronizer.waitForTaskCompletion();
 
@@ -192,9 +192,9 @@ unsigned long long Database::maximumSize() const
     return DatabaseManager::manager().getMaxSizeForDatabase(this);
 }
 
-bool Database::performOpenAndVerify(bool setVersionInNewDatabase, ExceptionCode& e, String& errorMessage)
+bool Database::performOpenAndVerify(bool setVersionInNewDatabase, DatabaseError& error, String& errorMessage)
 {
-    if (DatabaseBackend::performOpenAndVerify(setVersionInNewDatabase, e, errorMessage)) {
+    if (DatabaseBackend::performOpenAndVerify(setVersionInNewDatabase, error, errorMessage)) {
         if (databaseContext()->databaseThread())
             databaseContext()->databaseThread()->recordDatabaseOpen(this);
 
index 0703b3f..989b035 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "DatabaseBackend.h"
 #include "DatabaseBasicTypes.h"
+#include "DatabaseError.h"
 #include <wtf/Deque.h>
 #include <wtf/Forward.h>
 #include <wtf/text/WTFString.h>
@@ -91,8 +92,8 @@ private:
     void runTransaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
                         PassRefPtr<VoidCallback> successCallback, PassRefPtr<SQLTransactionWrapper>, bool readOnly);
 
-    bool openAndVerifyVersion(bool setVersionInNewDatabase, ExceptionCode&, String& errorMessage);
-    virtual bool performOpenAndVerify(bool setVersionInNewDatabase, ExceptionCode&, String& errorMessage);
+    bool openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&, String& errorMessage);
+    virtual bool performOpenAndVerify(bool setVersionInNewDatabase, DatabaseError&, String& errorMessage);
 
     void inProgressTransactionCompleted();
     void scheduleTransaction();
index 339913d..3e5b40c 100644 (file)
@@ -279,42 +279,40 @@ String DatabaseBackend::version() const
 
 class DoneCreatingDatabaseOnExitCaller {
 public:
-    DoneCreatingDatabaseOnExitCaller(DatabaseBackend* database, ExceptionCode& ec)
+    DoneCreatingDatabaseOnExitCaller(DatabaseBackend* database)
         : m_database(database)
-        , m_ec(ec)
+        , m_openSucceeded(false)
     {
     }
     ~DoneCreatingDatabaseOnExitCaller()
     {
 #if !PLATFORM(CHROMIUM)
-        // m_ec is not used in cross-platform code path. We don't have a macro for unused member variables,
-        // so just using UNUSED_PARAM.
-        // FIXME: Refactor the code to avoid the need for such wildly different behaviors.
-        UNUSED_PARAM(m_ec);
         DatabaseTracker::tracker().doneCreatingDatabase(m_database);
 #else
-        if (m_ec == INVALID_STATE_ERR)
+        if (!m_openSucceeded)
             DatabaseTracker::tracker().failedToOpenDatabase(m_database);
-#endif
-            
+#endif            
     }
+
+    void setOpenSucceeded() { m_openSucceeded = true; }
+
 private:
     DatabaseBackend* m_database;
-    ExceptionCode& m_ec; // This is a reference to a local variable in performOpenAndVerify(), so appropriate action could be taken based on its value at function exit time.
+    bool m_openSucceeded;
 };
 
-bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, ExceptionCode& ec, String& errorMessage)
+bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, DatabaseError& error, String& errorMessage)
 {
-    DoneCreatingDatabaseOnExitCaller onExitCaller(this, ec);
+    DoneCreatingDatabaseOnExitCaller onExitCaller(this);
     ASSERT(errorMessage.isEmpty());
-    ASSERT(!ec); // Better not have any exceptions already.
+    ASSERT(error == DatabaseError::None); // Better not have any errors already.
+    error = DatabaseError::CannotOpenDatabase; // Presumed failure. We'll clear it if we succeed below.
 
     const int maxSqliteBusyWaitTime = 30000;
 
     if (!m_sqliteDatabase.open(m_filename, true)) {
         reportOpenDatabaseResult(1, INVALID_STATE_ERR, m_sqliteDatabase.lastError());
         errorMessage = formatErrorMessage("unable to open database", m_sqliteDatabase.lastError(), m_sqliteDatabase.lastErrorMsg());
-        ec = INVALID_STATE_ERR;
         return false;
     }
     if (!m_sqliteDatabase.turnOnIncrementalAutoVacuum())
@@ -356,7 +354,6 @@ bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, E
             if (!transaction.inProgress()) {
                 reportOpenDatabaseResult(2, INVALID_STATE_ERR, m_sqliteDatabase.lastError());
                 errorMessage = formatErrorMessage("unable to open database, failed to start transaction", m_sqliteDatabase.lastError(), m_sqliteDatabase.lastErrorMsg());
-                ec = INVALID_STATE_ERR;
                 m_sqliteDatabase.close();
                 return false;
             }
@@ -368,7 +365,6 @@ bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, E
                 if (!m_sqliteDatabase.executeCommand("CREATE TABLE " + tableName + " (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL);")) {
                     reportOpenDatabaseResult(3, INVALID_STATE_ERR, m_sqliteDatabase.lastError());
                     errorMessage = formatErrorMessage("unable to open database, failed to create 'info' table", m_sqliteDatabase.lastError(), m_sqliteDatabase.lastErrorMsg());
-                    ec = INVALID_STATE_ERR;
                     transaction.rollback();
                     m_sqliteDatabase.close();
                     return false;
@@ -376,7 +372,6 @@ bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, E
             } else if (!getVersionFromDatabase(currentVersion, false)) {
                 reportOpenDatabaseResult(4, INVALID_STATE_ERR, m_sqliteDatabase.lastError());
                 errorMessage = formatErrorMessage("unable to open database, failed to read current version", m_sqliteDatabase.lastError(), m_sqliteDatabase.lastErrorMsg());
-                ec = INVALID_STATE_ERR;
                 transaction.rollback();
                 m_sqliteDatabase.close();
                 return false;
@@ -389,7 +384,6 @@ bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, E
                 if (!setVersionInDatabase(m_expectedVersion, false)) {
                     reportOpenDatabaseResult(5, INVALID_STATE_ERR, m_sqliteDatabase.lastError());
                     errorMessage = formatErrorMessage("unable to open database, failed to write current version", m_sqliteDatabase.lastError(), m_sqliteDatabase.lastErrorMsg());
-                    ec = INVALID_STATE_ERR;
                     transaction.rollback();
                     m_sqliteDatabase.close();
                     return false;
@@ -411,7 +405,6 @@ bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, E
     if ((!m_new || shouldSetVersionInNewDatabase) && m_expectedVersion.length() && m_expectedVersion != currentVersion) {
         reportOpenDatabaseResult(6, INVALID_STATE_ERR, 0);
         errorMessage = "unable to open database, version mismatch, '" + m_expectedVersion + "' does not match the currentVersion of '" + currentVersion + "'";
-        ec = INVALID_STATE_ERR;
         m_sqliteDatabase.close();
         return false;
     }
@@ -423,6 +416,10 @@ bool DatabaseBackend::performOpenAndVerify(bool shouldSetVersionInNewDatabase, E
     DatabaseTracker::tracker().addOpenDatabase(this);
     m_opened = true;
 
+    // Declare success:
+    error = DatabaseError::None; // Clear the presumed error from above.
+    onExitCaller.setOpenSucceeded();
+
     if (m_new && !shouldSetVersionInNewDatabase)
         m_expectedVersion = ""; // The caller provided a creationCallback which will set the expected version.
 
index 165d471..93c2dc7 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "DatabaseBasicTypes.h"
 #include "DatabaseDetails.h"
+#include "DatabaseError.h"
 #include "SQLiteDatabase.h"
 #include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
@@ -106,7 +107,7 @@ protected:
 
     void closeDatabase();
 
-    virtual bool performOpenAndVerify(bool shouldSetVersionInNewDatabase, ExceptionCode&, String& errorMessage);
+    virtual bool performOpenAndVerify(bool shouldSetVersionInNewDatabase, DatabaseError&, String& errorMessage);
 
     bool getVersionFromDatabase(String& version, bool shouldCacheVersion = true);
     bool setVersionInDatabase(const String& version, bool shouldCacheVersion = true);
index ea95c1c..fd523a9 100644 (file)
@@ -198,9 +198,11 @@ void DatabaseManager::didDestructDatabaseContext()
 
 PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* context,
     const String& name, const String& expectedVersion, const String& displayName,
-    unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& e)
+    unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback,
+    DatabaseError& error)
 {
     RefPtr<DatabaseContext> databaseContext = databaseContextFor(context);
+    ASSERT(error == DatabaseError::None);
 
     if (!canEstablishDatabase(context, name, displayName, estimatedSize)) {
         LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
@@ -210,7 +212,7 @@ PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* conte
     RefPtr<Database> database = adoptRef(new Database(databaseContext, name, expectedVersion, displayName, estimatedSize));
 
     String errorMessage;
-    if (!database->openAndVerifyVersion(!creationCallback, e, errorMessage)) {
+    if (!database->openAndVerifyVersion(!creationCallback, error, errorMessage)) {
         database->logErrorMessage(errorMessage);
         return 0;
     }
@@ -230,10 +232,11 @@ PassRefPtr<Database> DatabaseManager::openDatabase(ScriptExecutionContext* conte
 
 PassRefPtr<DatabaseSync> DatabaseManager::openDatabaseSync(ScriptExecutionContext* context,
     const String& name, const String& expectedVersion, const String& displayName,
-    unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
+    unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, DatabaseError& error)
 {
     RefPtr<DatabaseContext> databaseContext = databaseContextFor(context);
     ASSERT(context->isContextThread());
+    ASSERT(error == DatabaseError::None);
 
     if (!canEstablishDatabase(context, name, displayName, estimatedSize)) {
         LOG(StorageAPI, "Database %s for origin %s not allowed to be established", name.ascii().data(), context->securityOrigin()->toString().ascii().data());
@@ -243,7 +246,7 @@ PassRefPtr<DatabaseSync> DatabaseManager::openDatabaseSync(ScriptExecutionContex
     RefPtr<DatabaseSync> database = adoptRef(new DatabaseSync(databaseContext, name, expectedVersion, displayName, estimatedSize));
 
     String errorMessage;
-    if (!database->openAndVerifyVersion(!creationCallback, ec, errorMessage)) {
+    if (!database->openAndVerifyVersion(!creationCallback, error, errorMessage)) {
         database->logErrorMessage(errorMessage);
         return 0;
     }
index 78dc7d7..eab1f47 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "AbstractDatabaseServer.h"
 #include "DatabaseBasicTypes.h"
+#include "DatabaseError.h"
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
 #include <wtf/PassRefPtr.h>
@@ -77,8 +78,8 @@ public:
     void didDestructDatabaseContext() { }
 #endif
 
-    PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
-    PassRefPtr<DatabaseSync> openDatabaseSync(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
+    PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, DatabaseError&);
+    PassRefPtr<DatabaseSync> openDatabaseSync(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, DatabaseError&);
 
     bool hasOpenDatabases(ScriptExecutionContext*);
     void stopDatabases(ScriptExecutionContext*, DatabaseTaskSynchronizer*);
index 2bd8f3e..2248e38 100644 (file)
@@ -148,12 +148,12 @@ void DatabaseSync::runTransaction(PassRefPtr<SQLTransactionSyncCallback> callbac
     setLastErrorMessage("");
 }
 
-bool DatabaseSync::openAndVerifyVersion(bool setVersionInNewDatabase, ExceptionCode& ec, String& errorMessage)
+bool DatabaseSync::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError& error, String& errorMessage)
 {
 #if PLATFORM(CHROMIUM)
     DatabaseTracker::tracker().prepareToOpenDatabase(this);
 #endif
-    return performOpenAndVerify(setVersionInNewDatabase, ec, errorMessage);
+    return performOpenAndVerify(setVersionInNewDatabase, error, errorMessage);
 }
 
 void DatabaseSync::markAsDeletedAndClose()
index 7a6f3e7..476a08f 100644 (file)
@@ -77,7 +77,7 @@ private:
                  const String& displayName, unsigned long estimatedSize);
     void runTransaction(PassRefPtr<SQLTransactionSyncCallback>, bool readOnly, ExceptionCode&);
 
-    bool openAndVerifyVersion(bool setVersionInNewDatabase, ExceptionCode&, String& errorMessage);
+    bool openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&, String& errorMessage);
 
     String m_lastErrorMessage;
 
index 066725f..63aae36 100644 (file)
@@ -98,10 +98,10 @@ void DatabaseTask::performTask()
 // *** DatabaseOpenTask ***
 // Opens the database file and verifies the version matches the expected version.
 
-Database::DatabaseOpenTask::DatabaseOpenTask(Database* database, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, ExceptionCode& code, String& errorMessage, bool& success)
+Database::DatabaseOpenTask::DatabaseOpenTask(Database* database, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
     : DatabaseTask(database, synchronizer)
     , m_setVersionInNewDatabase(setVersionInNewDatabase)
-    , m_code(code)
+    , m_error(error)
     , m_errorMessage(errorMessage)
     , m_success(success)
 {
@@ -111,7 +111,7 @@ Database::DatabaseOpenTask::DatabaseOpenTask(Database* database, bool setVersion
 void Database::DatabaseOpenTask::doPerformTask()
 {
     String errorMessage;
-    m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_code, errorMessage);
+    m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_error, errorMessage);
     if (!m_success)
         m_errorMessage = errorMessage.isolatedCopy();
 }
index b5c6165..745e668 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "Database.h"
 #include "DatabaseBasicTypes.h"
+#include "DatabaseError.h"
 #include "SQLTransaction.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -99,13 +100,13 @@ private:
 
 class Database::DatabaseOpenTask : public DatabaseTask {
 public:
-    static PassOwnPtr<DatabaseOpenTask> create(Database* db, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, ExceptionCode& code, String& errorMessage, bool& success)
+    static PassOwnPtr<DatabaseOpenTask> create(Database* db, bool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
     {
-        return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, code, errorMessage, success));
+        return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, error, errorMessage, success));
     }
 
 private:
-    DatabaseOpenTask(Database*, bool setVersionInNewDatabase, DatabaseTaskSynchronizer*, ExceptionCode&, String& errorMessage, bool& success);
+    DatabaseOpenTask(Database*, bool setVersionInNewDatabase, DatabaseTaskSynchronizer*, DatabaseError&, String& errorMessage, bool& success);
 
     virtual void doPerformTask();
 #if !LOG_DISABLED
@@ -113,7 +114,7 @@ private:
 #endif
 
     bool m_setVersionInNewDatabase;
-    ExceptionCode& m_code;
+    DatabaseError& m_error;
     String& m_errorMessage;
     bool& m_success;
 };
index 15301da..b58a9ad 100644 (file)
@@ -43,23 +43,35 @@ namespace WebCore {
 PassRefPtr<Database> WorkerContextWebDatabase::openDatabase(WorkerContext* context, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
 {
     DatabaseManager& dbManager = DatabaseManager::manager();
-    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin()) || !dbManager.isAvailable()) {
+    RefPtr<Database> database;
+    DatabaseError error = DatabaseError::None;
+    if (dbManager.isAvailable() && context->securityOrigin()->canAccessDatabase(context->topOrigin()))
+        database = dbManager.openDatabase(context, name, version, displayName, estimatedSize, creationCallback, error);
+
+    ASSERT(error == DatabaseError::None || error == DatabaseError::CannotOpenDatabase);
+    if (error == DatabaseError::CannotOpenDatabase)
+        ec = INVALID_STATE_ERR;
+    if (!database && !ec)
         ec = SECURITY_ERR;
-        return 0;
-    }
 
-    return dbManager.openDatabase(context, name, version, displayName, estimatedSize, creationCallback, ec);
+    return database.release();
 }
 
 PassRefPtr<DatabaseSync> WorkerContextWebDatabase::openDatabaseSync(WorkerContext* context, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
 {
     DatabaseManager& dbManager = DatabaseManager::manager();
-    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin()) || !dbManager.isAvailable()) {
+    RefPtr<DatabaseSync> database;
+    DatabaseError error =  DatabaseError::None;
+    if (dbManager.isAvailable() && context->securityOrigin()->canAccessDatabase(context->topOrigin()))
+        database = dbManager.openDatabaseSync(context, name, version, displayName, estimatedSize, creationCallback, error);
+
+    ASSERT(error == DatabaseError::None || error == DatabaseError::CannotOpenDatabase);
+    if (error == DatabaseError::CannotOpenDatabase)
+        ec = INVALID_STATE_ERR;
+    if (!database && !ec)
         ec = SECURITY_ERR;
-        return 0;
-    }
 
-    return dbManager.openDatabaseSync(context, name, version, displayName, estimatedSize, creationCallback, ec);
+    return database.release();
 }
 
 } // namespace WebCore
index dd5dfa6..fa8da37 100644 (file)
             'Modules/webdatabase/DatabaseAuthorizer.cpp',
             'Modules/webdatabase/DatabaseAuthorizer.h',
             'Modules/webdatabase/DatabaseBackend.cpp',
+            'Modules/webdatabase/DatabaseBackend.h',
             'Modules/webdatabase/DatabaseCallback.h',
             'Modules/webdatabase/DatabaseContext.cpp',
             'Modules/webdatabase/DatabaseContext.h',
+            'Modules/webdatabase/DatabaseError.h',
             'Modules/webdatabase/DatabaseManager.cpp',
             'Modules/webdatabase/DatabaseServer.cpp',
             'Modules/webdatabase/DatabaseServer.h',