0

PPB_Flash cleanup part 2: move all the file stuff to ppb_flash_file.*.

ppb_flash_file.* is intended to contain multiple (very similar) interfaces, of
which the ModuleLocal stuff is one.

BUG=none
TEST="everything" still works

Review URL: http://codereview.chromium.org/6579026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75921 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
viettrungluu@chromium.org
2011-02-24 18:58:01 +00:00
parent 3fa964af1c
commit d07fa37911
15 changed files with 714 additions and 531 deletions

@ -5,10 +5,6 @@
#ifndef PPAPI_C_PRIVATE_PPB_FLASH_H_
#define PPAPI_C_PRIVATE_PPB_FLASH_H_
#ifdef _WIN32
#include <windows.h>
#endif
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_point.h"
@ -16,29 +12,7 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_var.h"
#define PPB_FLASH_INTERFACE "PPB_Flash;6"
#ifdef _WIN32
typedef HANDLE PP_FileHandle;
static const PP_FileHandle PP_kInvalidFileHandle = NULL;
#else
typedef int PP_FileHandle;
static const PP_FileHandle PP_kInvalidFileHandle = -1;
#endif
struct PP_CompletionCallback;
struct PP_FontDescription_Dev;
struct PP_FileInfo_Dev;
struct PP_DirEntry_Dev {
const char* name;
PP_Bool is_dir;
};
struct PP_DirContents_Dev {
int32_t count;
struct PP_DirEntry_Dev* entries;
};
#define PPB_FLASH_INTERFACE "PPB_Flash;7"
struct PPB_Flash {
// Sets or clears the rendering hint that the given plugin instance is always
@ -61,52 +35,6 @@ struct PPB_Flash {
// be a string in PAC format, or an undefined var on error.
struct PP_Var (*GetProxyForURL)(PP_Instance instance, const char* url);
// Opens a module-local file, returning a file descriptor (posix) or a HANDLE
// (win32) into file. Module-local file paths (here and below) are
// '/'-separated UTF-8 strings, relative to a module-specific root. The return
// value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in case
// of failure.
int32_t (*OpenModuleLocalFile)(PP_Instance instance,
const char* path,
int32_t mode,
PP_FileHandle* file);
// Renames a module-local file. The return value is the ppapi error, PP_OK if
// success, one of the PP_ERROR_* in case of failure.
int32_t (*RenameModuleLocalFile)(PP_Instance instance,
const char* path_from,
const char* path_to);
// Deletes a module-local file or directory. If recursive is set and the path
// points to a directory, deletes all the contents of the directory. The
// return value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in
// case of failure.
int32_t (*DeleteModuleLocalFileOrDir)(PP_Instance instance,
const char* path,
PP_Bool recursive);
// Creates a module-local directory. The return value is the ppapi error,
// PP_OK if success, one of the PP_ERROR_* in case of failure.
int32_t (*CreateModuleLocalDir)(PP_Instance instance, const char* path);
// Queries information about a module-local file. The return value is the
// ppapi error, PP_OK if success, one of the PP_ERROR_* in case of failure.
int32_t (*QueryModuleLocalFile)(PP_Instance instance,
const char* path,
struct PP_FileInfo_Dev* info);
// Gets the list of files contained in a module-local directory. The return
// value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in case
// of failure. If non-NULL, the returned contents should be freed with
// FreeModuleLocalDirContents.
int32_t (*GetModuleLocalDirContents)(PP_Instance instance,
const char* path,
struct PP_DirContents_Dev** contents);
// Frees the data allocated by GetModuleLocalDirContents.
void (*FreeModuleLocalDirContents)(PP_Instance instance,
struct PP_DirContents_Dev* contents);
// Navigate to URL. May open a new tab if target is not "_self". Return true
// if success. This differs from javascript:window.open() in that it bypasses
// the popup blocker, even when this is not called from an event handler.

@ -0,0 +1,89 @@
// 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_FLASH_FILE_H_
#define PPAPI_C_PRIVATE_PPB_FLASH_FILE_H_
#ifdef _WIN32
#include <windows.h>
#endif
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_instance.h"
#ifdef _WIN32
typedef HANDLE PP_FileHandle;
static const PP_FileHandle PP_kInvalidFileHandle = NULL;
#else
typedef int PP_FileHandle;
static const PP_FileHandle PP_kInvalidFileHandle = -1;
#endif
struct PP_CompletionCallback;
struct PP_FontDescription_Dev;
struct PP_FileInfo_Dev;
struct PP_DirEntry_Dev {
const char* name;
PP_Bool is_dir;
};
struct PP_DirContents_Dev {
int32_t count;
struct PP_DirEntry_Dev* entries;
};
// PPB_Flash_File_ModuleLocal --------------------------------------------------
#define PPB_FLASH_FILE_MODULELOCAL_INTERFACE "PPB_Flash_File_ModuleLocal;1"
struct PPB_Flash_File_ModuleLocal {
// Opens a module-local file, returning a file descriptor (posix) or a HANDLE
// (win32) into file. Module-local file paths (here and below) are
// '/'-separated UTF-8 strings, relative to a module-specific root. The return
// value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in case
// of failure.
int32_t (*OpenFile)(PP_Instance instance,
const char* path,
int32_t mode,
PP_FileHandle* file);
// Renames a module-local file. The return value is the ppapi error, PP_OK if
// success, one of the PP_ERROR_* in case of failure.
int32_t (*RenameFile)(PP_Instance instance,
const char* path_from,
const char* path_to);
// Deletes a module-local file or directory. If recursive is set and the path
// points to a directory, deletes all the contents of the directory. The
// return value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in
// case of failure.
int32_t (*DeleteFileOrDir)(PP_Instance instance,
const char* path,
PP_Bool recursive);
// Creates a module-local directory. The return value is the ppapi error,
// PP_OK if success, one of the PP_ERROR_* in case of failure.
int32_t (*CreateDir)(PP_Instance instance, const char* path);
// Queries information about a module-local file. The return value is the
// ppapi error, PP_OK if success, one of the PP_ERROR_* in case of failure.
int32_t (*QueryFile)(PP_Instance instance,
const char* path,
struct PP_FileInfo_Dev* info);
// Gets the list of files contained in a module-local directory. The return
// value is the ppapi error, PP_OK if success, one of the PP_ERROR_* in case
// of failure. If non-NULL, the returned contents should be freed with
// FreeDirContents.
int32_t (*GetDirContents)(PP_Instance instance,
const char* path,
struct PP_DirContents_Dev** contents);
// Frees the data allocated by GetDirContents.
void (*FreeDirContents)(PP_Instance instance,
struct PP_DirContents_Dev* contents);
};
#endif // PPAPI_C_PRIVATE_PPB_FLASH_FILE_H_

@ -8,7 +8,7 @@
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/private/ppb_flash.h" // For |PP_FileHandle|.
#include "ppapi/c/private/ppb_flash_file.h" // For |PP_FileHandle|.
#define PPB_FLASH_NETCONNECTOR_INTERFACE "PPB_Flash_NetConnector;1"

@ -91,6 +91,8 @@
'proxy/ppb_file_ref_proxy.h',
'proxy/ppb_file_system_proxy.cc',
'proxy/ppb_file_system_proxy.h',
'proxy/ppb_flash_file_proxy.cc',
'proxy/ppb_flash_file_proxy.h',
'proxy/ppb_flash_proxy.cc',
'proxy/ppb_flash_proxy.h',
'proxy/ppb_flash_menu_proxy.cc',

@ -37,6 +37,7 @@
#include "ppapi/c/ppb_url_response_info.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/c/private/ppb_flash_file.h"
#include "ppapi/c/private/ppb_flash_menu.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
@ -51,6 +52,7 @@
#include "ppapi/proxy/ppb_file_chooser_proxy.h"
#include "ppapi/proxy/ppb_file_ref_proxy.h"
#include "ppapi/proxy/ppb_file_system_proxy.h"
#include "ppapi/proxy/ppb_flash_file_proxy.h"
#include "ppapi/proxy/ppb_flash_proxy.h"
#include "ppapi/proxy/ppb_flash_menu_proxy.h"
#include "ppapi/proxy/ppb_font_proxy.h"
@ -107,6 +109,7 @@ InterfaceList::InterfaceList() {
AddPPB(PPB_FileChooser_Proxy::GetInfo());
AddPPB(PPB_FileRef_Proxy::GetInfo());
AddPPB(PPB_FileSystem_Proxy::GetInfo());
AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo());
AddPPB(PPB_Flash_Proxy::GetInfo());
AddPPB(PPB_Flash_Menu_Proxy::GetInfo());
AddPPB(PPB_Font_Proxy::GetInfo());

@ -24,6 +24,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_FILE_REF,
INTERFACE_ID_PPB_FILE_SYSTEM,
INTERFACE_ID_PPB_FLASH,
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
INTERFACE_ID_PPB_FLASH_MENU,
INTERFACE_ID_PPB_FONT,
INTERFACE_ID_PPB_FULLSCREEN,

@ -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.
@ -346,37 +346,6 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_GetProxyForURL,
PP_Instance /* instance */,
std::string /* url */,
pp::proxy::SerializedVar /* result */)
IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBFlash_OpenModuleLocalFile,
PP_Instance /* instance */,
std::string /* path */,
int32_t /* mode */,
IPC::PlatformFileForTransit /* file_handle */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_RenameModuleLocalFile,
PP_Instance /* instance */,
std::string /* path_from */,
std::string /* path_to */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir,
PP_Instance /* instance */,
std::string /* path */,
PP_Bool /* recursive */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_CreateModuleLocalDir,
PP_Instance /* instance */,
std::string /* path */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBFlash_QueryModuleLocalFile,
PP_Instance /* instance */,
std::string /* path */,
PP_FileInfo_Dev /* info */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_2(
PpapiHostMsg_PPBFlash_GetModuleLocalDirContents,
PP_Instance /* instance */,
std::string /* path */,
std::vector<pp::proxy::SerializedDirEntry> /* entries */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_NavigateToURL,
PP_Instance /* instance */,
std::string /* url */,
@ -387,6 +356,40 @@ IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBFlash_RunMessageLoop,
IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBFlash_QuitMessageLoop,
PP_Instance /* instance */)
// PPB_Flash_File_ModuleLocal.
IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBFlashFile_ModuleLocal_OpenFile,
PP_Instance /* instance */,
std::string /* path */,
int32_t /* mode */,
IPC::PlatformFileForTransit /* file_handle */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlashFile_ModuleLocal_RenameFile,
PP_Instance /* instance */,
std::string /* path_from */,
std::string /* path_to */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED3_1(
PpapiHostMsg_PPBFlashFile_ModuleLocal_DeleteFileOrDir,
PP_Instance /* instance */,
std::string /* path */,
PP_Bool /* recursive */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlashFile_ModuleLocal_CreateDir,
PP_Instance /* instance */,
std::string /* path */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBFlashFile_ModuleLocal_QueryFile,
PP_Instance /* instance */,
std::string /* path */,
PP_FileInfo_Dev /* info */,
int32_t /* result */)
IPC_SYNC_MESSAGE_ROUTED2_2(
PpapiHostMsg_PPBFlashFile_ModuleLocal_GetDirContents,
PP_Instance /* instance */,
std::string /* path */,
std::vector<pp::proxy::SerializedDirEntry> /* entries */,
int32_t /* result */)
// PPB_Flash_Menu
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlashMenu_Create,
PP_Instance /* instance */,

@ -0,0 +1,284 @@
// 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 "ppapi/proxy/ppb_flash_file_proxy.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "ppapi/c/dev/pp_file_info_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_file.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
namespace proxy {
namespace {
// Given an error code and a handle result from a Pepper API call, converts
// to a PlatformFileForTransit, possibly also updating the error value if
// an error occurred.
IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit(
int32_t* error,
base::PlatformFile file) {
if (*error != PP_OK)
return IPC::InvalidPlatformFileForTransit();
#if defined(OS_WIN)
/* TODO(brettw): figure out how to get the target process handle.
HANDLE result;
if (!::DuplicateHandle(::GetCurrentProcess(), file,
target_process, &result, 0, false,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
*error = PP_ERROR_NOACCESS;
return INVALID_HANDLE_VALUE;
}
return result;
*/
NOTIMPLEMENTED();
*error = PP_ERROR_NOACCESS;
return INVALID_HANDLE_VALUE;
#elif defined(OS_POSIX)
return base::FileDescriptor(file, true);
#endif
}
void FreeDirContents(PP_Instance /* instance */,
PP_DirContents_Dev* contents) {
for (int32_t i = 0; i < contents->count; ++i)
delete[] contents->entries[i].name;
delete[] contents->entries;
delete contents;
}
int32_t OpenModuleLocalFile(PP_Instance instance,
const char* path,
int32_t mode,
PP_FileHandle* file) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
IPC::PlatformFileForTransit transit;
dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_OpenFile(
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
instance, path, mode, &transit, &result));
*file = IPC::PlatformFileForTransitToPlatformFile(transit);
return result;
}
int32_t RenameModuleLocalFile(PP_Instance instance,
const char* path_from,
const char* path_to) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_RenameFile(
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
instance, path_from, path_to, &result));
return result;
}
int32_t DeleteModuleLocalFileOrDir(PP_Instance instance,
const char* path,
PP_Bool recursive) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_DeleteFileOrDir(
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
instance, path, recursive, &result));
return result;
}
int32_t CreateModuleLocalDir(PP_Instance instance, const char* path) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_CreateDir(
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL, instance, path, &result));
return result;
}
int32_t QueryModuleLocalFile(PP_Instance instance,
const char* path,
PP_FileInfo_Dev* info) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_QueryFile(
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL, instance, path, info, &result));
return result;
}
int32_t GetModuleLocalDirContents(PP_Instance instance,
const char* path,
PP_DirContents_Dev** contents) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
std::vector<SerializedDirEntry> entries;
dispatcher->Send(new PpapiHostMsg_PPBFlashFile_ModuleLocal_GetDirContents(
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
instance, path, &entries, &result));
if (result != PP_OK)
return result;
// Copy the serialized dir entries to the output struct.
*contents = new PP_DirContents_Dev;
(*contents)->count = static_cast<int32_t>(entries.size());
(*contents)->entries = new PP_DirEntry_Dev[entries.size()];
for (size_t i = 0; i < entries.size(); i++) {
const SerializedDirEntry& source = entries[i];
PP_DirEntry_Dev* dest = &(*contents)->entries[i];
char* name_copy = new char[source.name.size() + 1];
memcpy(name_copy, source.name.c_str(), source.name.size() + 1);
dest->name = name_copy;
dest->is_dir = BoolToPPBool(source.is_dir);
}
return result;
}
const PPB_Flash_File_ModuleLocal flash_file_module_local_interface = {
&OpenModuleLocalFile,
&RenameModuleLocalFile,
&DeleteModuleLocalFileOrDir,
&CreateModuleLocalDir,
&QueryModuleLocalFile,
&GetModuleLocalDirContents,
&FreeDirContents,
};
InterfaceProxy* CreateFlashFileModuleLocalProxy(Dispatcher* dispatcher,
const void* target_interface) {
return new PPB_Flash_File_ModuleLocal_Proxy(dispatcher, target_interface);
}
} // namespace
PPB_Flash_File_ModuleLocal_Proxy::PPB_Flash_File_ModuleLocal_Proxy(
Dispatcher* dispatcher,
const void* target_interface)
: InterfaceProxy(dispatcher, target_interface) {
}
PPB_Flash_File_ModuleLocal_Proxy::~PPB_Flash_File_ModuleLocal_Proxy() {
}
// static
const InterfaceProxy::Info* PPB_Flash_File_ModuleLocal_Proxy::GetInfo() {
static const Info info = {
&flash_file_module_local_interface,
PPB_FLASH_FILE_MODULELOCAL_INTERFACE,
INTERFACE_ID_PPB_FLASH_FILE_MODULELOCAL,
true,
&CreateFlashFileModuleLocalProxy,
};
return &info;
}
bool PPB_Flash_File_ModuleLocal_Proxy::OnMessageReceived(
const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_Flash_File_ModuleLocal_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_ModuleLocal_OpenFile,
OnMsgOpenFile)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_ModuleLocal_RenameFile,
OnMsgRenameFile)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_ModuleLocal_DeleteFileOrDir,
OnMsgDeleteFileOrDir)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_ModuleLocal_CreateDir,
OnMsgCreateDir)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_ModuleLocal_QueryFile,
OnMsgQueryFile)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashFile_ModuleLocal_GetDirContents,
OnMsgGetDirContents)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
// TODO(brettw) handle bad messages!
return handled;
}
void PPB_Flash_File_ModuleLocal_Proxy::OnMsgOpenFile(
PP_Instance instance,
const std::string& path,
int32_t mode,
IPC::PlatformFileForTransit* file_handle,
int32_t* result) {
base::PlatformFile file;
*result = ppb_flash_file_module_local_target()->
OpenFile(instance, path.c_str(), mode, &file);
*file_handle = PlatformFileToPlatformFileForTransit(result, file);
}
void PPB_Flash_File_ModuleLocal_Proxy::OnMsgRenameFile(
PP_Instance instance,
const std::string& path_from,
const std::string& path_to,
int32_t* result) {
*result = ppb_flash_file_module_local_target()->
RenameFile(instance, path_from.c_str(), path_to.c_str());
}
void PPB_Flash_File_ModuleLocal_Proxy::OnMsgDeleteFileOrDir(
PP_Instance instance,
const std::string& path,
PP_Bool recursive,
int32_t* result) {
*result = ppb_flash_file_module_local_target()->
DeleteFileOrDir(instance, path.c_str(), recursive);
}
void PPB_Flash_File_ModuleLocal_Proxy::OnMsgCreateDir(PP_Instance instance,
const std::string& path,
int32_t* result) {
*result = ppb_flash_file_module_local_target()->
CreateDir(instance, path.c_str());
}
void PPB_Flash_File_ModuleLocal_Proxy::OnMsgQueryFile(PP_Instance instance,
const std::string& path,
PP_FileInfo_Dev* info,
int32_t* result) {
*result = ppb_flash_file_module_local_target()->
QueryFile(instance, path.c_str(), info);
}
void PPB_Flash_File_ModuleLocal_Proxy::OnMsgGetDirContents(
PP_Instance instance,
const std::string& path,
std::vector<pp::proxy::SerializedDirEntry>* entries,
int32_t* result) {
PP_DirContents_Dev* contents = NULL;
*result = ppb_flash_file_module_local_target()->
GetDirContents(instance, path.c_str(), &contents);
if (*result != PP_OK)
return;
// Convert the list of entries to the serialized version.
entries->resize(contents->count);
for (int32_t i = 0; i < contents->count; i++) {
(*entries)[i].name.assign(contents->entries[i].name);
(*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir);
}
ppb_flash_file_module_local_target()->FreeDirContents(instance, contents);
}
} // namespace proxy
} // namespace pp

@ -0,0 +1,69 @@
// 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_PPB_FLASH_FILE_PROXY_H_
#define PPAPI_PPB_FLASH_FILE_PROXY_H_
#include <vector>
#include "ipc/ipc_platform_file.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/proxy/interface_proxy.h"
struct PP_FileInfo_Dev;
struct PPB_Flash_File_ModuleLocal;
namespace pp {
namespace proxy {
struct SerializedDirEntry;
class PPB_Flash_File_ModuleLocal_Proxy : public InterfaceProxy {
public:
PPB_Flash_File_ModuleLocal_Proxy(Dispatcher* dispatcher,
const void* target_interface);
virtual ~PPB_Flash_File_ModuleLocal_Proxy();
static const Info* GetInfo();
const PPB_Flash_File_ModuleLocal* ppb_flash_file_module_local_target() const {
return static_cast<const PPB_Flash_File_ModuleLocal*>(target_interface());
}
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
private:
// Message handlers.
void OnMsgOpenFile(PP_Instance instance,
const std::string& path,
int32_t mode,
IPC::PlatformFileForTransit* file_handle,
int32_t* result);
void OnMsgRenameFile(PP_Instance instance,
const std::string& path_from,
const std::string& path_to,
int32_t* result);
void OnMsgDeleteFileOrDir(PP_Instance instance,
const std::string& path,
PP_Bool recursive,
int32_t* result);
void OnMsgCreateDir(PP_Instance instance,
const std::string& path,
int32_t* result);
void OnMsgQueryFile(PP_Instance instance,
const std::string& path,
PP_FileInfo_Dev* info,
int32_t* result);
void OnMsgGetDirContents(PP_Instance instance,
const std::string& path,
std::vector<pp::proxy::SerializedDirEntry>* entries,
int32_t* result);
};
} // namespace proxy
} // namespace pp
#endif // PPAPI_PPB_FLASH_FILE_PROXY_H_

@ -6,11 +6,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "build/build_config.h"
#include "ppapi/c/dev/pp_file_info_dev.h"
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/proxy/plugin_dispatcher.h"
@ -23,33 +19,6 @@ namespace proxy {
namespace {
// Given an error code and a handle result from a Pepper API call, converts
// to a PlatformFileForTransit, possibly also updating the error value if
// an error occurred.
IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit(
int32_t* error,
base::PlatformFile file) {
if (*error != PP_OK)
return IPC::InvalidPlatformFileForTransit();
#if defined(OS_WIN)
/* TODO(brettw): figure out how to get the target process handle.
HANDLE result;
if (!::DuplicateHandle(::GetCurrentProcess(), file,
target_process, &result, 0, false,
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
*error = PP_ERROR_NOACCESS;
return INVALID_HANDLE_VALUE;
}
return result;
*/
NOTIMPLEMENTED();
*error = PP_ERROR_NOACCESS;
return INVALID_HANDLE_VALUE;
#elif defined(OS_POSIX)
return base::FileDescriptor(file, true);
#endif
}
void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(pp_instance);
if (dispatcher) {
@ -117,112 +86,6 @@ PP_Var GetProxyForURL(PP_Instance instance, const char* url) {
return result.Return(dispatcher);
}
int32_t OpenModuleLocalFile(PP_Instance instance,
const char* path,
int32_t mode,
PP_FileHandle* file) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
IPC::PlatformFileForTransit transit;
dispatcher->Send(new PpapiHostMsg_PPBFlash_OpenModuleLocalFile(
INTERFACE_ID_PPB_FLASH, instance, path, mode, &transit, &result));
*file = IPC::PlatformFileForTransitToPlatformFile(transit);
return result;
}
int32_t RenameModuleLocalFile(PP_Instance instance,
const char* path_from,
const char* path_to) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlash_RenameModuleLocalFile(
INTERFACE_ID_PPB_FLASH, instance, path_from, path_to, &result));
return result;
}
int32_t DeleteModuleLocalFileOrDir(PP_Instance instance,
const char* path,
PP_Bool recursive) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir(
INTERFACE_ID_PPB_FLASH, instance, path, recursive, &result));
return result;
}
int32_t CreateModuleLocalDir(PP_Instance instance, const char* path) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlash_CreateModuleLocalDir(
INTERFACE_ID_PPB_FLASH, instance, path, &result));
return result;
}
int32_t QueryModuleLocalFile(PP_Instance instance,
const char* path,
PP_FileInfo_Dev* info) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
dispatcher->Send(new PpapiHostMsg_PPBFlash_QueryModuleLocalFile(
INTERFACE_ID_PPB_FLASH, instance, path, info, &result));
return result;
}
int32_t GetModuleLocalDirContents(PP_Instance instance,
const char* path,
PP_DirContents_Dev** contents) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
int32_t result = PP_ERROR_FAILED;
std::vector<SerializedDirEntry> entries;
dispatcher->Send(new PpapiHostMsg_PPBFlash_GetModuleLocalDirContents(
INTERFACE_ID_PPB_FLASH, instance, path, &entries, &result));
if (result != PP_OK)
return result;
// Copy the serialized dir entries to the output struct.
*contents = new PP_DirContents_Dev;
(*contents)->count = static_cast<int32_t>(entries.size());
(*contents)->entries = new PP_DirEntry_Dev[entries.size()];
for (size_t i = 0; i < entries.size(); i++) {
const SerializedDirEntry& source = entries[i];
PP_DirEntry_Dev* dest = &(*contents)->entries[i];
char* name_copy = new char[source.name.size() + 1];
memcpy(name_copy, source.name.c_str(), source.name.size() + 1);
dest->name = name_copy;
dest->is_dir = BoolToPPBool(source.is_dir);
}
return result;
}
void FreeModuleLocalDirContents(PP_Instance /* instance */,
PP_DirContents_Dev* contents) {
for (int32_t i = 0; i < contents->count; ++i)
delete[] contents->entries[i].name;
delete[] contents->entries;
delete contents;
}
PP_Bool NavigateToURL(PP_Instance instance,
const char* url,
const char* target) {
@ -258,13 +121,6 @@ const PPB_Flash flash_interface = {
&SetInstanceAlwaysOnTop,
&DrawGlyphs,
&GetProxyForURL,
&OpenModuleLocalFile,
&RenameModuleLocalFile,
&DeleteModuleLocalFileOrDir,
&CreateModuleLocalDir,
&QueryModuleLocalFile,
&GetModuleLocalDirContents,
&FreeModuleLocalDirContents,
&NavigateToURL,
&RunMessageLoop,
&QuitMessageLoop,
@ -306,18 +162,6 @@ bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) {
OnMsgDrawGlyphs)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetProxyForURL,
OnMsgGetProxyForURL)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenModuleLocalFile,
OnMsgOpenModuleLocalFile)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RenameModuleLocalFile,
OnMsgRenameModuleLocalFile)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir,
OnMsgDeleteModuleLocalFileOrDir)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_CreateModuleLocalDir,
OnMsgCreateModuleLocalDir)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryModuleLocalFile,
OnMsgQueryModuleLocalFile)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetModuleLocalDirContents,
OnMsgGetModuleLocalDirContents)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_NavigateToURL, OnMsgNavigateToURL)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_RunMessageLoop,
OnMsgRunMessageLoop)
@ -364,73 +208,6 @@ void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Instance instance,
instance, url.c_str()));
}
void PPB_Flash_Proxy::OnMsgOpenModuleLocalFile(
PP_Instance instance,
const std::string& path,
int32_t mode,
IPC::PlatformFileForTransit* file_handle,
int32_t* result) {
base::PlatformFile file;
*result = ppb_flash_target()->OpenModuleLocalFile(instance, path.c_str(),
mode, &file);
*file_handle = PlatformFileToPlatformFileForTransit(result, file);
}
void PPB_Flash_Proxy::OnMsgRenameModuleLocalFile(
PP_Instance instance,
const std::string& path_from,
const std::string& path_to,
int32_t* result) {
*result = ppb_flash_target()->RenameModuleLocalFile(instance,
path_from.c_str(),
path_to.c_str());
}
void PPB_Flash_Proxy::OnMsgDeleteModuleLocalFileOrDir(
PP_Instance instance,
const std::string& path,
PP_Bool recursive,
int32_t* result) {
*result = ppb_flash_target()->DeleteModuleLocalFileOrDir(instance,
path.c_str(),
recursive);
}
void PPB_Flash_Proxy::OnMsgCreateModuleLocalDir(PP_Instance instance,
const std::string& path,
int32_t* result) {
*result = ppb_flash_target()->CreateModuleLocalDir(instance, path.c_str());
}
void PPB_Flash_Proxy::OnMsgQueryModuleLocalFile(PP_Instance instance,
const std::string& path,
PP_FileInfo_Dev* info,
int32_t* result) {
*result = ppb_flash_target()->QueryModuleLocalFile(instance, path.c_str(),
info);
}
void PPB_Flash_Proxy::OnMsgGetModuleLocalDirContents(
PP_Instance instance,
const std::string& path,
std::vector<pp::proxy::SerializedDirEntry>* entries,
int32_t* result) {
PP_DirContents_Dev* contents = NULL;
*result = ppb_flash_target()->GetModuleLocalDirContents(instance,
path.c_str(),
&contents);
if (*result != PP_OK)
return;
// Convert the list of entries to the serialized version.
entries->resize(contents->count);
for (int32_t i = 0; i < contents->count; i++) {
(*entries)[i].name.assign(contents->entries[i].name);
(*entries)[i].is_dir = PPBoolToBool(contents->entries[i].is_dir);
}
ppb_flash_target()->FreeModuleLocalDirContents(instance, contents);
}
void PPB_Flash_Proxy::OnMsgNavigateToURL(PP_Instance instance,
const std::string& url,
const std::string& target,

@ -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.
@ -19,8 +19,6 @@ namespace pp {
namespace proxy {
struct PPBFlash_DrawGlyphs_Params;
struct SerializedDirEntry;
class SerializedVar;
class SerializedVarReturnValue;
class PPB_Flash_Proxy : public InterfaceProxy {
@ -46,31 +44,6 @@ class PPB_Flash_Proxy : public InterfaceProxy {
void OnMsgGetProxyForURL(PP_Instance instance,
const std::string& url,
SerializedVarReturnValue result);
void OnMsgOpenModuleLocalFile(PP_Instance instance,
const std::string& path,
int32_t mode,
IPC::PlatformFileForTransit* file_handle,
int32_t* result);
void OnMsgRenameModuleLocalFile(PP_Instance instance,
const std::string& path_from,
const std::string& path_to,
int32_t* result);
void OnMsgDeleteModuleLocalFileOrDir(PP_Instance instance,
const std::string& path,
PP_Bool recursive,
int32_t* result);
void OnMsgCreateModuleLocalDir(PP_Instance instance,
const std::string& path,
int32_t* result);
void OnMsgQueryModuleLocalFile(PP_Instance instance,
const std::string& path,
PP_FileInfo_Dev* info,
int32_t* result);
void OnMsgGetModuleLocalDirContents(
PP_Instance instance,
const std::string& path,
std::vector<pp::proxy::SerializedDirEntry>* entries,
int32_t* result);
void OnMsgNavigateToURL(PP_Instance instance,
const std::string& url,
const std::string& target,

@ -295,6 +295,8 @@
'../plugins/ppapi/ppb_file_ref_impl.h',
'../plugins/ppapi/ppb_file_system_impl.cc',
'../plugins/ppapi/ppb_file_system_impl.h',
'../plugins/ppapi/ppb_flash_file_impl.cc',
'../plugins/ppapi/ppb_flash_file_impl.h',
'../plugins/ppapi/ppb_flash_impl.cc',
'../plugins/ppapi/ppb_flash_impl.h',
'../plugins/ppapi/ppb_flash_impl_linux.cc',

@ -0,0 +1,205 @@
// 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/ppb_flash_file_impl.h"
#include <string.h>
#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/plugin_delegate.h"
#include "webkit/plugins/ppapi/plugin_module.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource_tracker.h"
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;
int flags = 0;
if (mode & PP_FILEOPENFLAG_READ)
flags |= base::PLATFORM_FILE_READ;
if (mode & PP_FILEOPENFLAG_WRITE) {
flags |= base::PLATFORM_FILE_WRITE;
flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES;
}
if (mode & PP_FILEOPENFLAG_TRUNCATE) {
DCHECK(mode & PP_FILEOPENFLAG_WRITE);
flags |= base::PLATFORM_FILE_TRUNCATE;
}
if (mode & PP_FILEOPENFLAG_CREATE) {
if (mode & PP_FILEOPENFLAG_EXCLUSIVE)
flags |= base::PLATFORM_FILE_CREATE;
else
flags |= base::PLATFORM_FILE_OPEN_ALWAYS;
} else {
flags |= base::PLATFORM_FILE_OPEN;
}
base::PlatformFile base_file;
base::PlatformFileError result = instance->delegate()->OpenModuleLocalFile(
instance->module()->name(),
GetFilePathFromUTF8(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) {
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));
return PlatformFileErrorToPepperError(result);
}
int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance,
const char* path,
PP_Bool recursive) {
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));
return PlatformFileErrorToPepperError(result);
}
int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
if (!instance)
return PP_ERROR_FAILED;
base::PlatformFileError result = instance->delegate()->CreateModuleLocalDir(
instance->module()->name(), GetFilePathFromUTF8(path));
return PlatformFileErrorToPepperError(result);
}
int32_t QueryModuleLocalFile(PP_Instance pp_instance,
const char* path,
PP_FileInfo_Dev* info) {
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);
if (result == base::PLATFORM_FILE_OK) {
info->size = file_info.size;
info->creation_time = file_info.creation_time.ToDoubleT();
info->last_access_time = file_info.last_accessed.ToDoubleT();
info->last_modified_time = file_info.last_modified.ToDoubleT();
info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
if (file_info.is_directory)
info->type = PP_FILETYPE_DIRECTORY;
else
info->type = PP_FILETYPE_REGULAR;
}
return PlatformFileErrorToPepperError(result);
}
int32_t GetModuleLocalDirContents(PP_Instance pp_instance,
const char* path,
PP_DirContents_Dev** contents) {
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);
if (result != base::PLATFORM_FILE_OK)
return PlatformFileErrorToPepperError(result);
*contents = new PP_DirContents_Dev;
size_t count = pepper_contents.size();
(*contents)->count = count;
(*contents)->entries = new PP_DirEntry_Dev[count];
for (size_t i = 0; i < count; ++i) {
PP_DirEntry_Dev& entry = (*contents)->entries[i];
#if defined(OS_WIN)
const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value());
#else
const std::string& name = pepper_contents[i].name.value();
#endif
size_t size = name.size() + 1;
char* name_copy = new char[size];
memcpy(name_copy, name.c_str(), size);
entry.name = name_copy;
entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir);
}
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 = {
&OpenModuleLocalFile,
&RenameModuleLocalFile,
&DeleteModuleLocalFileOrDir,
&CreateModuleLocalDir,
&QueryModuleLocalFile,
&GetModuleLocalDirContents,
&FreeModuleLocalDirContents,
};
} // namespace
// static
const PPB_Flash_File_ModuleLocal*
PPB_Flash_File_ModuleLocal_Impl::GetInterface() {
return &ppb_flash_file_module_local;
}
} // namespace ppapi
} // namespace webkit

@ -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.
#ifndef WEBKIT_PLUGINS_PPAPI_PPB_FLASH_FILE_IMPL_H_
#define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_FILE_IMPL_H_
struct PPB_Flash_File_ModuleLocal;
namespace webkit {
namespace ppapi {
class PPB_Flash_File_ModuleLocal_Impl {
public:
static const PPB_Flash_File_ModuleLocal* GetInterface();
};
} // namespace ppapi
} // namespace webkit
#endif // WEBKIT_PLUGINS_PPAPI_PPB_FLASH_FILE_IMPL_H_

@ -4,22 +4,13 @@
#include "webkit/plugins/ppapi/ppb_flash_impl.h"
#include <string.h>
#include <string>
#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "ppapi/c/dev/pp_file_info_dev.h"
#include "ppapi/c/dev/ppb_file_io_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/private/ppb_flash.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/error_util.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/resource_tracker.h"
#include "webkit/plugins/ppapi/var.h"
@ -51,164 +42,6 @@ PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) {
return StringVar::StringToPPVar(instance->module(), proxy_host);
}
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;
int flags = 0;
if (mode & PP_FILEOPENFLAG_READ)
flags |= base::PLATFORM_FILE_READ;
if (mode & PP_FILEOPENFLAG_WRITE) {
flags |= base::PLATFORM_FILE_WRITE;
flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES;
}
if (mode & PP_FILEOPENFLAG_TRUNCATE) {
DCHECK(mode & PP_FILEOPENFLAG_WRITE);
flags |= base::PLATFORM_FILE_TRUNCATE;
}
if (mode & PP_FILEOPENFLAG_CREATE) {
if (mode & PP_FILEOPENFLAG_EXCLUSIVE)
flags |= base::PLATFORM_FILE_CREATE;
else
flags |= base::PLATFORM_FILE_OPEN_ALWAYS;
} else {
flags |= base::PLATFORM_FILE_OPEN;
}
base::PlatformFile base_file;
base::PlatformFileError result = instance->delegate()->OpenModuleLocalFile(
instance->module()->name(),
GetFilePathFromUTF8(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) {
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));
return PlatformFileErrorToPepperError(result);
}
int32_t DeleteModuleLocalFileOrDir(PP_Instance pp_instance,
const char* path,
PP_Bool recursive) {
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));
return PlatformFileErrorToPepperError(result);
}
int32_t CreateModuleLocalDir(PP_Instance pp_instance, const char* path) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
if (!instance)
return PP_ERROR_FAILED;
base::PlatformFileError result = instance->delegate()->CreateModuleLocalDir(
instance->module()->name(), GetFilePathFromUTF8(path));
return PlatformFileErrorToPepperError(result);
}
int32_t QueryModuleLocalFile(PP_Instance pp_instance,
const char* path,
PP_FileInfo_Dev* info) {
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);
if (result == base::PLATFORM_FILE_OK) {
info->size = file_info.size;
info->creation_time = file_info.creation_time.ToDoubleT();
info->last_access_time = file_info.last_accessed.ToDoubleT();
info->last_modified_time = file_info.last_modified.ToDoubleT();
info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
if (file_info.is_directory)
info->type = PP_FILETYPE_DIRECTORY;
else
info->type = PP_FILETYPE_REGULAR;
}
return PlatformFileErrorToPepperError(result);
}
int32_t GetModuleLocalDirContents(PP_Instance pp_instance,
const char* path,
PP_DirContents_Dev** contents) {
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);
if (result != base::PLATFORM_FILE_OK)
return PlatformFileErrorToPepperError(result);
*contents = new PP_DirContents_Dev;
size_t count = pepper_contents.size();
(*contents)->count = count;
(*contents)->entries = new PP_DirEntry_Dev[count];
for (size_t i = 0; i < count; ++i) {
PP_DirEntry_Dev& entry = (*contents)->entries[i];
#if defined(OS_WIN)
const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value());
#else
const std::string& name = pepper_contents[i].name.value();
#endif
size_t size = name.size() + 1;
char* name_copy = new char[size];
memcpy(name_copy, name.c_str(), size);
entry.name = name_copy;
entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir);
}
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;
}
PP_Bool NavigateToURL(PP_Instance pp_instance,
const char* url,
const char* target) {
@ -233,13 +66,6 @@ const PPB_Flash ppb_flash = {
&SetInstanceAlwaysOnTop,
&PPB_Flash_Impl::DrawGlyphs,
&GetProxyForURL,
&OpenModuleLocalFile,
&RenameModuleLocalFile,
&DeleteModuleLocalFileOrDir,
&CreateModuleLocalDir,
&QueryModuleLocalFile,
&GetModuleLocalDirContents,
&FreeModuleLocalDirContents,
&NavigateToURL,
&RunMessageLoop,
&QuitMessageLoop,