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 /chrome/browser | |
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 'chrome/browser')
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 56 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 4 |
2 files changed, 60 insertions, 0 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index b5d399d..3e26653 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -58,6 +58,7 @@ #include "chrome/common/worker_messages.h" #include "gfx/native_widget_types.h" #include "net/base/cookie_monster.h" +#include "net/base/file_stream.h" #include "net/base/keygen_handler.h" #include "net/base/load_flags.h" #include "net/base/mime_util.h" @@ -537,6 +538,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileModificationTime, OnGetFileModificationTime) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_OpenFile, OnOpenFile) IPC_MESSAGE_HANDLER(ViewHostMsg_Keygen, OnKeygen) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetExtensionMessageBundle, OnGetExtensionMessageBundle) @@ -1385,6 +1387,60 @@ void ResourceMessageFilter::OnGetFileInfoOnFileThread( NewRunnableMethod(this, &ResourceMessageFilter::Send, reply_msg)); } +void ResourceMessageFilter::OnOpenFile(const FilePath& path, + int mode, + IPC::Message* reply_msg) { + // Open the file only when the child process has been granted permission to + // upload the file. + // TODO(jianli): Do we need separate permission to control opening the file? + if (!ChildProcessSecurityPolicy::GetInstance()->CanUploadFile(id(), path)) { + ViewHostMsg_OpenFile::WriteReplyParams( + reply_msg, base::kInvalidPlatformFileValue); + Send(reply_msg); + return; + } + + // Opening the file could take a long time if it lives on a network share, + // so run it on the FILE thread. + ChromeThread::PostTask( + ChromeThread::FILE, FROM_HERE, + NewRunnableMethod( + this, &ResourceMessageFilter::OnOpenFileOnFileThread, + path, mode, reply_msg)); +} + +void ResourceMessageFilter::OnOpenFileOnFileThread(const FilePath& path, + int mode, + IPC::Message* reply_msg) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); + + base::PlatformFile file_handle = base::CreatePlatformFile( + path, + (mode == 0) ? (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ) + : (base::PLATFORM_FILE_CREATE_ALWAYS | + base::PLATFORM_FILE_WRITE), + NULL); + + base::PlatformFile target_file_handle; +#if defined(OS_WIN) + // Duplicate the file handle so that the renderer process can access the file. + if (!DuplicateHandle(GetCurrentProcess(), file_handle, + handle(), &target_file_handle, 0, false, + DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { + // file_handle is closed whether or not DuplicateHandle succeeds. + target_file_handle = INVALID_HANDLE_VALUE; + } +#else + target_file_handle = file_handle; +#endif + + ViewHostMsg_OpenFile::WriteReplyParams(reply_msg, target_file_handle); + + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &ResourceMessageFilter::Send, reply_msg)); +} + void ResourceMessageFilter::OnKeygen(uint32 key_size_index, const std::string& challenge_string, const GURL& url, diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 4a3f544..441e8f2 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -321,6 +321,10 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, void OnGetFileInfoOnFileThread(const FilePath& path, IPC::Message* reply_msg, FileInfoWriteFunc write_func); + void OnOpenFile(const FilePath& path, int mode,IPC::Message* reply_msg); + void OnOpenFileOnFileThread(const FilePath& path, + int mode, + IPC::Message* reply_msg); void OnKeygen(uint32 key_size_index, const std::string& challenge_string, const GURL& url, std::string* signed_public_key); void OnGetExtensionMessageBundle(const std::string& extension_id, |