summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/sql
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2009-08-11 17:01:47 +0100
committerBen Murdoch <benm@google.com>2009-08-11 18:21:02 +0100
commit0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch)
tree2943df35f62d885c89d01063cc528dd73b480fea /WebCore/platform/sql
parent7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff)
downloadexternal_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip
external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz
external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2
Merge in WebKit r47029.
Diffstat (limited to 'WebCore/platform/sql')
-rw-r--r--WebCore/platform/sql/SQLiteDatabase.cpp5
-rw-r--r--WebCore/platform/sql/SQLiteFileSystem.cpp123
-rw-r--r--WebCore/platform/sql/SQLiteFileSystem.h114
-rw-r--r--WebCore/platform/sql/SQLiteTransaction.cpp10
-rw-r--r--WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp112
-rw-r--r--WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp42
-rw-r--r--WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp42
-rw-r--r--WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp176
8 files changed, 616 insertions, 8 deletions
diff --git a/WebCore/platform/sql/SQLiteDatabase.cpp b/WebCore/platform/sql/SQLiteDatabase.cpp
index e16b04e..9a4e32a 100644
--- a/WebCore/platform/sql/SQLiteDatabase.cpp
+++ b/WebCore/platform/sql/SQLiteDatabase.cpp
@@ -29,6 +29,7 @@
#include "DatabaseAuthorizer.h"
#include "Logging.h"
+#include "SQLiteFileSystem.h"
#include "SQLiteStatement.h"
#include <sqlite3.h>
@@ -60,9 +61,7 @@ bool SQLiteDatabase::open(const String& filename)
{
close();
- // SQLite expects a null terminator on its UTF-16 strings.
- String path = filename;
- m_lastError = sqlite3_open16(path.charactersWithNullTermination(), &m_db);
+ m_lastError = SQLiteFileSystem::openDatabase(filename, &m_db);
if (m_lastError != SQLITE_OK) {
LOG_ERROR("SQLite database failed to load from %s\nCause - %s", filename.ascii().data(),
sqlite3_errmsg(m_db));
diff --git a/WebCore/platform/sql/SQLiteFileSystem.cpp b/WebCore/platform/sql/SQLiteFileSystem.cpp
new file mode 100644
index 0000000..8cd7e80
--- /dev/null
+++ b/WebCore/platform/sql/SQLiteFileSystem.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SQLiteFileSystem.h"
+
+#include "FileSystem.h"
+#include "SQLiteDatabase.h"
+#include "SQLiteStatement.h"
+#include <sqlite3.h>
+
+namespace WebCore {
+
+SQLiteFileSystem::SQLiteFileSystem()
+{
+}
+
+void SQLiteFileSystem::registerSQLiteVFS()
+{
+}
+
+int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database)
+{
+ // SQLite expects a null terminator on its UTF-16 strings.
+ String path = fileName;
+ return sqlite3_open16(path.charactersWithNullTermination(), database);
+}
+
+String SQLiteFileSystem::getFileNameForNewDatabase(const String& dbDir, const String&,
+ const String&, SQLiteDatabase* db)
+{
+ // try to get the next sequence number from the given database
+ // if we can't get a number, return an empty string
+ SQLiteStatement sequenceStatement(*db, "SELECT seq FROM sqlite_sequence WHERE name='Databases';");
+ if (sequenceStatement.prepare() != SQLResultOk)
+ return String();
+ int result = sequenceStatement.step();
+ int64_t seq = 0;
+ if (result == SQLResultRow)
+ seq = sequenceStatement.getColumnInt64(0);
+ else if (result != SQLResultDone)
+ return String();
+ sequenceStatement.finalize();
+
+ // increment the number until we can use it to form a file name that doesn't exist
+ String fileName;
+ do {
+ ++seq;
+ fileName = pathByAppendingComponent(dbDir, String::format("%016llx.db", seq));
+ } while (fileExists(fileName));
+
+ return String::format("%016llx.db", seq);
+}
+
+String SQLiteFileSystem::appendDatabaseFileNameToPath(const String& path, const String& fileName)
+{
+ return pathByAppendingComponent(path, fileName);
+}
+
+bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const String& path)
+{
+ if (path.isEmpty())
+ return false;
+ return makeAllDirectories(path);
+}
+
+bool SQLiteFileSystem::ensureDatabaseFileExists(const String& fileName, bool checkPathOnly)
+{
+ if (fileName.isEmpty())
+ return false;
+
+ if (checkPathOnly) {
+ String dir = directoryName(fileName);
+ return ensureDatabaseDirectoryExists(dir);
+ }
+
+ return fileExists(fileName);
+}
+
+bool SQLiteFileSystem::deleteEmptyDatabaseDirectory(const String& path)
+{
+ return deleteEmptyDirectory(path);
+}
+
+bool SQLiteFileSystem::deleteDatabaseFile(const String& fileName)
+{
+ return deleteFile(fileName);
+}
+
+long long SQLiteFileSystem::getDatabaseFileSize(const String& fileName)
+{
+ long long size;
+ return getFileSize(fileName, size) ? size : 0;
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/sql/SQLiteFileSystem.h b/WebCore/platform/sql/SQLiteFileSystem.h
new file mode 100644
index 0000000..0a26e9d
--- /dev/null
+++ b/WebCore/platform/sql/SQLiteFileSystem.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SQLiteFileSystem_h
+#define SQLiteFileSystem_h
+
+#include "PlatformString.h"
+#include <wtf/Threading.h>
+
+struct sqlite3;
+
+namespace WebCore {
+
+class SQLiteDatabase;
+
+// A class that abstracts the file system related operations required
+// by the WebKit database code.
+class SQLiteFileSystem {
+public:
+ // Registers a user-defined SQLite VFS.
+ static void registerSQLiteVFS();
+
+ // Opens a database file.
+ //
+ // fileName - The name of the database file.
+ // database - The SQLite structure that represents the database stored
+ // in the given file.
+ static int openDatabase(const String& fileName, sqlite3** database);
+
+ // Returns the file name for a database.
+ //
+ // dbDir - The directory where all databases are stored.
+ // dbName - The name of the database.
+ // originIdentifier - The origin that wants to use this database.
+ // db - A database with a number generator used to create unique file names.
+ static String getFileNameForNewDatabase(const String& dbDir, const String& dbName,
+ const String& originIdentifier, SQLiteDatabase* db);
+
+ // Creates an absolute file path given a directory and a file name.
+ //
+ // path - The directory.
+ // fileName - The file name.
+ static String appendDatabaseFileNameToPath(const String& path, const String& fileName);
+
+ // Makes sure the given directory exists, by creating all missing directories
+ // on the given path.
+ //
+ // path - The directory.
+ static bool ensureDatabaseDirectoryExists(const String& path);
+
+ // If 'checkPathOnly' is false, then this method only checks if the given file exists.
+ // If 'checkPathOnly' is true, then this method makes sure all directories on the
+ // given path exist by creating the missing ones, and does not check if the file
+ // itself exists.
+ //
+ // Sometimes we expect a DB file to exist; other times, we're OK with creating a new
+ // DB file, but we want to make sure that the directory in which we want to put the
+ // new DB file exists. This method covers both cases.
+ //
+ // fileName - The file name.
+ // checkPathOnly - If true, we only make sure that the given directory exists.
+ // If false, we only check if the file exists.
+ static bool ensureDatabaseFileExists(const String& fileName, bool checkPathOnly);
+
+ // Deletes an empty database directory.
+ //
+ // path - The directory.
+ static bool deleteEmptyDatabaseDirectory(const String& path);
+
+ // Deletes a database file.
+ //
+ // fileName - The file name.
+ static bool deleteDatabaseFile(const String& fileName);
+
+ // Returns the size of the database file.
+ //
+ // fileName - The file name.
+ static long long getDatabaseFileSize(const String& fileName);
+
+private:
+ // do not instantiate this class
+ SQLiteFileSystem();
+}; // class SQLiteFileSystem
+
+} // namespace WebCore
+
+#endif
diff --git a/WebCore/platform/sql/SQLiteTransaction.cpp b/WebCore/platform/sql/SQLiteTransaction.cpp
index 5018f5a..0a236be 100644
--- a/WebCore/platform/sql/SQLiteTransaction.cpp
+++ b/WebCore/platform/sql/SQLiteTransaction.cpp
@@ -20,7 +20,7 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
@@ -38,16 +38,16 @@ SQLiteTransaction::SQLiteTransaction(SQLiteDatabase& db)
SQLiteTransaction::~SQLiteTransaction()
{
- if (m_inProgress)
+ if (m_inProgress)
rollback();
}
-
+
void SQLiteTransaction::begin()
{
if (!m_inProgress) {
ASSERT(!m_db.m_transactionInProgress);
m_inProgress = m_db.executeCommand("BEGIN;");
- m_db.m_transactionInProgress = true;
+ m_db.m_transactionInProgress = m_inProgress;
}
}
@@ -76,5 +76,5 @@ void SQLiteTransaction::stop()
m_inProgress = false;
m_db.m_transactionInProgress = false;
}
-
+
} // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp
new file mode 100644
index 0000000..dc79fd0
--- /dev/null
+++ b/WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SQLiteFileSystem.h"
+
+#include "ChromiumBridge.h"
+#include "CString.h"
+#include "SQLiteDatabase.h"
+#include <sqlite3.h>
+
+#ifndef SQLITE_OPEN_FULLMUTEX
+#define SQLITE_OPEN_FULLMUTEX 0x00010000
+#endif
+
+// SQLiteFileSystem::registerSQLiteVFS() is implemented in the
+// platform-specific files SQLiteFileSystemChromium{Win|Posix}.cpp
+namespace WebCore {
+
+SQLiteFileSystem::SQLiteFileSystem()
+{
+}
+
+int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database)
+{
+ if (!ChromiumBridge::sandboxEnabled()) {
+ String path = fileName;
+ return sqlite3_open16(path.charactersWithNullTermination(), database);
+ }
+
+ // open databases using Chromium's VFS
+ return sqlite3_open_v2(fileName.utf8().data(), database,
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX,
+ "chromium_vfs");
+}
+
+String SQLiteFileSystem::getFileNameForNewDatabase(
+ const String&, const String& dbName, const String &originIdentifier, SQLiteDatabase*)
+{
+ // Chromium names DB files based on origin and DB name only
+ return originIdentifier + "_" + dbName + ".db";
+}
+
+String SQLiteFileSystem::appendDatabaseFileNameToPath(const String&, const String& fileName)
+{
+ // Chromium saves all DB files in the same directory (known by
+ // the browser process only); as far as the renderer processes
+ // are concerned, all DB files are saved in the "current" directory
+ return fileName;
+}
+
+bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const String&)
+{
+ // if the directory where Chromium stores the databases does not exist,
+ // it will be automatically created by the browser process;
+ // so as far as the WebKit code is concerned, this directory always exists
+ return true;
+}
+
+bool SQLiteFileSystem::ensureDatabaseFileExists(const String&, bool)
+{
+ // all database directories will be created as needed by the browser process
+ return true;
+}
+
+bool SQLiteFileSystem::deleteEmptyDatabaseDirectory(const String&)
+{
+ // Chromium does not use a separate directory for each database,
+ // so there's nothing to do here
+ return true;
+}
+
+bool SQLiteFileSystem::deleteDatabaseFile(const String& fileName)
+{
+ // return true if and only if the error code returned by
+ // ChromiumBridge::deleteDatabase() is 0
+ return (!ChromiumBridge::databaseDeleteFile(fileName));
+}
+
+long long SQLiteFileSystem::getDatabaseFileSize(const String& fileName)
+{
+ return ChromiumBridge::databaseGetFileSize(fileName);
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp
new file mode 100644
index 0000000..3582448
--- /dev/null
+++ b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SQLiteFileSystem.h"
+
+namespace WebCore {
+
+void SQLiteFileSystem::registerSQLiteVFS()
+{
+ // stub for registering Chromium's SQLite VFS for Linux
+ ASSERT_NOT_REACHED();
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp
new file mode 100644
index 0000000..35a40f5
--- /dev/null
+++ b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SQLiteFileSystem.h"
+
+namespace WebCore {
+
+void SQLiteFileSystem::registerSQLiteVFS()
+{
+ // stub for registering Chromium's SQLite VFS for Mac
+ ASSERT_NOT_REACHED();
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp
new file mode 100644
index 0000000..b357d4a
--- /dev/null
+++ b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SQLiteFileSystem.h"
+
+#include "ChromiumBridge.h"
+#include <sqlite3.h>
+#include <windows.h>
+
+// Defined in Chromium's codebase in third_party/sqlite/src/os_win.c
+extern "C" {
+int chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle);
+}
+
+// Chromium's Windows implementation of SQLite VFS
+namespace {
+
+// Opens a file.
+//
+// vfs - pointer to the sqlite3_vfs object.
+// fileName - the name of the file.
+// id - the structure that will manipulate the newly opened file.
+// desiredFlags - the desired open mode flags.
+// usedFlags - the actual open mode flags that were used.
+int chromiumOpen(sqlite3_vfs*, const char* fileName,
+ sqlite3_file* id, int desiredFlags, int* usedFlags)
+{
+ HANDLE h = WebCore::ChromiumBridge::databaseOpenFile(fileName, desiredFlags);
+ if (h == INVALID_HANDLE_VALUE) {
+ if (desiredFlags & SQLITE_OPEN_READWRITE) {
+ int newFlags = (desiredFlags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE;
+ return chromiumOpen(0, fileName, id, newFlags, usedFlags);
+ } else
+ return SQLITE_CANTOPEN;
+ }
+ if (usedFlags) {
+ if (desiredFlags & SQLITE_OPEN_READWRITE)
+ *usedFlags = SQLITE_OPEN_READWRITE;
+ else
+ *usedFlags = SQLITE_OPEN_READONLY;
+ }
+
+ chromium_sqlite3_initialize_win_sqlite3_file(id, h);
+ return SQLITE_OK;
+}
+
+// Deletes the given file.
+//
+// vfs - pointer to the sqlite3_vfs object.
+// fileName - the name of the file.
+// syncDir - determines if the directory to which this file belongs
+// should be synched after the file is deleted.
+int chromiumDelete(sqlite3_vfs*, const char* fileName, int)
+{
+ bool deleted = WebCore::ChromiumBridge::databaseDeleteFile(fileName);
+ DWORD rc = WebCore::ChromiumBridge::databaseGetFileAttributes(fileName);
+ return ((rc == INVALID_FILE_ATTRIBUTES) && deleted ?
+ SQLITE_OK : SQLITE_IOERR_DELETE);
+}
+
+// Check the existance and status of the given file.
+//
+// vfs - pointer to the sqlite3_vfs object.
+// fileName - the name of the file.
+// flag - the type of test to make on this file.
+// res - the result.
+int chromiumAccess(sqlite3_vfs*, const char* fileName, int flag, int* res)
+{
+ DWORD attr = WebCore::ChromiumBridge::databaseGetFileAttributes(fileName);
+ switch (flag) {
+ case SQLITE_ACCESS_READ:
+ case SQLITE_ACCESS_EXISTS:
+ *res = (attr != INVALID_FILE_ATTRIBUTES);
+ break;
+ case SQLITE_ACCESS_READWRITE:
+ *res = ((attr & FILE_ATTRIBUTE_READONLY) == 0);
+ break;
+ default:
+ return SQLITE_ERROR;
+ }
+
+ return SQLITE_OK;
+}
+
+// Turns a relative pathname into a full pathname.
+//
+// vfs - pointer to the sqlite3_vfs object.
+// relativePath - the relative path.
+// bufSize - the size of the output buffer in bytes.
+// absolutePath - the output buffer where the absolute path will be stored.
+int chromiumFullPathname(sqlite3_vfs* vfs, const char* relativePath,
+ int, char* absolutePath)
+{
+ // The renderer process doesn't need to know the absolute path of the file
+ sqlite3_snprintf(vfs->mxPathname, absolutePath, "%s", relativePath);
+ return SQLITE_OK;
+}
+
+#ifndef SQLITE_OMIT_LOAD_EXTENSION
+// Returns NULL, thus disallowing loading libraries in the renderer process.
+//
+// vfs - pointer to the sqlite3_vfs object.
+// fileName - the name of the shared library file.
+void* chromiumDlOpen(sqlite3_vfs*, const char*)
+{
+ return 0;
+}
+#else
+#define chromiumDlOpen 0
+#endif // SQLITE_OMIT_LOAD_EXTENSION
+
+} // namespace
+
+namespace WebCore {
+
+void SQLiteFileSystem::registerSQLiteVFS()
+{
+ // FIXME: Make sure there aren't any unintended consequences when VFS code is called in the browser process.
+ if (!ChromiumBridge::sandboxEnabled()) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ sqlite3_vfs* win32_vfs = sqlite3_vfs_find("win32");
+ static sqlite3_vfs chromium_vfs = {
+ 1,
+ win32_vfs->szOsFile,
+ win32_vfs->mxPathname,
+ 0,
+ "chromium_vfs",
+ 0,
+ chromiumOpen,
+ chromiumDelete,
+ chromiumAccess,
+ chromiumFullPathname,
+ chromiumDlOpen,
+ win32_vfs->xDlError,
+ win32_vfs->xDlSym,
+ win32_vfs->xDlClose,
+ win32_vfs->xRandomness,
+ win32_vfs->xSleep,
+ win32_vfs->xCurrentTime,
+ win32_vfs->xGetLastError
+ };
+ sqlite3_vfs_register(&chromium_vfs, 1);
+}
+
+} // namespace WebCore