diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:16:05 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:16:05 +0000 |
commit | 494184c1d68dfbdaa51af78f680e59dd0bfc6143 (patch) | |
tree | f897b02dc34dbc4e860c9dad561311d1a9e16e34 | |
parent | 287b86bfa8405f38377eb4b6c33c28b8a926fb2a (diff) | |
download | chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.zip chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.tar.gz chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.tar.bz2 |
Pepper/Flapper: Refactor module-local file stuff to make it easier/nicer to add file ref versions.
BUG=none
TEST=everything still works
Review URL: http://codereview.chromium.org/6599015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76124 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/pepper_file_messages.cc | 30 | ||||
-rw-r--r-- | chrome/common/pepper_file_messages.h | 25 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 102 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 39 | ||||
-rw-r--r-- | content/browser/renderer_host/pepper_file_message_filter.cc | 96 | ||||
-rw-r--r-- | content/browser/renderer_host/pepper_file_message_filter.h | 42 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/file_path.cc | 55 | ||||
-rw-r--r-- | webkit/plugins/ppapi/file_path.h | 50 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 32 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 36 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 38 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_file_impl.cc | 143 |
13 files changed, 396 insertions, 294 deletions
diff --git a/chrome/common/pepper_file_messages.cc b/chrome/common/pepper_file_messages.cc index 30f6ad1..83a933c 100644 --- a/chrome/common/pepper_file_messages.cc +++ b/chrome/common/pepper_file_messages.cc @@ -31,4 +31,34 @@ void ParamTraits<webkit::ppapi::DirEntry>::Log(const param_type& p, l->append(")"); } +void ParamTraits<webkit::ppapi::PepperFilePath>::Write(Message* m, + const param_type& p) { + WriteParam(m, static_cast<unsigned>(p.domain())); + WriteParam(m, p.path()); +} + +bool ParamTraits<webkit::ppapi::PepperFilePath>::Read(const Message* m, + void** iter, + param_type* p) { + unsigned domain; + FilePath path; + if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path)) + return false; + if (domain > webkit::ppapi::PepperFilePath::DOMAIN_MAX_VALID) + return false; + + *p = webkit::ppapi::PepperFilePath( + static_cast<webkit::ppapi::PepperFilePath::Domain>(domain), path); + return true; +} + +void ParamTraits<webkit::ppapi::PepperFilePath>::Log(const param_type& p, + std::string* l) { + l->append("("); + LogParam(static_cast<unsigned>(p.domain()), l); + l->append(", "); + LogParam(p.path(), l); + l->append(")"); +} + } // namespace IPC diff --git a/chrome/common/pepper_file_messages.h b/chrome/common/pepper_file_messages.h index 657b3e3..eff4d153 100644 --- a/chrome/common/pepper_file_messages.h +++ b/chrome/common/pepper_file_messages.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -11,6 +11,7 @@ #include "ipc/ipc_param_traits.h" #include "ipc/ipc_platform_file.h" #include "webkit/plugins/ppapi/dir_contents.h" +#include "webkit/plugins/ppapi/file_path.h" #define IPC_MESSAGE_START PepperFileMsgStart @@ -25,43 +26,51 @@ struct ParamTraits<webkit::ppapi::DirEntry> { static void Log(const param_type& p, std::string* l); }; +template <> +struct ParamTraits<webkit::ppapi::PepperFilePath> { + typedef webkit::ppapi::PepperFilePath param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + } // namespace IPC // Trusted Pepper Filesystem messages from the renderer to the browser. // Open the file. IPC_SYNC_MESSAGE_CONTROL2_2(PepperFileMsg_OpenFile, - FilePath /* path */, + webkit::ppapi::PepperFilePath /* path */, int /* flags */, base::PlatformFileError /* error_code */, IPC::PlatformFileForTransit /* result */) // Rename the file. IPC_SYNC_MESSAGE_CONTROL2_1(PepperFileMsg_RenameFile, - FilePath /* path_from */, - FilePath /* path_to */, + webkit::ppapi::PepperFilePath /* from_path */, + webkit::ppapi::PepperFilePath /* to_path */, base::PlatformFileError /* error_code */) // Delete the file. IPC_SYNC_MESSAGE_CONTROL2_1(PepperFileMsg_DeleteFileOrDir, - FilePath /* path */, + webkit::ppapi::PepperFilePath /* path */, bool /* recursive */, base::PlatformFileError /* error_code */) // Create the directory. IPC_SYNC_MESSAGE_CONTROL1_1(PepperFileMsg_CreateDir, - FilePath /* path */, + webkit::ppapi::PepperFilePath /* path */, base::PlatformFileError /* error_code */) // Query the file's info. IPC_SYNC_MESSAGE_CONTROL1_2(PepperFileMsg_QueryFile, - FilePath /* path */, + webkit::ppapi::PepperFilePath /* path */, base::PlatformFileInfo, /* info */ base::PlatformFileError /* error_code */) // Get the directory's contents. IPC_SYNC_MESSAGE_CONTROL1_2(PepperFileMsg_GetDirContents, - FilePath /* path */, + webkit::ppapi::PepperFilePath /* path */, webkit::ppapi::DirContents, /* contents */ base::PlatformFileError /* error_code */) diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 50dcd3d..e442cb2 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -14,7 +14,6 @@ #include "base/string_split.h" #include "base/task.h" #include "base/time.h" -#include "base/utf_string_conversions.h" #include "chrome/common/child_thread.h" #include "chrome/common/file_system/file_system_dispatcher.h" #include "chrome/common/pepper_file_messages.h" @@ -47,6 +46,7 @@ #include "webkit/fileapi/file_system_callback_dispatcher.h" #include "webkit/glue/context_menu.h" #include "webkit/plugins/npapi/webplugin.h" +#include "webkit/plugins/ppapi/file_path.h" #include "webkit/plugins/ppapi/ppb_file_io_impl.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -690,31 +690,14 @@ bool PepperPluginDelegateImpl::ReadDirectory( return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); } -FilePath GetModuleLocalFilePath(const std::string& module_name, - const FilePath& path) { -#if defined(OS_WIN) - FilePath full_path(UTF8ToUTF16(module_name)); -#else - FilePath full_path(module_name); -#endif - full_path = full_path.Append(path); - return full_path; -} - -base::PlatformFileError PepperPluginDelegateImpl::OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError PepperPluginDelegateImpl::OpenFile( + const webkit::ppapi::PepperFilePath& path, int flags, base::PlatformFile* file) { - FilePath full_path = GetModuleLocalFilePath(module_name, path); - if (full_path.empty()) { - *file = base::kInvalidPlatformFileValue; - return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; - } IPC::PlatformFileForTransit transit_file; base::PlatformFileError error; IPC::Message* msg = new PepperFileMsg_OpenFile( - full_path, flags, &error, &transit_file); + path, flags, &error, &transit_file); if (!render_view_->Send(msg)) { *file = base::kInvalidPlatformFileValue; return base::PLATFORM_FILE_ERROR_FAILED; @@ -723,86 +706,53 @@ base::PlatformFileError PepperPluginDelegateImpl::OpenModuleLocalFile( return error; } -base::PlatformFileError PepperPluginDelegateImpl::RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to) { - FilePath full_path_from = GetModuleLocalFilePath(module_name, path_from); - FilePath full_path_to = GetModuleLocalFilePath(module_name, path_to); - if (full_path_from.empty() || full_path_to.empty()) { - return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; - } +base::PlatformFileError PepperPluginDelegateImpl::RenameFile( + const webkit::ppapi::PepperFilePath& from_path, + const webkit::ppapi::PepperFilePath& to_path) { base::PlatformFileError error; - IPC::Message* msg = new PepperFileMsg_RenameFile( - full_path_from, full_path_to, &error); - if (!render_view_->Send(msg)) { + IPC::Message* msg = new PepperFileMsg_RenameFile(from_path, to_path, &error); + if (!render_view_->Send(msg)) return base::PLATFORM_FILE_ERROR_FAILED; - } return error; } -base::PlatformFileError PepperPluginDelegateImpl::DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError PepperPluginDelegateImpl::DeleteFileOrDir( + const webkit::ppapi::PepperFilePath& path, bool recursive) { - FilePath full_path = GetModuleLocalFilePath(module_name, path); - if (full_path.empty()) { - return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; - } base::PlatformFileError error; IPC::Message* msg = new PepperFileMsg_DeleteFileOrDir( - full_path, recursive, &error); - if (!render_view_->Send(msg)) { + path, recursive, &error); + if (!render_view_->Send(msg)) return base::PLATFORM_FILE_ERROR_FAILED; - } return error; } -base::PlatformFileError PepperPluginDelegateImpl::CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path) { - FilePath full_path = GetModuleLocalFilePath(module_name, path); - if (full_path.empty()) { - return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; - } +base::PlatformFileError PepperPluginDelegateImpl::CreateDir( + const webkit::ppapi::PepperFilePath& path) { base::PlatformFileError error; - IPC::Message* msg = new PepperFileMsg_CreateDir(full_path, &error); - if (!render_view_->Send(msg)) { + IPC::Message* msg = new PepperFileMsg_CreateDir(path, &error); + if (!render_view_->Send(msg)) return base::PLATFORM_FILE_ERROR_FAILED; - } return error; } -base::PlatformFileError PepperPluginDelegateImpl::QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError PepperPluginDelegateImpl::QueryFile( + const webkit::ppapi::PepperFilePath& path, base::PlatformFileInfo* info) { - FilePath full_path = GetModuleLocalFilePath(module_name, path); - if (full_path.empty()) { - return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; - } base::PlatformFileError error; - IPC::Message* msg = new PepperFileMsg_QueryFile(full_path, info, &error); - if (!render_view_->Send(msg)) { + IPC::Message* msg = new PepperFileMsg_QueryFile(path, info, &error); + if (!render_view_->Send(msg)) return base::PLATFORM_FILE_ERROR_FAILED; - } return error; } -base::PlatformFileError PepperPluginDelegateImpl::GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, - webkit::ppapi::DirContents* contents) { - FilePath full_path = GetModuleLocalFilePath(module_name, path); - if (full_path.empty()) { - return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; - } +base::PlatformFileError PepperPluginDelegateImpl::GetDirContents( + const webkit::ppapi::PepperFilePath& path, + webkit::ppapi::DirContents* contents) { base::PlatformFileError error; - IPC::Message* msg = - new PepperFileMsg_GetDirContents(full_path, contents, &error); - if (!render_view_->Send(msg)) { + IPC::Message* msg = new PepperFileMsg_GetDirContents(path, contents, &error); + if (!render_view_->Send(msg)) return base::PLATFORM_FILE_ERROR_FAILED; - } return error; } diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index f589687..30f2c94 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -28,12 +28,11 @@ class Rect; namespace webkit { namespace ppapi { - +class PepperFilePath; class PluginInstance; class PluginModule; - -} // namespace ppapi -} // namespace webkit +} +} namespace WebKit { class WebFileChooserCompletion; @@ -122,29 +121,23 @@ class PepperPluginDelegateImpl fileapi::FileSystemCallbackDispatcher* dispatcher); virtual bool ReadDirectory(const FilePath& directory_path, fileapi::FileSystemCallbackDispatcher* dispatcher); - virtual base::PlatformFileError OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, + virtual base::PlatformFileError OpenFile( + const webkit::ppapi::PepperFilePath& path, int flags, base::PlatformFile* file); - virtual base::PlatformFileError RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to); - virtual base::PlatformFileError DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, + virtual base::PlatformFileError RenameFile( + const webkit::ppapi::PepperFilePath& from_path, + const webkit::ppapi::PepperFilePath& to_path); + virtual base::PlatformFileError DeleteFileOrDir( + const webkit::ppapi::PepperFilePath& path, bool recursive); - virtual base::PlatformFileError CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path); - virtual base::PlatformFileError QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, + virtual base::PlatformFileError CreateDir( + const webkit::ppapi::PepperFilePath& path); + virtual base::PlatformFileError QueryFile( + const webkit::ppapi::PepperFilePath& path, base::PlatformFileInfo* info); - virtual base::PlatformFileError GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, + virtual base::PlatformFileError GetDirContents( + const webkit::ppapi::PepperFilePath& path, webkit::ppapi::DirContents* contents); virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); virtual int32_t ConnectTcp( diff --git a/content/browser/renderer_host/pepper_file_message_filter.cc b/content/browser/renderer_host/pepper_file_message_filter.cc index 9f7f9d9..4d81dc5 100644 --- a/content/browser/renderer_host/pepper_file_message_filter.cc +++ b/content/browser/renderer_host/pepper_file_message_filter.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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 "content/browser/renderer_host/pepper_file_message_filter.h" #include "base/callback.h" -#include "base/file_util.h" #include "base/file_path.h" +#include "base/file_util.h" #include "base/process_util.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/profiles/profile.h" @@ -14,11 +14,35 @@ #include "chrome/common/child_process_host.h" #include "chrome/common/pepper_file_messages.h" #include "ipc/ipc_platform_file.h" +#include "webkit/plugins/ppapi/file_path.h" #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" #endif +namespace { + +FilePath ConvertPepperFilePath( + const webkit::ppapi::PepperFilePath& pepper_path) { + FilePath file_path; + switch(pepper_path.domain()) { + case webkit::ppapi::PepperFilePath::DOMAIN_ABSOLUTE: + NOTIMPLEMENTED(); + break; + case webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL: + if (!pepper_path.path().IsAbsolute() && + !pepper_path.path().ReferencesParent()) + file_path = pepper_path.path(); + break; + default: + NOTREACHED(); + break; + } + return file_path; +} + +} // namespace + PepperFileMessageFilter::PepperFileMessageFilter( int child_id, Profile* profile) { pepper_path_ = profile->GetPath().Append(FILE_PATH_LITERAL("Pepper Data")); @@ -36,17 +60,16 @@ void PepperFileMessageFilter::OverrideThreadForMessage( *thread = BrowserThread::FILE; } -bool PepperFileMessageFilter::OnMessageReceived( - const IPC::Message& message, - bool* message_was_ok) { +bool PepperFileMessageFilter::OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(PepperFileMessageFilter, message, *message_was_ok) - IPC_MESSAGE_HANDLER(PepperFileMsg_OpenFile, OnPepperOpenFile) - IPC_MESSAGE_HANDLER(PepperFileMsg_RenameFile, OnPepperRenameFile) - IPC_MESSAGE_HANDLER(PepperFileMsg_DeleteFileOrDir, OnPepperDeleteFileOrDir) - IPC_MESSAGE_HANDLER(PepperFileMsg_CreateDir, OnPepperCreateDir) - IPC_MESSAGE_HANDLER(PepperFileMsg_QueryFile, OnPepperQueryFile) - IPC_MESSAGE_HANDLER(PepperFileMsg_GetDirContents, OnPepperGetDirContents) + IPC_MESSAGE_HANDLER(PepperFileMsg_OpenFile, OnOpenFile) + IPC_MESSAGE_HANDLER(PepperFileMsg_RenameFile, OnRenameFile) + IPC_MESSAGE_HANDLER(PepperFileMsg_DeleteFileOrDir, OnDeleteFileOrDir) + IPC_MESSAGE_HANDLER(PepperFileMsg_CreateDir, OnCreateDir) + IPC_MESSAGE_HANDLER(PepperFileMsg_QueryFile, OnQueryFile) + IPC_MESSAGE_HANDLER(PepperFileMsg_GetDirContents, OnGetDirContents) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; @@ -57,12 +80,12 @@ void PepperFileMessageFilter::OnDestruct() const { } // Called on the FILE thread: -void PepperFileMessageFilter::OnPepperOpenFile( - const FilePath& path, +void PepperFileMessageFilter::OnOpenFile( + const webkit::ppapi::PepperFilePath& path, int flags, base::PlatformFileError* error, IPC::PlatformFileForTransit* file) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; *file = IPC::InvalidPlatformFileForTransit(); @@ -101,27 +124,27 @@ void PepperFileMessageFilter::OnPepperOpenFile( #endif } -void PepperFileMessageFilter::OnPepperRenameFile( - const FilePath& path_from, - const FilePath& path_to, +void PepperFileMessageFilter::OnRenameFile( + const webkit::ppapi::PepperFilePath& from_path, + const webkit::ppapi::PepperFilePath& to_path, base::PlatformFileError* error) { - FilePath full_path_from = MakePepperPath(path_from); - FilePath full_path_to = MakePepperPath(path_to); - if (full_path_from.empty() || full_path_to.empty()) { + FilePath from_full_path = ConvertPepperFilePath(from_path); + FilePath to_full_path = ConvertPepperFilePath(to_path); + if (from_full_path.empty() || to_full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; } - bool result = file_util::Move(full_path_from, full_path_to); + bool result = file_util::Move(from_full_path, to_full_path); *error = result ? base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperDeleteFileOrDir( - const FilePath& path, +void PepperFileMessageFilter::OnDeleteFileOrDir( + const webkit::ppapi::PepperFilePath& path, bool recursive, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -132,10 +155,10 @@ void PepperFileMessageFilter::OnPepperDeleteFileOrDir( : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperCreateDir( - const FilePath& path, +void PepperFileMessageFilter::OnCreateDir( + const webkit::ppapi::PepperFilePath& path, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -146,11 +169,11 @@ void PepperFileMessageFilter::OnPepperCreateDir( : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperQueryFile( - const FilePath& path, +void PepperFileMessageFilter::OnQueryFile( + const webkit::ppapi::PepperFilePath& path, base::PlatformFileInfo* info, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -161,11 +184,11 @@ void PepperFileMessageFilter::OnPepperQueryFile( : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperGetDirContents( - const FilePath& path, +void PepperFileMessageFilter::OnGetDirContents( + const webkit::ppapi::PepperFilePath& path, webkit::ppapi::DirContents* contents, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -192,10 +215,3 @@ void PepperFileMessageFilter::OnPepperGetDirContents( *error = base::PLATFORM_FILE_OK; } - -FilePath PepperFileMessageFilter::MakePepperPath(const FilePath& base_path) { - if (base_path.IsAbsolute() || base_path.ReferencesParent()) { - return FilePath(); - } - return pepper_path_.Append(base_path); -} diff --git a/content/browser/renderer_host/pepper_file_message_filter.h b/content/browser/renderer_host/pepper_file_message_filter.h index a06d9a4..24bb1f1 100644 --- a/content/browser/renderer_host/pepper_file_message_filter.h +++ b/content/browser/renderer_host/pepper_file_message_filter.h @@ -20,6 +20,12 @@ class Profile; +namespace webkit { +namespace ppapi { +class PepperFilePath; +} +} + // A message filter for Pepper-specific File I/O messages. class PepperFileMessageFilter : public BrowserMessageFilter { public: @@ -38,26 +44,24 @@ class PepperFileMessageFilter : public BrowserMessageFilter { virtual ~PepperFileMessageFilter(); // Called on the FILE thread: - void OnPepperOpenFile(const FilePath& path, - int flags, - base::PlatformFileError* error, - IPC::PlatformFileForTransit* file); - void OnPepperRenameFile(const FilePath& path_from, - const FilePath& path_to, - base::PlatformFileError* error); - void OnPepperDeleteFileOrDir(const FilePath& path, - bool recursive, - base::PlatformFileError* error); - void OnPepperCreateDir(const FilePath& path, - base::PlatformFileError* error); - void OnPepperQueryFile(const FilePath& path, - base::PlatformFileInfo* info, + void OnOpenFile(const webkit::ppapi::PepperFilePath& path, + int flags, + base::PlatformFileError* error, + IPC::PlatformFileForTransit* file); + void OnRenameFile(const webkit::ppapi::PepperFilePath& from_path, + const webkit::ppapi::PepperFilePath& to_path, + base::PlatformFileError* error); + void OnDeleteFileOrDir(const webkit::ppapi::PepperFilePath& path, + bool recursive, base::PlatformFileError* error); - void OnPepperGetDirContents(const FilePath& path, - webkit::ppapi::DirContents* contents, - base::PlatformFileError* error); - - FilePath MakePepperPath(const FilePath& base_path); + void OnCreateDir(const webkit::ppapi::PepperFilePath& path, + base::PlatformFileError* error); + void OnQueryFile(const webkit::ppapi::PepperFilePath& path, + base::PlatformFileInfo* info, + base::PlatformFileError* error); + void OnGetDirContents(const webkit::ppapi::PepperFilePath& path, + webkit::ppapi::DirContents* contents, + base::PlatformFileError* error); // The channel associated with the renderer connection. This pointer is not // owned by this class. diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 2edea03..45ca5db 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -263,6 +263,8 @@ '../plugins/ppapi/event_conversion.h', '../plugins/ppapi/file_callbacks.cc', '../plugins/ppapi/file_callbacks.h', + '../plugins/ppapi/file_path.cc', + '../plugins/ppapi/file_path.h', '../plugins/ppapi/fullscreen_container.h', '../plugins/ppapi/npapi_glue.cc', '../plugins/ppapi/npapi_glue.h', diff --git a/webkit/plugins/ppapi/file_path.cc b/webkit/plugins/ppapi/file_path.cc new file mode 100644 index 0000000..a7ed447 --- /dev/null +++ b/webkit/plugins/ppapi/file_path.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2011 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/plugins/ppapi/file_path.h" + +#include <string> + +#include "webkit/plugins/ppapi/plugin_module.h" + +#if defined(OS_WIN) +#include "base/utf_string_conversions.h" +#endif + +namespace webkit { +namespace ppapi { + +namespace { + +FilePath GetFilePathFromUTF8(const std::string& utf8_path) { +#if defined(OS_WIN) + return FilePath(UTF8ToUTF16(utf8_path)); +#else + return FilePath(utf8_path); +#endif +} + +} // namespace + +PepperFilePath::PepperFilePath() + : domain_(DOMAIN_INVALID), + path_() { +} + +PepperFilePath::PepperFilePath(Domain domain, FilePath path) + : domain_(domain), + path_(path) { + // TODO(viettrungluu): Should we DCHECK() some things here? +} + +// static +PepperFilePath PepperFilePath::MakeAbsolute(const char* utf8_path) { + return PepperFilePath(DOMAIN_ABSOLUTE, GetFilePathFromUTF8(utf8_path)); +} + +// static +PepperFilePath PepperFilePath::MakeModuleLocal(PluginModule* module, + const char* utf8_path) { + FilePath full_path = GetFilePathFromUTF8(module->name()).Append( + GetFilePathFromUTF8(utf8_path)); + return PepperFilePath(DOMAIN_MODULE_LOCAL, full_path); +} + +} // namespace ppapi +} // namespace webkit diff --git a/webkit/plugins/ppapi/file_path.h b/webkit/plugins/ppapi/file_path.h new file mode 100644 index 0000000..6d6f4dc --- /dev/null +++ b/webkit/plugins/ppapi/file_path.h @@ -0,0 +1,50 @@ +// Copyright (c) 2011 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 WEBKIT_PLUGINS_PPAPI_FILE_PATH_H_ +#define WEBKIT_PLUGINS_PPAPI_FILE_PATH_H_ + +#include <string> + +#include "base/file_path.h" + +namespace webkit { +namespace ppapi { + +class PluginModule; + +// TODO(vtl): Once we put |::FilePath| into the |base| namespace, get rid of the +// |Pepper| (or |PEPPER_|) prefixes. Right now, it's just too +// confusing/dangerous! + +class PepperFilePath { + public: + enum Domain { + DOMAIN_INVALID = 0, + DOMAIN_ABSOLUTE, + DOMAIN_MODULE_LOCAL, + + // Used for validity-checking. + DOMAIN_MAX_VALID = DOMAIN_MODULE_LOCAL + }; + + PepperFilePath(); + PepperFilePath(Domain d, FilePath p); + + static PepperFilePath MakeAbsolute(const char* utf8_path); + static PepperFilePath MakeModuleLocal(PluginModule* module, + const char* utf8_path); + + Domain domain() const { return domain_; } + const FilePath& path() const { return path_; } + + private: + Domain domain_; + FilePath path_; +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_FILE_PATH_H_ diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 54e55ee..6f55e9b 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -113,44 +113,38 @@ bool MockPluginDelegate::ReadDirectory( return false; } -base::PlatformFileError MockPluginDelegate::OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::OpenFile( + const PepperFilePath& path, int flags, base::PlatformFile* file) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to) { +base::PlatformFileError MockPluginDelegate::RenameFile( + const PepperFilePath& from_path, + const PepperFilePath& to_path) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::DeleteFileOrDir( + const PepperFilePath& path, bool recursive) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path) { +base::PlatformFileError MockPluginDelegate::CreateDir( + const PepperFilePath& path) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::QueryFile( + const PepperFilePath& path, base::PlatformFileInfo* info) { return base::PLATFORM_FILE_ERROR_FAILED; } -base::PlatformFileError MockPluginDelegate::GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, +base::PlatformFileError MockPluginDelegate::GetDirContents( + const PepperFilePath& path, DirContents* contents) { return base::PLATFORM_FILE_ERROR_FAILED; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 75d4637..6efa63f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -57,30 +57,18 @@ class MockPluginDelegate : public PluginDelegate { virtual bool ReadDirectory( const FilePath& directory_path, fileapi::FileSystemCallbackDispatcher* dispatcher); - virtual base::PlatformFileError OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, - int flags, - base::PlatformFile* file); - virtual base::PlatformFileError RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to); - virtual base::PlatformFileError DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, - bool recursive); - virtual base::PlatformFileError CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path); - virtual base::PlatformFileError QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, - base::PlatformFileInfo* info); - virtual base::PlatformFileError GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, - DirContents* contents); + virtual base::PlatformFileError OpenFile(const PepperFilePath& path, + int flags, + base::PlatformFile* file); + virtual base::PlatformFileError RenameFile(const PepperFilePath& from_path, + const PepperFilePath& to_path); + virtual base::PlatformFileError DeleteFileOrDir(const PepperFilePath& path, + bool recursive); + virtual base::PlatformFileError CreateDir(const PepperFilePath& path); + virtual base::PlatformFileError QueryFile(const PepperFilePath& path, + base::PlatformFileInfo* info); + virtual base::PlatformFileError GetDirContents(const PepperFilePath& path, + DirContents* contents); virtual scoped_refptr<base::MessageLoopProxy> GetFileThreadMessageLoopProxy(); virtual int32_t ConnectTcp( diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 32bc025..72d5c9b 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -63,6 +63,7 @@ namespace ppapi { class FileIO; class FullscreenContainer; +class PepperFilePath; class PluginInstance; class PluginModule; class PPB_Flash_Menu_Impl; @@ -242,6 +243,7 @@ class PluginDelegate { virtual bool AsyncOpenFile(const FilePath& path, int flags, AsyncOpenFileCallback* callback) = 0; + virtual bool OpenFileSystem( const GURL& url, fileapi::FileSystemType type, @@ -266,30 +268,18 @@ class PluginDelegate { const FilePath& directory_path, fileapi::FileSystemCallbackDispatcher* dispatcher) = 0; - virtual base::PlatformFileError OpenModuleLocalFile( - const std::string& module_name, - const FilePath& path, - int flags, - base::PlatformFile* file) = 0; - virtual base::PlatformFileError RenameModuleLocalFile( - const std::string& module_name, - const FilePath& path_from, - const FilePath& path_to) = 0; - virtual base::PlatformFileError DeleteModuleLocalFileOrDir( - const std::string& module_name, - const FilePath& path, - bool recursive) = 0; - virtual base::PlatformFileError CreateModuleLocalDir( - const std::string& module_name, - const FilePath& path) = 0; - virtual base::PlatformFileError QueryModuleLocalFile( - const std::string& module_name, - const FilePath& path, - base::PlatformFileInfo* info) = 0; - virtual base::PlatformFileError GetModuleLocalDirContents( - const std::string& module_name, - const FilePath& path, - DirContents* contents) = 0; + virtual base::PlatformFileError OpenFile(const PepperFilePath& path, + int flags, + base::PlatformFile* file) = 0; + virtual base::PlatformFileError RenameFile(const PepperFilePath& from_path, + const PepperFilePath& to_path) = 0; + virtual base::PlatformFileError DeleteFileOrDir(const PepperFilePath& path, + bool recursive) = 0; + virtual base::PlatformFileError CreateDir(const PepperFilePath& path) = 0; + virtual base::PlatformFileError QueryFile(const PepperFilePath& path, + base::PlatformFileInfo* info) = 0; + virtual base::PlatformFileError GetDirContents(const PepperFilePath& path, + DirContents* contents) = 0; // Returns a MessageLoopProxy instance associated with the message loop // of the file thread in this renderer. diff --git a/webkit/plugins/ppapi/ppb_flash_file_impl.cc b/webkit/plugins/ppapi/ppb_flash_file_impl.cc index c71a8d1..bbd7f97 100644 --- a/webkit/plugins/ppapi/ppb_flash_file_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_file_impl.cc @@ -8,119 +8,150 @@ #include <string> -#include "base/file_path.h" -#include "base/utf_string_conversions.h" #include "ppapi/c/dev/pp_file_info_dev.h" #include "ppapi/c/dev/ppb_file_io_dev.h" #include "ppapi/c/private/ppb_flash_file.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/error_util.h" +#include "webkit/plugins/ppapi/file_path.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" +#if defined(OS_WIN) +#include "base/utf_string_conversions.h" +#endif + namespace webkit { namespace ppapi { namespace { -FilePath GetFilePathFromUTF8(const char* path) { -#if defined(OS_WIN) - return FilePath(UTF8ToUTF16(path)); -#else - return FilePath(path); -#endif -} - -int32_t OpenModuleLocalFile(PP_Instance pp_instance, - const char* path, - int32_t mode, - PP_FileHandle* file) { - PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); - if (!instance) - return PP_ERROR_FAILED; - +// TODO(viettrungluu): The code below is duplicated in ppb_file_io_impl.cc +// (where it's incorrect to boot). +// Returns |true| if okay. +bool ConvertFromPPFileOpenFlags(int32_t pp_open_flags, int* flags_out) { int flags = 0; - if (mode & PP_FILEOPENFLAG_READ) + if (pp_open_flags & PP_FILEOPENFLAG_READ) flags |= base::PLATFORM_FILE_READ; - if (mode & PP_FILEOPENFLAG_WRITE) { + if (pp_open_flags & PP_FILEOPENFLAG_WRITE) { flags |= base::PLATFORM_FILE_WRITE; flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; } - if (mode & PP_FILEOPENFLAG_TRUNCATE) { - DCHECK(mode & PP_FILEOPENFLAG_WRITE); + if (pp_open_flags & PP_FILEOPENFLAG_TRUNCATE) { + if (!(pp_open_flags & PP_FILEOPENFLAG_WRITE)) + return false; flags |= base::PLATFORM_FILE_TRUNCATE; } - - if (mode & PP_FILEOPENFLAG_CREATE) { - if (mode & PP_FILEOPENFLAG_EXCLUSIVE) + if (pp_open_flags & PP_FILEOPENFLAG_CREATE) { + if (pp_open_flags & PP_FILEOPENFLAG_EXCLUSIVE) flags |= base::PLATFORM_FILE_CREATE; else flags |= base::PLATFORM_FILE_OPEN_ALWAYS; } else { flags |= base::PLATFORM_FILE_OPEN; } + *flags_out = flags; + return true; +} + +void FreeDirContents(PP_Instance instance, PP_DirContents_Dev* contents) { + DCHECK(contents); + for (int32_t i = 0; i < contents->count; ++i) { + delete [] contents->entries[i].name; + } + delete [] contents->entries; + delete contents; +} + +} // namespace + +// PPB_Flash_File_ModuleLocal_Impl --------------------------------------------- + +namespace { + +int32_t OpenModuleLocalFile(PP_Instance pp_instance, + const char* path, + int32_t mode, + PP_FileHandle* file) { + int flags = 0; + if (!path || !ConvertFromPPFileOpenFlags(mode, &flags) || !file) + return PP_ERROR_BADARGUMENT; + + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); + if (!instance) + return PP_ERROR_FAILED; base::PlatformFile base_file; - base::PlatformFileError result = instance->delegate()->OpenModuleLocalFile( - instance->module()->name(), - GetFilePathFromUTF8(path), + base::PlatformFileError result = instance->delegate()->OpenFile( + PepperFilePath::MakeModuleLocal(instance->module(), path), flags, &base_file); *file = base_file; return PlatformFileErrorToPepperError(result); } - int32_t RenameModuleLocalFile(PP_Instance pp_instance, - const char* path_from, - const char* path_to) { + const char* from_path, + const char* to_path) { + if (!from_path || !to_path) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; - base::PlatformFileError result = instance->delegate()->RenameModuleLocalFile( - instance->module()->name(), - GetFilePathFromUTF8(path_from), - GetFilePathFromUTF8(path_to)); + base::PlatformFileError result = instance->delegate()->RenameFile( + PepperFilePath::MakeModuleLocal(instance->module(), from_path), + PepperFilePath::MakeModuleLocal(instance->module(), to_path)); return PlatformFileErrorToPepperError(result); } int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance, const char* path, PP_Bool recursive) { + if (!path) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; - base::PlatformFileError result = - instance->delegate()->DeleteModuleLocalFileOrDir( - instance->module()->name(), GetFilePathFromUTF8(path), - PPBoolToBool(recursive)); + base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( + PepperFilePath::MakeModuleLocal(instance->module(), path), + PPBoolToBool(recursive)); return PlatformFileErrorToPepperError(result); } int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) { + if (!path) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; - base::PlatformFileError result = instance->delegate()->CreateModuleLocalDir( - instance->module()->name(), GetFilePathFromUTF8(path)); + base::PlatformFileError result = instance->delegate()->CreateDir( + PepperFilePath::MakeModuleLocal(instance->module(), path)); return PlatformFileErrorToPepperError(result); } int32_t QueryModuleLocalFile(PP_Instance pp_instance, const char* path, PP_FileInfo_Dev* info) { + if (!path || !info) + return PP_ERROR_BADARGUMENT; + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; base::PlatformFileInfo file_info; - base::PlatformFileError result = instance->delegate()->QueryModuleLocalFile( - instance->module()->name(), GetFilePathFromUTF8(path), &file_info); + base::PlatformFileError result = instance->delegate()->QueryFile( + PepperFilePath::MakeModuleLocal(instance->module(), path), + &file_info); if (result == base::PLATFORM_FILE_OK) { info->size = file_info.size; info->creation_time = file_info.creation_time.ToDoubleT(); @@ -138,17 +169,17 @@ int32_t QueryModuleLocalFile(PP_Instance pp_instance, int32_t GetModuleLocalDirContents(PP_Instance pp_instance, const char* path, PP_DirContents_Dev** contents) { + if (!path || !contents) + return PP_ERROR_BADARGUMENT; PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); if (!instance) return PP_ERROR_FAILED; *contents = NULL; DirContents pepper_contents; - base::PlatformFileError result = - instance->delegate()->GetModuleLocalDirContents( - instance->module()->name(), - GetFilePathFromUTF8(path), - &pepper_contents); + base::PlatformFileError result = instance->delegate()->GetDirContents( + PepperFilePath::MakeModuleLocal(instance->module(), path), + &pepper_contents); if (result != base::PLATFORM_FILE_OK) return PlatformFileErrorToPepperError(result); @@ -173,24 +204,14 @@ int32_t GetModuleLocalDirContents(PP_Instance pp_instance, return PP_OK; } -void FreeModuleLocalDirContents(PP_Instance instance, - PP_DirContents_Dev* contents) { - DCHECK(contents); - for (int32_t i = 0; i < contents->count; ++i) { - delete [] contents->entries[i].name; - } - delete [] contents->entries; - delete contents; -} - -const PPB_Flash_File_ModuleLocal ppb_flash_file_module_local = { +const PPB_Flash_File_ModuleLocal ppb_flash_file_modulelocal = { &OpenModuleLocalFile, &RenameModuleLocalFile, &DeleteModuleLocalFileOrDir, &CreateModuleLocalDir, &QueryModuleLocalFile, &GetModuleLocalDirContents, - &FreeModuleLocalDirContents, + &FreeDirContents, }; } // namespace @@ -198,7 +219,7 @@ const PPB_Flash_File_ModuleLocal ppb_flash_file_module_local = { // static const PPB_Flash_File_ModuleLocal* PPB_Flash_File_ModuleLocal_Impl::GetInterface() { - return &ppb_flash_file_module_local; + return &ppb_flash_file_modulelocal; } } // namespace ppapi |