diff options
author | dpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-02 19:25:17 +0000 |
---|---|---|
committer | dpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-02 19:25:17 +0000 |
commit | 5ad7617cd93b48a67395f532b8483b8ace445ca2 (patch) | |
tree | ef6ec65870ccdea737de7e0fdcf1d89e2d887511 /chrome | |
parent | f83773f72845ed180a23dcbbfa9afbc3c295f758 (diff) | |
download | chromium_src-5ad7617cd93b48a67395f532b8483b8ace445ca2.zip chromium_src-5ad7617cd93b48a67395f532b8483b8ace445ca2.tar.gz chromium_src-5ad7617cd93b48a67395f532b8483b8ace445ca2.tar.bz2 |
Applying factory pattern (through NativeMetafileFactory class). It is used to retrieve different printing contexts (based on the platform and user preferences).
BUG=NONE
TEST=NONE
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=76553
Reverted: http://src.chromium.org/viewvc/chrome?view=rev&revision=76555
Review URL: http://codereview.chromium.org/6544028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/printing/print_view_manager.cc | 3 | ||||
-rw-r--r-- | chrome/common/common_param_traits_unittest.cc | 39 | ||||
-rw-r--r-- | chrome/plugin/webplugin_delegate_stub.cc | 22 | ||||
-rw-r--r-- | chrome/renderer/mock_printer.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 22 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_mac.mm | 31 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_pepper.cc | 40 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.cc | 16 | ||||
-rw-r--r-- | chrome/service/service_utility_process_host.cc | 14 | ||||
-rw-r--r-- | chrome/utility/utility_thread.cc | 15 |
11 files changed, 134 insertions, 87 deletions
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 8a8de31..42b0500 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -18,6 +18,7 @@ #include "content/browser/tab_contents/navigation_entry.h" #include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" +#include "printing/native_metafile_factory.h" #include "printing/native_metafile.h" #include "printing/printed_document.h" #include "ui/base/l10n/l10n_util.h" @@ -130,7 +131,7 @@ void PrintViewManager::OnDidPrintPage( } } - scoped_ptr<NativeMetafile> metafile(new NativeMetafile()); + scoped_ptr<NativeMetafile> metafile(NativeMetafileFactory::CreateMetafile()); if (metafile_must_be_valid) { if (!metafile->Init(shared_buf.memory(), params.data_size)) { NOTREACHED() << "Invalid metafile header"; diff --git a/chrome/common/common_param_traits_unittest.cc b/chrome/common/common_param_traits_unittest.cc index 9a95c0f0..1dd62f6 100644 --- a/chrome/common/common_param_traits_unittest.cc +++ b/chrome/common/common_param_traits_unittest.cc @@ -14,12 +14,16 @@ #include "ipc/ipc_message_utils.h" #include "net/base/host_port_pair.h" #include "printing/backend/print_backend.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" #include "ui/gfx/rect.h" +#if defined(OS_WIN) +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" +#endif + // Tests that serialize/deserialize correctly understand each other TEST(IPCMessageTest, Serialize) { const char* serialize_cases[] = { @@ -227,42 +231,45 @@ TEST(IPCMessageTest, PageRange) { EXPECT_TRUE(input == output); } -// Tests printing::NativeMetafile serialization. +// Tests printing::Emf serialization. // 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) TEST(IPCMessageTest, Metafile) { - printing::NativeMetafile metafile; + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); RECT test_rect = {0, 0, 100, 100}; - // Create a metsfile using the screen DC as a reference. - metafile.CreateDc(NULL, NULL); - metafile.CloseDc(); + // Create a metafile 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); + IPC::ParamTraits<printing::NativeMetafile>::Write(&msg, *metafile); - printing::NativeMetafile output; + scoped_ptr<printing::NativeMetafile> output( + printing::NativeMetafileFactory::CreateMetafile()); void* iter = NULL; EXPECT_TRUE(IPC::ParamTraits<printing::NativeMetafile>::Read( - &msg, &iter, &output)); + &msg, &iter, output.get())); - EXPECT_EQ(metafile.GetDataSize(), output.GetDataSize()); - EXPECT_EQ(metafile.GetBounds(), output.GetBounds()); - EXPECT_EQ(::GetDeviceCaps(metafile.hdc(), LOGPIXELSX), - ::GetDeviceCaps(output.hdc(), LOGPIXELSX)); + 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; + 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; + scoped_ptr<printing::NativeMetafile> bad_output( + printing::NativeMetafileFactory::CreateMetafile()); iter = NULL; EXPECT_FALSE(IPC::ParamTraits<printing::NativeMetafile>::Read( - &bad_msg, &iter, &bad_output)); + &bad_msg, &iter, bad_output.get())); } #endif // defined(OS_WIN) diff --git a/chrome/plugin/webplugin_delegate_stub.cc b/chrome/plugin/webplugin_delegate_stub.cc index 6b0f39a..75a3dc8 100644 --- a/chrome/plugin/webplugin_delegate_stub.cc +++ b/chrome/plugin/webplugin_delegate_stub.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 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. @@ -14,7 +14,6 @@ #include "chrome/plugin/plugin_channel.h" #include "chrome/plugin/plugin_thread.h" #include "chrome/plugin/webplugin_proxy.h" -#include "printing/native_metafile.h" #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npruntime.h" #include "skia/ext/platform_device.h" @@ -23,6 +22,12 @@ #include "webkit/plugins/npapi/webplugin_delegate_impl.h" #include "webkit/glue/webcursor.h" +#if defined(OS_WIN) +#include "base/scoped_ptr.h" +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" +#endif // defined(OS_WIN) + #if defined(ENABLE_GPU) #include "app/gfx/gl/gl_context.h" #endif @@ -281,26 +286,27 @@ void WebPluginDelegateStub::OnDidPaint() { void WebPluginDelegateStub::OnPrint(base::SharedMemoryHandle* shared_memory, uint32* size) { #if defined(OS_WIN) - printing::NativeMetafile metafile; - if (!metafile.CreateDc(NULL, NULL)) { + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); + if (!metafile->CreateDc(NULL, NULL)) { NOTREACHED(); return; } - HDC hdc = metafile.hdc(); + HDC hdc = metafile->hdc(); skia::PlatformDevice::InitializeDC(hdc); delegate_->Print(hdc); - if (!metafile.CloseDc()) { + if (!metafile->CloseDc()) { NOTREACHED(); return; } - *size = metafile.GetDataSize(); + *size = metafile->GetDataSize(); DCHECK(*size); base::SharedMemory shared_buf; CreateSharedBuffer(*size, &shared_buf, shared_memory); // Retrieve a copy of the data. - bool success = metafile.GetData(shared_buf.memory(), *size); + bool success = metafile->GetData(shared_buf.memory(), *size); DCHECK(success); #else // TODO(port): plugin printing. diff --git a/chrome/renderer/mock_printer.cc b/chrome/renderer/mock_printer.cc index b579f88..4510bfc 100644 --- a/chrome/renderer/mock_printer.cc +++ b/chrome/renderer/mock_printer.cc @@ -9,6 +9,8 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "ipc/ipc_message_utils.h" +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" #include "printing/units.h" #include "testing/gtest/include/gtest/gtest.h" @@ -131,9 +133,10 @@ void MockPrinter::PrintPage(const ViewHostMsg_DidPrintPage_Params& params) { base::SharedMemory metafile_data(params.metafile_data_handle, true); #endif metafile_data.Map(params.data_size); - printing::NativeMetafile metafile; - metafile.Init(metafile_data.memory(), params.data_size); - printing::Image image(metafile); + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); + metafile->Init(metafile_data.memory(), params.data_size); + printing::Image image(*metafile); MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(), params.data_size, image); diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index c4446d3..8fec47f 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -6,8 +6,10 @@ #include "base/file_descriptor_posix.h" #include "base/logging.h" +#include "base/scoped_ptr.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" +#include "printing/native_metafile_factory.h" #include "printing/native_metafile.h" #include "skia/ext/vector_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" @@ -23,14 +25,15 @@ void PrintWebViewHelper::CreatePreviewDocument( const ViewMsg_PrintPages_Params& params, WebFrame* frame) { // We only can use PDF in the renderer because Cairo needs to create a // temporary file for a PostScript surface. - printing::NativeMetafile metafile; + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); int page_count = 0; - if (!RenderPages(params, frame, false, &page_count, &metafile)) + if (!RenderPages(params, frame, false, &page_count, metafile.get())) return; // Get the size of the resulting metafile. - uint32 buf_size = metafile.GetDataSize(); + uint32 buf_size = metafile->GetDataSize(); DCHECK_GT(buf_size, 0u); ViewHostMsg_DidPreviewDocument_Params preview_params; @@ -38,7 +41,7 @@ void PrintWebViewHelper::CreatePreviewDocument( preview_params.expected_pages_count = page_count; preview_params.data_size = buf_size; - if (!CopyMetafileDataToSharedMem(&metafile, + if (!CopyMetafileDataToSharedMem(metafile.get(), &(preview_params.metafile_data_handle))) { preview_params.expected_pages_count = 0; preview_params.data_size = 0; @@ -51,7 +54,8 @@ void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, WebNode* node) { // We only can use PDF in the renderer because Cairo needs to create a // temporary file for a PostScript surface. - printing::NativeMetafile metafile; + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); int page_count = 0; bool send_expected_page_count = #if defined(OS_CHROMEOS) @@ -61,12 +65,12 @@ void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, #endif // defined(OS_CHROMEOS) if (!RenderPages(params, frame, send_expected_page_count, &page_count, - &metafile)) { + metafile.get())) { return; } // Get the size of the resulting metafile. - uint32 buf_size = metafile.GetDataSize(); + uint32 buf_size = metafile->GetDataSize(); DCHECK_GT(buf_size, 0u); #if defined(OS_CHROMEOS) @@ -78,7 +82,7 @@ void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, &sequence_number))) { return; } - if (!metafile.SaveTo(fd)) + if (!metafile->SaveTo(fd)) return; // Tell the browser we've finished writing the file. @@ -105,7 +109,7 @@ void PrintWebViewHelper::PrintPages(const ViewMsg_PrintPages_Params& params, NOTREACHED() << "Map failed"; return; } - metafile.GetData(shared_buf.memory(), buf_size); + metafile->GetData(shared_buf.memory(), buf_size); printed_page_params.data_size = buf_size; shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), &(printed_page_params.metafile_data_handle)); diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm index 4abae95..4dc218c 100644 --- a/chrome/renderer/print_web_view_helper_mac.mm +++ b/chrome/renderer/print_web_view_helper_mac.mm @@ -7,8 +7,11 @@ #import <AppKit/AppKit.h> #include "base/logging.h" +#include "base/scoped_ptr.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" using WebKit::WebFrame; @@ -16,8 +19,9 @@ using WebKit::WebFrame; void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, const gfx::Size& canvas_size, WebFrame* frame) { - printing::NativeMetafile metafile; - if (!metafile.Init()) + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); + if (!metafile->Init()) return; float scale_factor = frame->getPrintPageShrink(params.page_number); @@ -26,11 +30,11 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, // Render page for printing. gfx::Point origin(0.0f, 0.0f); RenderPage(params.params.printable_size, origin, scale_factor, page_number, - frame, &metafile); - metafile.Close(); + frame, metafile.get()); + metafile->Close(); ViewHostMsg_DidPrintPage_Params page_params; - page_params.data_size = metafile.GetDataSize(); + page_params.data_size = metafile->GetDataSize(); page_params.page_number = page_number; page_params.document_cookie = params.params.document_cookie; page_params.actual_shrink = scale_factor; @@ -41,7 +45,7 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, params.params.printable_size.height()); // Ask the browser to create the shared memory for us. - if (!CopyMetafileDataToSharedMem(&metafile, + if (!CopyMetafileDataToSharedMem(metafile.get(), &(page_params.metafile_data_handle))) { page_params.data_size = 0; } @@ -61,8 +65,9 @@ void PrintWebViewHelper::CreatePreviewDocument( if (!page_count) return; - printing::NativeMetafile metafile; - if (!metafile.Init()) + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); + if (!metafile->Init()) return; float scale_factor = frame->getPrintPageShrink(0); @@ -70,25 +75,25 @@ void PrintWebViewHelper::CreatePreviewDocument( if (params.pages.empty()) { for (int i = 0; i < page_count; ++i) { RenderPage(printParams.page_size, origin, scale_factor, i, frame, - &metafile); + metafile.get()); } } else { for (size_t i = 0; i < params.pages.size(); ++i) { if (params.pages[i] >= page_count) break; RenderPage(printParams.page_size, origin, scale_factor, - static_cast<int>(params.pages[i]), frame, &metafile); + static_cast<int>(params.pages[i]), frame, metafile.get()); } } - metafile.Close(); + metafile->Close(); ViewHostMsg_DidPreviewDocument_Params preview_params; - preview_params.data_size = metafile.GetDataSize(); + preview_params.data_size = metafile->GetDataSize(); preview_params.document_cookie = params.params.document_cookie; preview_params.expected_pages_count = page_count; // Ask the browser to create the shared memory for us. - if (!CopyMetafileDataToSharedMem(&metafile, + if (!CopyMetafileDataToSharedMem(metafile.get(), &(preview_params.metafile_data_handle))) { preview_params.data_size = 0; preview_params.expected_pages_count = 0; diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index ccce2e9..e0332c8 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -8,6 +8,8 @@ #include "base/process_util.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" #include "printing/units.h" #include "skia/ext/vector_canvas.h" #include "skia/ext/vector_platform_device.h" @@ -67,7 +69,8 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, WebFrame* frame) { // Generate a memory-based metafile. It will use the current screen's DPI. // Each metafile contains a single page. - scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); metafile->CreateDc(NULL, NULL); DCHECK(metafile->hdc()); skia::PlatformDevice::InitializeDC(metafile->hdc()); @@ -133,7 +136,8 @@ void PrintWebViewHelper::CreatePreviewDocument( // PDF backend" work is completed for windows, make changes to replace this // EMF with PDF metafile. // http://code.google.com/p/chromium/issues/detail?id=62889 - scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); metafile->CreateDc(NULL, NULL); DCHECK(metafile->hdc()); skia::PlatformDevice::InitializeDC(metafile->hdc()); @@ -258,7 +262,7 @@ void PrintWebViewHelper::RenderPage( NOTREACHED(); scoped_ptr<printing::NativeMetafile> metafile2( - new printing::NativeMetafile); + printing::NativeMetafileFactory::CreateMetafile()); // Page used alpha blend, but printer doesn't support it. Rewrite the // metafile and flatten out the transparency. HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); diff --git a/chrome/renderer/webplugin_delegate_pepper.cc b/chrome/renderer/webplugin_delegate_pepper.cc index 921138f..43709f8 100644 --- a/chrome/renderer/webplugin_delegate_pepper.cc +++ b/chrome/renderer/webplugin_delegate_pepper.cc @@ -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. @@ -15,18 +15,12 @@ #include "base/file_path.h" #include "base/file_util.h" -#if defined(OS_MACOSX) -#include "base/mac/mac_util.h" -#endif #include "base/md5.h" #include "base/message_loop.h" #include "base/metrics/histogram.h" #include "base/metrics/stats_counters.h" #include "base/path_service.h" #include "base/process_util.h" -#if defined(OS_MACOSX) -#include "base/mac/scoped_cftyperef.h" -#endif #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string_util.h" @@ -39,17 +33,9 @@ #include "chrome/renderer/pepper_widget.h" #include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_view.h" -#if defined(OS_LINUX) -#include "chrome/renderer/renderer_sandbox_support_linux.h" -#endif #include "chrome/renderer/webplugin_delegate_proxy.h" #include "ui/gfx/blit.h" -#if defined(OS_WIN) -#include "printing/units.h" -#include "skia/ext/vector_platform_device.h" -#include "ui/gfx/codec/jpeg_codec.h" -#include "ui/gfx/gdi_util.h" -#endif +#include "printing/native_metafile_factory.h" #include "printing/native_metafile.h" #include "third_party/npapi/bindings/npapi_extensions.h" #include "third_party/npapi/bindings/npapi_extensions_private.h" @@ -64,6 +50,19 @@ #include "webkit/plugins/npapi/plugin_host.h" #include "webkit/plugins/npapi/plugin_stream_url.h" +#if defined(OS_MACOSX) +#include "base/mac/mac_util.h" +#include "base/mac/scoped_cftyperef.h" +#elif defined(OS_LINUX) +#include "chrome/renderer/renderer_sandbox_support_linux.h" +#include "printing/pdf_ps_metafile_cairo.h" +#elif defined(OS_WIN) +#include "printing/units.h" +#include "skia/ext/vector_platform_device.h" +#include "ui/gfx/codec/jpeg_codec.h" +#include "ui/gfx/gdi_util.h" +#endif + #if defined(ENABLE_GPU) #include "webkit/plugins/npapi/plugin_constants_win.h" #endif @@ -1222,7 +1221,7 @@ bool WebPluginDelegatePepper::VectorPrintPage(int page_number, // directly. cairo_t* context = canvas->beginPlatformPaint(); printing::NativeMetafile* metafile = - printing::NativeMetafile::FromCairoContext(context); + printing::PdfPsMetafile::FromCairoContext(context); DCHECK(metafile); if (metafile) { ret = metafile->SetRawData(pdf_output, output_size); @@ -1231,14 +1230,15 @@ bool WebPluginDelegatePepper::VectorPrintPage(int page_number, } canvas->endPlatformPaint(); #elif defined(OS_MACOSX) - printing::NativeMetafile metafile; + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); // Create a PDF metafile and render from there into the passed in context. - if (metafile.Init(pdf_output, output_size)) { + if (metafile->Init(pdf_output, output_size)) { // Flip the transform. CGContextSaveGState(canvas); CGContextTranslateCTM(canvas, 0, current_printable_area_.height()); CGContextScaleCTM(canvas, 1.0, -1.0); - ret = metafile.RenderPage(1, canvas, current_printable_area_.ToCGRect(), + ret = metafile->RenderPage(1, canvas, current_printable_area_.ToCGRect(), true, false, true, true); CGContextRestoreGState(canvas); } diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 0c98871..bc65843 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -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. @@ -15,6 +15,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/ref_counted.h" +#include "base/scoped_ptr.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/sys_info.h" @@ -33,7 +34,6 @@ #include "grit/renderer_resources.h" #include "ipc/ipc_channel_handle.h" #include "net/base/mime_util.h" -#include "printing/native_metafile.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" @@ -54,6 +54,11 @@ #include "ipc/ipc_channel_posix.h" #endif +#if defined(OS_WIN) +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" +#endif + using WebKit::WebBindings; using WebKit::WebCursorInfo; using WebKit::WebDragData; @@ -926,13 +931,14 @@ void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { } #if defined(OS_WIN) - printing::NativeMetafile metafile; - if (!metafile.Init(memory.memory(), size)) { + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); + if (!metafile->Init(memory.memory(), size)) { NOTREACHED(); return; } // Playback the buffer. - metafile.Playback(context, NULL); + metafile->Playback(context, NULL); #else // TODO(port): plugin printing. NOTIMPLEMENTED(); diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc index b63e27f..a340d8d 100644 --- a/chrome/service/service_utility_process_host.cc +++ b/chrome/service/service_utility_process_host.cc @@ -13,13 +13,15 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/utility_messages.h" #include "ipc/ipc_switches.h" -#include "printing/native_metafile.h" #include "printing/page_range.h" #include "ui/base/ui_base_switches.h" #include "ui/gfx/rect.h" #if defined(OS_WIN) +#include "base/scoped_ptr.h" #include "base/win/scoped_handle.h" +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" #endif ServiceUtilityProcessHost::ServiceUtilityProcessHost( @@ -202,13 +204,15 @@ void ServiceUtilityProcessHost::Client::MetafileAvailable( if (!scratch_metafile_dir.Set(metafile_path.DirName())) LOG(WARNING) << "Unable to set scratch metafile directory"; #if defined(OS_WIN) - printing::NativeMetafile metafile; - if (!metafile.CreateFromFile(metafile_path)) { + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); + if (!metafile->CreateFromFile(metafile_path)) { OnRenderPDFPagesToMetafileFailed(); } else { - OnRenderPDFPagesToMetafileSucceeded(metafile, highest_rendered_page_number); + OnRenderPDFPagesToMetafileSucceeded(*metafile, + highest_rendered_page_number); // Close it so that ScopedTempDir can delete the folder. - metafile.CloseEmf(); + metafile->CloseEmf(); } #endif // defined(OS_WIN) } diff --git a/chrome/utility/utility_thread.cc b/chrome/utility/utility_thread.cc index 6d078e3..0556cbb 100644 --- a/chrome/utility/utility_thread.cc +++ b/chrome/utility/utility_thread.cc @@ -18,7 +18,6 @@ #include "chrome/common/serialized_script_value.h" #include "chrome/common/utility_messages.h" #include "chrome/common/web_resource/web_resource_unpacker.h" -#include "printing/native_metafile.h" #include "printing/page_range.h" #include "printing/units.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -29,7 +28,10 @@ #if defined(OS_WIN) #include "app/win/iat_patch_function.h" +#include "base/scoped_ptr.h" #include "base/win/scoped_handle.h" +#include "printing/native_metafile_factory.h" +#include "printing/native_metafile.h" #endif namespace { @@ -135,10 +137,15 @@ void UtilityThread::OnRenderPDFPagesToMetafile( const std::vector<printing::PageRange>& page_ranges) { bool succeeded = false; #if defined(OS_WIN) - printing::NativeMetafile metafile; + scoped_ptr<printing::NativeMetafile> metafile( + printing::NativeMetafileFactory::CreateMetafile()); int highest_rendered_page_number = 0; - succeeded = RenderPDFToWinMetafile(pdf_file, metafile_path, render_area, - render_dpi, page_ranges, &metafile, + succeeded = RenderPDFToWinMetafile(pdf_file, + metafile_path, + render_area, + render_dpi, + page_ranges, + metafile.get(), &highest_rendered_page_number); if (succeeded) { Send(new UtilityHostMsg_RenderPDFPagesToMetafile_Succeeded( |