diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-05 23:36:16 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-05 23:36:16 +0000 |
commit | 76bf34a3260833d1cd522a9a7ccc4114baa4b72b (patch) | |
tree | dbd0196dca13c32c6ccdc289dbea541285baedf3 /ppapi/proxy | |
parent | 32e6ccc621eeacc29df1c4c3fc88fa496351ff84 (diff) | |
download | chromium_src-76bf34a3260833d1cd522a9a7ccc4114baa4b72b.zip chromium_src-76bf34a3260833d1cd522a9a7ccc4114baa4b72b.tar.gz chromium_src-76bf34a3260833d1cd522a9a7ccc4114baa4b72b.tar.bz2 |
Revert 221284 "Pepper: Move FileRef to the "new" resource proxy."
> Pepper: Move FileRef to the "new" resource proxy.
>
> This change moves the FileRef implementation from the previous one in the "old"
> resource model (ppb_file_ref_impl.cc) to the "new" resource model
> (pepper_file_ref_host.cc), and from the renderer to the browser.
>
> As many as possible of the supporting changes were split off to other changes
> to minimize the size of this change. Unfortunately, a lot of changes for
> URLLoader had to be rolled into this change.
>
> The data structures for CreateInfo have changed, and all users of FileRef have
> to be moved over, which is what causes this change to be so large.
>
> TBR=dmichael@chromium.org, jschuh@chromium.org, yzshen@chromium.org
> BUG=225441
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=216744
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=218305
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=219911
>
> Review URL: https://codereview.chromium.org/21966004
TBR=teravest@chromium.org
Review URL: https://codereview.chromium.org/23647008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221544 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/file_chooser_resource.cc | 16 | ||||
-rw-r--r-- | ppapi/proxy/file_chooser_resource.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/file_chooser_resource_unittest.cc | 19 | ||||
-rw-r--r-- | ppapi/proxy/file_io_resource.cc | 9 | ||||
-rw-r--r-- | ppapi/proxy/file_io_resource.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/file_ref_resource.cc | 51 | ||||
-rw-r--r-- | ppapi/proxy/file_ref_resource.h | 16 | ||||
-rw-r--r-- | ppapi/proxy/flash_drm_resource.cc | 13 | ||||
-rw-r--r-- | ppapi/proxy/flash_drm_resource.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/flash_file_resource.cc | 1 | ||||
-rw-r--r-- | ppapi/proxy/interface_list.cc | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 102 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_param_traits.cc | 52 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_param_traits.h | 19 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_ref_proxy.cc | 549 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_ref_proxy.h | 138 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 13 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.h | 6 | ||||
-rw-r--r-- | ppapi/proxy/url_loader_resource.cc | 28 | ||||
-rw-r--r-- | ppapi/proxy/url_response_info_resource.cc | 2 |
20 files changed, 947 insertions, 100 deletions
diff --git a/ppapi/proxy/file_chooser_resource.cc b/ppapi/proxy/file_chooser_resource.cc index 9847e29..ebd545c 100644 --- a/ppapi/proxy/file_chooser_resource.cc +++ b/ppapi/proxy/file_chooser_resource.cc @@ -9,8 +9,8 @@ #include "ipc/ipc_message.h" #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/dispatch_reply_message.h" -#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/shared_impl/var.h" namespace ppapi { @@ -100,25 +100,19 @@ void FileChooserResource::PopulateAcceptTypes( void FileChooserResource::OnPluginMsgShowReply( const ResourceMessageReplyParams& params, - const std::vector<FileRefCreateInfo>& chosen_files) { + const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { if (output_.is_valid()) { // Using v0.6 of the API with the output array. std::vector<PP_Resource> files; - for (size_t i = 0; i < chosen_files.size(); i++) { - files.push_back(FileRefResource::CreateFileRef( - connection(), - pp_instance(), - chosen_files[i])); - } + for (size_t i = 0; i < chosen_files.size(); i++) + files.push_back(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); output_.StoreResourceVector(files); } else { // Convert each of the passed in file infos to resources. These will be // owned by the FileChooser object until they're passed to the plugin. DCHECK(file_queue_.empty()); for (size_t i = 0; i < chosen_files.size(); i++) { - file_queue_.push(FileRefResource::CreateFileRef( - connection(), - pp_instance(), + file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef( chosen_files[i])); } } diff --git a/ppapi/proxy/file_chooser_resource.h b/ppapi/proxy/file_chooser_resource.h index b744e91..58331db 100644 --- a/ppapi/proxy/file_chooser_resource.h +++ b/ppapi/proxy/file_chooser_resource.h @@ -17,7 +17,7 @@ namespace ppapi { -struct FileRefCreateInfo; +struct PPB_FileRef_CreateInfo; namespace proxy { @@ -56,7 +56,7 @@ class PPAPI_PROXY_EXPORT FileChooserResource private: void OnPluginMsgShowReply( const ResourceMessageReplyParams& params, - const std::vector<FileRefCreateInfo>& chosen_files); + const std::vector<PPB_FileRef_CreateInfo>& chosen_files); int32_t ShowInternal(PP_Bool save_as, const PP_Var& suggested_file_name, diff --git a/ppapi/proxy/file_chooser_resource_unittest.cc b/ppapi/proxy/file_chooser_resource_unittest.cc index 4ba5bd9..a5801ee 100644 --- a/ppapi/proxy/file_chooser_resource_unittest.cc +++ b/ppapi/proxy/file_chooser_resource_unittest.cc @@ -5,7 +5,6 @@ #include "base/message_loop/message_loop.h" #include "ppapi/c/dev/ppb_file_chooser_dev.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/c/ppb_file_ref.h" #include "ppapi/proxy/file_chooser_resource.h" #include "ppapi/proxy/locking_resource_releaser.h" #include "ppapi/proxy/ppapi_messages.h" @@ -92,14 +91,13 @@ TEST_F(FileChooserResourceTest, Show) { reply_params.set_result(PP_OK); // Synthesize a response with one file ref in it. Note that it must have a - // pending_host_resource_id set. Since there isn't actually a host, this can - // be whatever we want. - std::vector<FileRefCreateInfo> create_info_array; - FileRefCreateInfo create_info; - create_info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL; - create_info.display_name = "bar"; - create_info.browser_pending_host_resource_id = 12; - create_info.renderer_pending_host_resource_id = 15; + // host resource value set or deserialization will fail. Since there isn't + // actually a host, this can be whatever we want. + std::vector<PPB_FileRef_CreateInfo> create_info_array; + PPB_FileRef_CreateInfo create_info; + create_info.resource.SetHostResource(pp_instance(), 123); + create_info.path = "foo/bar"; + create_info.name = "baz"; create_info_array.push_back(create_info); ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived( PpapiPluginMsg_ResourceReply(reply_params, @@ -117,8 +115,9 @@ TEST_F(FileChooserResourceTest, Show) { { ProxyAutoLock lock; ScopedPPVar release_name_var(ScopedPPVar::PassRef(), name_var); - EXPECT_VAR_IS_STRING("bar", name_var); + EXPECT_VAR_IS_STRING(create_info.name, name_var); } + // Path should be undefined since it's external filesystem. PP_Var path_var(file_ref_iface->GetPath(dest[0])); { ProxyAutoLock lock; diff --git a/ppapi/proxy/file_io_resource.cc b/ppapi/proxy/file_io_resource.cc index fc53fb0..76ee51c 100644 --- a/ppapi/proxy/file_io_resource.cc +++ b/ppapi/proxy/file_io_resource.cc @@ -111,13 +111,9 @@ int32_t FileIOResource::Open(PP_Resource file_ref, if (rv != PP_OK) return rv; - // Take a reference on the FileRef resource while we're opening the file; we - // don't want the plugin destroying it during the Open operation. - file_ref_ = enter.resource(); - Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, PpapiHostMsg_FileIO_Open( - file_ref, + enter.resource()->host_resource().host_resource(), open_flags), base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, callback)); @@ -414,9 +410,6 @@ void FileIOResource::OnPluginMsgOpenFileComplete( const ResourceMessageReplyParams& params) { DCHECK(state_manager_.get_pending_operation() == FileIOStateManager::OPERATION_EXCLUSIVE); - - // Release the FileRef resource. - file_ref_ = NULL; if (params.result() == PP_OK) state_manager_.SetOpenSucceed(); diff --git a/ppapi/proxy/file_io_resource.h b/ppapi/proxy/file_io_resource.h index 26c4abb..1a888d1 100644 --- a/ppapi/proxy/file_io_resource.h +++ b/ppapi/proxy/file_io_resource.h @@ -7,13 +7,11 @@ #include <string> -#include "base/memory/scoped_ptr.h" #include "ppapi/c/private/pp_file_handle.h" #include "ppapi/proxy/connection.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_proxy_export.h" #include "ppapi/shared_impl/file_io_state_manager.h" -#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_file_io_api.h" namespace ppapi { @@ -139,8 +137,6 @@ class PPAPI_PROXY_EXPORT FileIOResource PP_FileSystemType file_system_type_; FileIOStateManager state_manager_; - scoped_refptr<Resource> file_ref_; - DISALLOW_COPY_AND_ASSIGN(FileIOResource); }; diff --git a/ppapi/proxy/file_ref_resource.cc b/ppapi/proxy/file_ref_resource.cc index 7cd96bc..4c098a5 100644 --- a/ppapi/proxy/file_ref_resource.cc +++ b/ppapi/proxy/file_ref_resource.cc @@ -22,7 +22,7 @@ namespace proxy { FileRefResource::FileRefResource( Connection connection, PP_Instance instance, - const FileRefCreateInfo& create_info) + const FileRef_CreateInfo& create_info) : PluginResource(connection, instance), create_info_(create_info), file_system_resource_(create_info.file_system_plugin_resource) { @@ -34,26 +34,19 @@ FileRefResource::FileRefResource( create_info_.internal_path.erase(path_size - 1, 1); path_var_ = new StringVar(create_info_.internal_path); + create_info_.display_name = GetNameForInternalFilePath( create_info_.internal_path); } name_var_ = new StringVar(create_info_.display_name); - if (create_info_.browser_pending_host_resource_id != 0 && - create_info_.renderer_pending_host_resource_id != 0) { - AttachToPendingHost(BROWSER, create_info_.browser_pending_host_resource_id); - AttachToPendingHost(RENDERER, - create_info_.renderer_pending_host_resource_id); + if (create_info_.pending_host_resource_id != 0) { + AttachToPendingHost(BROWSER, create_info_.pending_host_resource_id); } else { - CHECK(create_info_.browser_pending_host_resource_id == 0); - CHECK(create_info_.renderer_pending_host_resource_id == 0); CHECK(create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL); SendCreate(BROWSER, PpapiHostMsg_FileRef_CreateInternal( create_info.file_system_plugin_resource, create_info.internal_path)); - SendCreate(RENDERER, PpapiHostMsg_FileRef_CreateInternal( - create_info.file_system_plugin_resource, - create_info.internal_path)); } } @@ -64,7 +57,7 @@ FileRefResource::~FileRefResource() { PP_Resource FileRefResource::CreateFileRef( Connection connection, PP_Instance instance, - const FileRefCreateInfo& create_info) { + const FileRef_CreateInfo& create_info) { // If we have a valid file_system resource, ensure that its type matches that // of the fs_type parameter. if (create_info.file_system_plugin_resource != 0) { @@ -89,7 +82,9 @@ PP_Resource FileRefResource::CreateFileRef( } thunk::PPB_FileRef_API* FileRefResource::AsPPB_FileRef_API() { - return this; + // TODO: return "this" once we update PPB_FileRef_API. + NOTREACHED(); + return NULL; } PP_FileSystemType FileRefResource::GetFileSystemType() const { @@ -116,7 +111,7 @@ PP_Resource FileRefResource::GetParent() { pos++; std::string parent_path = create_info_.internal_path.substr(0, pos); - ppapi::FileRefCreateInfo parent_info; + ppapi::FileRef_CreateInfo parent_info; parent_info.file_system_type = create_info_.file_system_type; parent_info.internal_path = parent_path; parent_info.display_name = GetNameForInternalFilePath(parent_path); @@ -189,9 +184,33 @@ int32_t FileRefResource::ReadDirectoryEntries( return PP_OK_COMPLETIONPENDING; } -const FileRefCreateInfo& FileRefResource::GetCreateInfo() const { +/* +const FileRef_CreateInfo& FileRefResource::GetCreateInfo() const { return create_info_; } +*/ +const PPB_FileRef_CreateInfo& FileRefResource::GetCreateInfo() const { + // FIXME + NOTREACHED(); + PPB_FileRef_CreateInfo *info = new PPB_FileRef_CreateInfo(); + return *info; +} + +// TODO(teravest): Remove this when we are finished moving to the new proxy. +int32_t FileRefResource::QueryInHost(linked_ptr<PP_FileInfo> info, + scoped_refptr<TrackedCallback> callback) { + NOTREACHED(); + return PP_ERROR_FAILED; +} + +// TODO(teravest): Remove this when we are finished moving to the new proxy. +int32_t FileRefResource::ReadDirectoryEntriesInHost( + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, + linked_ptr<std::vector<PP_FileType> > file_types, + scoped_refptr<TrackedCallback> callback) { + NOTREACHED(); + return PP_ERROR_FAILED; +} PP_Var FileRefResource::GetAbsolutePath() { if (!absolute_path_var_.get()) { @@ -229,7 +248,7 @@ void FileRefResource::OnDirectoryEntriesReply( const PP_ArrayOutput& output, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const std::vector<ppapi::FileRefCreateInfo>& infos, + const std::vector<ppapi::FileRef_CreateInfo>& infos, const std::vector<PP_FileType>& file_types) { if (!TrackedCallback::IsPending(callback)) return; diff --git a/ppapi/proxy/file_ref_resource.h b/ppapi/proxy/file_ref_resource.h index f982438..82570fb 100644 --- a/ppapi/proxy/file_ref_resource.h +++ b/ppapi/proxy/file_ref_resource.h @@ -29,7 +29,7 @@ class PPAPI_PROXY_EXPORT FileRefResource public: static PP_Resource CreateFileRef(Connection connection, PP_Instance instance, - const FileRefCreateInfo& info); + const FileRef_CreateInfo& info); virtual ~FileRefResource(); @@ -55,7 +55,13 @@ class PPAPI_PROXY_EXPORT FileRefResource virtual int32_t ReadDirectoryEntries( const PP_ArrayOutput& output, scoped_refptr<TrackedCallback> callback) OVERRIDE; - virtual const FileRefCreateInfo& GetCreateInfo() const OVERRIDE; + virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const OVERRIDE; + virtual int32_t QueryInHost(linked_ptr<PP_FileInfo> info, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t ReadDirectoryEntriesInHost( + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, + linked_ptr<std::vector<PP_FileType> > file_types, + scoped_refptr<TrackedCallback> callback) OVERRIDE; // Private API virtual PP_Var GetAbsolutePath() OVERRIDE; @@ -63,7 +69,7 @@ class PPAPI_PROXY_EXPORT FileRefResource private: FileRefResource(Connection connection, PP_Instance instance, - const FileRefCreateInfo& info); + const FileRef_CreateInfo& info); void RunTrackedCallback(scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params); @@ -77,11 +83,11 @@ class PPAPI_PROXY_EXPORT FileRefResource const PP_ArrayOutput& output, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const std::vector<ppapi::FileRefCreateInfo>& infos, + const std::vector<ppapi::FileRef_CreateInfo>& infos, const std::vector<PP_FileType>& file_types); // Populated after creation. - FileRefCreateInfo create_info_; + FileRef_CreateInfo create_info_; // Some file ref operations may fail if the the file system resource inside // create_info_ is destroyed. Therefore, we explicitly hold a reference to diff --git a/ppapi/proxy/flash_drm_resource.cc b/ppapi/proxy/flash_drm_resource.cc index 889aa72..a4be23b 100644 --- a/ppapi/proxy/flash_drm_resource.cc +++ b/ppapi/proxy/flash_drm_resource.cc @@ -7,8 +7,9 @@ #include "base/bind.h" #include "ppapi/c/pp_errors.h" #include "ppapi/proxy/dispatch_reply_message.h" -#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" +#include "ppapi/shared_impl/ppb_file_ref_shared.h" #include "ppapi/shared_impl/var.h" namespace ppapi { @@ -87,14 +88,10 @@ void FlashDRMResource::OnPluginMsgGetVoucherFileReply( PP_Resource* dest, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const FileRefCreateInfo& file_info) { + const PPB_FileRef_CreateInfo& file_info) { if (TrackedCallback::IsPending(callback)) { - if (params.result() == PP_OK) { - *dest = FileRefResource::CreateFileRef( - connection(), - pp_instance(), - file_info); - } + if (params.result() == PP_OK) + *dest = PPB_FileRef_Proxy::DeserializeFileRef(file_info); callback->Run(params.result()); } } diff --git a/ppapi/proxy/flash_drm_resource.h b/ppapi/proxy/flash_drm_resource.h index 9a4b31c..12c71e8 100644 --- a/ppapi/proxy/flash_drm_resource.h +++ b/ppapi/proxy/flash_drm_resource.h @@ -11,7 +11,7 @@ #include "ppapi/thunk/ppb_flash_drm_api.h" namespace ppapi { -struct FileRefCreateInfo; +struct PPB_FileRef_CreateInfo; } namespace ppapi { @@ -44,7 +44,7 @@ class FlashDRMResource void OnPluginMsgGetVoucherFileReply(PP_Resource* dest, scoped_refptr<TrackedCallback> callback, const ResourceMessageReplyParams& params, - const FileRefCreateInfo& file_info); + const PPB_FileRef_CreateInfo& file_info); DISALLOW_COPY_AND_ASSIGN(FlashDRMResource); }; diff --git a/ppapi/proxy/flash_file_resource.cc b/ppapi/proxy/flash_file_resource.cc index ce7a2ce..1387eb7 100644 --- a/ppapi/proxy/flash_file_resource.cc +++ b/ppapi/proxy/flash_file_resource.cc @@ -13,7 +13,6 @@ #include "ppapi/shared_impl/time_conversion.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" -#include "ppapi/thunk/ppb_file_ref_api.h" namespace ppapi { namespace proxy { diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index a72f472..115516f 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -101,6 +101,7 @@ #include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_core_proxy.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 2793e5f..f108812 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -202,12 +202,11 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::DirEntry) IPC_STRUCT_TRAITS_MEMBER(is_dir) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(ppapi::FileRefCreateInfo) +IPC_STRUCT_TRAITS_BEGIN(ppapi::FileRef_CreateInfo) IPC_STRUCT_TRAITS_MEMBER(file_system_type) IPC_STRUCT_TRAITS_MEMBER(internal_path) IPC_STRUCT_TRAITS_MEMBER(display_name) - IPC_STRUCT_TRAITS_MEMBER(browser_pending_host_resource_id) - IPC_STRUCT_TRAITS_MEMBER(renderer_pending_host_resource_id) + IPC_STRUCT_TRAITS_MEMBER(pending_host_resource_id) IPC_STRUCT_TRAITS_MEMBER(file_system_plugin_resource) IPC_STRUCT_TRAITS_END() @@ -299,7 +298,8 @@ IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(ppapi::URLRequestInfoData::BodyItem) IPC_STRUCT_TRAITS_MEMBER(is_file) IPC_STRUCT_TRAITS_MEMBER(data) - IPC_STRUCT_TRAITS_MEMBER(file_ref_pp_resource) + // Note: we don't serialize file_ref. + IPC_STRUCT_TRAITS_MEMBER(file_ref_host_resource) IPC_STRUCT_TRAITS_MEMBER(start_offset) IPC_STRUCT_TRAITS_MEMBER(number_of_bytes) IPC_STRUCT_TRAITS_MEMBER(expected_last_modified_time) @@ -486,6 +486,30 @@ IPC_MESSAGE_ROUTED4(PpapiMsg_PPBAudio_NotifyAudioStreamCreated, ppapi::proxy::SerializedHandle /* socket_handle */, ppapi::proxy::SerializedHandle /* handle */) +// PPB_FileRef. +// TODO(teravest): Remove these messages when we've switched over to the "new" +// proxy. +IPC_MESSAGE_ROUTED3( + PpapiMsg_PPBFileRef_CallbackComplete, + ppapi::HostResource /* resource */, + uint32_t /* callback_id */, + int32_t /* result */) + +IPC_MESSAGE_ROUTED4( + PpapiMsg_PPBFileRef_QueryCallbackComplete, + ppapi::HostResource /* resource */, + PP_FileInfo /* file_info */, + uint32_t /* callback_id */, + int32_t /* result */) + +IPC_MESSAGE_ROUTED5( + PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete, + ppapi::HostResource /* resource */, + std::vector<ppapi::PPB_FileRef_CreateInfo> /* files */, + std::vector<PP_FileType> /* file_types */, + uint32_t /* callback_id */, + int32_t /* result */) + // PPB_FileSystem. IPC_MESSAGE_ROUTED2( PpapiMsg_PPBFileSystem_OpenComplete, @@ -748,6 +772,43 @@ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_AddRefResource, IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_ReleaseResource, ppapi::HostResource) +// PPB_FileRef. +// TODO(teravest): Remove these messages when we've switched over to the "new" +// proxy. +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFileRef_Create, + PP_Instance /* instance */, + PP_Resource /* file_system */, + std::string /* path */, + ppapi::PPB_FileRef_CreateInfo /* result */) +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileRef_GetParent, + ppapi::HostResource /* file_ref */, + ppapi::PPB_FileRef_CreateInfo /* result */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileRef_MakeDirectory, + ppapi::HostResource /* file_ref */, + PP_Bool /* make_ancestors */, + uint32_t /* callback_id */) +IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFileRef_Touch, + ppapi::HostResource /* file_ref */, + PP_Time /* last_access */, + PP_Time /* last_modified */, + uint32_t /* callback_id */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileRef_Delete, + ppapi::HostResource /* file_ref */, + uint32_t /* callback_id */) +IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileRef_Rename, + ppapi::HostResource /* file_ref */, + ppapi::HostResource /* new_file_ref */, + uint32_t /* callback_id */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileRef_Query, + ppapi::HostResource /* file_ref */, + uint32_t /* callback_id */) +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileRef_GetAbsolutePath, + ppapi::HostResource /* file_ref */, + ppapi::proxy::SerializedVar /* result */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFileRef_ReadDirectoryEntries, + ppapi::HostResource /* file_ref */, + uint32_t /* callback_id */) + // PPB_Graphics3D. IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics3D_Create, PP_Instance /* instance */, @@ -1141,6 +1202,7 @@ IPC_MESSAGE_ROUTED2( ppapi::proxy::ResourceMessageReplyParams /* reply_params */, IPC::Message /* nested_msg */) + IPC_SYNC_MESSAGE_CONTROL2_2(PpapiHostMsg_ResourceSyncCall, ppapi::proxy::ResourceMessageCallParams /* call_params */, IPC::Message /* nested_msg */, @@ -1214,7 +1276,7 @@ IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileChooser_Show, std::string /* suggested_file_name */, std::vector<std::string> /* accept_mime_types */) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileChooser_ShowReply, - std::vector<ppapi::FileRefCreateInfo> /* files */) + std::vector<ppapi::PPB_FileRef_CreateInfo> /* files */) // FileIO IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileIO_Create) @@ -1290,10 +1352,10 @@ IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileRef_QueryReply, // location indicated by the FileRef. IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileRef_ReadDirectoryEntries) -// FileRefCreateInfo does not provide file type information, so two +// FileRef_CreateInfo does not provide file type information, so two // corresponding vectors are returned. IPC_MESSAGE_CONTROL2(PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply, - std::vector<ppapi::FileRefCreateInfo> /* files */, + std::vector<ppapi::FileRef_CreateInfo> /* files */, std::vector<PP_FileType> /* file_types */) // Requests that the browser reply with the absolute path to the indicated @@ -1334,7 +1396,7 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_FlashDRM_GetVoucherFile) // Reply message for GetVoucherFile which contains the CreateInfo for a // PPB_FileRef which points to the voucher file. IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FlashDRM_GetVoucherFileReply, - ppapi::FileRefCreateInfo /* file_info */) + ppapi::PPB_FileRef_CreateInfo /* file_info */) // Gamepad. IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_Create) @@ -1713,6 +1775,30 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_BrowserFontSingleton_GetFontFamilies) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply, std::string /* families */) +// FileRef. +// Requests that the browser reply with file system and path information about +// the resource indicated in |params| which exists in the given +// |child_process_id|. |routing_id| is sent so that the reply can be routed +// properly in the renderer. +// Only sent from the renderer to the browser. +IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileRef_GetInfoForRenderer, + int /* routing_id */, + int /* child_process_id */, + int32_t /* sequence */, + std::vector<PP_Resource> /* resources */) + +// Reply to PpapiHostMsg_FileRef_GetInfoForRenderer with a sequence number for +// invoking the right callback, |fs_type| which indicates the file system, and +// path information in either |file_system_url_spec| (for internal file systems) +// or |external_path| (for external file systems). +// Only sent from the browser to the renderer. +IPC_MESSAGE_ROUTED5(PpapiHostMsg_FileRef_GetInfoForRendererReply, + int32_t /* sequence */, + std::vector<PP_Resource> /* resources */, + std::vector<PP_FileSystemType> /* fs_type */, + std::vector<std::string> /* file_system_url_spec */, + std::vector<base::FilePath> /* external_path */) + // Flash ----------------------------------------------------------------------- IPC_MESSAGE_CONTROL0(PpapiHostMsg_Flash_Create) diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc index 5d4345f..ca25f82 100644 --- a/ppapi/proxy/ppapi_param_traits.cc +++ b/ppapi/proxy/ppapi_param_traits.cc @@ -175,6 +175,36 @@ void ParamTraits<PP_NetAddress_Private>::Log(const param_type& p, l->append(" bytes)>"); } +// TODO(teravest): Remove this when FileRef is moved to the "new" proxy. +// PPB_FileRef_CreateInfo ------------------------------------------------------ + +// static +void ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Write(Message* m, + const param_type& p) { + ParamTraits<ppapi::HostResource>::Write(m, p.resource); + ParamTraits<int>::Write(m, p.file_system_type); + ParamTraits<std::string>::Write(m, p.path); + ParamTraits<std::string>::Write(m, p.name); + ParamTraits<PP_Resource>::Write(m, p.file_system_plugin_resource); +} + +// static +bool ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Read(const Message* m, + PickleIterator* iter, + param_type* r) { + return + ParamTraits<ppapi::HostResource>::Read(m, iter, &r->resource) && + ParamTraits<int>::Read(m, iter, &r->file_system_type) && + ParamTraits<std::string>::Read(m, iter, &r->path) && + ParamTraits<std::string>::Read(m, iter, &r->name) && + ParamTraits<PP_Resource>::Read(m, iter, &r->file_system_plugin_resource); +} + +// static +void ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Log(const param_type& p, + std::string* l) { +} + // HostResource ---------------------------------------------------------------- // static @@ -244,6 +274,28 @@ void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log( std::string* l) { } +// std::vector<PPB_FileRef_CreateInfo> ----------------------------------------- + +void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Write( + Message* m, + const param_type& p) { + WriteVectorWithoutCopy(m, p); +} + +// static +bool ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Read( + const Message* m, + PickleIterator* iter, + param_type* r) { + return ReadVectorWithoutCopy(m, iter, r); +} + +// static +void ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Log( + const param_type& p, + std::string* l) { +} + // ppapi::PpapiPermissions ----------------------------------------------------- void ParamTraits<ppapi::PpapiPermissions>::Write(Message* m, diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h index b56ec3e..f56415a8 100644 --- a/ppapi/proxy/ppapi_param_traits.h +++ b/ppapi/proxy/ppapi_param_traits.h @@ -17,6 +17,7 @@ #include "ppapi/shared_impl/file_path.h" #include "ppapi/shared_impl/file_ref_create_info.h" #include "ppapi/shared_impl/ppapi_permissions.h" +#include "ppapi/shared_impl/ppb_file_ref_shared.h" #include "ppapi/shared_impl/socket_option_data.h" struct PP_FileInfo; @@ -76,6 +77,15 @@ struct PPAPI_PROXY_EXPORT ParamTraits< static void Log(const param_type& p, std::string* l); }; +// TODO(teravest): Remove this when we've switched over to the new proxy. +template<> +struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::PPB_FileRef_CreateInfo> { + typedef ppapi::PPB_FileRef_CreateInfo param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + template<> struct PPAPI_PROXY_EXPORT ParamTraits< ppapi::proxy::PPBURLLoader_UpdateProgress_Params> { @@ -144,6 +154,15 @@ struct PPAPI_PROXY_EXPORT ParamTraits< }; template<> +struct PPAPI_PROXY_EXPORT ParamTraits< std::vector< + ppapi::PPB_FileRef_CreateInfo> > { + typedef std::vector<ppapi::PPB_FileRef_CreateInfo> param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template<> struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::PpapiPermissions> { typedef ppapi::PpapiPermissions param_type; static void Write(Message* m, const param_type& p); diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc new file mode 100644 index 0000000..62c55da --- /dev/null +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -0,0 +1,549 @@ +// Copyright (c) 2012 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 "ppapi/proxy/ppb_file_ref_proxy.h" + +#include <map> + +#include "base/bind.h" +#include "ppapi/c/pp_directory_entry.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/ppb_file_ref.h" +#include "ppapi/c/private/ppb_file_ref_private.h" +#include "ppapi/c/private/ppb_proxy_private.h" +#include "ppapi/proxy/enter_proxy.h" +#include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/serialized_var.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/ppb_file_ref_shared.h" +#include "ppapi/shared_impl/scoped_pp_resource.h" +#include "ppapi/shared_impl/tracked_callback.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_FileRef_API; +using ppapi::thunk::ResourceCreationAPI; + +namespace ppapi { +namespace proxy { + +namespace { + +void ReleaseEntries(const std::vector<PP_DirectoryEntry>& entries) { + ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); + for (std::vector<PP_DirectoryEntry>::const_iterator it = entries.begin(); + it != entries.end(); ++it) + tracker->ReleaseResource(it->file_ref); +} + +} // namespace + +class FileRef : public PPB_FileRef_Shared { + public: + explicit FileRef(const PPB_FileRef_CreateInfo& info); + virtual ~FileRef(); + + // Resource overrides. + virtual void LastPluginRefWasDeleted() OVERRIDE; + + // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). + virtual PP_Resource GetParent() OVERRIDE; + virtual int32_t MakeDirectory( + PP_Bool make_ancestors, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Touch(PP_Time last_access_time, + PP_Time last_modified_time, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Rename(PP_Resource new_file_ref, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t Query(PP_FileInfo* info, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t ReadDirectoryEntries( + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t QueryInHost( + linked_ptr<PP_FileInfo> info, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t ReadDirectoryEntriesInHost( + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, + linked_ptr<std::vector<PP_FileType> > file_types, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual PP_Var GetAbsolutePath() OVERRIDE; + + // Executes the pending callback with the given ID. See pending_callbacks_. + void ExecuteCallback(uint32_t callback_id, int32_t result); + int32_t SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); + int32_t SetReadDirectoryEntriesOutput( + uint32_t callback_id, + const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, + const std::vector<PP_FileType>& file_types); + + private: + PluginDispatcher* GetDispatcher() const { + return PluginDispatcher::GetForResource(this); + } + + // Adds a callback to the list and returns its ID. + uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); + + // This class can have any number of out-standing requests with completion + // callbacks, in contrast to most resources which have one possible pending + // callback pending (like a Flush callback). + // + // To keep track of them, assign integer IDs to the callbacks, which is how + // the callback will be identified when it's passed to the host and then + // back here. Use unsigned so that overflow is well-defined. + uint32_t next_callback_id_; + typedef std::map<uint32_t, + scoped_refptr<TrackedCallback> > PendingCallbackMap; + PendingCallbackMap pending_callbacks_; + + // Used to keep pointers to PP_FileInfo instances that are written before + // callbacks are invoked. The id of a pending file info will match that of + // the corresponding callback. + typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; + PendingFileInfoMap pending_file_infos_; + + // Used to keep PP_ArrayOutput instances that are written before callbacks + // are invoked. The id of a pending array output will match that of the + // corresponding callback. + typedef std::map<uint32_t, PP_ArrayOutput> + PendingReadDirectoryEntriesOutputMap; + PendingReadDirectoryEntriesOutputMap pending_read_entries_outputs_; + + // Holds a reference on plugin side when running out of process, so that + // FileSystem won't die before FileRef. See PPB_FileRef_Impl for + // corresponding code for in-process mode. Note that this workaround will + // be no longer needed after FileRef refactoring. + ScopedPPResource file_system_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); +}; + +FileRef::FileRef(const PPB_FileRef_CreateInfo& info) + : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), + next_callback_id_(0u), + file_system_(info.file_system_plugin_resource) { +} + +FileRef::~FileRef() { + // The callbacks map should have been cleared by LastPluginRefWasDeleted. + DCHECK(pending_callbacks_.empty()); + DCHECK(pending_file_infos_.empty()); + DCHECK(pending_read_entries_outputs_.empty()); +} + +void FileRef::LastPluginRefWasDeleted() { + // The callback tracker will abort our callbacks for us. + pending_callbacks_.clear(); + pending_file_infos_.clear(); + pending_read_entries_outputs_.clear(); +} + +PP_Resource FileRef::GetParent() { + PPB_FileRef_CreateInfo create_info; + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( + API_ID_PPB_FILE_REF, host_resource(), &create_info)); + return PPB_FileRef_Proxy::DeserializeFileRef(create_info); +} + +int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, + scoped_refptr<TrackedCallback> callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_MakeDirectory( + API_ID_PPB_FILE_REF, host_resource(), make_ancestors, + SendCallback(callback))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileRef::Touch(PP_Time last_access_time, + PP_Time last_modified_time, + scoped_refptr<TrackedCallback> callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Touch( + API_ID_PPB_FILE_REF, host_resource(), last_access_time, + last_modified_time, SendCallback(callback))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileRef::Delete(scoped_refptr<TrackedCallback> callback) { + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Delete( + API_ID_PPB_FILE_REF, host_resource(), SendCallback(callback))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileRef::Rename(PP_Resource new_file_ref, + scoped_refptr<TrackedCallback> callback) { + Resource* new_file_ref_object = + PpapiGlobals::Get()->GetResourceTracker()->GetResource(new_file_ref); + if (!new_file_ref_object || + new_file_ref_object->host_resource().instance() != pp_instance()) + return PP_ERROR_BADRESOURCE; + + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Rename( + API_ID_PPB_FILE_REF, host_resource(), + new_file_ref_object->host_resource(), SendCallback(callback))); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileRef::Query(PP_FileInfo* info, + scoped_refptr<TrackedCallback> callback) { + // Store the pending file info id. + uint32_t id = SendCallback(callback); + pending_file_infos_[id] = info; + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( + API_ID_PPB_FILE_REF, host_resource(), id)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileRef::ReadDirectoryEntries( + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) { + // Store the pending read entries output id. + uint32_t id = SendCallback(callback); + pending_read_entries_outputs_[id] = output; + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadDirectoryEntries( + API_ID_PPB_FILE_REF, host_resource(), id)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t FileRef::QueryInHost( + linked_ptr<PP_FileInfo> info, + scoped_refptr<TrackedCallback> callback) { + NOTREACHED(); + return PP_ERROR_FAILED; +} + +int32_t FileRef::ReadDirectoryEntriesInHost( + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, + linked_ptr<std::vector<PP_FileType> > file_types, + scoped_refptr<TrackedCallback> callback) { + NOTREACHED(); + return PP_ERROR_FAILED; +} + +PP_Var FileRef::GetAbsolutePath() { + ReceiveSerializedVarReturnValue result; + GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( + API_ID_PPB_FILE_REF, host_resource(), &result)); + return result.Return(GetDispatcher()); +} + +void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { + PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); + if (found == pending_callbacks_.end()) { + // This will happen when the plugin deletes its resource with a pending + // callback. The callback will be locally issued with an ABORTED call while + // the operation may still be pending in the renderer. + return; + } + + // Executing the callback may mutate the callback list. + scoped_refptr<TrackedCallback> callback = found->second; + pending_callbacks_.erase(found); + callback->Run(result); +} + +int32_t FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { + PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); + if (found == pending_file_infos_.end()) + return PP_ERROR_FAILED; + PP_FileInfo* target_info = found->second; + *target_info = info; + pending_file_infos_.erase(found); + return PP_OK; +} + +int32_t FileRef::SetReadDirectoryEntriesOutput( + uint32_t callback_id, + const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, + const std::vector<PP_FileType>& file_types) { + PendingReadDirectoryEntriesOutputMap::iterator found = + pending_read_entries_outputs_.find(callback_id); + if (found == pending_read_entries_outputs_.end()) + return PP_ERROR_FAILED; + + PP_ArrayOutput output = found->second; + pending_read_entries_outputs_.erase(found); + + std::vector<PP_DirectoryEntry> entries; + for (size_t i = 0; i < infos.size(); ++i) { + PP_DirectoryEntry entry; + entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); + entry.file_type = file_types[i]; + entries.push_back(entry); + } + + ArrayWriter writer(output); + if (!writer.is_valid()) { + ReleaseEntries(entries); + return PP_ERROR_BADARGUMENT; + } + + writer.StoreVector(entries); + return PP_OK; +} + +uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { + // In extreme cases the IDs may wrap around, so avoid duplicates. + while (pending_callbacks_.count(next_callback_id_)) + ++next_callback_id_; + + pending_callbacks_[next_callback_id_] = callback; + return next_callback_id_++; +} + +PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) + : InterfaceProxy(dispatcher), + callback_factory_(this) { +} + +PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { +} + +// static +PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Instance instance, + PP_Resource file_system, + const char* path) { + PPB_FileRef_CreateInfo create_info; + PluginDispatcher::GetForInstance(instance)->Send( + new PpapiHostMsg_PPBFileRef_Create( + API_ID_PPB_FILE_REF, instance, file_system, path, &create_info)); + return PPB_FileRef_Proxy::DeserializeFileRef(create_info); +} + +bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) +#if !defined(OS_NACL) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, + OnMsgMakeDirectory) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_ReadDirectoryEntries, + OnMsgReadDirectoryEntries) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, + OnMsgGetAbsolutePath) +#endif // !defined(OS_NACL) + + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, + OnMsgCallbackComplete) + IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, + OnMsgQueryCallbackComplete) + IPC_MESSAGE_HANDLER( + PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete, + OnMsgReadDirectoryEntriesCallbackComplete) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +// static +void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, + PPB_FileRef_CreateInfo* result) { + EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); + if (enter.succeeded()) + *result = enter.object()->GetCreateInfo(); +} + +// static +PP_Resource PPB_FileRef_Proxy::DeserializeFileRef( + const PPB_FileRef_CreateInfo& serialized) { + if (serialized.resource.is_null()) + return 0; // Resource invalid. + return (new FileRef(serialized))->GetReference(); +} + +#if !defined(OS_NACL) +void PPB_FileRef_Proxy::OnMsgCreate(PP_Instance pp_instance, + PP_Resource file_system, + const std::string& path, + PPB_FileRef_CreateInfo* result) { + thunk::EnterResourceCreation enter(pp_instance); + if (enter.failed()) + return; + + PP_Resource resource = enter.functions()->CreateFileRef( + pp_instance, file_system, path.c_str()); + if (!resource) + return; // CreateInfo default constructor initializes to 0. + SerializeFileRef(resource, result); +} + +void PPB_FileRef_Proxy::OnMsgGetParent(const HostResource& host_resource, + PPB_FileRef_CreateInfo* result) { + EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); + if (enter.succeeded()) + SerializeFileRef(enter.object()->GetParent(), result); +} + +void PPB_FileRef_Proxy::OnMsgMakeDirectory(const HostResource& host_resource, + PP_Bool make_ancestors, + uint32_t callback_id) { + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( + host_resource, callback_factory_, + &PPB_FileRef_Proxy::OnCallbackCompleteInHost, host_resource, callback_id); + if (enter.succeeded()) { + enter.SetResult(enter.object()->MakeDirectory(make_ancestors, + enter.callback())); + } +} + +void PPB_FileRef_Proxy::OnMsgTouch(const HostResource& host_resource, + PP_Time last_access, + PP_Time last_modified, + uint32_t callback_id) { + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( + host_resource, callback_factory_, + &PPB_FileRef_Proxy::OnCallbackCompleteInHost, host_resource, callback_id); + if (enter.succeeded()) { + enter.SetResult(enter.object()->Touch(last_access, last_modified, + enter.callback())); + } +} + +void PPB_FileRef_Proxy::OnMsgDelete(const HostResource& host_resource, + uint32_t callback_id) { + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( + host_resource, callback_factory_, + &PPB_FileRef_Proxy::OnCallbackCompleteInHost, host_resource, callback_id); + if (enter.succeeded()) + enter.SetResult(enter.object()->Delete(enter.callback())); +} + +void PPB_FileRef_Proxy::OnMsgRename(const HostResource& file_ref, + const HostResource& new_file_ref, + uint32_t callback_id) { + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( + file_ref, callback_factory_, + &PPB_FileRef_Proxy::OnCallbackCompleteInHost, file_ref, callback_id); + if (enter.succeeded()) { + enter.SetResult(enter.object()->Rename(new_file_ref.host_resource(), + enter.callback())); + } +} + +void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref, + uint32_t callback_id) { + linked_ptr<PP_FileInfo> info(new PP_FileInfo()); + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( + file_ref, callback_factory_, + &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, + info, callback_id); + if (enter.succeeded()) + enter.SetResult(enter.object()->QueryInHost(info, enter.callback())); +} + +void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, + SerializedVarReturnValue result) { + EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); + if (enter.succeeded()) + result.Return(dispatcher(), enter.object()->GetAbsolutePath()); +} + +void PPB_FileRef_Proxy::OnMsgReadDirectoryEntries(const HostResource& file_ref, + uint32_t callback_id) { + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files( + new std::vector<ppapi::PPB_FileRef_CreateInfo>()); + linked_ptr<std::vector<PP_FileType> > file_types( + new std::vector<PP_FileType>()); + HostCallbackParams params(file_ref, callback_id); + EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( + file_ref, callback_factory_, + &PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost, + params, files, file_types); + if (enter.succeeded()) { + enter.SetResult(enter.object()->ReadDirectoryEntriesInHost( + files, file_types, enter.callback())); + } +} + +#endif // !defined(OS_NACL) + +void PPB_FileRef_Proxy::OnMsgCallbackComplete( + const HostResource& host_resource, + uint32_t callback_id, + int32_t result) { + // Forward the callback info to the plugin resource. + EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); + if (enter.succeeded()) + static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); +} + +void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( + const HostResource& host_resource, + const PP_FileInfo& info, + uint32_t callback_id, + int32_t result) { + EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); + if (!enter.succeeded()) + return; + + if (result == PP_OK) { + result = static_cast<FileRef*>(enter.object())->SetFileInfo( + callback_id, info); + } + static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); +} + +void PPB_FileRef_Proxy::OnMsgReadDirectoryEntriesCallbackComplete( + const HostResource& host_resource, + const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, + const std::vector<PP_FileType>& file_types, + uint32_t callback_id, + int32_t result) { + CHECK_EQ(infos.size(), file_types.size()); + + EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); + if (!enter.succeeded()) + return; + + if (result == PP_OK) { + result = + static_cast<FileRef*>(enter.object())->SetReadDirectoryEntriesOutput( + callback_id, infos, file_types); + } + static_cast<FileRef*>(enter.object())->ExecuteCallback( + callback_id, result); +} + +#if !defined(OS_NACL) +void PPB_FileRef_Proxy::OnCallbackCompleteInHost( + int32_t result, + const HostResource& host_resource, + uint32_t callback_id) { + // Execute OnMsgCallbackComplete in the plugin process. + Send(new PpapiMsg_PPBFileRef_CallbackComplete( + API_ID_PPB_FILE_REF, host_resource, callback_id, result)); +} + +void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( + int32_t result, + const HostResource& host_resource, + linked_ptr<PP_FileInfo> info, + uint32_t callback_id) { + Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( + API_ID_PPB_FILE_REF, host_resource, *info, callback_id, result)); +} + +void PPB_FileRef_Proxy::OnReadDirectoryEntriesCallbackCompleteInHost( + int32_t result, + HostCallbackParams params, + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, + linked_ptr<std::vector<PP_FileType> > file_types) { + Send(new PpapiMsg_PPBFileRef_ReadDirectoryEntriesCallbackComplete( + API_ID_PPB_FILE_REF, params.host_resource, + *files, *file_types, params.callback_id, result)); +} + +#endif // !defined(OS_NACL) + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppb_file_ref_proxy.h b/ppapi/proxy/ppb_file_ref_proxy.h new file mode 100644 index 0000000..cbfadb5 --- /dev/null +++ b/ppapi/proxy/ppb_file_ref_proxy.h @@ -0,0 +1,138 @@ +// 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 PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ +#define PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/memory/linked_ptr.h" +#include "ppapi/c/pp_file_info.h" +#include "ppapi/c/pp_module.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_time.h" +#include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/proxy/proxy_completion_callback_factory.h" +#include "ppapi/shared_impl/host_resource.h" +#include "ppapi/utility/completion_callback_factory.h" + +namespace ppapi { + +struct PPB_FileRef_CreateInfo; + +namespace proxy { + +class SerializedVarReturnValue; + +class PPAPI_PROXY_EXPORT PPB_FileRef_Proxy + : public NON_EXPORTED_BASE(InterfaceProxy) { + public: + explicit PPB_FileRef_Proxy(Dispatcher* dispatcher); + virtual ~PPB_FileRef_Proxy(); + + static PP_Resource CreateProxyResource(PP_Instance instance, + PP_Resource file_system, + const char* path); + static PP_Resource CreateProxyResource( + const PPB_FileRef_CreateInfo& serialized); + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + // Takes a resource in the host and converts it into a serialized file ref + // "create info" for reconstitution in the plugin. This struct contains all + // the necessary information about the file ref. + // + // Various PPAPI functions return file refs from various interfaces, so this + // function is public so anybody can send a file ref. + static void SerializeFileRef(PP_Resource file_ref, + PPB_FileRef_CreateInfo* result); + + // Creates a plugin resource from the given CreateInfo sent from the host. + // The value will be the result of calling SerializeFileRef on the host. + // This represents passing the resource ownership to the plugin. This + // function also checks the validity of the result and returns 0 on failure. + // + // Various PPAPI functions return file refs from various interfaces, so this + // function is public so anybody can receive a file ref. + static PP_Resource DeserializeFileRef( + const PPB_FileRef_CreateInfo& serialized); + + static const ApiID kApiID = API_ID_PPB_FILE_REF; + + private: + // Plugin -> host message handlers. + void OnMsgCreate(PP_Instance instance, + PP_Resource file_system, + const std::string& path, + PPB_FileRef_CreateInfo* result); + void OnMsgGetParent(const HostResource& host_resource, + PPB_FileRef_CreateInfo* result); + void OnMsgMakeDirectory(const HostResource& host_resource, + PP_Bool make_ancestors, + uint32_t callback_id); + void OnMsgTouch(const HostResource& host_resource, + PP_Time last_access, + PP_Time last_modified, + uint32_t callback_id); + void OnMsgDelete(const HostResource& host_resource, + uint32_t callback_id); + void OnMsgRename(const HostResource& file_ref, + const HostResource& new_file_ref, + uint32_t callback_id); + void OnMsgQuery(const HostResource& file_ref, + uint32_t callback_id); + void OnMsgGetAbsolutePath(const HostResource& host_resource, + SerializedVarReturnValue result); + void OnMsgReadDirectoryEntries(const HostResource& file_ref, + uint32_t callback_id); + + // Host -> Plugin message handlers. + void OnMsgCallbackComplete(const HostResource& host_resource, + uint32_t callback_id, + int32_t result); + void OnMsgQueryCallbackComplete(const HostResource& host_resource, + const PP_FileInfo& info, + uint32_t callback_id, + int32_t result); + void OnMsgReadDirectoryEntriesCallbackComplete( + const HostResource& host_resource, + const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, + const std::vector<PP_FileType>& file_types, + uint32_t callback_id, + int32_t result); + + struct HostCallbackParams { + HostCallbackParams(const HostResource& host_res, uint32_t cb_id) + : host_resource(host_res), callback_id(cb_id) { + } + HostResource host_resource; + uint32_t callback_id; + }; + + void OnCallbackCompleteInHost(int32_t result, + const HostResource& host_resource, + uint32_t callback_id); + void OnQueryCallbackCompleteInHost( + int32_t result, + const HostResource& host_resource, + linked_ptr<PP_FileInfo> info, + uint32_t callback_id); + void OnReadDirectoryEntriesCallbackCompleteInHost( + int32_t result, + HostCallbackParams params, + linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files, + linked_ptr<std::vector<PP_FileType> > file_types); + + ProxyCompletionCallbackFactory<PPB_FileRef_Proxy> callback_factory_; + + DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPB_FILE_REF_PROXY_H_ diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 88f99e32..4814c97 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -11,7 +11,6 @@ #include "ppapi/proxy/ext_crx_file_system_private_resource.h" #include "ppapi/proxy/file_chooser_resource.h" #include "ppapi/proxy/file_io_resource.h" -#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/file_system_resource.h" #include "ppapi/proxy/flash_drm_resource.h" #include "ppapi/proxy/flash_font_file_resource.h" @@ -27,6 +26,7 @@ #include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_broker_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" #include "ppapi/proxy/ppb_graphics_3d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" @@ -78,10 +78,15 @@ PP_Resource ResourceCreationProxy::CreateFileIO(PP_Instance instance) { return (new FileIOResource(GetConnection(), instance))->GetReference(); } +PP_Resource ResourceCreationProxy::CreateFileRef(PP_Instance instance, + PP_Resource file_system, + const char* path) { + return PPB_FileRef_Proxy::CreateProxyResource(instance, file_system, path); +} + PP_Resource ResourceCreationProxy::CreateFileRef( - PP_Instance instance, - const FileRefCreateInfo& create_info) { - return FileRefResource::CreateFileRef(GetConnection(), instance, create_info); + const PPB_FileRef_CreateInfo& create_info) { + return PPB_FileRef_Proxy::DeserializeFileRef(create_info); } PP_Resource ResourceCreationProxy::CreateFileSystem( diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index a8101db..edca902 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -38,9 +38,11 @@ class ResourceCreationProxy : public InterfaceProxy, // ResourceCreationAPI (called in plugin). virtual PP_Resource CreateFileIO(PP_Instance instance) OVERRIDE; + virtual PP_Resource CreateFileRef(PP_Instance instance, + PP_Resource file_system, + const char* path) OVERRIDE; virtual PP_Resource CreateFileRef( - PP_Instance instance, - const FileRefCreateInfo& create_info) OVERRIDE; + const PPB_FileRef_CreateInfo& create_info) OVERRIDE; virtual PP_Resource CreateFileSystem(PP_Instance instance, PP_FileSystemType type) OVERRIDE; virtual PP_Resource CreateIMEInputEvent(PP_Instance instance, diff --git a/ppapi/proxy/url_loader_resource.cc b/ppapi/proxy/url_loader_resource.cc index 1ff0a5e..5bbc937 100644 --- a/ppapi/proxy/url_loader_resource.cc +++ b/ppapi/proxy/url_loader_resource.cc @@ -9,8 +9,8 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_url_loader.h" #include "ppapi/proxy/dispatch_reply_message.h" -#include "ppapi/proxy/file_ref_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/url_request_info_resource.h" #include "ppapi/proxy/url_response_info_resource.h" #include "ppapi/shared_impl/ppapi_globals.h" @@ -158,14 +158,9 @@ int32_t URLLoaderResource::ReadResponseBody( int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; - if (!response_info_.get()) + if (!response_info_.get() || + !response_info_->data().body_as_file_ref.resource.is_null()) return PP_ERROR_FAILED; - - // Fail if we have a valid file ref. - // ReadResponseBody() is for reading to a user-provided buffer. - if (response_info_->data().body_as_file_ref.IsValid()) - return PP_ERROR_FAILED; - if (bytes_to_read <= 0 || !buffer) return PP_ERROR_BADARGUMENT; @@ -191,11 +186,8 @@ int32_t URLLoaderResource::FinishStreamingToFile( int32_t rv = ValidateCallback(callback); if (rv != PP_OK) return rv; - if (!response_info_.get()) - return PP_ERROR_FAILED; - - // Fail if we do not have a valid file ref. - if (!response_info_->data().body_as_file_ref.IsValid()) + if (!response_info_.get() || + response_info_->data().body_as_file_ref.resource.is_null()) return PP_ERROR_FAILED; // We may have already reached EOF. @@ -365,10 +357,10 @@ void URLLoaderResource::RunCallback(int32_t result) { void URLLoaderResource::SaveResponseInfo(const URLResponseInfoData& data) { // Create a proxy resource for the the file ref host resource if needed. PP_Resource body_as_file_ref = 0; - if (data.body_as_file_ref.IsValid()) { - body_as_file_ref = FileRefResource::CreateFileRef(connection(), - pp_instance(), - data.body_as_file_ref); + if (!data.body_as_file_ref.resource.is_null()) { + thunk::EnterResourceCreationNoLock enter(pp_instance()); + body_as_file_ref = + enter.functions()->CreateFileRef(data.body_as_file_ref); } response_info_ = new URLResponseInfoResource( connection(), pp_instance(), data, body_as_file_ref); @@ -397,4 +389,4 @@ size_t URLLoaderResource::FillUserBuffer() { } } // namespace proxy -} // namespace ppapi +} // namespace ppapi
\ No newline at end of file diff --git a/ppapi/proxy/url_response_info_resource.cc b/ppapi/proxy/url_response_info_resource.cc index 315b4a1..85dae9a 100644 --- a/ppapi/proxy/url_response_info_resource.cc +++ b/ppapi/proxy/url_response_info_resource.cc @@ -4,7 +4,7 @@ #include "ppapi/proxy/url_response_info_resource.h" -#include "ppapi/proxy/file_ref_resource.h" +#include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/resource_creation_api.h" |