2009-07-20 Dumitru Daniliuc <dumi@chromium.org>
authoreroman@chromium.org <eroman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Jul 2009 17:56:55 +0000 (17:56 +0000)
committereroman@chromium.org <eroman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Jul 2009 17:56:55 +0000 (17:56 +0000)
        Reviewed by Dimitri Glazkov.

        Adding the Win SQLite VFS implementation for Chromium, and stubs
        for the Mac and Linux VFSs.

        https://bugs.webkit.org/show_bug.cgi?id=26940

        * WebCore.gypi:
        * platform/chromium/ChromiumBridge.h:
        * platform/sql/chromium/SQLiteFileSystemChromium.cpp: Added.
        * platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp: Added.
        * platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp: Added.
        * platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp: Added.

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

WebCore/ChangeLog
WebCore/WebCore.gypi
WebCore/platform/chromium/ChromiumBridge.h
WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp [new file with mode: 0644]
WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp [new file with mode: 0644]
WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp [new file with mode: 0644]
WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp [new file with mode: 0644]

index 8983c353d2668dc799ac10ed6aec5a86dd3018b9..9e0a2bd440d8b7f30c786b534b4b7c7bc240e224 100644 (file)
@@ -1,3 +1,19 @@
+2009-07-20  Dumitru Daniliuc  <dumi@chromium.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Adding the Win SQLite VFS implementation for Chromium, and stubs
+        for the Mac and Linux VFSs.
+
+        https://bugs.webkit.org/show_bug.cgi?id=26940
+
+        * WebCore.gypi:
+        * platform/chromium/ChromiumBridge.h:
+        * platform/sql/chromium/SQLiteFileSystemChromium.cpp: Added.
+        * platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp: Added.
+        * platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp: Added.
+        * platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp: Added.
+
 2009-07-20  Xan Lopez  <xlopez@igalia.com>
 
         Reviewed by Gustavo Noronha.
index 0c54cc19a7dc3ad81bf302ad3083b921022ff6a7..d36688ec52b30d93b2ff4ab1b5ddd5705aa21376 100644 (file)
             'platform/sql/SQLiteAuthorizer.cpp',
             'platform/sql/SQLiteDatabase.cpp',
             'platform/sql/SQLiteDatabase.h',
-            'platform/sql/SQLiteFileSystem.h',
             'platform/sql/SQLiteFileSystem.cpp',
+            'platform/sql/SQLiteFileSystem.h',
             'platform/sql/SQLiteStatement.cpp',
             'platform/sql/SQLiteStatement.h',
             'platform/sql/SQLiteTransaction.cpp',
             'platform/sql/SQLiteTransaction.h',
+            'platform/sql/chromium/SQLiteFileSystemChromium.cpp',
+            'platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp',
+            'platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp',
+            'platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp',
             'platform/symbian/FloatPointSymbian.cpp',
             'platform/symbian/FloatRectSymbian.cpp',
             'platform/symbian/IntPointSymbian.cpp',
index b0ab421a7fa6c062b4ed4b5d426ad3fd52736bf3..9600a634c3854361a8c1836af929fcfc7454a53c 100644 (file)
@@ -31,6 +31,7 @@
 #ifndef ChromiumBridge_h
 #define ChromiumBridge_h
 
+#include "FileSystem.h"
 #include "LinkHash.h"
 #include "PassRefPtr.h"
 #include "PasteboardPrivate.h"
@@ -177,6 +178,25 @@ namespace WebCore {
         // Widget -------------------------------------------------------------
         static void widgetSetCursor(Widget*, const Cursor&);
         static void widgetSetFocus(Widget*);
+
+        // HTML5 DB -----------------------------------------------------------
+
+#if ENABLE(DATABASE)
+        // Opens a database file
+        // 'desiredFlags' is a collection of OR'd SQLite constants that
+        // determine how the file should be opened
+        static PlatformFileHandle databaseOpenFile(const String& fileName, int desiredFlags);
+
+        // Deletes a database file
+        // Returns 'true' if the file was deleted; 'false' otherwise
+        static bool databaseDeleteFile(const String& fileName);
+
+        // Returns the file attributes of the given database file
+        static long databaseGetFileAttributes(const String& fileName);
+
+        // Returns size of the given file
+        static long long databaseGetFileSize(const String& fileName);
+#endif
     };
 
 } // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp
new file mode 100644 (file)
index 0000000..fdb50d0
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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)
+{
+    // 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 (file)
index 0000000..e0a8236
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp
new file mode 100644 (file)
index 0000000..9551e99
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp
new file mode 100644 (file)
index 0000000..8de35b6
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * 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()
+{
+    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