diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 01:15:54 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 01:15:54 +0000 |
commit | 1f8b34120905d0cb89f8a35c2a9e38ee1747c878 (patch) | |
tree | 63687e8e964bacf3491ad111d4aad28fc17dad25 /webkit | |
parent | 97880fa256d45accb61d1c9887bb7e28724286cd (diff) | |
download | chromium_src-1f8b34120905d0cb89f8a35c2a9e38ee1747c878.zip chromium_src-1f8b34120905d0cb89f8a35c2a9e38ee1747c878.tar.gz chromium_src-1f8b34120905d0cb89f8a35c2a9e38ee1747c878.tar.bz2 |
This CL is doing a bunch of Misc work to make LocalStorage data persist.
First of all, this allows WebKit clients to specify whether or not the VFS should be used. In the browser process, we never want it to be.
Next, this allows WebKit clients to specify the behavior of WebKit's FileSystem code. By default, they should all be NOT_REACHED(). The browser process implements the two of these I need for LocalStorage, but it'll be really easy for the rest to be implemented as needed.
Next, this adds a function that storage routines can call to ensure that lazily initialized stuff that must be initialized on the main WebKit thread is initialized. Right now, this is just used to initialize the UTF8 conversion tables, but I'm sure there'll be more overt time.
Lastly, this uses the profile directory stored by webkit_context_ to derive the path LocalStorage should use.
This CL also cleans up a few minor style issues as it goes.
TEST=none
BUG=4360
Review URL: http://codereview.chromium.org/159778
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22452 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/api/public/WebKitClient.h | 63 | ||||
-rw-r--r-- | webkit/api/src/ChromiumBridge.cpp | 72 | ||||
-rw-r--r-- | webkit/api/src/WebKit.cpp | 10 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 59 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 13 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 4 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_worker/test_worker_main.cc | 4 |
7 files changed, 160 insertions, 65 deletions
diff --git a/webkit/api/public/WebKitClient.h b/webkit/api/public/WebKitClient.h index 026caf5..2757a96 100644 --- a/webkit/api/public/WebKitClient.h +++ b/webkit/api/public/WebKitClient.h @@ -31,6 +31,8 @@ #ifndef WebKitClient_h #define WebKitClient_h +#include <time.h> + #include "WebCommon.h" #include "WebLocalizedString.h" @@ -81,7 +83,16 @@ namespace WebKit { // File ---------------------------------------------------------------- + // Various file/directory related functions. These map 1:1 with + // functions in WebCore's FileSystem.h. + virtual bool fileExists(const WebString& path) = 0; + virtual bool deleteFile(const WebString& path) = 0; + virtual bool deleteEmptyDirectory(const WebString& path) = 0; virtual bool getFileSize(const WebString& path, long long& result) = 0; + virtual bool getFileModificationTime(const WebString& path, time_t& result) = 0; + virtual WebString directoryName(const WebString& path) = 0; + virtual WebString pathByAppendingComponent(const WebString& path, const WebString& component) = 0; + virtual bool makeAllDirectories(const WebString& path) = 0; // History ------------------------------------------------------------- @@ -95,6 +106,26 @@ namespace WebKit { // hash must have been generated by calling VisitedLinkHash(). virtual bool isLinkVisited(unsigned long long linkHash) = 0; + // HTML5 DB ------------------------------------------------------------ + +#if defined(OS_WIN) + typedef HANDLE FileType; +#else + typedef int FileType; +#endif + + // Opens a database file + virtual FileType databaseOpenFile(const WebString& fileName, int desiredFlags) = 0; + + // Deletes a database file and returns the error code + virtual bool databaseDeleteFile(const WebString& fileName) = 0; + + // Returns the attributes of the given database file + virtual long databaseGetFileAttributes(const WebString& fileName) = 0; + + // Returns the size of the given database file + virtual long long databaseGetFileSize(const WebString& fileName) = 0; + // Message Ports ------------------------------------------------------- @@ -145,6 +176,18 @@ namespace WebKit { virtual WebString queryLocalizedString(WebLocalizedString::Name, int numericValue) = 0; + // Sandbox ------------------------------------------------------------ + + // In some browsers, a "sandbox" restricts what operations a program + // is allowed to preform. Such operations are typically abstracted out + // via this API, but sometimes (like in HTML 5 database opening) WebKit + // needs to behave differently based on whether it's restricted or not. + // In these cases (and these cases only) you can call this function. + // It's OK for this value to be conservitive (i.e. true even if the + // sandbox isn't active). + virtual bool sandboxEnabled() = 0; + + // Sudden Termination -------------------------------------------------- // Disable/Enable sudden termination. @@ -166,26 +209,6 @@ namespace WebKit { // Callable from a background WebKit thread. virtual void callOnMainThread(void (*func)()) = 0; - - // HTML5 DB ------------------------------------------------------------ - -#if defined(OS_WIN) -typedef HANDLE FileType; -#else -typedef int FileType; -#endif - - // Opens a database file - virtual FileType databaseOpenFile(const WebString& fileName, int desiredFlags) = 0; - - // Deletes a database file and returns the error code - virtual bool databaseDeleteFile(const WebString& fileName) = 0; - - // Returns the attributes of the given database file - virtual long databaseGetFileAttributes(const WebString& fileName) = 0; - - // Returns the size of the given database file - virtual long long databaseGetFileSize(const WebString& fileName) = 0; }; } // namespace WebKit diff --git a/webkit/api/src/ChromiumBridge.cpp b/webkit/api/src/ChromiumBridge.cpp index 53e6487..e48b4b7 100644 --- a/webkit/api/src/ChromiumBridge.cpp +++ b/webkit/api/src/ChromiumBridge.cpp @@ -152,20 +152,17 @@ void ChromiumBridge::prefetchDNS(const String& hostname) bool ChromiumBridge::fileExists(const String& path) { - ASSERT_NOT_REACHED(); - return false; + return webKitClient()->fileExists(path); } bool ChromiumBridge::deleteFile(const String& path) { - ASSERT_NOT_REACHED(); - return false; + return webKitClient()->deleteFile(path); } bool ChromiumBridge::deleteEmptyDirectory(const String& path) { - ASSERT_NOT_REACHED(); - return false; + return webKitClient()->deleteEmptyDirectory(path); } bool ChromiumBridge::getFileSize(const String& path, long long& result) @@ -175,26 +172,22 @@ bool ChromiumBridge::getFileSize(const String& path, long long& result) bool ChromiumBridge::getFileModificationTime(const String& path, time_t& result) { - ASSERT_NOT_REACHED(); - return false; + return webKitClient()->getFileModificationTime(path, result); } String ChromiumBridge::directoryName(const String& path) { - ASSERT_NOT_REACHED(); - return String(); + return webKitClient()->directoryName(path); } String ChromiumBridge::pathByAppendingComponent(const String& path, const String& component) { - ASSERT_NOT_REACHED(); - return String(); + return webKitClient()->pathByAppendingComponent(path, component); } bool ChromiumBridge::makeAllDirectories(const String& path) { - ASSERT_NOT_REACHED(); - return false; + return webKitClient()->makeAllDirectories(path); } // Font ----------------------------------------------------------------------- @@ -220,6 +213,30 @@ String ChromiumBridge::getFontFamilyForCharacters(const UChar* characters, size_ } #endif +// HTML5 DB ------------------------------------------------------------------- + +#if ENABLE(DATABASE) +PlatformFileHandle ChromiumBridge::databaseOpenFile(const String& fileName, int desiredFlags) +{ + return webKitClient()->databaseOpenFile(WebString(fileName), desiredFlags); +} + +bool ChromiumBridge::databaseDeleteFile(const String& fileName) +{ + return webKitClient()->databaseDeleteFile(WebString(fileName)); +} + +long ChromiumBridge::databaseGetFileAttributes(const String& fileName) +{ + return webKitClient()->databaseGetFileAttributes(WebString(fileName)); +} + +long long ChromiumBridge::databaseGetFileSize(const String& fileName) +{ + return webKitClient()->databaseGetFileSize(WebString(fileName)); +} +#endif + // Language ------------------------------------------------------------------- String ChromiumBridge::computedDefaultLanguage() @@ -295,7 +312,7 @@ PassRefPtr<Image> ChromiumBridge::loadPlatformImageResource(const char* name) bool ChromiumBridge::sandboxEnabled() { - return true; + return webKitClient()->sandboxEnabled(); } // SharedTimers --------------------------------------------------------------- @@ -472,29 +489,4 @@ bool ChromiumBridge::isLinkVisited(WebCore::LinkHash visitedLinkHash) return webKitClient()->isLinkVisited(visitedLinkHash); } -// HTML5 DB ------------------------------------------------------------------- - -#if ENABLE(DATABASE) -PlatformFileHandle ChromiumBridge::databaseOpenFile(const String& fileName, - int desiredFlags) -{ - return webKitClient()->databaseOpenFile(WebString(fileName), desiredFlags); -} - -bool ChromiumBridge::databaseDeleteFile(const String& fileName) -{ - return webKitClient()->databaseDeleteFile(WebString(fileName)); -} - -long ChromiumBridge::databaseGetFileAttributes(const String& fileName) -{ - return webKitClient()->databaseGetFileAttributes(WebString(fileName)); -} - -long long ChromiumBridge::databaseGetFileSize(const String& fileName) -{ - return webKitClient()->databaseGetFileSize(WebString(fileName)); -} -#endif - } // namespace WebCore diff --git a/webkit/api/src/WebKit.cpp b/webkit/api/src/WebKit.cpp index 8fa42bb..93ddc72 100644 --- a/webkit/api/src/WebKit.cpp +++ b/webkit/api/src/WebKit.cpp @@ -38,6 +38,7 @@ #include "DOMTimer.h" #include "FrameLoader.h" #include "Page.h" +#include "TextEncoding.h" #include "V8Binding.h" #include "V8Proxy.h" #include "WorkerContextExecutionProxy.h" @@ -65,6 +66,15 @@ void initialize(WebKitClient* webKitClient) // 4ms prevents the CPU from spinning too busily and provides a balance // between CPU spinning and the smallest possible interval timer. WebCore::DOMTimer::setMinTimerInterval(0.004); + + // There are some code paths (for example, running WebKit in the browser + // process and calling into LocalStorage before anything else) where the + // UTF8 string encoding tables are used on a background thread before + // they're set up. This is a problem because their set up routines assert + // they're running on the main WebKitThread. It might be possible to make + // the initialization thread-safe, but given that so many code paths use + // this, initializing this lazily probably doesn't buy us much. + WebCore::UTF8Encoding(); } void shutdown() diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 9a19bf5..7233a1f 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -4,6 +4,8 @@ #include "webkit/glue/webkitclient_impl.h" +#include "base/file_path.h" +#include "base/file_util.h" #include "base/message_loop.h" #include "base/platform_file.h" #include "base/stats_counters.h" @@ -227,23 +229,72 @@ void WebKitClientImpl::callOnMainThread(void (*func)()) { } base::PlatformFile WebKitClientImpl::databaseOpenFile( - const WebKit::WebString& file_name, int desired_flags) { + const WebKit::WebString& file_name, int desired_flags) { return base::kInvalidPlatformFileValue; } bool WebKitClientImpl::databaseDeleteFile( - const WebKit::WebString& file_name) { + const WebKit::WebString& file_name) { return false; } long WebKitClientImpl::databaseGetFileAttributes( - const WebKit::WebString& file_name) { + const WebKit::WebString& file_name) { return 0; } long long WebKitClientImpl::databaseGetFileSize( - const WebKit::WebString& file_name) { + const WebKit::WebString& file_name) { return 0; } +bool WebKitClientImpl::fileExists(const WebKit::WebString& path) { + NOTREACHED(); + return false; +} + +bool WebKitClientImpl::deleteFile(const WebKit::WebString& path) { + NOTREACHED(); + return false; +} + +bool WebKitClientImpl::deleteEmptyDirectory(const WebKit::WebString& path) { + NOTREACHED(); + return false; +} + +bool WebKitClientImpl::getFileSize(const WebKit::WebString& path, + long long& result) { + NOTREACHED(); + return false; +} + +bool WebKitClientImpl::getFileModificationTime(const WebKit::WebString& path, + time_t& result) { + NOTREACHED(); + return false; +} + +WebKit::WebString WebKitClientImpl::directoryName( + const WebKit::WebString& path) { + NOTREACHED(); + return WebKit::WebString(); +} + +WebKit::WebString WebKitClientImpl::pathByAppendingComponent( + const WebKit::WebString& webkit_path, + const WebKit::WebString& webkit_component) { + FilePath path(webkit_glue::WebStringToFilePathString(webkit_path)); + FilePath component(webkit_glue::WebStringToFilePathString(webkit_component)); + FilePath combined_path = path.Append(component); + return webkit_glue::FilePathStringToWebString(combined_path.value()); +} + +bool WebKitClientImpl::makeAllDirectories( + const WebKit::WebString& path) { + DCHECK(!sandboxEnabled()); + FilePath::StringType file_path = webkit_glue::WebStringToFilePathString(path); + return file_util::CreateDirectory(FilePath(file_path)); +} + } // namespace webkit_glue diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index e3035ae..8b6574e 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -41,11 +41,22 @@ class WebKitClientImpl : public WebKit::WebKitClient { virtual void suddenTerminationChanged(bool enabled) { } virtual base::PlatformFile databaseOpenFile( - const WebKit::WebString& file_name, int desired_flags); + const WebKit::WebString& file_name, int desired_flags); virtual bool databaseDeleteFile(const WebKit::WebString& file_name); virtual long databaseGetFileAttributes(const WebKit::WebString& file_name); virtual long long databaseGetFileSize(const WebKit::WebString& file_name); + virtual bool fileExists(const WebKit::WebString& path); + virtual bool deleteFile(const WebKit::WebString& path); + virtual bool deleteEmptyDirectory(const WebKit::WebString& path); + virtual bool getFileSize(const WebKit::WebString& path, long long& result); + virtual bool getFileModificationTime(const WebKit::WebString& path, + time_t& result); + virtual WebKit::WebString directoryName(const WebKit::WebString& path); + virtual WebKit::WebString pathByAppendingComponent( + const WebKit::WebString& path, const WebKit::WebString& component); + virtual bool makeAllDirectories(const WebKit::WebString& path); + private: void DoTimeout() { if (shared_timer_func_) diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index dbb8e81..6db295c 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -74,6 +74,10 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { return NULL; } + virtual bool sandboxEnabled() { + return false; + } + virtual bool getFileSize(const WebKit::WebString& path, long long& result) { return file_util::GetFileSize( FilePath(webkit_glue::WebStringToFilePathString(path)), diff --git a/webkit/tools/test_shell/test_worker/test_worker_main.cc b/webkit/tools/test_shell/test_worker/test_worker_main.cc index 2739640..9a5912d 100644 --- a/webkit/tools/test_shell/test_worker/test_worker_main.cc +++ b/webkit/tools/test_shell/test_worker/test_worker_main.cc @@ -48,6 +48,10 @@ class WorkerWebKitClientImpl : public webkit_glue::WebKitClientImpl { return NULL; } + virtual bool sandboxEnabled() { + return true; + } + virtual unsigned long long visitedLinkHash(const char* canonicalURL, size_t length) { NOTREACHED(); |