summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 21:54:06 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-11 21:54:06 +0000
commit7d748990b39550c77aa914ba6846885dd7352e10 (patch)
tree3777582ee9816b3488f218b594db1918e5ebe752 /chrome
parent03e204f307255e8f39aeb002f94b8eb04137e7f9 (diff)
downloadchromium_src-7d748990b39550c77aa914ba6846885dd7352e10.zip
chromium_src-7d748990b39550c77aa914ba6846885dd7352e10.tar.gz
chromium_src-7d748990b39550c77aa914ba6846885dd7352e10.tar.bz2
Connect the right metafiles for print preview on Linux and Windows.
+ Remove the NativeMetafileFactory since we can't just use preview flag. + Update each Metafile constructor site to use PreviewMetafile or NativeMetafileImpl. + Fix misc. problems blocking pdf generation on Windows. + Rename the metafile interface. BUG=NONE TEST=NONE Review URL: http://codereview.chromium.org/6826027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/printing/print_dialog_gtk.cc5
-rw-r--r--chrome/browser/printing/print_dialog_gtk.h10
-rw-r--r--chrome/browser/printing/print_view_manager.cc10
-rw-r--r--chrome/browser/ui/webui/print_preview_handler.cc18
-rw-r--r--chrome/common/common_param_traits_unittest.cc5
-rw-r--r--chrome/renderer/mock_printer.cc11
-rw-r--r--chrome/renderer/print_web_view_helper.cc3
-rw-r--r--chrome/renderer/print_web_view_helper.h12
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc42
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm37
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc137
11 files changed, 133 insertions, 157 deletions
diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc
index 24d87fb..4f549db 100644
--- a/chrome/browser/printing/print_dialog_gtk.cc
+++ b/chrome/browser/printing/print_dialog_gtk.cc
@@ -17,6 +17,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
+#include "printing/metafile.h"
#include "printing/print_settings_initializer_gtk.h"
// static
@@ -85,7 +86,7 @@ void PrintDialogGtk::ShowDialog(
gtk_widget_show(dialog_);
}
-void PrintDialogGtk::PrintDocument(const NativeMetafile* metafile,
+void PrintDialogGtk::PrintDocument(const printing::Metafile* metafile,
const string16& document_name) {
// This runs on the print worker thread, does not block the UI thread.
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -164,7 +165,7 @@ void PrintDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
}
}
-void PrintDialogGtk::SaveDocumentToDisk(const NativeMetafile* metafile,
+void PrintDialogGtk::SaveDocumentToDisk(const printing::Metafile* metafile,
const string16& document_name) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
diff --git a/chrome/browser/printing/print_dialog_gtk.h b/chrome/browser/printing/print_dialog_gtk.h
index 79266b3..c6d999f 100644
--- a/chrome/browser/printing/print_dialog_gtk.h
+++ b/chrome/browser/printing/print_dialog_gtk.h
@@ -13,7 +13,6 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/browser_thread.h"
-#include "printing/native_metafile.h"
#include "printing/print_dialog_gtk_interface.h"
#include "printing/printing_context_cairo.h"
#include "ui/base/gtk/gtk_signal.h"
@@ -22,7 +21,10 @@ namespace base {
class WaitableEvent;
}
-using printing::NativeMetafile;
+namespace printing {
+class Metafile;
+}
+
using printing::PrintingContextCairo;
// Needs to be freed on the UI thread to clean up its GTK members variables.
@@ -38,7 +40,7 @@ class PrintDialogGtk
// printing::PrintDialogGtkInterface implementation.
virtual void ShowDialog(
PrintingContextCairo::PrintSettingsCallback* callback);
- virtual void PrintDocument(const NativeMetafile* metafile,
+ virtual void PrintDocument(const printing::Metafile* metafile,
const string16& document_name);
virtual void AddRefToDialog();
virtual void ReleaseDialog();
@@ -54,7 +56,7 @@ class PrintDialogGtk
CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, int);
// Saves data in |metafile| to disk for document named |document_name|.
- void SaveDocumentToDisk(const NativeMetafile* metafile,
+ void SaveDocumentToDisk(const printing::Metafile* metafile,
const string16& document_name);
// Prints document named |document_name|.
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 4d8cdda..fdae7ed 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -19,8 +19,8 @@
#include "content/common/notification_details.h"
#include "content/common/notification_source.h"
#include "grit/generated_resources.h"
-#include "printing/native_metafile.h"
-#include "printing/native_metafile_factory.h"
+#include "printing/metafile.h"
+#include "printing/metafile_impl.h"
#include "printing/printed_document.h"
#include "ui/base/l10n/l10n_util.h"
@@ -146,11 +146,9 @@ void PrintViewManager::OnDidPrintPage(
}
}
- scoped_ptr<NativeMetafile> metafile;
+ scoped_ptr<Metafile> metafile(new NativeMetafile);
if (metafile_must_be_valid) {
- metafile.reset(NativeMetafileFactory::CreateFromData(shared_buf.memory(),
- params.data_size));
- if (!metafile.get()) {
+ if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
NOTREACHED() << "Invalid metafile header";
tab_contents()->Stop();
return;
diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc
index 08f506a..9811baf 100644
--- a/chrome/browser/ui/webui/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview_handler.cc
@@ -18,8 +18,8 @@
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "printing/backend/print_backend.h"
-#include "printing/native_metafile_factory.h"
-#include "printing/native_metafile.h"
+#include "printing/metafile.h"
+#include "printing/metafile_impl.h"
#include "printing/print_job_constants.h"
namespace {
@@ -121,7 +121,7 @@ class EnumeratePrintersTaskProxy
class PrintToPdfTask : public Task {
public:
// Takes ownership of |metafile|.
- PrintToPdfTask(printing::NativeMetafile* metafile, const FilePath& path)
+ PrintToPdfTask(printing::Metafile* metafile, const FilePath& path)
: metafile_(metafile), path_(path) {
}
@@ -134,7 +134,7 @@ class PrintToPdfTask : public Task {
private:
// The metafile holding the PDF data.
- scoped_ptr<printing::NativeMetafile> metafile_;
+ scoped_ptr<printing::Metafile> metafile_;
// The absolute path where the file will be saved.
FilePath path_;
@@ -262,21 +262,15 @@ void PrintPreviewHandler::SelectFile() {
void PrintPreviewHandler::FileSelected(const FilePath& path,
int index, void* params) {
-#if defined(OS_POSIX)
PrintPreviewUIHTMLSource::PrintPreviewData data;
PrintPreviewUI* pp_ui = reinterpret_cast<PrintPreviewUI*>(web_ui_);
pp_ui->html_source()->GetPrintPreviewData(&data);
DCHECK(data.first != NULL);
DCHECK(data.second > 0);
- printing::NativeMetafile* metafile =
- printing::NativeMetafileFactory::CreateFromData(data.first->memory(),
- data.second);
- metafile->FinishDocument();
+ printing::PreviewMetafile* metafile = new printing::PreviewMetafile;
+ metafile->InitFromData(data.first->memory(), data.second);
PrintToPdfTask* task = new PrintToPdfTask(metafile, path);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task);
-#else
- NOTIMPLEMENTED();
-#endif
}
diff --git a/chrome/common/common_param_traits_unittest.cc b/chrome/common/common_param_traits_unittest.cc
index 1460986..bc47418 100644
--- a/chrome/common/common_param_traits_unittest.cc
+++ b/chrome/common/common_param_traits_unittest.cc
@@ -18,11 +18,6 @@
#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[] = {
diff --git a/chrome/renderer/mock_printer.cc b/chrome/renderer/mock_printer.cc
index a4efbfe..1a9236c 100644
--- a/chrome/renderer/mock_printer.cc
+++ b/chrome/renderer/mock_printer.cc
@@ -8,8 +8,7 @@
#include "base/shared_memory.h"
#include "chrome/common/print_messages.h"
#include "ipc/ipc_message_utils.h"
-#include "printing/native_metafile_factory.h"
-#include "printing/native_metafile.h"
+#include "printing/metafile_impl.h"
#include "printing/units.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -137,11 +136,9 @@ void MockPrinter::PrintPage(const PrintHostMsg_DidPrintPage_Params& params) {
base::SharedMemory metafile_data(params.metafile_data_handle, true);
#endif
metafile_data.Map(params.data_size);
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::CreateFromData(metafile_data.memory(),
- params.data_size));
- CHECK(metafile.get());
- printing::Image image(*metafile);
+ printing::NativeMetafile metafile;
+ metafile.InitFromData(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.cc b/chrome/renderer/print_web_view_helper.cc
index 5dbd07d..33ac578 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -15,6 +15,7 @@
#include "content/common/view_messages.h"
#include "content/renderer/render_view.h"
#include "grit/generated_resources.h"
+#include "printing/metafile.h"
#include "printing/units.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
@@ -636,7 +637,7 @@ void PrintWebViewHelper::RenderPagesForPreview(WebKit::WebFrame* frame,
#if defined(OS_POSIX)
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
- printing::NativeMetafile* metafile,
+ printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
base::SharedMemoryHandle mem_handle;
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index aea048c..686e7d9 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -11,7 +11,7 @@
#include "base/time.h"
#include "content/renderer/render_view_observer.h"
#include "content/renderer/render_view_observer_tracker.h"
-#include "printing/native_metafile.h"
+#include "printing/metafile.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
#include "ui/gfx/size.h"
@@ -152,7 +152,7 @@ class PrintWebViewHelper : public RenderViewObserver ,
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebKit::WebFrame* frame,
- printing::NativeMetafile* metafile,
+ printing::Metafile* metafile,
scoped_ptr<skia::VectorCanvas>* canvas);
#else
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
@@ -177,25 +177,25 @@ class PrintWebViewHelper : public RenderViewObserver ,
#if defined(OS_WIN)
void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor,
int page_number, WebKit::WebFrame* frame,
- scoped_ptr<printing::NativeMetafile>* metafile);
+ scoped_ptr<printing::Metafile>* metafile);
#elif defined(OS_MACOSX)
void RenderPage(const gfx::Size& page_size, const gfx::Point& content_origin,
const float& scale_factor, int page_number,
- WebKit::WebFrame* frame, printing::NativeMetafile* metafile);
+ WebKit::WebFrame* frame, printing::Metafile* metafile);
#elif defined(OS_POSIX)
bool RenderPages(const PrintMsg_PrintPages_Params& params,
WebKit::WebFrame* frame,
WebKit::WebNode* node,
bool send_expected_page_count,
int* page_count,
- printing::NativeMetafile* metafile);
+ printing::Metafile* metafile);
#endif // defined(OS_WIN)
// Helper methods -----------------------------------------------------------
bool CopyAndPrint(WebKit::WebFrame* web_frame);
- bool CopyMetafileDataToSharedMem(printing::NativeMetafile* metafile,
+ bool CopyMetafileDataToSharedMem(printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle);
static void GetPageSizeAndMarginsInPoints(
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 30ddb6b..ecb7b7b 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -9,9 +9,9 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/common/print_messages.h"
#include "content/common/view_messages.h"
-#include "printing/native_metafile_factory.h"
-#include "printing/native_metafile_skia_wrapper.h"
-#include "printing/native_metafile.h"
+#include "printing/metafile.h"
+#include "printing/metafile_impl.h"
+#include "printing/metafile_skia_wrapper.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "ui/gfx/point.h"
@@ -26,17 +26,16 @@ using WebKit::WebNode;
void PrintWebViewHelper::CreatePreviewDocument(
const PrintMsg_PrintPages_Params& params, WebKit::WebFrame* frame,
WebKit::WebNode* node) {
- // We only can use PDF in the renderer because Cairo needs to create a
- // temporary file for a PostScript surface.
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
int page_count = 0;
+ printing::PreviewMetafile metafile;
+ if (!metafile.Init())
+ return;
- if (!RenderPages(params, frame, node, false, &page_count, metafile.get()))
+ if (!RenderPages(params, frame, node, false, &page_count, &metafile))
return;
// Get the size of the resulting metafile.
- uint32 buf_size = metafile->GetDataSize();
+ uint32 buf_size = metafile.GetDataSize();
DCHECK_GT(buf_size, 0u);
PrintHostMsg_DidPreviewDocument_Params preview_params;
@@ -44,7 +43,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
preview_params.expected_pages_count = page_count;
preview_params.data_size = buf_size;
- if (!CopyMetafileDataToSharedMem(metafile.get(),
+ if (!CopyMetafileDataToSharedMem(&metafile,
&(preview_params.metafile_data_handle))) {
preview_params.expected_pages_count = 0;
preview_params.data_size = 0;
@@ -55,10 +54,6 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
WebFrame* frame,
WebNode* node) {
- // We only can use PDF in the renderer because Cairo needs to create a
- // temporary file for a PostScript surface.
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
int page_count = 0;
bool send_expected_page_count =
#if defined(OS_CHROMEOS)
@@ -67,13 +62,17 @@ void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
true;
#endif // defined(OS_CHROMEOS)
+ printing::NativeMetafile metafile;
+ if (!metafile.Init())
+ return;
+
if (!RenderPages(params, frame, node, send_expected_page_count, &page_count,
- metafile.get())) {
+ &metafile)) {
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)
@@ -85,7 +84,7 @@ void PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
&sequence_number))) {
return;
}
- if (!metafile->SaveToFD(fd))
+ if (!metafile.SaveToFD(fd))
return;
// Tell the browser we've finished writing the file.
@@ -112,7 +111,7 @@ void PrintWebViewHelper::PrintPages(const PrintMsg_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));
@@ -149,7 +148,7 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
WebKit::WebNode* node,
bool send_expected_page_count,
int* page_count,
- printing::NativeMetafile* metafile) {
+ printing::Metafile* metafile) {
PrintMsg_Print_Params printParams = params.params;
scoped_ptr<skia::VectorCanvas> canvas;
@@ -197,7 +196,7 @@ void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame,
- printing::NativeMetafile* metafile,
+ printing::Metafile* metafile,
scoped_ptr<skia::VectorCanvas>* canvas) {
double content_width_in_points;
double content_height_in_points;
@@ -228,8 +227,7 @@ void PrintWebViewHelper::PrintPageInternal(
return;
canvas->reset(new skia::VectorCanvas(device));
- printing::NativeMetafileSkiaWrapper::SetMetafileOnCanvas(canvas->get(),
- metafile);
+ printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas->get(), metafile);
frame->printPage(params.page_number, canvas->get());
// TODO(myhuang): We should handle transformation for paper margins.
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index b5c8b29..759cb6c 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -7,10 +7,9 @@
#import <AppKit/AppKit.h>
#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
#include "chrome/common/print_messages.h"
-#include "printing/native_metafile_factory.h"
-#include "printing/native_metafile.h"
+#include "printing/metafile.h"
+#include "printing/metafile_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
using WebKit::WebFrame;
@@ -19,9 +18,8 @@ void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame) {
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
- if(!metafile.get())
+ printing::NativeMetafile metafile;
+ if (!metafile.Init())
return;
float scale_factor = frame->getPrintPageShrink(params.page_number);
@@ -30,11 +28,11 @@ void PrintWebViewHelper::PrintPageInternal(
// Render page for printing.
gfx::Point origin(0.0f, 0.0f);
RenderPage(params.params.printable_size, origin, scale_factor, page_number,
- frame, metafile.get());
- metafile->FinishDocument();
+ frame, &metafile);
+ metafile.FinishDocument();
PrintHostMsg_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;
@@ -45,7 +43,7 @@ void PrintWebViewHelper::PrintPageInternal(
params.params.printable_size.height());
// Ask the browser to create the shared memory for us.
- if (!CopyMetafileDataToSharedMem(metafile.get(),
+ if (!CopyMetafileDataToSharedMem(&metafile,
&(page_params.metafile_data_handle))) {
page_params.data_size = 0;
}
@@ -66,9 +64,8 @@ void PrintWebViewHelper::CreatePreviewDocument(
if (!page_count)
return;
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
- if(!metafile.get())
+ printing::PreviewMetafile metafile;
+ if (!metafile.Init())
return;
float scale_factor = frame->getPrintPageShrink(0);
@@ -76,26 +73,26 @@ 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.get());
+ &metafile);
}
} 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.get());
+ static_cast<int>(params.pages[i]), frame, &metafile);
}
}
- metafile->FinishDocument();
+ metafile.FinishDocument();
PrintHostMsg_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.get(),
- &(preview_params.metafile_data_handle))) {
+ if (!CopyMetafileDataToSharedMem(&metafile,
+ &(preview_params.metafile_data_handle))) {
preview_params.data_size = 0;
preview_params.expected_pages_count = 0;
}
@@ -105,7 +102,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::RenderPage(
const gfx::Size& page_size, const gfx::Point& content_origin,
const float& scale_factor, int page_number, WebFrame* frame,
- printing::NativeMetafile* metafile) {
+ printing::Metafile* metafile) {
bool success = metafile->StartPage(page_size, content_origin, scale_factor);
DCHECK(success);
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 0652cfc..d7ebaf5 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -6,9 +6,10 @@
#include "base/logging.h"
#include "base/process_util.h"
+#include "base/scoped_ptr.h"
#include "chrome/common/print_messages.h"
-#include "printing/native_metafile_factory.h"
-#include "printing/native_metafile.h"
+#include "printing/metafile.h"
+#include "printing/metafile_impl.h"
#include "printing/units.h"
#include "skia/ext/vector_canvas.h"
#include "skia/ext/vector_platform_device_emf_win.h"
@@ -72,8 +73,8 @@ void PrintWebViewHelper::PrintPageInternal(
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(
- printing::NativeMetafileFactory::Create());
+ scoped_ptr<printing::Metafile> metafile(new printing::NativeMetafile);
+ metafile->Init();
DCHECK(metafile->context());
skia::PlatformDevice::InitializeDC(metafile->context());
@@ -131,38 +132,28 @@ void PrintWebViewHelper::CreatePreviewDocument(
if (!page_count)
return;
- // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of
- // single page metafile. For print preview, we need a metafile with multiple
- // pages.
- // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia
- // 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(
- printing::NativeMetafileFactory::Create());
- DCHECK(metafile->context());
- skia::PlatformDevice::InitializeDC(metafile->context());
+ scoped_ptr<printing::Metafile> metafile(new printing::PreviewMetafile);
+ metafile->Init();
// Calculate the dpi adjustment.
- float shrink = static_cast<float>(params.params.desired_dpi /
- params.params.dpi);
+ float shrink = static_cast<float>(print_params.desired_dpi /
+ print_params.dpi);
if (params.pages.empty()) {
for (int i = 0; i < page_count; ++i) {
float scale_factor = shrink;
- RenderPage(params.params, &scale_factor, i, frame, &metafile);
+ RenderPage(print_params, &scale_factor, i, frame, &metafile);
}
} else {
for (size_t i = 0; i < params.pages.size(); ++i) {
if (params.pages[i] >= page_count)
break;
float scale_factor = shrink;
- RenderPage(params.params, &scale_factor,
+ RenderPage(print_params, &scale_factor,
static_cast<int>(params.pages[i]), frame, &metafile);
}
}
- // Close the device context to retrieve the compiled metafile.
if (!metafile->FinishDocument())
NOTREACHED();
@@ -192,9 +183,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
void PrintWebViewHelper::RenderPage(
const PrintMsg_Print_Params& params, float* scale_factor, int page_number,
- WebFrame* frame, scoped_ptr<printing::NativeMetafile>* metafile) {
- DCHECK(metafile->get()->context());
-
+ WebFrame* frame, scoped_ptr<printing::Metafile>* metafile) {
double content_width_in_points;
double content_height_in_points;
double margin_top_in_points;
@@ -231,59 +220,63 @@ void PrintWebViewHelper::RenderPage(
bool result = (*metafile)->FinishPage();
DCHECK(result);
- skia::VectorPlatformDeviceEmf* platform_device =
- static_cast<skia::VectorPlatformDeviceEmf*>(device);
- if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) {
- // Currently, we handle alpha blend transparency for a single page.
- // Therefore, expecting a metafile with page count 1.
- DCHECK((*metafile)->GetPageCount() == 1);
-
- // Close the device context to retrieve the compiled metafile.
- if (!(*metafile)->FinishDocument())
- NOTREACHED();
-
- scoped_ptr<printing::NativeMetafile> metafile2(
- printing::NativeMetafileFactory::Create());
- // Page used alpha blend, but printer doesn't support it. Rewrite the
- // metafile and flatten out the transparency.
- HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));
- if (!bitmap_dc)
- NOTREACHED() << "Bitmap DC creation failed";
- SetGraphicsMode(bitmap_dc, GM_ADVANCED);
- void* bits = NULL;
- BITMAPINFO hdr;
- gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader);
- HBITMAP hbitmap = CreateDIBSection(
- bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0);
- if (!hbitmap)
- NOTREACHED() << "Raster bitmap creation for printing failed";
-
- HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
- RECT rect = {0, 0, width, height };
- HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
- FillRect(bitmap_dc, &rect, whiteBrush);
-
- HDC hdc = metafile2->context();
- DCHECK(hdc);
- skia::PlatformDevice::InitializeDC(hdc);
-
- RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT();
- // Process the old metafile, placing all non-AlphaBlend calls into the
- // new metafile, and copying the results of all the AlphaBlend calls
- // from the bitmap DC.
- EnumEnhMetaFile(hdc,
- (*metafile)->emf(),
- EnhMetaFileProc,
- &bitmap_dc,
- &metafile_bounds);
-
- SelectObject(bitmap_dc, old_bitmap);
- metafile->reset(metafile2.release());
+ if (!params.supports_alpha_blend) {
+ // PreviewMetafile (PDF) supports alpha blend, so we only hit this case
+ // for NativeMetafile.
+ skia::VectorPlatformDeviceEmf* platform_device =
+ static_cast<skia::VectorPlatformDeviceEmf*>(device);
+ if (platform_device->alpha_blend_used()) {
+ // Currently, we handle alpha blend transparency for a single page.
+ // Therefore, expecting a metafile with page count 1.
+ DCHECK_EQ(1U, (*metafile)->GetPageCount());
+
+ // Close the device context to retrieve the compiled metafile.
+ if (!(*metafile)->FinishDocument())
+ NOTREACHED();
+
+ // Page used alpha blend, but printer doesn't support it. Rewrite the
+ // metafile and flatten out the transparency.
+ HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));
+ if (!bitmap_dc)
+ NOTREACHED() << "Bitmap DC creation failed";
+ SetGraphicsMode(bitmap_dc, GM_ADVANCED);
+ void* bits = NULL;
+ BITMAPINFO hdr;
+ gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader);
+ HBITMAP hbitmap = CreateDIBSection(
+ bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0);
+ if (!hbitmap)
+ NOTREACHED() << "Raster bitmap creation for printing failed";
+
+ HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
+ RECT rect = {0, 0, width, height };
+ HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
+ FillRect(bitmap_dc, &rect, whiteBrush);
+
+ scoped_ptr<printing::Metafile> metafile2(new printing::NativeMetafile);
+ metafile2->Init();
+ HDC hdc = metafile2->context();
+ DCHECK(hdc);
+ skia::PlatformDevice::InitializeDC(hdc);
+
+ RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT();
+ // Process the old metafile, placing all non-AlphaBlend calls into the
+ // new metafile, and copying the results of all the AlphaBlend calls
+ // from the bitmap DC.
+ EnumEnhMetaFile(hdc,
+ (*metafile)->emf(),
+ EnhMetaFileProc,
+ &bitmap_dc,
+ &metafile_bounds);
+
+ SelectObject(bitmap_dc, old_bitmap);
+ metafile->reset(metafile2.release());
+ }
}
}
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
- printing::NativeMetafile* metafile,
+ printing::Metafile* metafile,
base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
base::SharedMemory shared_buf;