2009-08-28 Dumitru Daniliuc <dumi@chromium.org>
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Aug 2009 21:44:35 +0000 (21:44 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Aug 2009 21:44:35 +0000 (21:44 +0000)
        Reviewed by Dimitri Glazkov.

        Adding Chromium's VFS for Linux and Mac.

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

        * WebCore.gypi:
        * platform/chromium/ChromiumBridge.h:
        * platform/sql/chromium/SQLiteFileSystemChromium.cpp:
        (WebCore::SQLiteFileSystem::openDatabase):
        (WebCore::SQLiteFileSystem::deleteDatabaseFile):
        * platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp: Removed.
        * platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp: Removed.
        * platform/sql/chromium/SQLiteFileSystemChromiumPosix.cpp: Added.
        * platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp:

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

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

index 880abda0436661c68b20fb8350a8b2b8d34e0f9a..069f29d0eeec2f052a5dc4c6d8f5f77e1c05ffaf 100644 (file)
@@ -1,3 +1,21 @@
+2009-08-28  Dumitru Daniliuc  <dumi@chromium.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Adding Chromium's VFS for Linux and Mac.
+
+        https://bugs.webkit.org/show_bug.cgi?id=28750
+
+        * WebCore.gypi:
+        * platform/chromium/ChromiumBridge.h:
+        * platform/sql/chromium/SQLiteFileSystemChromium.cpp:
+        (WebCore::SQLiteFileSystem::openDatabase):
+        (WebCore::SQLiteFileSystem::deleteDatabaseFile):
+        * platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp: Removed.
+        * platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp: Removed.
+        * platform/sql/chromium/SQLiteFileSystemChromiumPosix.cpp: Added.
+        * platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp:
+
 2009-08-28  Vitaly Repeshko  <vitalyr@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 0a0f13ad4758f549b03ed7680d03d8707d1d96fd..f0bdd5899d829a427ad0acc7ff2374ab27aa2a3d 100644 (file)
             '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/SQLiteFileSystemChromiumPosix.cpp',
             'platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp',
             'platform/symbian/FloatPointSymbian.cpp',
             'platform/symbian/FloatRectSymbian.cpp',
index bca8c525315e1ffbffe9016d7150ea769d692427..aaa2db7ce4dea1b73c4b7eefb99658f3fb5c901a 100644 (file)
@@ -103,12 +103,16 @@ namespace WebCore {
 
         // Forms --------------------------------------------------------------
         static void notifyFormStateChanged(const Document*);
-        
+
         // HTML5 DB -----------------------------------------------------------
 #if ENABLE(DATABASE)
-        static PlatformFileHandle databaseOpenFile(const String& fileName, int desiredFlags);
-        static bool databaseDeleteFile(const String& fileName);
+        // Returns a handle to the DB file and ooptionally a handle to its containing directory
+        static PlatformFileHandle databaseOpenFile(const String& fileName, int desiredFlags, PlatformFileHandle* dirHandle = 0);
+        // Returns a SQLite code (SQLITE_OK = 0, on success)
+        static int databaseDeleteFile(const String& fileName, bool syncDir = false);
+        // Returns the attributes of the DB file
         static long databaseGetFileAttributes(const String& fileName);
+        // Returns the size of the DB file
         static long long databaseGetFileSize(const String& fileName);
 #endif
 
index dc79fd027b452f98032bd80204da0ac98a23ab10..3cf961f2b5cd09ed518a5b836184c609239bfa30 100644 (file)
@@ -55,10 +55,10 @@ int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database)
         return sqlite3_open16(path.charactersWithNullTermination(), database);
     }
 
-    // open databases using Chromium's VFS
+    // open databases using the default VFS
+    // in renderers, it should be Chromium's VFS; in the browser process it should be SQLite's default VFS
     return sqlite3_open_v2(fileName.utf8().data(), database,
-                           SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX,
-                           "chromium_vfs");
+                           SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, 0);
 }
 
 String SQLiteFileSystem::getFileNameForNewDatabase(
@@ -99,9 +99,7 @@ bool SQLiteFileSystem::deleteEmptyDatabaseDirectory(const String&)
 
 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));
+    return (ChromiumBridge::databaseDeleteFile(fileName) == SQLITE_OK);
 }
 
 long long SQLiteFileSystem::getDatabaseFileSize(const String& fileName)
diff --git a/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp
deleted file mode 100644 (file)
index 3582448..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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
deleted file mode 100644 (file)
index 35a40f5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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/SQLiteFileSystemChromiumPosix.cpp b/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumPosix.cpp
new file mode 100644 (file)
index 0000000..937f0b3
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * 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 <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+using namespace WebCore;
+
+// Defined in Chromium's codebase in third_party/sqlite/src/os_unix.c
+extern "C" {
+void initUnixFile(sqlite3_file* file);
+int fillInUnixFile(sqlite3_vfs* vfs, int fd, int dirfd, sqlite3_file* file, const char* fileName, int noLock);
+}
+
+// Chromium's Posix 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* vfs, const char* fileName,
+                 sqlite3_file* id, int desiredFlags, int* usedFlags)
+{
+    initUnixFile(id);
+    int dirfd = -1;
+    int fd = ChromiumBridge::databaseOpenFile(fileName, desiredFlags, &dirfd);
+    if (fd < 0) {
+        if (desiredFlags & SQLITE_OPEN_READWRITE) {
+            int newFlags = (desiredFlags & ~(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)) | SQLITE_OPEN_READONLY;
+            return chromiumOpen(vfs, fileName, id, newFlags, usedFlags);
+        } else
+            return SQLITE_CANTOPEN;
+    }
+    if (usedFlags)
+        *usedFlags = desiredFlags;
+
+    fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+    if (dirfd >= 0)
+        fcntl(dirfd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+
+    // The mask 0x00007F00 gives us the 7 bits that determine the type of the file SQLite is trying to open.
+    int fileType = desiredFlags & 0x00007F00;
+    int noLock = (fileType != SQLITE_OPEN_MAIN_DB);
+    return fillInUnixFile(vfs, fd, dirfd, id, fileName, noLock);
+}
+
+// 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 syncDir)
+{
+    return ChromiumBridge::databaseDeleteFile(fileName, syncDir);
+}
+
+// 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)
+{
+    int attr = static_cast<int>(ChromiumBridge::databaseGetFileAttributes(fileName));
+    if (attr < 0) {
+        *res = 0;
+        return SQLITE_OK;
+    }
+
+    switch (flag) {
+    case SQLITE_ACCESS_EXISTS:
+        *res = 1;   // if the file doesn't exist, attr < 0
+        break;
+    case SQLITE_ACCESS_READWRITE:
+        *res = (attr & W_OK) && (attr & R_OK);
+        break;
+    case SQLITE_ACCESS_READ:
+        *res = (attr & R_OK);
+        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* unix_vfs = sqlite3_vfs_find("unix");
+    static sqlite3_vfs chromium_vfs = {
+        1,
+        unix_vfs->szOsFile,
+        unix_vfs->mxPathname,
+        0,
+        "chromium_vfs",
+        0,
+        chromiumOpen,
+        chromiumDelete,
+        chromiumAccess,
+        chromiumFullPathname,
+        chromiumDlOpen,
+        unix_vfs->xDlError,
+        unix_vfs->xDlSym,
+        unix_vfs->xDlClose,
+        unix_vfs->xRandomness,
+        unix_vfs->xSleep,
+        unix_vfs->xCurrentTime,
+        unix_vfs->xGetLastError
+    };
+    sqlite3_vfs_register(&chromium_vfs, 1);
+}
+
+} // namespace WebCore
index b357d4a8b1dcf2d55f6728df62d57fb5bd8c832a..f9551229066953425974af2cf887fbff19be3fe3 100644 (file)
@@ -35,6 +35,8 @@
 #include <sqlite3.h>
 #include <windows.h>
 
+using namespace WebCore;
+
 // 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);
@@ -53,7 +55,7 @@ namespace {
 int chromiumOpen(sqlite3_vfs*, const char* fileName,
                  sqlite3_file* id, int desiredFlags, int* usedFlags)
 {
-    HANDLE h = WebCore::ChromiumBridge::databaseOpenFile(fileName, desiredFlags);
+    HANDLE h = ChromiumBridge::databaseOpenFile(fileName, desiredFlags);
     if (h == INVALID_HANDLE_VALUE) {
         if (desiredFlags & SQLITE_OPEN_READWRITE) {
             int newFlags = (desiredFlags | SQLITE_OPEN_READONLY) & ~SQLITE_OPEN_READWRITE;
@@ -80,10 +82,7 @@ int chromiumOpen(sqlite3_vfs*, const char* fileName,
 //           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);
+    return ChromiumBridge::databaseDeleteFile(fileName);
 }
 
 // Check the existance and status of the given file.
@@ -94,7 +93,7 @@ int chromiumDelete(sqlite3_vfs*, const char* fileName, int)
 // res - the result.
 int chromiumAccess(sqlite3_vfs*, const char* fileName, int flag, int* res)
 {
-    DWORD attr = WebCore::ChromiumBridge::databaseGetFileAttributes(fileName);
+    DWORD attr = ChromiumBridge::databaseGetFileAttributes(fileName);
     switch (flag) {
     case SQLITE_ACCESS_READ:
     case SQLITE_ACCESS_EXISTS: