summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-12 16:25:01 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-12 16:25:01 +0000
commit43a4020cd2aa067b10c55731978d9ac127a4cd50 (patch)
treee1fbf216dbd797608aa0eb7134b4e09700b50165 /ppapi
parent2140bd517307f12157235ff301c55ad84607c21a (diff)
downloadchromium_src-43a4020cd2aa067b10c55731978d9ac127a4cd50.zip
chromium_src-43a4020cd2aa067b10c55731978d9ac127a4cd50.tar.gz
chromium_src-43a4020cd2aa067b10c55731978d9ac127a4cd50.tar.bz2
Add proxies for some of the PDF & Flash functionality. There are still a few
unimplemented parts in the Flash proxy, and I only implemented the necessary part of the PDF one. TEST=none BUG=none Review URL: http://codereview.chromium.org/4752008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65951 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/ppapi.gyp6
-rw-r--r--ppapi/proxy/DEPS7
-rw-r--r--ppapi/proxy/dispatcher.cc12
-rw-r--r--ppapi/proxy/interface_id.h5
-rw-r--r--ppapi/proxy/plugin_resource.h2
-rw-r--r--ppapi/proxy/ppapi_messages.cc1
-rw-r--r--ppapi/proxy/ppapi_messages.h16
-rw-r--r--ppapi/proxy/ppapi_messages_internal.h66
-rw-r--r--ppapi/proxy/ppapi_param_traits.cc119
-rw-r--r--ppapi/proxy/ppapi_param_traits.h28
-rw-r--r--ppapi/proxy/ppb_buffer_proxy.cc151
-rw-r--r--ppapi/proxy/ppb_buffer_proxy.h41
-rw-r--r--ppapi/proxy/ppb_flash_proxy.cc288
-rw-r--r--ppapi/proxy/ppb_flash_proxy.h82
-rw-r--r--ppapi/proxy/ppb_pdf_proxy.cc166
-rw-r--r--ppapi/proxy/ppb_pdf_proxy.h46
16 files changed, 1034 insertions, 2 deletions
diff --git a/ppapi/ppapi.gyp b/ppapi/ppapi.gyp
index 56c8881..5d6f78e 100644
--- a/ppapi/ppapi.gyp
+++ b/ppapi/ppapi.gyp
@@ -518,12 +518,16 @@
'proxy/ppapi_messages_internal.h',
'proxy/ppapi_param_traits.cc',
'proxy/ppapi_param_traits.h',
+ 'proxy/ppb_buffer_proxy.cc',
+ 'proxy/ppb_buffer_proxy.h',
'proxy/ppb_char_set_proxy.cc',
'proxy/ppb_char_set_proxy.h',
'proxy/ppb_core_proxy.cc',
'proxy/ppb_core_proxy.h',
'proxy/ppb_cursor_control_proxy.cc',
'proxy/ppb_cursor_control_proxy.h',
+ 'proxy/ppb_flash_proxy.cc',
+ 'proxy/ppb_flash_proxy.h',
'proxy/ppb_font_proxy.cc',
'proxy/ppb_font_proxy.h',
'proxy/ppb_fullscreen_proxy.cc',
@@ -534,6 +538,8 @@
'proxy/ppb_image_data_proxy.h',
'proxy/ppb_instance_proxy.cc',
'proxy/ppb_instance_proxy.h',
+ 'proxy/ppb_pdf_proxy.cc',
+ 'proxy/ppb_pdf_proxy.h',
'proxy/ppb_testing_proxy.cc',
'proxy/ppb_testing_proxy.h',
'proxy/ppb_url_loader_proxy.cc',
diff --git a/ppapi/proxy/DEPS b/ppapi/proxy/DEPS
new file mode 100644
index 0000000..377524e
--- /dev/null
+++ b/ppapi/proxy/DEPS
@@ -0,0 +1,7 @@
+include_rules = [
+ # These files are really Chrome-only and we don't want to expose them, but
+ # we need to use them for the proxy. Allow the code here to pull these
+ # headers (which don't depend on anything else).
+ "+webkit/glue/plugins/ppb_private.h",
+ "+webkit/glue/plugins/ppb_private2.h",
+]
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index 491b964..b1ce1c4 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -12,9 +12,12 @@
#include "base/logging.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sync_channel.h"
+#include "ppapi/c/dev/ppb_buffer_dev.h"
#include "ppapi/c/dev/ppb_char_set_dev.h"
-#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/dev/ppb_cursor_control_dev.h"
+#include "ppapi/c/dev/ppb_cursor_control_dev.h"
+#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/c/dev/ppb_fullscreen_dev.h"
#include "ppapi/c/dev/ppb_fullscreen_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
@@ -28,6 +31,7 @@
#include "ppapi/c/ppb_url_response_info.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/ppb_buffer_proxy.h"
#include "ppapi/proxy/ppb_char_set_proxy.h"
#include "ppapi/proxy/ppb_core_proxy.h"
#include "ppapi/proxy/ppb_cursor_control_proxy.h"
@@ -36,6 +40,7 @@
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/ppb_instance_proxy.h"
+#include "ppapi/proxy/ppb_pdf_proxy.h"
#include "ppapi/proxy/ppb_testing_proxy.h"
#include "ppapi/proxy/ppb_url_loader_proxy.h"
#include "ppapi/proxy/ppb_url_request_info_proxy.h"
@@ -44,6 +49,7 @@
#include "ppapi/proxy/ppp_class_proxy.h"
#include "ppapi/proxy/ppp_instance_proxy.h"
#include "ppapi/proxy/var_serialization_rules.h"
+#include "webkit/glue/plugins/ppb_private.h"
namespace pp {
namespace proxy {
@@ -210,6 +216,8 @@ void Dispatcher::OnMsgDeclareInterfaces(
InterfaceProxy* Dispatcher::CreateProxyForInterface(
const std::string& interface_name,
const void* interface_functions) {
+ if (interface_name == PPB_BUFFER_DEV_INTERFACE)
+ return new PPB_Buffer_Proxy(this, interface_functions);
if (interface_name == PPB_CHAR_SET_DEV_INTERFACE)
return new PPB_CharSet_Proxy(this, interface_functions);
if (interface_name == PPB_CORE_INTERFACE)
@@ -226,6 +234,8 @@ InterfaceProxy* Dispatcher::CreateProxyForInterface(
return new PPB_ImageData_Proxy(this, interface_functions);
if (interface_name == PPB_INSTANCE_INTERFACE)
return new PPB_Instance_Proxy(this, interface_functions);
+ if (interface_name == PPB_PRIVATE_INTERFACE)
+ return new PPB_Pdf_Proxy(this, interface_functions);
if (interface_name == PPB_TESTING_DEV_INTERFACE)
return new PPB_Testing_Proxy(this, interface_functions);
if (interface_name == PPB_URLLOADER_INTERFACE)
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index c181a83..f0ae597 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -12,14 +12,17 @@ namespace proxy {
// to route messages to the appropriate message handler.
enum InterfaceID {
// Zero is reserved for control messages.
- INTERFACE_ID_PPB_CHAR_SET = 1,
+ INTERFACE_ID_PPB_BUFFER = 1,
+ INTERFACE_ID_PPB_CHAR_SET,
INTERFACE_ID_PPB_CORE,
INTERFACE_ID_PPB_CURSORCONTROL,
+ INTERFACE_ID_PPB_FLASH,
INTERFACE_ID_PPB_FONT,
INTERFACE_ID_PPB_FULLSCREEN,
INTERFACE_ID_PPB_GRAPHICS_2D,
INTERFACE_ID_PPB_IMAGE_DATA,
INTERFACE_ID_PPB_INSTANCE,
+ INTERFACE_ID_PPB_PDF,
INTERFACE_ID_PPB_TESTING,
INTERFACE_ID_PPB_URL_LOADER,
INTERFACE_ID_PPB_URL_REQUEST_INFO,
diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h
index 072f2cb..09ed59f 100644
--- a/ppapi/proxy/plugin_resource.h
+++ b/ppapi/proxy/plugin_resource.h
@@ -11,9 +11,11 @@
// If you inherit from resource, make sure you add the class name here.
#define FOR_ALL_RESOURCES(F) \
+ F(Buffer) \
F(Font) \
F(Graphics2D) \
F(ImageData) \
+ F(PrivateFontFile) \
F(URLLoader) \
F(URLRequestInfo)\
F(URLResponseInfo)
diff --git a/ppapi/proxy/ppapi_messages.cc b/ppapi/proxy/ppapi_messages.cc
index 1cc617b..da3601f 100644
--- a/ppapi/proxy/ppapi_messages.cc
+++ b/ppapi/proxy/ppapi_messages.cc
@@ -6,6 +6,7 @@
#include "base/file_path.h"
#include "ipc/ipc_channel_handle.h"
+#include "ppapi/c/dev/pp_file_info_dev.h"
#include "ppapi/c/ppb_var.h"
// This actually defines the implementations of all the IPC message functions.
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index dc68991..5b5caf2 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -34,6 +34,11 @@ struct SerializedFontDescription {
int32_t word_spacing;
};
+struct SerializedDirEntry {
+ std::string name;
+ bool is_dir;
+};
+
// Since there are so many parameters, DrawTextAt requires this separate
// structure. This includes everything but the font name. Because the font name
// is a var, it's much more convenient to use the normal way of passing a
@@ -50,6 +55,17 @@ struct PPBFont_DrawTextAt_Params {
PP_Bool image_data_is_opaque;
};
+struct PPBFlash_DrawGlyphs_Params {
+ PP_Resource pp_image_data;
+ SerializedFontDescription font_desc;
+ uint32_t color;
+ PP_Point position;
+ PP_Rect clip;
+ float transformation[3][3];
+ std::vector<uint16_t> glyph_indices;
+ std::vector<PP_Point> glyph_advances;
+};
+
} // namespace proxy
} // namespace pp
diff --git a/ppapi/proxy/ppapi_messages_internal.h b/ppapi/proxy/ppapi_messages_internal.h
index 2a2c636..3e85955 100644
--- a/ppapi/proxy/ppapi_messages_internal.h
+++ b/ppapi/proxy/ppapi_messages_internal.h
@@ -137,6 +137,13 @@ IPC_BEGIN_MESSAGES(PpapiHost)
IPC_MESSAGE_CONTROL1(PpapiHostMsg_PluginLoaded,
IPC::ChannelHandle /* handle */)
+ // PPB_Buffer.
+ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBBuffer_Create,
+ PP_Module /* module */,
+ int32_t /* size */,
+ PP_Resource /* result_resource */,
+ uint64_t /* result_shm_handle */)
+
// PPB_Core.
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_AddRefResource, PP_Resource)
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_ReleaseResource, PP_Resource)
@@ -178,6 +185,53 @@ IPC_BEGIN_MESSAGES(PpapiHost)
PP_Instance /* instance */,
PP_Bool /* result */)
+ // PPB_Flash.
+ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop,
+ PP_Instance /* instance */,
+ bool /* on_top */)
+ IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBFlash_DrawGlyphs,
+ pp::proxy::PPBFlash_DrawGlyphs_Params /* params */)
+ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_GetProxyForURL,
+ PP_Module /* module */,
+ std::string /* url */,
+ pp::proxy::SerializedVar /* result */)
+ IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBFlash_OpenModuleLocalFile,
+ PP_Module /* module */,
+ std::string /* path */,
+ int32_t /* mode */,
+ IPC::PlatformFileForTransit /* file_handle */,
+ int32_t /* result */)
+ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_RenameModuleLocalFile,
+ PP_Module /* module */,
+ std::string /* path_from */,
+ std::string /* path_to */,
+ int32_t /* result */)
+ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir,
+ PP_Module /* module */,
+ std::string /* path */,
+ bool /* recursive */,
+ int32_t /* result */)
+ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_CreateModuleLocalDir,
+ PP_Module /* module */,
+ std::string /* path */,
+ int32_t /* result */)
+ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBFlash_QueryModuleLocalFile,
+ PP_Module /* module */,
+ std::string /* path */,
+ PP_FileInfo_Dev /* info */,
+ int32_t /* result */)
+ IPC_SYNC_MESSAGE_ROUTED2_2(
+ PpapiHostMsg_PPBFlash_GetModuleLocalDirContents,
+ PP_Module /* module */,
+ 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 */,
+ std::string /* target */,
+ bool /* result */)
+
// PPB_Font.
IPC_SYNC_MESSAGE_ROUTED2_3(
PpapiHostMsg_PPBFont_Create,
@@ -282,6 +336,18 @@ IPC_BEGIN_MESSAGES(PpapiHost)
pp::proxy::SerializedVar /* out_exception */,
pp::proxy::SerializedVar /* result */)
+ IPC_SYNC_MESSAGE_ROUTED3_1(
+ PpapiHostMsg_PPBPdf_GetFontFileWithFallback,
+ PP_Module /* module */,
+ pp::proxy::SerializedFontDescription /* description */,
+ int32_t /* charset */,
+ PP_Resource /* result */)
+ IPC_SYNC_MESSAGE_ROUTED2_1(
+ PpapiHostMsg_PPBPdf_GetFontTableForPrivateFontFile,
+ PP_Resource /* font_file */,
+ uint32_t /* table */,
+ std::string /* result */)
+
// PPB_Testing.
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBTesting_ReadImageData,
PP_Resource /* device_context_2d */,
diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc
index 5e2dfd7..dbd527d 100644
--- a/ppapi/proxy/ppapi_param_traits.cc
+++ b/ppapi/proxy/ppapi_param_traits.cc
@@ -6,6 +6,7 @@
#include <string.h> // For memcpy
+#include "ppapi/c/dev/pp_file_info_dev.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/ppapi_messages.h"
@@ -36,6 +37,46 @@ bool ParamTraits<PP_Bool>::Read(const Message* m, void** iter, param_type* r) {
void ParamTraits<PP_Bool>::Log(const param_type& p, std::string* l) {
}
+// PP_FileInfo_Dev -------------------------------------------------------------
+
+// static
+void ParamTraits<PP_FileInfo_Dev>::Write(Message* m, const param_type& p) {
+ ParamTraits<int64_t>::Write(m, p.size);
+ ParamTraits<int>::Write(m, static_cast<int>(p.type));
+ ParamTraits<int>::Write(m, static_cast<int>(p.system_type));
+ ParamTraits<double>::Write(m, p.creation_time);
+ ParamTraits<double>::Write(m, p.last_access_time);
+ ParamTraits<double>::Write(m, p.last_modified_time);
+}
+
+// static
+bool ParamTraits<PP_FileInfo_Dev>::Read(const Message* m, void** iter,
+ param_type* r) {
+ int type, system_type;
+ if (!ParamTraits<int64_t>::Read(m, iter, &r->size) ||
+ !ParamTraits<int>::Read(m, iter, &type) ||
+ !ParamTraits<int>::Read(m, iter, &system_type) ||
+ !ParamTraits<double>::Read(m, iter, &r->creation_time) ||
+ !ParamTraits<double>::Read(m, iter, &r->last_access_time) ||
+ !ParamTraits<double>::Read(m, iter, &r->last_modified_time))
+ return false;
+ if (type != PP_FILETYPE_REGULAR &&
+ type != PP_FILETYPE_DIRECTORY &&
+ type != PP_FILETYPE_OTHER)
+ return false;
+ r->type = static_cast<PP_FileType_Dev>(type);
+ if (system_type != PP_FILESYSTEMTYPE_EXTERNAL &&
+ system_type != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
+ system_type != PP_FILESYSTEMTYPE_LOCALTEMPORARY)
+ return false;
+ r->system_type = static_cast<PP_FileSystemType_Dev>(system_type);
+ return true;
+}
+
+// static
+void ParamTraits<PP_FileInfo_Dev>::Log(const param_type& p, std::string* l) {
+}
+
// PP_InputEvent ---------------------------------------------------------------
// static
@@ -139,6 +180,62 @@ bool ParamTraits<PP_Size>::Read(const Message* m, void** iter, param_type* r) {
void ParamTraits<PP_Size>::Log(const param_type& p, std::string* l) {
}
+// PPBFlash_DrawGlyphs_Params --------------------------------------------------
+
+// static
+void ParamTraits<pp::proxy::PPBFlash_DrawGlyphs_Params>::Write(
+ Message* m,
+ const param_type& p) {
+ ParamTraits<PP_Resource>::Write(m, p.pp_image_data);
+ ParamTraits<pp::proxy::SerializedFontDescription>::Write(m, p.font_desc);
+ ParamTraits<uint32_t>::Write(m, p.color);
+ ParamTraits<PP_Point>::Write(m, p.position);
+ ParamTraits<PP_Rect>::Write(m, p.clip);
+ ParamTraits<float>::Write(m, p.transformation[0][0]);
+ ParamTraits<float>::Write(m, p.transformation[0][1]);
+ ParamTraits<float>::Write(m, p.transformation[0][2]);
+ ParamTraits<float>::Write(m, p.transformation[1][0]);
+ ParamTraits<float>::Write(m, p.transformation[1][1]);
+ ParamTraits<float>::Write(m, p.transformation[1][2]);
+ ParamTraits<float>::Write(m, p.transformation[2][0]);
+ ParamTraits<float>::Write(m, p.transformation[2][1]);
+ ParamTraits<float>::Write(m, p.transformation[2][2]);
+ ParamTraits<std::vector<uint16_t> >::Write(m, p.glyph_indices);
+ ParamTraits<std::vector<PP_Point> >::Write(m, p.glyph_advances);
+}
+
+// static
+bool ParamTraits<pp::proxy::PPBFlash_DrawGlyphs_Params>::Read(
+ const Message* m,
+ void** iter,
+ param_type* r) {
+ return
+ ParamTraits<PP_Resource>::Read(m, iter, &r->pp_image_data) &&
+ ParamTraits<pp::proxy::SerializedFontDescription>::Read(m, iter,
+ &r->font_desc) &&
+ ParamTraits<uint32_t>::Read(m, iter, &r->color) &&
+ ParamTraits<PP_Point>::Read(m, iter, &r->position) &&
+ ParamTraits<PP_Rect>::Read(m, iter, &r->clip) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[0][0]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[0][1]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[0][2]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[1][0]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[1][1]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[1][2]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[2][0]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[2][1]) &&
+ ParamTraits<float>::Read(m, iter, &r->transformation[2][2]) &&
+ ParamTraits<std::vector<uint16_t> >::Read(m, iter, &r->glyph_indices) &&
+ ParamTraits<std::vector<PP_Point> >::Read(m, iter, &r->glyph_advances) &&
+ r->glyph_indices.size() == r->glyph_advances.size();
+}
+
+// static
+void ParamTraits<pp::proxy::PPBFlash_DrawGlyphs_Params>::Log(
+ const param_type& p,
+ std::string* l) {
+}
+
// PPBFont_DrawTextAt_Params ---------------------------------------------------
// static
@@ -179,6 +276,28 @@ void ParamTraits<pp::proxy::PPBFont_DrawTextAt_Params>::Log(
std::string* l) {
}
+// SerializedDirEntry ----------------------------------------------------------
+
+// static
+void ParamTraits<pp::proxy::SerializedDirEntry>::Write(Message* m,
+ const param_type& p) {
+ ParamTraits<std::string>::Write(m, p.name);
+ ParamTraits<bool>::Write(m, p.is_dir);
+}
+
+// static
+bool ParamTraits<pp::proxy::SerializedDirEntry>::Read(const Message* m,
+ void** iter,
+ param_type* r) {
+ return ParamTraits<std::string>::Read(m, iter, &r->name) &&
+ ParamTraits<bool>::Read(m, iter, &r->is_dir);
+}
+
+// static
+void ParamTraits<pp::proxy::SerializedDirEntry>::Log(const param_type& p,
+ std::string* l) {
+}
+
// SerializedVar ---------------------------------------------------------------
// static
diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h
index 2bb2a7a..fea2594d 100644
--- a/ppapi/proxy/ppapi_param_traits.h
+++ b/ppapi/proxy/ppapi_param_traits.h
@@ -6,17 +6,21 @@
#define PPAPI_PROXY_PPAPI_PARAM_TRAITS_H_
#include "ipc/ipc_message_utils.h"
+#include "ipc/ipc_platform_file.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_input_event.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/proxy/serialized_var.h" // TODO(brettw) eraseme.
+struct PP_FileInfo_Dev;
struct PP_ObjectProperty;
namespace pp {
namespace proxy {
+struct PPBFlash_DrawGlyphs_Params;
struct PPBFont_DrawTextAt_Params;
+struct SerializedDirEntry;
struct SerializedFontDescription;
class SerializedVar;
}
@@ -33,6 +37,14 @@ struct ParamTraits<PP_Bool> {
};
template<>
+struct ParamTraits<PP_FileInfo_Dev> {
+ typedef PP_FileInfo_Dev param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+template<>
struct ParamTraits<PP_InputEvent> {
typedef PP_InputEvent param_type;
static void Write(Message* m, const param_type& p);
@@ -73,6 +85,14 @@ struct ParamTraits<PP_Size> {
};
template<>
+struct ParamTraits<pp::proxy::PPBFlash_DrawGlyphs_Params> {
+ typedef pp::proxy::PPBFlash_DrawGlyphs_Params param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+template<>
struct ParamTraits<pp::proxy::PPBFont_DrawTextAt_Params> {
typedef pp::proxy::PPBFont_DrawTextAt_Params param_type;
static void Write(Message* m, const param_type& p);
@@ -81,6 +101,14 @@ struct ParamTraits<pp::proxy::PPBFont_DrawTextAt_Params> {
};
template<>
+struct ParamTraits<pp::proxy::SerializedDirEntry> {
+ typedef pp::proxy::SerializedDirEntry param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+template<>
struct ParamTraits<pp::proxy::SerializedFontDescription> {
typedef pp::proxy::SerializedFontDescription param_type;
static void Write(Message* m, const param_type& p);
diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc
new file mode 100644
index 0000000..610ef0b
--- /dev/null
+++ b/ppapi/proxy/ppb_buffer_proxy.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2010 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_buffer_proxy.h"
+
+#include <vector>
+
+#include "base/logging.h"
+#include "build/build_config.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/dev/ppb_buffer_dev.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace pp {
+namespace proxy {
+
+class Buffer : public PluginResource {
+ public:
+ Buffer(uint64_t memory_handle, int32_t size);
+ virtual ~Buffer();
+
+ // Resource overrides.
+ virtual Buffer* AsBuffer() { return this; }
+
+ int32_t size() const { return size_; }
+
+ void* Map();
+ void Unmap();
+
+ private:
+ uint64_t memory_handle_;
+ int32_t size_;
+
+ void* mapped_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(Buffer);
+};
+
+Buffer::Buffer(uint64_t memory_handle, int32_t size)
+ : memory_handle_(memory_handle),
+ size_(size),
+ mapped_data_(NULL) {
+}
+
+Buffer::~Buffer() {
+ Unmap();
+}
+
+void* Buffer::Map() {
+ // TODO(brettw) implement this.
+ return mapped_data_;
+}
+
+void Buffer::Unmap() {
+ // TODO(brettw) implement this.
+}
+
+namespace {
+
+PP_Resource Create(PP_Module module_id, int32_t size) {
+ PP_Resource result = 0;
+ uint64_t shm_handle = -1;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBBuffer_Create(
+ INTERFACE_ID_PPB_BUFFER, module_id, size,
+ &result, &shm_handle));
+ if (!result)
+ return 0;
+
+ linked_ptr<Buffer> object(new Buffer(shm_handle, size));
+ PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
+ result, object);
+ return result;
+}
+
+PP_Bool IsBuffer(PP_Resource resource) {
+ Buffer* object = PluginResource::GetAs<Buffer>(resource);
+ return BoolToPPBool(!!object);
+}
+
+PP_Bool Describe(PP_Resource resource, int32_t* size_in_bytes) {
+ Buffer* object = PluginResource::GetAs<Buffer>(resource);
+ if (!object) {
+ *size_in_bytes = 0;
+ return PP_FALSE;
+ }
+ *size_in_bytes = object->size();
+ return PP_TRUE;
+}
+
+void* Map(PP_Resource resource) {
+ Buffer* object = PluginResource::GetAs<Buffer>(resource);
+ if (!object)
+ return NULL;
+ return object->Map();
+}
+
+void Unmap(PP_Resource resource) {
+ Buffer* object = PluginResource::GetAs<Buffer>(resource);
+ if (object)
+ object->Unmap();
+}
+
+const PPB_Buffer_Dev ppb_buffer = {
+ &Create,
+ &IsBuffer,
+ &Describe,
+ &Map,
+ &Unmap,
+};
+
+} // namespace
+
+PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Buffer_Proxy::~PPB_Buffer_Proxy() {
+}
+
+const void* PPB_Buffer_Proxy::GetSourceInterface() const {
+ return &ppb_buffer;
+}
+
+InterfaceID PPB_Buffer_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_BUFFER;
+}
+
+void PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate)
+ IPC_END_MESSAGE_MAP()
+ // TODO(brettw) handle bad messages!
+}
+
+void PPB_Buffer_Proxy::OnMsgCreate(PP_Module module,
+ int32_t size,
+ PP_Resource* result_resource,
+ uint64_t* result_shm_handle) {
+ *result_resource = ppb_buffer_target()->Create(module, size);
+ // TODO(brettw) set the shm handle from a trusted interface.
+ *result_shm_handle = 0;
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_buffer_proxy.h b/ppapi/proxy/ppb_buffer_proxy.h
new file mode 100644
index 0000000..e1bedf9
--- /dev/null
+++ b/ppapi/proxy/ppb_buffer_proxy.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2010 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_BUFFER_PROXY_H_
+#define PPAPI_PPB_BUFFER_PROXY_H_
+
+#include "ppapi/c/pp_module.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPB_Buffer_Dev;
+
+namespace pp {
+namespace proxy {
+
+class PPB_Buffer_Proxy : public InterfaceProxy {
+ public:
+ PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_Buffer_Proxy();
+
+ const PPB_Buffer_Dev* ppb_buffer_target() const {
+ return static_cast<const PPB_Buffer_Dev*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgCreate(PP_Module module,
+ int32_t size,
+ PP_Resource* result_resource,
+ uint64_t* result_shm_handle);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PPB_BUFFER_PROXY_H_
diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc
new file mode 100644
index 0000000..2a6e237
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_proxy.cc
@@ -0,0 +1,288 @@
+// Copyright (c) 2010 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_proxy.h"
+
+#include "base/logging.h"
+#include "build/build_config.h"
+#include "ppapi/c/dev/pp_file_info_dev.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/serialized_var.h"
+#include "webkit/glue/plugins/ppb_private2.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;
+*/
+ *error = PP_ERROR_NOACCESS;
+ return INVALID_HANDLE_VALUE;
+#elif defined(OS_POSIX)
+ return base::FileDescriptor(file, true);
+#endif
+}
+
+void SetInstanceAlwaysOnTop(PP_Instance pp_instance, bool on_top) {
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop(
+ INTERFACE_ID_PPB_FLASH, pp_instance, on_top));
+}
+
+bool DrawGlyphs(PP_Resource pp_image_data,
+ const PP_FontDescription_Dev* font_desc,
+ uint32_t color,
+ PP_Point position,
+ PP_Rect clip,
+ float transformation[3][3],
+ uint32_t glyph_count,
+ uint16_t glyph_indices[],
+ PP_Point glyph_advances[]) {
+ return false; // TODO(brettw): implement this.
+}
+
+PP_Var GetProxyForURL(PP_Module pp_module, const char* url) {
+ ReceiveSerializedVarReturnValue result;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_GetProxyForURL(
+ INTERFACE_ID_PPB_FLASH, pp_module, url, &result));
+ return result.Return(PluginDispatcher::Get());
+}
+
+int32_t OpenModuleLocalFile(PP_Module module,
+ const char* path,
+ int32_t mode,
+ PP_FileHandle* file) {
+ int32_t result = PP_ERROR_FAILED;
+ IPC::PlatformFileForTransit transit;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_OpenModuleLocalFile(
+ INTERFACE_ID_PPB_FLASH, module, path, mode, &transit, &result));
+ *file = IPC::PlatformFileForTransitToPlatformFile(transit);
+ return result;
+}
+
+int32_t RenameModuleLocalFile(PP_Module module,
+ const char* path_from,
+ const char* path_to) {
+ int32_t result = PP_ERROR_FAILED;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_RenameModuleLocalFile(
+ INTERFACE_ID_PPB_FLASH, module, path_from, path_to, &result));
+ return result;
+}
+
+int32_t DeleteModuleLocalFileOrDir(PP_Module module,
+ const char* path,
+ bool recursive) {
+ int32_t result = PP_ERROR_FAILED;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBFlash_DeleteModuleLocalFileOrDir(
+ INTERFACE_ID_PPB_FLASH, module, path, recursive, &result));
+ return result;
+}
+
+int32_t CreateModuleLocalDir(PP_Module module, const char* path) {
+ int32_t result = PP_ERROR_FAILED;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFlash_CreateModuleLocalDir(
+ INTERFACE_ID_PPB_FLASH, module, path, &result));
+ return result;
+}
+
+int32_t QueryModuleLocalFile(PP_Module module,
+ const char* path,
+ PP_FileInfo_Dev* info) {
+ int32_t result = PP_ERROR_FAILED;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBFlash_QueryModuleLocalFile(
+ INTERFACE_ID_PPB_FLASH, module, path, info, &result));
+ return result;
+}
+
+int32_t GetModuleLocalDirContents(PP_Module module,
+ const char* path,
+ PP_DirContents_Dev** contents) {
+ int32_t result = PP_ERROR_FAILED;
+ std::vector<SerializedDirEntry> entries;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBFlash_GetModuleLocalDirContents(
+ INTERFACE_ID_PPB_FLASH, module, path, &entries, &result));
+
+ // TODO(brettw) implement this.
+
+ return result;
+}
+
+void FreeModuleLocalDirContents(PP_Module module,
+ PP_DirContents_Dev* contents) {
+ // TODO(brettw) implement this.
+}
+
+bool NavigateToURL(PP_Instance pp_instance,
+ const char* url,
+ const char* target) {
+ bool result = false;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBFlash_NavigateToURL(
+ INTERFACE_ID_PPB_FLASH, pp_instance, url, target, &result));
+ return result;
+}
+
+const PPB_Private2 ppb_flash = {
+ &SetInstanceAlwaysOnTop,
+ &DrawGlyphs,
+ &GetProxyForURL,
+ &OpenModuleLocalFile,
+ &RenameModuleLocalFile,
+ &DeleteModuleLocalFileOrDir,
+ &CreateModuleLocalDir,
+ &QueryModuleLocalFile,
+ &GetModuleLocalDirContents,
+ &FreeModuleLocalDirContents,
+ &NavigateToURL,
+};
+
+} // namespace
+
+PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Flash_Proxy::~PPB_Flash_Proxy() {
+}
+
+const void* PPB_Flash_Proxy::GetSourceInterface() const {
+ return &ppb_flash;
+}
+
+InterfaceID PPB_Flash_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_FLASH;
+}
+
+void PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop,
+ OnMsgSetInstanceAlwaysOnTop)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DrawGlyphs,
+ 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_END_MESSAGE_MAP()
+ // TODO(brettw) handle bad messages!
+}
+
+void PPB_Flash_Proxy::OnMsgSetInstanceAlwaysOnTop(
+ PP_Instance instance,
+ bool on_top) {
+ ppb_flash_target()->SetInstanceAlwaysOnTop(instance, on_top);
+}
+
+void PPB_Flash_Proxy::OnMsgDrawGlyphs(
+ const pp::proxy::PPBFlash_DrawGlyphs_Params& params) {
+ // TODO(brettw) implement this.
+}
+
+void PPB_Flash_Proxy::OnMsgGetProxyForURL(PP_Module module,
+ const std::string& url,
+ SerializedVarReturnValue result) {
+ result.Return(dispatcher(), ppb_flash_target()->GetProxyForURL(
+ module, url.c_str()));
+}
+
+void PPB_Flash_Proxy::OnMsgOpenModuleLocalFile(
+ PP_Module module,
+ const std::string& path,
+ int32_t mode,
+ IPC::PlatformFileForTransit* file_handle,
+ int32_t* result) {
+ base::PlatformFile file;
+ *result = ppb_flash_target()->OpenModuleLocalFile(module, path.c_str(), mode,
+ &file);
+ *file_handle = PlatformFileToPlatformFileForTransit(result, file);
+}
+
+void PPB_Flash_Proxy::OnMsgRenameModuleLocalFile(
+ PP_Module module,
+ const std::string& path_from,
+ const std::string& path_to,
+ int32_t* result) {
+ *result = ppb_flash_target()->RenameModuleLocalFile(module, path_from.c_str(),
+ path_to.c_str());
+}
+
+void PPB_Flash_Proxy::OnMsgDeleteModuleLocalFileOrDir(
+ PP_Module module,
+ const std::string& path,
+ bool recursive,
+ int32_t* result) {
+ *result = ppb_flash_target()->DeleteModuleLocalFileOrDir(module, path.c_str(),
+ recursive);
+}
+
+void PPB_Flash_Proxy::OnMsgCreateModuleLocalDir(PP_Module module,
+ const std::string& path,
+ int32_t* result) {
+ *result = ppb_flash_target()->CreateModuleLocalDir(module, path.c_str());
+}
+
+void PPB_Flash_Proxy::OnMsgQueryModuleLocalFile(PP_Module module,
+ const std::string& path,
+ PP_FileInfo_Dev* info,
+ int32_t* result) {
+ *result = ppb_flash_target()->QueryModuleLocalFile(module, path.c_str(),
+ info);
+}
+
+void PPB_Flash_Proxy::OnMsgGetModuleLocalDirContents(
+ PP_Module module,
+ const std::string& path,
+ std::vector<pp::proxy::SerializedDirEntry>* entries,
+ int32_t* result) {
+ // TODO(brettw) implement this.
+}
+
+void PPB_Flash_Proxy::OnMsgNavigateToURL(PP_Instance instance,
+ const std::string& url,
+ const std::string& target,
+ bool* result) {
+ *result = ppb_flash_target()->NavigateToURL(instance, url.c_str(),
+ target.c_str());
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h
new file mode 100644
index 0000000..0c7f1ab
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_proxy.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2010 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_PROXY_H_
+#define PPAPI_PPB_FLASH_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_Private2;
+
+namespace pp {
+namespace proxy {
+
+struct PPBFlash_DrawGlyphs_Params;
+struct SerializedDirEntry;
+class SerializedVar;
+class SerializedVarReturnValue;
+
+class PPB_Flash_Proxy : public InterfaceProxy {
+ public:
+ PPB_Flash_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_Flash_Proxy();
+
+ const PPB_Private2* ppb_flash_target() const {
+ return static_cast<const PPB_Private2*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgSetInstanceAlwaysOnTop(PP_Instance instance,
+ bool on_top);
+ void OnMsgDrawGlyphs(const pp::proxy::PPBFlash_DrawGlyphs_Params& params);
+ void OnMsgGetProxyForURL(PP_Module module,
+ const std::string& url,
+ SerializedVarReturnValue result);
+ void OnMsgOpenModuleLocalFile(PP_Module module,
+ const std::string& path,
+ int32_t mode,
+ IPC::PlatformFileForTransit* file_handle,
+ int32_t* result);
+ void OnMsgRenameModuleLocalFile(PP_Module module,
+ const std::string& path_from,
+ const std::string& path_to,
+ int32_t* result);
+ void OnMsgDeleteModuleLocalFileOrDir(PP_Module module,
+ const std::string& path,
+ bool recursive,
+ int32_t* result);
+ void OnMsgCreateModuleLocalDir(PP_Module module,
+ const std::string& path,
+ int32_t* result);
+ void OnMsgQueryModuleLocalFile(PP_Module module,
+ const std::string& path,
+ PP_FileInfo_Dev* info,
+ int32_t* result);
+ void OnMsgGetModuleLocalDirContents(
+ PP_Module module,
+ 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,
+ bool* result);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PPB_FLASH_PROXY_H_
diff --git a/ppapi/proxy/ppb_pdf_proxy.cc b/ppapi/proxy/ppb_pdf_proxy.cc
new file mode 100644
index 0000000..c706804
--- /dev/null
+++ b/ppapi/proxy/ppb_pdf_proxy.cc
@@ -0,0 +1,166 @@
+// Copyright (c) 2010 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_pdf_proxy.h"
+
+#include <string.h> // For memcpy.
+
+#include <map>
+
+#include "base/linked_ptr.h"
+#include "base/logging.h"
+#include "build/build_config.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "webkit/glue/plugins/ppb_private.h"
+
+namespace pp {
+namespace proxy {
+
+class PrivateFontFile : public PluginResource {
+ public:
+ PrivateFontFile() {}
+ virtual ~PrivateFontFile() {}
+
+ // Resource overrides.
+ virtual PrivateFontFile* AsPrivateFontFile() { return this; }
+
+ // Sees if we have a cache of the font table and returns a pointer to it.
+ // Returns NULL if we don't have it.
+ std::string* GetFontTable(uint32_t table) const;
+
+ std::string* AddFontTable(uint32_t table, const std::string& contents);
+
+ private:
+ typedef std::map<uint32_t, linked_ptr<std::string> > FontTableMap;
+ FontTableMap font_tables_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrivateFontFile);
+};
+
+std::string* PrivateFontFile::GetFontTable(uint32_t table) const {
+ FontTableMap::const_iterator found = font_tables_.find(table);
+ if (found == font_tables_.end())
+ return NULL;
+ return found->second.get();
+}
+
+std::string* PrivateFontFile::AddFontTable(uint32_t table,
+ const std::string& contents) {
+ linked_ptr<std::string> heap_string(new std::string(contents));
+ font_tables_[table] = heap_string;
+ return heap_string.get();
+}
+
+namespace {
+
+PP_Resource GetFontFileWithFallback(
+ PP_Module module_id,
+ const PP_FontDescription_Dev* description,
+ PP_PrivateFontCharset charset) {
+ SerializedFontDescription desc;
+ // TODO(brettw): serialize the description!
+
+ PP_Resource result = 0;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBPdf_GetFontFileWithFallback(
+ INTERFACE_ID_PPB_PDF, module_id, desc, charset, &result));
+ if (!result)
+ return 0;
+
+ linked_ptr<PrivateFontFile> object(new PrivateFontFile);
+ PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
+ result, object);
+ return result;
+}
+
+bool GetFontTableForPrivateFontFile(PP_Resource font_file,
+ uint32_t table,
+ void* output,
+ uint32_t* output_length) {
+ PrivateFontFile* object = PluginResource::GetAs<PrivateFontFile>(font_file);
+ if (!object)
+ return false;
+
+ std::string* contents = object->GetFontTable(table);
+ if (!contents) {
+ std::string deserialized;
+ PluginDispatcher::Get()->Send(
+ new PpapiHostMsg_PPBPdf_GetFontTableForPrivateFontFile(
+ INTERFACE_ID_PPB_PDF, font_file, table, &deserialized));
+ if (deserialized.empty())
+ return false;
+ contents = object->AddFontTable(table, deserialized);
+ }
+
+ *output_length = static_cast<uint32_t>(contents->size());
+ if (output)
+ memcpy(output, contents->c_str(), *output_length);
+ return true;
+}
+
+const PPB_Private ppb_private = {
+ NULL, // &GetLocalizedString,
+ NULL, // &GetResourceImage,
+ &GetFontFileWithFallback,
+ &GetFontTableForPrivateFontFile,
+};
+
+} // namespace
+
+PPB_Pdf_Proxy::PPB_Pdf_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Pdf_Proxy::~PPB_Pdf_Proxy() {
+}
+
+const void* PPB_Pdf_Proxy::GetSourceInterface() const {
+ return &ppb_private;
+}
+
+InterfaceID PPB_Pdf_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_PDF;
+}
+
+void PPB_Pdf_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_Pdf_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBPdf_GetFontFileWithFallback,
+ OnMsgGetFontFileWithFallback)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBPdf_GetFontTableForPrivateFontFile,
+ OnMsgGetFontTableForPrivateFontFile)
+ IPC_END_MESSAGE_MAP()
+ // TODO(brettw): handle bad messages!
+}
+
+void PPB_Pdf_Proxy::OnMsgGetFontFileWithFallback(
+ PP_Module module,
+ const SerializedFontDescription& in_desc,
+ int32_t charset,
+ PP_Resource* result) {
+ PP_FontDescription_Dev desc;
+ // TODO(brettw) deserialize this value!
+ *result = ppb_pdf_target()->GetFontFileWithFallback(module, &desc,
+ static_cast<PP_PrivateFontCharset>(charset));
+}
+
+void PPB_Pdf_Proxy::OnMsgGetFontTableForPrivateFontFile(PP_Resource font_file,
+ uint32_t table,
+ std::string* result) {
+ // TODO(brettw): It would be nice not to copy here. At least on Linux,
+ // we can map the font file into shared memory and read it that way.
+ uint32_t table_length = 0;
+ if (!ppb_pdf_target()->GetFontTableForPrivateFontFile(
+ font_file, table, NULL, &table_length))
+ return;
+
+ result->resize(table_length);
+ ppb_pdf_target()->GetFontTableForPrivateFontFile(font_file, table,
+ const_cast<char*>(result->c_str()), &table_length);
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_pdf_proxy.h b/ppapi/proxy/ppb_pdf_proxy.h
new file mode 100644
index 0000000..43b90d6
--- /dev/null
+++ b/ppapi/proxy/ppb_pdf_proxy.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2010 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_PDF_PROXY_H_
+#define PPAPI_PPB_PDF_PROXY_H_
+
+#include "ppapi/c/pp_module.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPB_Private;
+
+namespace pp {
+namespace proxy {
+
+struct SerializedFontDescription;
+
+class PPB_Pdf_Proxy : public InterfaceProxy {
+ public:
+ PPB_Pdf_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_Pdf_Proxy();
+
+ const PPB_Private* ppb_pdf_target() const {
+ return static_cast<const PPB_Private*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgGetFontFileWithFallback(PP_Module module,
+ const SerializedFontDescription& desc,
+ int32_t charset,
+ PP_Resource* result);
+ void OnMsgGetFontTableForPrivateFontFile(PP_Resource font_file,
+ uint32_t table,
+ std::string* result);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PPB_PDF_PROXY_H_