| From 65d2934485139bf8ca6fd42405f7a8fd4145481c Mon Sep 17 00:00:00 2001 |
| From: dumi <dumi@chromium.org> |
| Date: Mon, 20 Jul 2009 23:40:51 +0000 |
| Subject: [PATCH 03/11] Modify default VFS to support WebDatabase. |
| |
| The renderer WebDatabase implementation needs to broker certain requests |
| to the browser. This modifies SQLite to allow monkey-patching the VFS |
| to support this. |
| |
| NOTE(shess): This patch relies on core SQLite implementation details |
| remaining unchanged. When importing a new version of SQLite, pay very |
| close attention to whether the change is still doing what is intended. |
| |
| Original review URLs: |
| https://codereview.chromium.org/159044 |
| https://codereview.chromium.org/384075 |
| https://codereview.chromium.org/377039 |
| [Possibly not a complete list.] |
| --- |
| third_party/sqlite/src/src/os_unix.c | 49 ++++++++++++++++++++++++++++++++++ |
| third_party/sqlite/src/src/os_win.c | 8 ++++++ |
| third_party/sqlite/src/src/sqlite.h.in | 23 ++++++++++++++++ |
| 3 files changed, 80 insertions(+) |
| |
| diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/os_unix.c |
| index 8ab779a35288..44f6d67ee07f 100644 |
| --- a/third_party/sqlite/src/src/os_unix.c |
| +++ b/third_party/sqlite/src/src/os_unix.c |
| @@ -1346,6 +1346,12 @@ static int fileHasMoved(unixFile *pFile){ |
| return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; |
| #else |
| struct stat buf; |
| + |
| + /* TODO(shess): This check doesn't work when the Chromium's WebDB code is |
| + ** running in the sandbox. |
| + */ |
| + return 0; |
| + |
| return pFile->pInode!=0 && |
| (osStat(pFile->zPath, &buf)!=0 |
| || (u64)buf.st_ino!=pFile->pInode->fileId.ino); |
| @@ -5640,6 +5646,44 @@ static int findCreateFileMode( |
| } |
| |
| /* |
| +** Initialize |unixFile| internals of |file| on behalf of chromiumOpen() in |
| +** WebDatabase SQLiteFileSystemPosix.cpp. Function is a subset of unixOpen(), |
| +** each duplicated piece is marked by "Duplicated in" comment in unixOpen(). |
| +*/ |
| +CHROMIUM_SQLITE_API |
| +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs, |
| + int fd, |
| + sqlite3_file* pFile, |
| + const char* zPath, |
| + int noLock, |
| + int flags) { |
| + unixFile *p = (unixFile *)pFile; |
| + const int eType = flags&0xFFFFFF00; /* Type of file to open */ |
| + const int ctrlFlags = (noLock ? UNIXFILE_NOLOCK : 0); |
| + int rc; |
| + |
| + memset(p, 0, sizeof(unixFile)); |
| + |
| + /* osStat() will not work in the sandbox, so findReusableFd() will always |
| + ** fail, so directly include the failure-case setup then initialize pUnused. |
| + */ |
| + if( eType==SQLITE_OPEN_MAIN_DB ){ |
| + p->pUnused = sqlite3_malloc(sizeof(*p->pUnused)); |
| + if (!p->pUnused) { |
| + return SQLITE_NOMEM_BKPT; |
| + } |
| + p->pUnused->fd = fd; |
| + p->pUnused->flags = flags; |
| + } |
| + |
| + rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| + if( rc!=SQLITE_OK ){ |
| + sqlite3_free(p->pUnused); |
| + } |
| + return rc; |
| +} |
| + |
| +/* |
| ** Open the file zPath. |
| ** |
| ** Previously, the SQLite OS layer used three functions in place of this |
| @@ -5740,6 +5784,7 @@ static int unixOpen( |
| sqlite3_randomness(0,0); |
| } |
| |
| + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ |
| memset(p, 0, sizeof(unixFile)); |
| |
| if( eType==SQLITE_OPEN_MAIN_DB ){ |
| @@ -5748,6 +5793,7 @@ static int unixOpen( |
| if( pUnused ){ |
| fd = pUnused->fd; |
| }else{ |
| + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ |
| pUnused = sqlite3_malloc64(sizeof(*pUnused)); |
| if( !pUnused ){ |
| return SQLITE_NOMEM_BKPT; |
| @@ -5825,6 +5871,7 @@ static int unixOpen( |
| } |
| |
| if( p->pUnused ){ |
| + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ |
| p->pUnused->fd = fd; |
| p->pUnused->flags = flags; |
| } |
| @@ -5903,10 +5950,12 @@ static int unixOpen( |
| } |
| #endif |
| |
| + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ |
| rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); |
| |
| open_finished: |
| if( rc!=SQLITE_OK ){ |
| + /* Duplicated in chromium_sqlite3_fill_in_unix_sqlite3_file(). */ |
| sqlite3_free(p->pUnused); |
| } |
| return rc; |
| diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os_win.c |
| index a87d7d09256d..1d9abf0a8f35 100644 |
| --- a/third_party/sqlite/src/src/os_win.c |
| +++ b/third_party/sqlite/src/src/os_win.c |
| @@ -5998,4 +5998,12 @@ int sqlite3_os_end(void){ |
| return SQLITE_OK; |
| } |
| |
| +CHROMIUM_SQLITE_API |
| +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle) { |
| + winFile* winSQLite3File = (winFile*)file; |
| + memset(file, 0, sizeof(*file)); |
| + winSQLite3File->pMethod = &winIoMethod; |
| + winSQLite3File->h = handle; |
| +} |
| + |
| #endif /* SQLITE_OS_WIN */ |
| diff --git a/third_party/sqlite/src/src/sqlite.h.in b/third_party/sqlite/src/src/sqlite.h.in |
| index 9175dde682e9..c65406abe596 100644 |
| --- a/third_party/sqlite/src/src/sqlite.h.in |
| +++ b/third_party/sqlite/src/src/sqlite.h.in |
| @@ -7921,6 +7921,29 @@ int sqlite3_strnicmp(const char *, const char *, int); |
| */ |
| int sqlite3_strglob(const char *zGlob, const char *zStr); |
| |
| +/* Begin WebDatabase patch for Chromium */ |
| +/* Expose some SQLite internals for the WebDatabase vfs. |
| +** DO NOT EXTEND THE USE OF THIS. |
| +*/ |
| +#ifndef CHROMIUM_SQLITE_API |
| +#define CHROMIUM_SQLITE_API SQLITE_API |
| +#endif |
| +#if defined(CHROMIUM_SQLITE_INTERNALS) |
| +#ifdef _WIN32 |
| +CHROMIUM_SQLITE_API |
| +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE handle); |
| +#else /* _WIN32 */ |
| +CHROMIUM_SQLITE_API |
| +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs, |
| + int fd, |
| + sqlite3_file* pFile, |
| + const char* zPath, |
| + int noLock, |
| + int flags); |
| +#endif /* _WIN32 */ |
| +#endif /* CHROMIUM_SQLITE_INTERNALS */ |
| +/* End WebDatabase patch for Chromium */ |
| + |
| /* |
| ** CAPI3REF: String LIKE Matching |
| * |
| -- |
| 2.13.5 |
| |