diff options
Diffstat (limited to 'Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp')
-rw-r--r-- | Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp b/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp index 8ccaa5a80..641281ef5 100644 --- a/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp +++ b/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.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 @@ -25,39 +25,37 @@ */ #include "config.h" - -#if ENABLE(SQL_DATABASE) - #include "DOMWindowWebDatabase.h" #include "DOMWindow.h" #include "Database.h" -#include "DatabaseCallback.h" #include "DatabaseManager.h" #include "Document.h" -#include "Frame.h" +#include "ExceptionCode.h" #include "SecurityOrigin.h" namespace WebCore { -PassRefPtr<Database> DOMWindowWebDatabase::openDatabase(DOMWindow* window, const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec) +ExceptionOr<RefPtr<Database>> DOMWindowWebDatabase::openDatabase(DOMWindow& window, const String& name, const String& version, const String& displayName, unsigned estimatedSize, RefPtr<DatabaseCallback>&& creationCallback) { - if (!window->isCurrentlyDisplayedInFrame()) - return 0; - - 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, error); - ASSERT(database || error != DatabaseError::None); - ec = DatabaseManager::exceptionCodeForDatabaseError(error); - } else - ec = SECURITY_ERR; - - return database; + if (!window.isCurrentlyDisplayedInFrame()) + return RefPtr<Database> { nullptr }; + auto& manager = DatabaseManager::singleton(); + if (!manager.isAvailable()) + return Exception { SECURITY_ERR }; + auto* document = window.document(); + if (!document) + return Exception { SECURITY_ERR }; + auto& securityOrigin = document->securityOrigin(); + if (!securityOrigin.canAccessDatabase(document->topOrigin())) + return Exception { SECURITY_ERR }; + auto result = manager.openDatabase(*window.document(), name, version, displayName, estimatedSize, WTFMove(creationCallback)); + if (result.hasException()) { + // FIXME: To preserve our past behavior, this discards the error string in the exception. + // At a later time we may decide that we want to use the error strings, and if so we can just return the exception as is. + return Exception { result.releaseException().code() }; + } + return RefPtr<Database> { result.releaseReturnValue() }; } } // namespace WebCore - -#endif // ENABLE(SQL_DATABASE) |