diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-20 00:15:43 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-20 00:15:43 +0000 |
commit | 130954003bdd03f9c3ae563a2ed67466528e71c5 (patch) | |
tree | c59200233fd6fdaeec0c6279efa5fdba2493f402 /chrome/common | |
parent | 8a871374acb440a7d35a7b6c10840c7a2f712b65 (diff) | |
download | chromium_src-130954003bdd03f9c3ae563a2ed67466528e71c5.zip chromium_src-130954003bdd03f9c3ae563a2ed67466528e71c5.tar.gz chromium_src-130954003bdd03f9c3ae563a2ed67466528e71c5.tar.bz2 |
Created a host for running the utility process as a child of the service process. This is used for rendering PDFs to a metafile in a sandbox for the Cloud Print proxy on Windows.
BUG=None
TEST=Test Windows Cloud Print proxy
Review URL: http://codereview.chromium.org/2917013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/common_param_traits.cc | 51 | ||||
-rw-r--r-- | chrome/common/common_param_traits.h | 25 | ||||
-rw-r--r-- | chrome/common/common_param_traits_unittest.cc | 72 | ||||
-rw-r--r-- | chrome/common/utility_messages_internal.h | 27 |
4 files changed, 175 insertions, 0 deletions
diff --git a/chrome/common/common_param_traits.cc b/chrome/common/common_param_traits.cc index 70227da..54bb550 100644 --- a/chrome/common/common_param_traits.cc +++ b/chrome/common/common_param_traits.cc @@ -7,6 +7,9 @@ #include "chrome/common/chrome_constants.h" #include "gfx/rect.h" #include "googleurl/src/gurl.h" +#include "printing/native_metafile.h" +#include "printing/page_range.h" + #ifndef EXCLUDE_SKIA_DEPENDENCIES #include "third_party/skia/include/core/SkBitmap.h" #endif @@ -302,4 +305,52 @@ void ParamTraits<Geoposition>::Log(const Geoposition& p, std::wstring* l) { LogParam(p.error_code, l); } +void ParamTraits<printing::PageRange>::Write(Message* m, const param_type& p) { + WriteParam(m, p.from); + WriteParam(m, p.to); +} + +bool ParamTraits<printing::PageRange>::Read( + const Message* m, void** iter, param_type* p) { + return ReadParam(m, iter, &p->from) && + ReadParam(m, iter, &p->to); +} + +void ParamTraits<printing::PageRange>::Log( + const param_type& p, std::wstring* l) { + l->append(L"("); + LogParam(p.to, l); + l->append(L", "); + LogParam(p.from, l); + l->append(L")"); +} + +void ParamTraits<printing::NativeMetafile>::Write( + Message* m, const param_type& p) { + std::vector<uint8> buffer; + uint32 size = p.GetDataSize(); + if (size) { + buffer.resize(size); + p.GetData(&buffer.front(), size); + } + WriteParam(m, buffer); +} + +bool ParamTraits<printing::NativeMetafile>::Read( + const Message* m, void** iter, param_type* p) { + std::vector<uint8> buffer; +#if defined(OS_WIN) + return ReadParam(m, iter, &buffer) && + p->CreateFromData(&buffer.front(), static_cast<uint32>(buffer.size())); +#else // defined(OS_WIN) + return ReadParam(m, iter, &buffer) && + p->Init(&buffer.front(), static_cast<uint32>(buffer.size())); +#endif // defined(OS_WIN) +} + +void ParamTraits<printing::NativeMetafile>::Log( + const param_type& p, std::wstring* l) { + l->append(StringPrintf(L"<printing::NativeMetafile>")); +} + } // namespace IPC diff --git a/chrome/common/common_param_traits.h b/chrome/common/common_param_traits.h index 4ac0272..300dd2e 100644 --- a/chrome/common/common_param_traits.h +++ b/chrome/common/common_param_traits.h @@ -22,6 +22,7 @@ #include "ipc/ipc_message_utils.h" #include "net/base/upload_data.h" #include "net/url_request/url_request_status.h" +#include "printing/native_metafile.h" #include "webkit/glue/password_form.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/window_open_disposition.h" @@ -38,6 +39,10 @@ class Rect; class Size; } // namespace gfx +namespace printing { +struct PageRange; +} // namespace printing + namespace webkit_glue { struct WebApplicationInfo; } // namespace webkit_glue @@ -474,6 +479,26 @@ struct ParamTraits<webkit_glue::PasswordForm> { } }; +template <> +struct ParamTraits<printing::PageRange> { + typedef printing::PageRange 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::wstring* l); +}; + +template <> +struct ParamTraits<printing::NativeMetafile> { + typedef printing::NativeMetafile 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::wstring* l); +}; + } // namespace IPC #endif // CHROME_COMMON_COMMON_PARAM_TRAITS_H_ diff --git a/chrome/common/common_param_traits_unittest.cc b/chrome/common/common_param_traits_unittest.cc index 842ea95..032f471 100644 --- a/chrome/common/common_param_traits_unittest.cc +++ b/chrome/common/common_param_traits_unittest.cc @@ -8,12 +8,23 @@ #include "base/scoped_ptr.h" #include "base/values.h" #include "chrome/common/common_param_traits.h" +#include "gfx/rect.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message.h" #include "ipc/ipc_message_utils.h" +#include "printing/native_metafile.h" +#include "printing/page_range.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#ifndef NDEBUG +namespace { +void IgnoreAssertHandler(const std::string& str) { +} +} // namespace + +#endif // NDEBUG + // Tests that serialize/deserialize correctly understand each other TEST(IPCMessageTest, Serialize) { const char* serialize_cases[] = { @@ -205,3 +216,64 @@ TEST(IPCMessageTest, Geoposition) { L"<Geoposition::ErrorCode>2", log_message.c_str()); } + +// Tests printing::PageRange serialization +TEST(IPCMessageTest, PageRange) { + printing::PageRange input; + input.from = 2; + input.to = 45; + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + IPC::ParamTraits<printing::PageRange>::Write(&msg, input); + + printing::PageRange output; + void* iter = NULL; + EXPECT_TRUE(IPC::ParamTraits<printing::PageRange>::Read( + &msg, &iter, &output)); + EXPECT_TRUE(input == output); +} + +// Tests printing::NativeMetafile serialization. +TEST(IPCMessageTest, Metafile) { + // TODO(sanjeevr): Make this test meaningful for non-Windows platforms. We + // need to initialize the metafile using alternate means on the other OSes. +#if defined(OS_WIN) + printing::NativeMetafile metafile; + RECT test_rect = {0, 0, 100, 100}; + // Create a metsfile using the screen DC as a reference. + metafile.CreateDc(NULL, NULL); + metafile.CloseDc(); + + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, metafile); + + printing::NativeMetafile output; + void* iter = NULL; + EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( + &msg, &iter, &output)); + + EXPECT_EQ(metafile.GetDataSize(), output.GetDataSize()); + EXPECT_EQ(metafile.GetBounds(), output.GetBounds()); + EXPECT_EQ(::GetDeviceCaps(metafile.hdc(), LOGPIXELSX), + ::GetDeviceCaps(output.hdc(), LOGPIXELSX)); + + // Also test the corrupt case. + IPC::Message bad_msg(1, 2, IPC::Message::PRIORITY_NORMAL); + // Write some bogus metafile data. + const size_t bogus_data_size = metafile.GetDataSize() * 2; + scoped_array<char> bogus_data(new char[bogus_data_size]); + memset(bogus_data.get(), 'B', bogus_data_size); + bad_msg.WriteData(bogus_data.get(), bogus_data_size); + // Make sure we don't read out the metafile! + printing::NativeMetafile bad_output; + iter = NULL; + // The Emf code on Windows DCHECKs if it cannot create the metafile. +#ifndef NDEBUG + logging::SetLogAssertHandler(IgnoreAssertHandler); +#endif // NDEBUG + EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( + &bad_msg, &iter, &bad_output)); +#else // defined(OS_WIN) + NOTIMPLEMENTED(); +#endif // defined(OS_WIN) +} + diff --git a/chrome/common/utility_messages_internal.h b/chrome/common/utility_messages_internal.h index 5c3f971..9231501 100644 --- a/chrome/common/utility_messages_internal.h +++ b/chrome/common/utility_messages_internal.h @@ -13,6 +13,10 @@ // from it via utility_messages.h. #include "ipc/ipc_message_macros.h" +#include "base/platform_file.h" +#include "gfx/rect.h" +#include "printing/native_metafile.h" +#include "printing/page_range.h" #include "third_party/skia/include/core/SkBitmap.h" //------------------------------------------------------------------------------ @@ -37,6 +41,13 @@ IPC_BEGIN_MESSAGES(Utility) // Tell the utility process to decode the given image data. IPC_MESSAGE_CONTROL1(UtilityMsg_DecodeImage, std::vector<unsigned char>) // encoded image contents + + // Tell the utility process to render the given PDF into a metafile. + IPC_MESSAGE_CONTROL4(UtilityMsg_RenderPDFPagesToMetafile, + base::PlatformFile, // PDF file + gfx::Rect, // Render Area + int, // DPI + std::vector<printing::PageRange>) IPC_END_MESSAGES(Utility) //------------------------------------------------------------------------------ @@ -84,4 +95,20 @@ IPC_BEGIN_MESSAGES(UtilityHost) // Reply when an error occured decoding the image. IPC_MESSAGE_CONTROL0(UtilityHostMsg_DecodeImage_Failed) + + // Reply when the utility process has succeeded in rendering the PDF. + IPC_MESSAGE_CONTROL2(UtilityHostMsg_RenderPDFPagesToMetafile_Succeeded, + printing::NativeMetafile, // Output metafile + int) // Highest rendered page number + + // Reply when an error occured rendering the PDF. + IPC_MESSAGE_CONTROL0(UtilityHostMsg_RenderPDFPagesToMetafile_Failed) + +#if defined(OS_WIN) + // Request that the given font be loaded by the host so it's cached by the + // OS. Please see ChildProcessHost::PreCacheFont for details. + IPC_SYNC_MESSAGE_CONTROL1_0(UtilityHostMsg_PreCacheFont, + LOGFONT /* font data */) +#endif // defined(OS_WIN) + IPC_END_MESSAGES(UtilityHost) |