Skip to content

Commit

Permalink
Implement FileRef GetPathPrivate interface for O3D
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jhorwich@chromium.org committed Nov 28, 2011
1 parent 9a0fafb commit f12a383
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ppapi/api/private/ppb_file_ref_private.idl
Original file line number Diff line number Diff line change
@@ -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);
};


42 changes: 42 additions & 0 deletions ppapi/c/private/ppb_file_ref_private.h
Original file line number Diff line number Diff line change
@@ -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_ */
2 changes: 2 additions & 0 deletions ppapi/proxy/interface_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions ppapi/proxy/ppapi_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions ppapi/proxy/ppb_file_ref_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -179,6 +196,18 @@ PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher)
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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions ppapi/proxy/ppb_file_ref_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions ppapi/shared_impl/file_ref_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
3 changes: 3 additions & 0 deletions ppapi/thunk/ppb_file_ref_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions ppapi/thunk/ppb_file_ref_thunk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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
2 changes: 2 additions & 0 deletions ppapi/thunk/thunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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*
Expand Down
14 changes: 14 additions & 0 deletions webkit/plugins/ppapi/ppb_file_ref_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions webkit/plugins/ppapi/ppb_file_ref_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(); }

Expand All @@ -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);
};

Expand Down

0 comments on commit f12a383

Please sign in to comment.