Chromium Code Reviews| Index: content/browser/renderer_host/pepper_file_message_filter.cc |
| diff --git a/content/browser/renderer_host/pepper_file_message_filter.cc b/content/browser/renderer_host/pepper_file_message_filter.cc |
| index a86542ef14ea395ea2bd937b85457af794b932c4..7d71f236fc597de824a0cf1b513dba9e4a2de175 100644 |
| --- a/content/browser/renderer_host/pepper_file_message_filter.cc |
| +++ b/content/browser/renderer_host/pepper_file_message_filter.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/file_util.h" |
| #include "base/platform_file.h" |
| #include "base/process_util.h" |
| +#include "base/utf_string_conversions.h" |
| #include "content/browser/child_process_security_policy_impl.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -59,6 +60,8 @@ bool PepperFileMessageFilter::OnMessageReceived(const IPC::Message& message, |
| IPC_MESSAGE_HANDLER(PepperFileMsg_CreateDir, OnCreateDir) |
| IPC_MESSAGE_HANDLER(PepperFileMsg_QueryFile, OnQueryFile) |
| IPC_MESSAGE_HANDLER(PepperFileMsg_GetDirContents, OnGetDirContents) |
| + IPC_MESSAGE_HANDLER(PepperFileMsg_CreateTemporaryFile, |
| + OnCreateTemporaryFile) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP_EX() |
| return handled; |
| @@ -220,6 +223,54 @@ void PepperFileMessageFilter::OnGetDirContents( |
| *error = base::PLATFORM_FILE_OK; |
| } |
| +void PepperFileMessageFilter::OnCreateTemporaryFile( |
| + const ppapi::PepperFilePath& dir_path, |
| + base::PlatformFileError* error, |
| + IPC::PlatformFileForTransit* file, |
| + std::string* file_name) { |
| + *error = base::PLATFORM_FILE_ERROR_FAILED; |
| + *file = IPC::InvalidPlatformFileForTransit(); |
| + file_name->clear(); |
| + |
| + FilePath validated_dir_path = ValidateAndConvertPepperFilePath( |
| + dir_path, kReadPermissions | kWritePermissions); |
| + if (validated_dir_path.empty()) { |
| + *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
| + return; |
| + } |
| + |
| + FilePath file_path; |
| + if (!file_util::CreateTemporaryFileInDir(validated_dir_path, &file_path)) |
| + return; |
| + |
| + base::PlatformFile file_handle = base::CreatePlatformFile( |
| + file_path, |
| + base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_EXCLUSIVE_READ | |
|
viettrungluu
2012/06/07 20:17:36
Why do you want exclusive read and write?
yzshen1
2012/06/07 21:42:06
I am not sure. Do you know about any scenario that
|
| + base::PLATFORM_FILE_EXCLUSIVE_WRITE | base::PLATFORM_FILE_TEMPORARY | |
| + base::PLATFORM_FILE_DELETE_ON_CLOSE, |
| + NULL, error); |
| + |
| + if (*error != base::PLATFORM_FILE_OK || |
| + file_handle == base::kInvalidPlatformFileValue) { |
| + return; |
| + } |
| + |
| +#if defined(OS_WIN) |
| + if (!DuplicateHandle(GetCurrentProcess(), file_handle, |
| + peer_handle(), file, 0, false, |
| + DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
| + // file_handle is closed whether or not DuplicateHandle succeeds. |
| + *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
| + *file = INVALID_HANDLE_VALUE; |
| + return; |
| + } |
| + *file_name = UTF16ToUTF8(file_path.BaseName().value()); |
| +#else |
| + *file = base::FileDescriptor(file_handle, true); |
| + *file_name = file_path.BaseName().value(); |
| +#endif |
| +} |
| + |
| FilePath PepperFileMessageFilter::ValidateAndConvertPepperFilePath( |
| const ppapi::PepperFilePath& pepper_path, int flags) { |
| FilePath file_path; // Empty path returned on error. |