diff options
author | jhorwich@chromium.org <jhorwich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-28 23:11:45 +0000 |
---|---|---|
committer | jhorwich@chromium.org <jhorwich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-28 23:11:45 +0000 |
commit | f12a383094546716230f0f4517468c6c64299e60 (patch) | |
tree | 65e825b49b2a3589b129488690080e9aa9eceaf9 | |
parent | 9a0fafb5c1fe5733282742fca8a5b5bd14e83ea6 (diff) | |
download | chromium_src-f12a383094546716230f0f4517468c6c64299e60.zip chromium_src-f12a383094546716230f0f4517468c6c64299e60.tar.gz chromium_src-f12a383094546716230f0f4517468c6c64299e60.tar.bz2 |
Implement FileRef GetPathPrivate interface for O3D
This is an implementation of a new private interface to get the filepath of a file downloaded with URLLoader and URLRequestInfo.SetStreamToFile(true). The file will be read in its entirety during a successful URLLoader.FinishStreamingToFile callback.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8604006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111805 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ppapi/api/private/ppb_file_ref_private.idl | 21 | ||||
-rw-r--r-- | ppapi/c/private/ppb_file_ref_private.h | 42 | ||||
-rw-r--r-- | ppapi/proxy/interface_list.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_ref_proxy.cc | 38 | ||||
-rw-r--r-- | ppapi/proxy/ppb_file_ref_proxy.h | 6 | ||||
-rw-r--r-- | ppapi/shared_impl/file_ref_impl.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/ppb_file_ref_api.h | 3 | ||||
-rw-r--r-- | ppapi/thunk/ppb_file_ref_thunk.cc | 16 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_ref_impl.cc | 14 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_file_ref_impl.h | 8 |
12 files changed, 156 insertions, 0 deletions
diff --git a/ppapi/api/private/ppb_file_ref_private.idl b/ppapi/api/private/ppb_file_ref_private.idl new file mode 100644 index 0000000..7ce053a --- /dev/null +++ b/ppapi/api/private/ppb_file_ref_private.idl @@ -0,0 +1,21 @@ +/* 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. + */ + +/* This file contains PPB_FileRefPrivate interface. */ + +/* PPB_FileRefPrivate interface */ +interface PPB_FileRefPrivate { + /** + * GetAbsolutePath() returns the absolute path of the file. + * + * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file + * reference. + * + * @return A <code>PP_Var</code> containing the absolute path of the file. + */ + PP_Var GetAbsolutePath([in] PP_Resource file_ref); +}; + + diff --git a/ppapi/c/private/ppb_file_ref_private.h b/ppapi/c/private/ppb_file_ref_private.h new file mode 100644 index 0000000..ea1dabe --- /dev/null +++ b/ppapi/c/private/ppb_file_ref_private.h @@ -0,0 +1,42 @@ +/* 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_C_PRIVATE_PPB_FILE_REF_PRIVATE_H_ +#define PPAPI_C_PRIVATE_PPB_FILE_REF_PRIVATE_H_ + +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/pp_var.h" + +#define PPB_FILEREFPRIVATE_INTERFACE_0_1 "PPB_FileRefPrivate;0.1" +#define PPB_FILEREFPRIVATE_INTERFACE PPB_FILEREFPRIVATE_INTERFACE_0_1 + +/** + * @file + * This file contains the <code>PPB_FileRefPrivate</code> interface. + */ + + +/** + * @addtogroup Interfaces + * @{ + */ +/* PPB_FileRefPrivate interface */ +struct PPB_FileRefPrivate { + /** + * GetAbsolutePath() returns the absolute path of the file. + * + * @param[in] file_ref A <code>PP_Resource</code> corresponding to a file + * reference. + * + * @return A <code>PP_Var</code> containing the absolute path of the file. + */ + struct PP_Var (*GetAbsolutePath)(PP_Resource file_ref); +}; +/** + * @} + */ + +#endif /* PPAPI_C_PRIVATE_PPB_FILE_REF_PRIVATE_H_ */ diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 96ee6bc..8893168 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -42,6 +42,7 @@ #include "ppapi/c/ppb_var.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppp_instance.h" +#include "ppapi/c/private/ppb_file_ref_private.h" #include "ppapi/c/private/ppb_flash_clipboard.h" #include "ppapi/c/private/ppb_flash_file.h" #include "ppapi/c/private/ppb_flash_fullscreen.h" @@ -180,6 +181,7 @@ InterfaceList::InterfaceList() { AddPPB(PPB_Testing_Proxy::GetInfo()); AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); + AddPPB(PPB_FileRef_Proxy::GetPrivateInfo()); // PPP (plugin) interfaces. AddPPP(PPP_Graphics3D_Proxy::GetInfo()); diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 758e040..01c8d50 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -631,6 +631,9 @@ IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFileRef_Rename, ppapi::HostResource /* file_ref */, ppapi::HostResource /* new_file_ref */, int /* callback_id */) +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFileRef_GetAbsolutePath, + ppapi::HostResource /* file_ref */, + ppapi::proxy::SerializedVar /* result */) // PPB_FileSystem. IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFileSystem_Create, diff --git a/ppapi/proxy/ppb_file_ref_proxy.cc b/ppapi/proxy/ppb_file_ref_proxy.cc index e6a8b94..55ef63b 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.cc +++ b/ppapi/proxy/ppb_file_ref_proxy.cc @@ -9,6 +9,7 @@ #include "base/bind.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" @@ -42,6 +43,7 @@ class FileRef : public FileRefImpl { virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE; virtual int32_t Rename(PP_Resource new_file_ref, PP_CompletionCallback callback) OVERRIDE; + virtual PP_Var GetAbsolutePath() OVERRIDE; // Executes the pending callback with the given ID. See pending_callbacks_. void ExecuteCallback(int callback_id, int32_t result); @@ -144,6 +146,13 @@ int32_t FileRef::Rename(PP_Resource new_file_ref, return PP_OK_COMPLETIONPENDING; } +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(int callback_id, int32_t result) { PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); if (found == pending_callbacks_.end()) { @@ -171,6 +180,14 @@ int FileRef::SendCallback(PP_CompletionCallback callback) { return next_callback_id_++; } +namespace { + +InterfaceProxy* CreateFileRefProxy(Dispatcher* dispatcher) { + return new PPB_FileRef_Proxy(dispatcher); +} + +} // namespace + PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) : InterfaceProxy(dispatcher), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { @@ -180,6 +197,18 @@ PPB_FileRef_Proxy::~PPB_FileRef_Proxy() { } // static +const InterfaceProxy::Info* PPB_FileRef_Proxy::GetPrivateInfo() { + static const Info info = { + thunk::GetPPB_FileRefPrivate_Thunk(), + PPB_FILEREFPRIVATE_INTERFACE, + API_ID_NONE, // URL_LOADER is the canonical one. + false, + &CreateFileRefProxy + }; + return &info; +} + +// static PP_Resource PPB_FileRef_Proxy::CreateProxyResource(PP_Resource file_system, const char* path) { Resource* file_system_object = @@ -205,6 +234,8 @@ bool PPB_FileRef_Proxy::OnMessageReceived(const IPC::Message& msg) { 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_GetAbsolutePath, + OnMsgGetAbsolutePath) IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, OnMsgCallbackComplete) @@ -294,6 +325,13 @@ void PPB_FileRef_Proxy::OnMsgRename(const HostResource& file_ref, } } +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::OnMsgCallbackComplete( const HostResource& host_resource, int callback_id, diff --git a/ppapi/proxy/ppb_file_ref_proxy.h b/ppapi/proxy/ppb_file_ref_proxy.h index 83fee18..200d7cf 100644 --- a/ppapi/proxy/ppb_file_ref_proxy.h +++ b/ppapi/proxy/ppb_file_ref_proxy.h @@ -22,11 +22,15 @@ struct PPB_FileRef_CreateInfo; namespace proxy { +class SerializedVarReturnValue; + class PPB_FileRef_Proxy : public InterfaceProxy { public: explicit PPB_FileRef_Proxy(Dispatcher* dispatcher); virtual ~PPB_FileRef_Proxy(); + static const Info* GetPrivateInfo(); + static PP_Resource CreateProxyResource(PP_Resource file_system, const char* path); @@ -76,6 +80,8 @@ class PPB_FileRef_Proxy : public InterfaceProxy { void OnMsgRename(const HostResource& file_ref, const HostResource& new_file_ref, int callback_id); + void OnMsgGetAbsolutePath(const HostResource& host_resource, + SerializedVarReturnValue result); // Host -> Plugin message handlers. void OnMsgCallbackComplete(const HostResource& host_resource, diff --git a/ppapi/shared_impl/file_ref_impl.h b/ppapi/shared_impl/file_ref_impl.h index 3f4bf8f..58ee0fe 100644 --- a/ppapi/shared_impl/file_ref_impl.h +++ b/ppapi/shared_impl/file_ref_impl.h @@ -47,6 +47,7 @@ class PPAPI_SHARED_EXPORT FileRefImpl : public Resource, virtual PP_Var GetName() const OVERRIDE; virtual PP_Var GetPath() const OVERRIDE; virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const OVERRIDE; + virtual PP_Var GetAbsolutePath() = 0; private: PPB_FileRef_CreateInfo create_info_; diff --git a/ppapi/thunk/ppb_file_ref_api.h b/ppapi/thunk/ppb_file_ref_api.h index ddcae7c..ca74003 100644 --- a/ppapi/thunk/ppb_file_ref_api.h +++ b/ppapi/thunk/ppb_file_ref_api.h @@ -34,6 +34,9 @@ class PPAPI_THUNK_EXPORT PPB_FileRef_API { // Intermal function for use in proxying. Returns the internal CreateInfo // (the contained resource does not carry a ref on behalf of the caller). virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const = 0; + + // Private API + virtual PP_Var GetAbsolutePath() = 0; }; } // namespace thunk diff --git a/ppapi/thunk/ppb_file_ref_thunk.cc b/ppapi/thunk/ppb_file_ref_thunk.cc index 542a7c7..5041c55 100644 --- a/ppapi/thunk/ppb_file_ref_thunk.cc +++ b/ppapi/thunk/ppb_file_ref_thunk.cc @@ -6,6 +6,7 @@ #include "ppapi/c/ppb_file_ref.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_file_ref_private.h" #include "ppapi/thunk/common.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" @@ -98,6 +99,13 @@ int32_t Rename(PP_Resource file_ref, return MayForceCallback(callback, result); } +PP_Var GetAbsolutePath(PP_Resource file_ref) { + EnterResource<PPB_FileRef_API> enter(file_ref, true); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.object()->GetAbsolutePath(); +} + const PPB_FileRef g_ppb_file_ref_thunk = { &Create, &IsFileRef, @@ -111,11 +119,19 @@ const PPB_FileRef g_ppb_file_ref_thunk = { &Rename }; +const PPB_FileRefPrivate g_ppb_file_ref_private_thunk = { + &GetAbsolutePath +}; + } // namespace const PPB_FileRef* GetPPB_FileRef_Thunk() { return &g_ppb_file_ref_thunk; } +const PPB_FileRefPrivate* GetPPB_FileRefPrivate_Thunk() { + return &g_ppb_file_ref_private_thunk; +} + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 5f6a62c..5fb38b4 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -34,6 +34,7 @@ struct PPB_BufferTrusted; struct PPB_Context3DTrusted_Dev; struct PPB_FileChooserTrusted; struct PPB_FileIOTrusted; +struct PPB_FileRefPrivate; struct PPB_Flash_Clipboard; struct PPB_Flash_Menu; struct PPB_Flash_NetConnector; @@ -63,6 +64,7 @@ PPAPI_THUNK_EXPORT const PPB_Context3DTrusted_Dev* PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted* GetPPB_FileChooser_Trusted_Thunk(); PPAPI_THUNK_EXPORT const PPB_FileIOTrusted* GetPPB_FileIOTrusted_Thunk(); +PPAPI_THUNK_EXPORT const PPB_FileRefPrivate* GetPPB_FileRefPrivate_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_Clipboard* GetPPB_Flash_Clipboard_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector* diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index 673ec01..3b39ce6 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -244,6 +244,20 @@ int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, return PP_OK_COMPLETIONPENDING; } +PP_Var PPB_FileRef_Impl::GetAbsolutePath() { + if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) + return GetPath(); + if (!external_path_var_.get()) { + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_MakeNull(); + external_path_var_ = new StringVar( + plugin_module->pp_module(), + external_file_system_path_.AsUTF8Unsafe()); + } + return external_path_var_->GetPPVar(); +} + FilePath PPB_FileRef_Impl::GetSystemPath() const { if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { NOTREACHED(); diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h index 64926de..39bc80b 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.h +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h @@ -11,10 +11,13 @@ #include "googleurl/src/gurl.h" #include "ppapi/c/ppb_file_ref.h" #include "ppapi/shared_impl/file_ref_impl.h" +#include "ppapi/shared_impl/var.h" namespace webkit { namespace ppapi { +using ::ppapi::StringVar; + class PPB_FileSystem_Impl; class PPB_FileRef_Impl : public ::ppapi::FileRefImpl { @@ -43,6 +46,7 @@ class PPB_FileRef_Impl : public ::ppapi::FileRefImpl { virtual int32_t Delete(PP_CompletionCallback callback) OVERRIDE; virtual int32_t Rename(PP_Resource new_file_ref, PP_CompletionCallback callback) OVERRIDE; + virtual PP_Var GetAbsolutePath(); PPB_FileSystem_Impl* file_system() const { return file_system_.get(); } @@ -67,6 +71,10 @@ class PPB_FileRef_Impl : public ::ppapi::FileRefImpl { // Used only for external filesystems. FilePath external_file_system_path_; + // Lazily initialized var created from the external path. This is so we can + // return the identical string object every time it is requested. + scoped_refptr<StringVar> external_path_var_; + DISALLOW_COPY_AND_ASSIGN(PPB_FileRef_Impl); }; |