2009-08-03 Jeremy Orlow <jorlow@chromium.org>
authorjorlow@chromium.org <jorlow@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Aug 2009 01:08:54 +0000 (01:08 +0000)
committerjorlow@chromium.org <jorlow@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Aug 2009 01:08:54 +0000 (01:08 +0000)
        Reviewed by Darin Fisher.

        Chromium code sometimes isn't sandboxed and needs to access the FS.
        https://bugs.webkit.org/show_bug.cgi?id=27954

        These changes are the WebKit side of http://codereview.chromium.org/159778 which
        aims to make LocalStorage persistent.

        This change runs all FileSystem routines through the ChromiumBridge so that
        WebKitClients can handle them if they choose to.  For now, the only such client
        will be the one running in the browser process.

        It also adds a method called sandboxEnabled to the Chromium bridge so that the
        SQLite file system code can shift its behavior depending on whether we're
        inside a sandbox or not.

        * platform/chromium/ChromiumBridge.h:
        * platform/chromium/FileSystemChromium.cpp:
        (WebCore::deleteFile):
        (WebCore::deleteEmptyDirectory):
        (WebCore::getFileModificationTime):
        (WebCore::directoryName):
        (WebCore::pathByAppendingComponent):
        (WebCore::makeAllDirectories):
        (WebCore::fileExists):
        * platform/sql/chromium/SQLiteFileSystemChromium.cpp:
        (WebCore::SQLiteFileSystem::openDatabase):
        * platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp:
        (WebCore::SQLiteFileSystem::registerSQLiteVFS):

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

WebCore/ChangeLog
WebCore/platform/chromium/ChromiumBridge.h
WebCore/platform/chromium/FileSystemChromium.cpp
WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp
WebCore/platform/sql/chromium/SQLiteFileSystemChromiumLinux.cpp
WebCore/platform/sql/chromium/SQLiteFileSystemChromiumMac.cpp
WebCore/platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp

index f8245cbf5527e7a9492204edea064a73cfc1d272..82ff6a4a600c288a35801a9589fe76878179348a 100644 (file)
@@ -1,3 +1,35 @@
+2009-08-03  Jeremy Orlow  <jorlow@chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Chromium code sometimes isn't sandboxed and needs to access the FS.
+        https://bugs.webkit.org/show_bug.cgi?id=27954
+
+        These changes are the WebKit side of http://codereview.chromium.org/159778 which
+        aims to make LocalStorage persistent.
+
+        This change runs all FileSystem routines through the ChromiumBridge so that
+        WebKitClients can handle them if they choose to.  For now, the only such client
+        will be the one running in the browser process.
+
+        It also adds a method called sandboxEnabled to the Chromium bridge so that the
+        SQLite file system code can shift its behavior depending on whether we're
+        inside a sandbox or not.
+
+        * platform/chromium/ChromiumBridge.h:
+        * platform/chromium/FileSystemChromium.cpp:
+        (WebCore::deleteFile):
+        (WebCore::deleteEmptyDirectory):
+        (WebCore::getFileModificationTime):
+        (WebCore::directoryName):
+        (WebCore::pathByAppendingComponent):
+        (WebCore::makeAllDirectories):
+        (WebCore::fileExists):
+        * platform/sql/chromium/SQLiteFileSystemChromium.cpp:
+        (WebCore::SQLiteFileSystem::openDatabase):
+        * platform/sql/chromium/SQLiteFileSystemChromiumWin.cpp:
+        (WebCore::SQLiteFileSystem::registerSQLiteVFS):
+
 2009-08-03  Alpha Lam  <hclam@chromium.org>
 
         Reviewed by David Levin.
index 9600a634c3854361a8c1836af929fcfc7454a53c..bca8c525315e1ffbffe9016d7150ea769d692427 100644 (file)
@@ -84,7 +84,14 @@ namespace WebCore {
         static void prefetchDNS(const String& hostname);
 
         // File ---------------------------------------------------------------
-        static bool getFileSize(const String& path, long long& result);
+        static bool fileExists(const String&);
+        static bool deleteFile(const String&);
+        static bool deleteEmptyDirectory(const String&);
+        static bool getFileSize(const String&, long long& result);
+        static bool getFileModificationTime(const String&, time_t& result);
+        static String directoryName(const String& path);
+        static String pathByAppendingComponent(const String& path, const String& component);
+        static bool makeAllDirectories(const String& path);
 
         // Font ---------------------------------------------------------------
 #if PLATFORM(WIN_OS)
@@ -96,6 +103,14 @@ 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);
+        static long databaseGetFileAttributes(const String& fileName);
+        static long long databaseGetFileSize(const String& fileName);
+#endif
 
         // JavaScript ---------------------------------------------------------
         static void notifyJSOutOfMemory(Frame*);
@@ -126,6 +141,9 @@ namespace WebCore {
         // Resources ----------------------------------------------------------
         static PassRefPtr<Image> loadPlatformImageResource(const char* name);
 
+        // Sandbox ------------------------------------------------------------
+        static bool sandboxEnabled();
+
         // Screen -------------------------------------------------------------
         static int screenDepth(Widget*);
         static int screenDepthPerComponent(Widget*);
@@ -178,25 +196,6 @@ 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
index 0a48852057f366be13713b040edfc5bcf71020d3..30674d9800c0e91108a2f1e7601d9caba0e0be84 100644 (file)
 
 namespace WebCore {
 
-bool deleteFile(const String&)
+bool deleteFile(const String& path)
 {
-    notImplemented();
-    return false;
+    return ChromiumBridge::deleteFile(path);
 }
 
-bool deleteEmptyDirectory(const String&)
+bool deleteEmptyDirectory(const String& path)
 {
-    notImplemented();
-    return false;
+    return ChromiumBridge::deleteEmptyDirectory(path);
 }
 
 bool getFileSize(const String& path, long long& result)
@@ -54,34 +52,29 @@ bool getFileSize(const String& path, long long& result)
     return ChromiumBridge::getFileSize(path, result);
 }
 
-bool getFileModificationTime(const String&, time_t& result)
+bool getFileModificationTime(const String& path, time_t& result)
 {
-    notImplemented();
-    return false;
+    return ChromiumBridge::getFileModificationTime(path, result);
 }
 
-String directoryName(const String&)
+String directoryName(const String& path)
 {
-    notImplemented();
-    return String();
+    return ChromiumBridge::directoryName(path);
 }
 
 String pathByAppendingComponent(const String& path, const String& component)
 {
-    notImplemented();
-    return String();
+    return ChromiumBridge::pathByAppendingComponent(path, component);
 }
 
 bool makeAllDirectories(const String& path)
 {
-    notImplemented();
-    return false;
+    return ChromiumBridge::makeAllDirectories(path);
 }
 
-bool fileExists(const String&)
+bool fileExists(const String& path)
 {
-    notImplemented();
-    return false;
+    return ChromiumBridge::fileExists(path);
 }
 
 } // namespace WebCore
index fdb50d0a2ae8b4123e5657abf10f170a5db0f75a..dc79fd027b452f98032bd80204da0ac98a23ab10 100644 (file)
@@ -50,6 +50,11 @@ 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,
index e0a8236a3c0ad4832ca54e7e3c22489283b204b5..358244828647a00ac073dd4bbbba81c0b030fde8 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
 void SQLiteFileSystem::registerSQLiteVFS()
 {
     // stub for registering Chromium's SQLite VFS for Linux
+    ASSERT_NOT_REACHED();
 }
 
 } // namespace WebCore
index 9551e99b01a5691d0f38b7edd5a80259b8fb5835..35a40f52018901cbee837228c9d33e5254f72e9a 100644 (file)
@@ -36,6 +36,7 @@ namespace WebCore {
 void SQLiteFileSystem::registerSQLiteVFS()
 {
     // stub for registering Chromium's SQLite VFS for Mac
+    ASSERT_NOT_REACHED();
 }
 
 } // namespace WebCore
index 8de35b658d577180e9d0e3f21f9e1c9e9a016a95..b357d4a8b1dcf2d55f6728df62d57fb5bd8c832a 100644 (file)
@@ -143,6 +143,12 @@ 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,