Commit f5869d8b authored by raymes@chromium.org's avatar raymes@chromium.org

Implement the host side of the PPB_PDF proxy.

TBR=brettw@chromium.org


Review URL: https://chromiumcodereview.appspot.com/13004012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192669 0039d316-1c4b-4281-b951-d872f2087c98
parent c89aae03
......@@ -228,6 +228,8 @@
'renderer/pepper/pepper_flash_renderer_host.h',
'renderer/pepper/pepper_helper.cc',
'renderer/pepper/pepper_helper.h',
'renderer/pepper/pepper_pdf_host.cc',
'renderer/pepper/pepper_pdf_host.h',
'renderer/pepper/pepper_shared_memory_message_filter.cc',
'renderer/pepper/pepper_shared_memory_message_filter.h',
'renderer/pepper/ppb_nacl_private_impl.cc',
......
......@@ -10,6 +10,7 @@
#include "chrome/renderer/pepper/pepper_flash_fullscreen_host.h"
#include "chrome/renderer/pepper/pepper_flash_menu_host.h"
#include "chrome/renderer/pepper/pepper_flash_renderer_host.h"
#include "chrome/renderer/pepper/pepper_pdf_host.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/host/resource_host.h"
......@@ -96,6 +97,16 @@ ChromeRendererPepperHostFactory::CreateResourceHost(
}
}
if (host_->GetPpapiHost()->permissions().HasPermission(
ppapi::PERMISSION_PRIVATE)) {
switch (message.type()) {
case PpapiHostMsg_PDF_Create::ID: {
return scoped_ptr<ResourceHost>(new PepperPDFHost(
host_, instance, params.pp_resource()));
}
}
}
return scoped_ptr<ResourceHost>();
}
......
This diff is collapsed.
// Copyright (c) 2013 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 CHROME_RENDERER_PEPPER_PEPPER_PDF_HOST_H_
#define CHROME_RENDERER_PEPPER_PEPPER_PDF_HOST_H_
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ppapi/c/ppb_image_data.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/serialized_structs.h"
struct PP_Size;
class SkBitmap;
namespace content {
class RendererPpapiHost;
}
namespace ppapi {
class HostResource;
}
namespace ppapi {
namespace host {
struct HostMessageContext;
}
}
namespace chrome {
class PepperPDFHost : public ppapi::host::ResourceHost {
public:
PepperPDFHost(content::RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource);
virtual ~PepperPDFHost();
virtual int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) OVERRIDE;
private:
int32_t OnHostMsgGetLocalizedString(ppapi::host::HostMessageContext* context,
PP_ResourceString string_id);
int32_t OnHostMsgDidStartLoading(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgDidStopLoading(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgSetContentRestriction(
ppapi::host::HostMessageContext* context,
int restrictions);
int32_t OnHostMsgUserMetricsRecordAction(
ppapi::host::HostMessageContext* context,
const std::string& action);
int32_t OnHostMsgHasUnsupportedFeature(
ppapi::host::HostMessageContext* context);
int32_t OnHostMsgPrint(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgSaveAs(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgGetResourceImage(ppapi::host::HostMessageContext* context,
PP_ResourceImage image_id,
float scale);
bool CreateImageData(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
const SkBitmap& pixels_to_write,
ppapi::HostResource* result,
std::string* out_image_data_desc,
ppapi::proxy::ImageHandle* out_image_handle,
uint32_t* out_byte_count);
content::RendererPpapiHost* host_;
DISALLOW_COPY_AND_ASSIGN(PepperPDFHost);
};
} // namespace chrome
#endif // CHROME_RENDERER_PEPPER_PEPPER_PDF_HOST_H_
......@@ -1252,6 +1252,8 @@ TEST_PPAPI_OUT_OF_PROCESS(FlashFile)
#endif
TEST_PPAPI_OUT_OF_PROCESS(MAYBE_FlashFullscreen)
TEST_PPAPI_OUT_OF_PROCESS(PDF)
TEST_PPAPI_IN_PROCESS(TalkPrivate)
TEST_PPAPI_OUT_OF_PROCESS(TalkPrivate)
......
......@@ -495,6 +495,8 @@
'tests/test_flash_message_loop.h',
'tests/test_net_address_private.cc',
'tests/test_net_address_private.h',
'tests/test_pdf.cc',
'tests/test_pdf.h',
'tests/test_resource_array.cc',
'tests/test_resource_array.h',
'tests/test_struct_sizes.c',
......
......@@ -164,8 +164,9 @@ PP_Resource PDFResource::GetResourceImageForScale(PP_ResourceImage image_id,
HostResource resource;
std::string image_data_desc;
int fd;
if (!UnpackMessage<PpapiPluginMsg_PDF_GetResourceImageReply>(
reply, &resource, &image_data_desc)) {
reply, &resource, &image_data_desc, &fd)) {
return 0;
}
......@@ -176,19 +177,18 @@ PP_Resource PDFResource::GetResourceImageForScale(PP_ResourceImage image_id,
PP_ImageDataDesc desc;
memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
base::SharedMemoryHandle handle;
if (!reply_params.TakeSharedMemoryHandleAtIndex(0, &handle))
return 0;
// We always succeed after this point (on non-android platforms, so we don't
// have to worry about leaking |handle|.
#if defined(OS_ANDROID)
// This is compiled into android for tests only.
return 0;
#elif defined(OS_WIN) || defined(OS_MACOSX)
base::SharedMemoryHandle handle;
if (!reply_params.TakeSharedMemoryHandleAtIndex(0, &handle))
return 0;
return (new ImageData(resource, desc, handle))->GetReference();
#elif defined(OS_LINUX)
return (new ImageData(resource, desc, fd))->GetReference();
#else
return (new ImageData(resource, desc, handle.fd))->GetReference();
#error Not implemented.
#endif
}
......
......@@ -171,7 +171,8 @@ TEST_F(PDFResourceTest, GetResourceImageForScale) {
memcpy(&image_data_desc[0], &expected_desc, sizeof(PP_ImageDataDesc));
SerializedHandle serialized_handle(SerializedHandle::SHARED_MEMORY);
PpapiPluginMsg_PDF_GetResourceImageReply reply_msg(expected_resource,
image_data_desc);
image_data_desc,
0);
ResourceSyncCallHandler handler(
&sink(),
PpapiHostMsg_PDF_GetResourceImage::ID,
......
......@@ -41,6 +41,7 @@
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/c/private/ppb_host_resolver_private.h"
#include "ppapi/c/private/ppb_net_address_private.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/c/private/ppb_tcp_socket_private.h"
#include "ppapi/c/private/ppb_udp_socket_private.h"
#include "ppapi/c/private/ppp_flash_browser_operations.h"
......@@ -85,6 +86,8 @@ IPC_ENUM_TRAITS(PP_PrintOrientation_Dev)
IPC_ENUM_TRAITS(PP_PrintOutputFormat_Dev)
IPC_ENUM_TRAITS(PP_PrintScalingOption_Dev)
IPC_ENUM_TRAITS(PP_PrivateFontCharset)
IPC_ENUM_TRAITS(PP_ResourceImage)
IPC_ENUM_TRAITS(PP_ResourceString)
IPC_ENUM_TRAITS(PP_TextInput_Type)
IPC_ENUM_TRAITS(PP_TrueTypeFontFamily_Dev)
IPC_ENUM_TRAITS(PP_TrueTypeFontStyle_Dev)
......@@ -1130,21 +1133,6 @@ IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Start,
IPC_MESSAGE_CONTROL1(PpapiHostMsg_PPBNetworkMonitor_Stop,
uint32 /* plugin_dispatcher_id */)
#if !defined(OS_NACL) && !defined(NACL_WIN64)
// PPB_PDF
IPC_SYNC_MESSAGE_ROUTED3_1(
PpapiHostMsg_PPBPDF_GetFontFileWithFallback,
PP_Instance /* instance */,
ppapi::proxy::SerializedFontDescription /* description */,
int32_t /* charset */,
ppapi::HostResource /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(
PpapiHostMsg_PPBPDF_GetFontTableForPrivateFontFile,
ppapi::HostResource /* font_file */,
uint32_t /* table */,
std::string /* result */)
#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
// PPB_Testing.
IPC_SYNC_MESSAGE_ROUTED3_1(
PpapiHostMsg_PPBTesting_ReadImageData,
......@@ -1753,7 +1741,7 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_PDF_Create)
// Requests the localized string for the given ID.
IPC_MESSAGE_CONTROL1(PpapiHostMsg_PDF_GetLocalizedString,
int /* string_id */)
PP_ResourceString /* string_id */)
// Reply for PpapiHostMsg_PDF_GetLocalizedString containing the localized
// string.
IPC_MESSAGE_CONTROL1(PpapiPluginMsg_PDF_GetLocalizedStringReply,
......@@ -1784,15 +1772,18 @@ IPC_MESSAGE_CONTROL0(PpapiHostMsg_PDF_SaveAs)
// Requests a resource image for the plugin at a particular scale.
IPC_MESSAGE_CONTROL2(PpapiHostMsg_PDF_GetResourceImage,
int /* image_id */,
PP_ResourceImage /* image_id */,
float /* scale */)
// Reply for PpapiHostMsg_PDF_GetResourceImage containing the host resource id
// of the image and a string (representing a PP_ImageDataDesc) containing the
// properties of the image. Also carries a shared memory handle pointing to the
// memory containg the image.
IPC_MESSAGE_CONTROL2(PpapiPluginMsg_PDF_GetResourceImageReply,
// memory containg the image. On linux, the handle is transmitted in this
// message as |fd|. This is due to the unfortunate way that ImageHandles are
// defined for use with PPB_ImageData.
IPC_MESSAGE_CONTROL3(PpapiPluginMsg_PDF_GetResourceImageReply,
ppapi::HostResource /* resource_id */,
std::string /* image_data_desc */)
std::string /* image_data_desc */,
int /* fd */)
// VideoCapture_Dev, plugin -> host
IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_Create)
......
......@@ -17,6 +17,7 @@
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb_image_data.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/proxy/ppapi_proxy_export.h"
#include "ppapi/proxy/serialized_structs.h"
#include "ppapi/shared_impl/ppb_image_data_shared.h"
#include "ppapi/shared_impl/resource.h"
......@@ -31,9 +32,10 @@ class SerializedHandle;
// The proxied image data resource. Unlike most resources, this needs to be
// public in the header since a number of other resources need to access it.
class ImageData : public ppapi::Resource,
public ppapi::thunk::PPB_ImageData_API,
public ppapi::PPB_ImageData_Shared {
class PPAPI_PROXY_EXPORT ImageData
: public ppapi::Resource,
public NON_EXPORTED_BASE(ppapi::thunk::PPB_ImageData_API),
public ppapi::PPB_ImageData_Shared {
public:
#if !defined(OS_NACL)
ImageData(const ppapi::HostResource& resource,
......
......@@ -117,6 +117,7 @@ struct PPPDecryptor_Buffer {
base::SharedMemoryHandle handle;
};
// TODO(raymes): Make ImageHandle compatible with SerializedHandle.
#if defined(OS_WIN)
typedef HANDLE ImageHandle;
#elif defined(OS_MACOSX) || defined(OS_ANDROID)
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/tests/test_pdf.h"
#include "ppapi/c/private/ppb_pdf.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/point.h"
#include "ppapi/cpp/private/pdf.h"
#include "ppapi/cpp/var.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(PDF);
TestPDF::TestPDF(TestingInstance* instance)
: TestCase(instance) {
}
void TestPDF::RunTests(const std::string& filter) {
RUN_TEST(GetLocalizedString, filter);
RUN_TEST(GetResourceImage, filter);
}
std::string TestPDF::TestGetLocalizedString() {
pp::Var string = pp::PDF::GetLocalizedString(instance_,
PP_RESOURCESTRING_PDFGETPASSWORD);
ASSERT_TRUE(string.is_string());
ASSERT_EQ("This document is password protected. Please enter a password.",
string.AsString());
PASS();
}
std::string TestPDF::TestGetResourceImage() {
pp::ImageData data =
pp::PDF::GetResourceImage(instance_, PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN);
ASSERT_EQ(43, data.size().width());
ASSERT_EQ(42, data.size().height());
for (int i = 0; i < data.size().width(); ++i) {
for (int j = 0; j < data.size().height(); ++j) {
pp::Point point(i, j);
ASSERT_NE(*data.GetAddr32(point), 0);
}
}
PASS();
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PAPPI_TESTS_TEST_PDF_H_
#define PAPPI_TESTS_TEST_PDF_H_
#include <string>
#include "ppapi/c/pp_stdint.h"
#include "ppapi/tests/test_case.h"
class TestPDF : public TestCase {
public:
explicit TestPDF(TestingInstance* instance);
// TestCase implementation.
virtual void RunTests(const std::string& filter);
private:
std::string TestGetLocalizedString();
std::string TestGetResourceImage();
};
#endif // PAPPI_TESTS_TEST_PDF_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment