diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-06 21:08:59 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-06 21:08:59 +0000 |
commit | 10b998f8a366c02a69b1e8688a1b5e0cb653a154 (patch) | |
tree | 4aa5d267e957f46ead7fd6742ade99679ff57a4c /webkit | |
parent | 0568e6ca9cba8826a42eed080e569dba3fe6afec (diff) | |
download | chromium_src-10b998f8a366c02a69b1e8688a1b5e0cb653a154.zip chromium_src-10b998f8a366c02a69b1e8688a1b5e0cb653a154.tar.gz chromium_src-10b998f8a366c02a69b1e8688a1b5e0cb653a154.tar.bz2 |
Add Chromium side implementation for WebFileSystem interface in WebKit.
BUG=none
TEST=non
Review URL: http://codereview.chromium.org/1748015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webfilesystem_impl.cc | 154 | ||||
-rw-r--r-- | webkit/glue/webfilesystem_impl.h | 54 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 67 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 14 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 25 |
6 files changed, 220 insertions, 96 deletions
diff --git a/webkit/glue/webfilesystem_impl.cc b/webkit/glue/webfilesystem_impl.cc new file mode 100644 index 0000000..0573045 --- /dev/null +++ b/webkit/glue/webfilesystem_impl.cc @@ -0,0 +1,154 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#include "webkit/glue/webfilesystem_impl.h" + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "net/base/file_stream.h" +#include "net/base/net_util.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" +#include "third_party/WebKit/WebKit/chromium/public/WebURL.h" +#include "webkit/glue/webkit_glue.h" + +using WebKit::WebString; + +namespace webkit_glue { + +WebFileSystemImpl::WebFileSystemImpl() + : sandbox_enabled_(true) { +} + +bool WebFileSystemImpl::fileExists(const WebString& path) { + FilePath::StringType file_path = WebStringToFilePathString(path); + return file_util::PathExists(FilePath(file_path)); +} + +bool WebFileSystemImpl::deleteFile(const WebString& path) { + NOTREACHED(); + return false; +} + +bool WebFileSystemImpl::deleteEmptyDirectory(const WebString& path) { + NOTREACHED(); + return false; +} + +bool WebFileSystemImpl::getFileSize(const WebString& path, long long& result) { + if (sandbox_enabled_) { + NOTREACHED(); + return false; + } + return file_util::GetFileSize(WebStringToFilePath(path), + reinterpret_cast<int64*>(&result)); +} + +bool WebFileSystemImpl::getFileModificationTime(const WebString& path, + double& result) { + if (sandbox_enabled_) { + NOTREACHED(); + return false; + } + file_util::FileInfo info; + if (!file_util::GetFileInfo(WebStringToFilePath(path), &info)) + return false; + result = info.last_modified.ToDoubleT(); + return true; +} + +WebString WebFileSystemImpl::directoryName(const WebString& path) { + NOTREACHED(); + return WebString(); +} + +WebString WebFileSystemImpl::pathByAppendingComponent( + const WebString& webkit_path, + const WebString& webkit_component) { + FilePath path(WebStringToFilePathString(webkit_path)); + FilePath component(WebStringToFilePathString(webkit_component)); + FilePath combined_path = path.Append(component); + return FilePathStringToWebString(combined_path.value()); +} + +bool WebFileSystemImpl::makeAllDirectories(const WebString& path) { + DCHECK(!sandbox_enabled_); + FilePath::StringType file_path = WebStringToFilePathString(path); + return file_util::CreateDirectory(FilePath(file_path)); +} + +WebString WebFileSystemImpl::getAbsolutePath(const WebString& path) { + FilePath file_path(WebStringToFilePathString(path)); + file_util::AbsolutePath(&file_path); + return FilePathStringToWebString(file_path.value()); +} + +bool WebFileSystemImpl::isDirectory(const WebString& path) { + FilePath file_path(WebStringToFilePathString(path)); + return file_util::DirectoryExists(file_path); +} + +WebKit::WebURL WebFileSystemImpl::filePathToURL(const WebString& path) { + return net::FilePathToFileURL(WebStringToFilePath(path)); +} + +base::PlatformFile WebFileSystemImpl::openFile(const WebString& path, + int mode) { + if (sandbox_enabled_) { + NOTREACHED(); + return base::kInvalidPlatformFileValue; + } + return base::CreatePlatformFile( + WebStringToFilePath(path), + (mode == 0) ? (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ) + : (base::PLATFORM_FILE_CREATE_ALWAYS | + base::PLATFORM_FILE_WRITE), + NULL); +} + +void WebFileSystemImpl::closeFile(base::PlatformFile& handle) { + if (handle == base::kInvalidPlatformFileValue) + return; + if (base::ClosePlatformFile(handle)) + handle = base::kInvalidPlatformFileValue; +} + +long long WebFileSystemImpl::seekFile(base::PlatformFile handle, + long long offset, + int origin) { + if (handle == base::kInvalidPlatformFileValue) + return -1; + net::FileStream file_stream(handle, 0); + return file_stream.Seek(static_cast<net::Whence>(origin), offset); +} + +bool WebFileSystemImpl::truncateFile(base::PlatformFile handle, + long long offset) { + if (handle == base::kInvalidPlatformFileValue || offset < 0) + return false; + net::FileStream file_stream(handle, base::PLATFORM_FILE_WRITE); + return file_stream.Truncate(offset) >= 0; +} + +int WebFileSystemImpl::readFromFile(base::PlatformFile handle, + char* data, + int length) { + if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) + return -1; + std::string buffer; + buffer.resize(length); + net::FileStream file_stream(handle, base::PLATFORM_FILE_READ); + return file_stream.Read(data, length, NULL); +} + +int WebFileSystemImpl::writeToFile(base::PlatformFile handle, + const char* data, + int length) { + if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) + return -1; + net::FileStream file_stream(handle, base::PLATFORM_FILE_WRITE); + return file_stream.Write(data, length, NULL); +} + +} // namespace webkit_glue diff --git a/webkit/glue/webfilesystem_impl.h b/webkit/glue/webfilesystem_impl.h new file mode 100644 index 0000000..875a13b --- /dev/null +++ b/webkit/glue/webfilesystem_impl.h @@ -0,0 +1,54 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +#ifndef WEBFILESYSTEM_IMPL_H_ +#define WEBFILESYSTEM_IMPL_H_ + +#include "base/platform_file.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" + +namespace webkit_glue { + +class WebFileSystemImpl : public WebKit::WebFileSystem { + public: + WebFileSystemImpl(); + virtual ~WebFileSystemImpl() { } + + // WebFileSystem methods: + 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, + double& 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); + virtual WebKit::WebString getAbsolutePath(const WebKit::WebString& path); + virtual bool isDirectory(const WebKit::WebString& path); + virtual WebKit::WebURL filePathToURL(const WebKit::WebString& path); + virtual base::PlatformFile openFile(const WebKit::WebString& path, int mode); + virtual void closeFile(base::PlatformFile& handle); + virtual long long seekFile(base::PlatformFile handle, + long long offset, + int origin); + virtual bool truncateFile(base::PlatformFile handle, long long offset); + virtual int readFromFile(base::PlatformFile handle, char* data, int length); + virtual int writeToFile(base::PlatformFile handle, + const char* data, + int length); + + void set_sandbox_enabled(bool sandbox_enabled) { + sandbox_enabled_ = sandbox_enabled; + } + + protected: + bool sandbox_enabled_; +}; + +} // namespace webkit_glue + +#endif // WEBFILESYSTEM_IMPL_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 1f5e950..aec0904 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -254,6 +254,8 @@ 'webdropdata.cc', 'webdropdata_win.cc', 'webdropdata.h', + 'webfilesystem_impl.cc', + 'webfilesystem_impl.h', 'webkit_glue.cc', 'webkit_glue.h', 'webkitclient_impl.cc', diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index bedae2d..a065ad8 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -12,8 +12,6 @@ #include <vector> -#include "base/file_path.h" -#include "base/file_util.h" #include "base/lock.h" #include "base/message_loop.h" #include "base/process_util.h" @@ -25,7 +23,6 @@ #include "base/trace_event.h" #include "grit/webkit_resources.h" #include "grit/webkit_strings.h" -#include "net/base/net_util.h" #include "third_party/WebKit/WebKit/chromium/public/WebCookie.h" #include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrameClient.h" @@ -425,70 +422,6 @@ size_t WebKitClientImpl::memoryUsageMB() { return current_mem_usage; } -bool WebKitClientImpl::fileExists(const WebKit::WebString& path) { - FilePath::StringType file_path = webkit_glue::WebStringToFilePathString(path); - return file_util::PathExists(FilePath(file_path)); -} - -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, - double& 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)); -} - -WebKit::WebString WebKitClientImpl::getAbsolutePath( - const WebKit::WebString& path) { - FilePath file_path(webkit_glue::WebStringToFilePathString(path)); - file_util::AbsolutePath(&file_path); - return webkit_glue::FilePathStringToWebString(file_path.value()); -} - -bool WebKitClientImpl::isDirectory(const WebKit::WebString& path) { - FilePath file_path(webkit_glue::WebStringToFilePathString(path)); - return file_util::DirectoryExists(file_path); -} - -WebKit::WebURL WebKitClientImpl::filePathToURL(const WebKit::WebString& path) { - return net::FilePathToFileURL(webkit_glue::WebStringToFilePath(path)); -} - void WebKitClientImpl::SuspendSharedTimer() { ++shared_timer_suspended_; } diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index a6bdad5..6b8e345 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -23,20 +23,6 @@ class WebKitClientImpl : public WebKit::WebKitClient { // WebKitClient methods (partial implementation): virtual WebKit::WebThemeEngine* themeEngine(); - 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, - double& 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); - virtual WebKit::WebString getAbsolutePath(const WebKit::WebString& path); - virtual bool isDirectory(const WebKit::WebString& path); - virtual WebKit::WebURL filePathToURL(const WebKit::WebString& path); virtual base::PlatformFile databaseOpenFile( const WebKit::WebString& vfs_file_name, int desired_flags, diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index bf0a8ad..c4e79b4 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -7,10 +7,12 @@ #include "base/file_util.h" #include "base/path_service.h" +#include "base/platform_file.h" #include "base/scoped_temp_dir.h" #include "base/stats_counters.h" #include "base/string_util.h" #include "media/base/media.h" +#include "net/base/file_stream.h" #include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/WebKit/chromium/public/WebDatabase.h" #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" @@ -28,6 +30,7 @@ #include "webkit/extensions/v8/gears_extension.h" #include "webkit/extensions/v8/interval_extension.h" #include "webkit/glue/webclipboard_impl.h" +#include "webkit/glue/webfilesystem_impl.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webkitclient_impl.h" #include "webkit/tools/test_shell/mock_webclipboard_impl.h" @@ -88,6 +91,8 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { WebKit::WebDatabase::setObserver(&database_system_); + file_system_.set_sandbox_enabled(false); + #if defined(OS_WIN) // Ensure we pick up the default theme engine. SetThemeEngine(NULL); @@ -112,6 +117,10 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { } } + virtual WebKit::WebFileSystem* fileSystem() { + return &file_system_; + } + virtual WebKit::WebSandboxSupport* sandboxSupport() { return NULL; } @@ -148,21 +157,6 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { return SimpleDatabaseSystem::GetInstance()->GetFileSize(vfs_file_name); } - virtual bool getFileSize(const WebKit::WebString& path, long long& result) { - return file_util::GetFileSize( - webkit_glue::WebStringToFilePath(path), - reinterpret_cast<int64*>(&result)); - } - - virtual bool getFileModificationTime(const WebKit::WebString& path, - double& result) { - file_util::FileInfo info; - if (!file_util::GetFileInfo(webkit_glue::WebStringToFilePath(path), &info)) - return false; - result = info.last_modified.ToDoubleT(); - return true; - } - virtual unsigned long long visitedLinkHash(const char* canonicalURL, size_t length) { return 0; @@ -238,6 +232,7 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { TestShellWebMimeRegistryImpl mime_registry_; MockWebClipboardImpl mock_clipboard_; webkit_glue::WebClipboardImpl real_clipboard_; + webkit_glue::WebFileSystemImpl file_system_; ScopedTempDir appcache_dir_; SimpleAppCacheSystem appcache_system_; SimpleDatabaseSystem database_system_; |