summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka <vitalybuka@chromium.org>2014-08-28 16:42:24 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-28 23:43:19 +0000
commit36259ca6a4aa40fa18c2ccbffa4e6b3a8b711868 (patch)
treec94d8428c3fdbaed0c5cd452a8a44c79a9bfadff
parent60a5bf4a8a5d1a2dad8e7a67f81e72756e886266 (diff)
downloadchromium_src-36259ca6a4aa40fa18c2ccbffa4e6b3a8b711868.zip
chromium_src-36259ca6a4aa40fa18c2ccbffa4e6b3a8b711868.tar.gz
chromium_src-36259ca6a4aa40fa18c2ccbffa4e6b3a8b711868.tar.bz2
Removed print_web_view_helper_win.cc
Removed win_pdf_metafile_for_printing gyp option. Removed WIN_PDF_METAFILE_FOR_PRINTING define. BUG=170859 TBR=yzshen Review URL: https://codereview.chromium.org/516823002 Cr-Commit-Position: refs/heads/master@{#292501}
-rw-r--r--build/common.gypi7
-rw-r--r--build/config/BUILD.gn3
-rw-r--r--chrome/browser/BUILD.gn2
-rw-r--r--chrome/browser/printing/print_view_manager_base.cc55
-rw-r--r--chrome/browser/printing/print_view_manager_base.h13
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_renderer.gypi10
-rw-r--r--chrome/common/chrome_utility_printing_messages.h9
-rw-r--r--chrome/common/print_messages.h5
-rw-r--r--chrome/renderer/BUILD.gn6
-rw-r--r--chrome/renderer/printing/print_web_view_helper.cc5
-rw-r--r--chrome/renderer/printing/print_web_view_helper.h15
-rw-r--r--chrome/renderer/printing/print_web_view_helper_browsertest.cc8
-rw-r--r--chrome/renderer/printing/print_web_view_helper_win.cc253
-rw-r--r--chrome/service/service_utility_process_host.cc6
-rw-r--r--chrome/utility/printing_handler.cc12
-rw-r--r--chrome/utility/printing_handler.h8
-rw-r--r--content/renderer/pepper/pepper_plugin_instance_impl.cc5
-rw-r--r--printing/metafile_impl.h10
19 files changed, 51 insertions, 383 deletions
diff --git a/build/common.gypi b/build/common.gypi
index 6b0bffa..2624784 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -473,9 +473,6 @@
# print, UI, etc.
'enable_printing%': 1,
- # Windows prints using a PDF as the metafile from the renderer.
- 'win_pdf_metafile_for_printing%': 1,
-
# Set the version of CLD.
# 0: Don't specify the version. This option is for the Finch testing.
# 1: Use only CLD1.
@@ -1155,7 +1152,6 @@
'test_isolation_outdir%': '<(test_isolation_outdir)',
'test_isolation_fail_on_missing': '<(test_isolation_fail_on_missing)',
'enable_printing%': '<(enable_printing)',
- 'win_pdf_metafile_for_printing%': '<(win_pdf_metafile_for_printing)',
'enable_spellcheck%': '<(enable_spellcheck)',
'enable_google_now%': '<(enable_google_now)',
'cld_version%': '<(cld_version)',
@@ -2862,9 +2858,6 @@
['enable_printing==2', {
'defines': ['ENABLE_PRINTING=1'],
}],
- ['OS=="win" and win_pdf_metafile_for_printing==1', {
- 'defines': ['WIN_PDF_METAFILE_FOR_PRINTING=1'],
- }],
['enable_spellcheck==1', {
'defines': ['ENABLE_SPELLCHECK=1'],
}],
diff --git a/build/config/BUILD.gn b/build/config/BUILD.gn
index b0daaf1..b3702b1 100644
--- a/build/config/BUILD.gn
+++ b/build/config/BUILD.gn
@@ -135,9 +135,6 @@ config("feature_flags") {
if (enable_themes) {
defines += [ "ENABLE_THEMES=1" ]
}
- if (is_win && win_pdf_metafile_for_printing) {
- defines += [ "WIN_PDF_METAFILE_FOR_PRINTING=1" ]
- }
if (enable_captive_portal_detection) {
defines += [ "ENABLE_CAPTIVE_PORTAL_DETECTION=1" ]
}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 14ed087..e1222c3 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -418,7 +418,7 @@ static_library("browser") {
deps += [
"//printing",
]
- if (is_win && win_pdf_metafile_for_printing) {
+ if (is_win) {
sources += rebase_path(gypi_values.chrome_browser_printing_emf_sources,
".", "//chrome")
}
diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc
index 55c9a57d..5886209 100644
--- a/chrome/browser/printing/print_view_manager_base.cc
+++ b/chrome/browser/printing/print_view_manager_base.cc
@@ -33,10 +33,11 @@
#include "chrome/browser/printing/print_error_dialog.h"
#endif
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
#include "base/memory/ref_counted.h"
#include "base/memory/ref_counted_memory.h"
#include "chrome/browser/printing/pdf_to_emf_converter.h"
+#include "printing/emf_win.h"
#include "printing/pdf_render_settings.h"
#endif
@@ -47,11 +48,6 @@ namespace printing {
namespace {
-#if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)
-// Limits memory usage by raster to 64 MiB.
-const int kMaxRasterSizeInPixels = 16*1024*1024;
-#endif
-
} // namespace
PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
@@ -62,10 +58,9 @@ PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents)
cookie_(0),
queue_(g_browser_process->print_job_manager()->queue()) {
DCHECK(queue_.get());
-#if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \
- defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if !defined(OS_MACOSX)
expecting_first_page_ = true;
-#endif
+#endif // OS_MACOSX
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
printing_enabled_.Init(
@@ -129,7 +124,7 @@ void PrintViewManagerBase::OnDidGetDocumentCookie(int cookie) {
cookie_ = cookie;
}
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
void PrintViewManagerBase::OnPdfToEmfConverted(
const PrintHostMsg_DidPrintPage_Params& params,
double scale_factor,
@@ -158,7 +153,7 @@ void PrintViewManagerBase::OnPdfToEmfConverted(
ShouldQuitFromInnerMessageLoop();
}
-#endif // WIN_PDF_METAFILE_FOR_PRINTING
+#endif // OS_WIN
void PrintViewManagerBase::OnDidPrintPage(
const PrintHostMsg_DidPrintPage_Params& params) {
@@ -172,13 +167,12 @@ void PrintViewManagerBase::OnDidPrintPage(
return;
}
-#if (defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)) || \
- defined(OS_MACOSX)
+#if defined(OS_MACOSX)
const bool metafile_must_be_valid = true;
-#elif defined(OS_POSIX) || defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#else
const bool metafile_must_be_valid = expecting_first_page_;
expecting_first_page_ = false;
-#endif
+#endif // OS_MACOSX
base::SharedMemory shared_buf(params.metafile_data_handle, true);
if (metafile_must_be_valid) {
@@ -198,32 +192,10 @@ void PrintViewManagerBase::OnDidPrintPage(
}
}
-#if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)
- bool big_emf = (params.data_size && params.data_size >= kMetafileMaxSize);
- int raster_size =
- std::min(params.page_size.GetArea(), kMaxRasterSizeInPixels);
- if (big_emf) {
- scoped_ptr<NativeMetafile> raster_metafile(
- metafile->RasterizeMetafile(raster_size));
- if (raster_metafile.get()) {
- metafile.swap(raster_metafile);
- } else if (big_emf) {
- // Don't fall back to emf here.
- NOTREACHED() << "size:" << params.data_size;
- TerminatePrintJob(true);
- web_contents()->Stop();
- return;
- }
- }
-#endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING
-
-#if !defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if !defined(OS_WIN)
// Update the rendered document. It will send notifications to the listener.
document->SetPage(params.page_number,
metafile.release(),
-#if defined(OS_WIN)
- params.actual_shrink,
-#endif // OS_WIN
params.page_size,
params.content_area);
@@ -247,7 +219,7 @@ void PrintViewManagerBase::OnDidPrintPage(
base::Unretained(this),
params));
}
-#endif // !WIN_PDF_METAFILE_FOR_PRINTING
+#endif // !OS_WIN
}
void PrintViewManagerBase::OnPrintingFailed(int cookie) {
@@ -454,10 +426,9 @@ void PrintViewManagerBase::DisconnectFromCurrentPrintJob() {
// DO NOT wait for the job to finish.
ReleasePrintJob();
}
-#if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \
- defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if !defined(OS_MACOSX)
expecting_first_page_ = true;
-#endif
+#endif // OS_MACOSX
}
void PrintViewManagerBase::PrintingDone(bool success) {
diff --git a/chrome/browser/printing/print_view_manager_base.h b/chrome/browser/printing/print_view_manager_base.h
index ef48ed5..7a93fe1 100644
--- a/chrome/browser/printing/print_view_manager_base.h
+++ b/chrome/browser/printing/print_view_manager_base.h
@@ -131,12 +131,12 @@ class PrintViewManagerBase : public content::NotificationObserver,
// Release the PrinterQuery associated with our |cookie_|.
void ReleasePrinterQuery();
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
// Called on completion of converting the pdf to emf.
void OnPdfToEmfConverted(const PrintHostMsg_DidPrintPage_Params& params,
double scale_factor,
const std::vector<base::FilePath>& emf_file);
-#endif
+#endif // OS_WIN
content::NotificationRegistrar registrar_;
@@ -154,15 +154,14 @@ class PrintViewManagerBase : public content::NotificationObserver,
// print settings are being loaded.
bool inside_inner_message_loop_;
-#if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \
- defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if !defined(OS_MACOSX)
// Set to true when OnDidPrintPage() should be expecting the first page.
bool expecting_first_page_;
-#endif
+#endif // OS_MACOSX
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
scoped_ptr<PdfToEmfConverter> pdf_to_emf_converter_;
-#endif
+#endif // OS_WIN
// The document cookie of the current PrinterQuery.
int cookie_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 0a480a2..4fc4663 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3213,7 +3213,7 @@
],
'sources': [ '<@(chrome_browser_basic_printing_sources)' ],
'conditions': [
- ['OS=="win" and win_pdf_metafile_for_printing==1', {
+ ['OS=="win"', {
'sources': [ '<@(chrome_browser_printing_emf_sources)' ],
}],
# Full printing on top of the above.
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index 9e6a242..285cdf3 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -256,6 +256,7 @@
'renderer/printing/print_web_view_helper_android.cc',
'renderer/printing/print_web_view_helper_linux.cc',
'renderer/printing/print_web_view_helper_mac.mm',
+ 'renderer/printing/print_web_view_helper_pdf_win.cc',
],
'chrome_renderer_full_printing_sources': [
'renderer/pepper/chrome_pdf_print_client.cc',
@@ -390,15 +391,6 @@
'<@(chrome_renderer_full_printing_sources)',
],
}],
- ['win_pdf_metafile_for_printing==1', {
- 'sources': [
- 'renderer/printing/print_web_view_helper_pdf_win.cc',
- ],
- }, {
- 'sources': [
- 'renderer/printing/print_web_view_helper_win.cc',
- ],
- }],
['OS!="android"', {
'sources': [
'<@(chrome_renderer_non_android_sources)',
diff --git a/chrome/common/chrome_utility_printing_messages.h b/chrome/common/chrome_utility_printing_messages.h
index 876d4af..4858367 100644
--- a/chrome/common/chrome_utility_printing_messages.h
+++ b/chrome/common/chrome_utility_printing_messages.h
@@ -85,8 +85,7 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
std::string /* printer name */)
-
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
// Tell the utility process to render the given PDF into a metafile.
// The metafile path will have ".%d" inserted where the %d is the page number.
// If no page range is specified, all pages will be converted.
@@ -95,7 +94,7 @@ IPC_MESSAGE_CONTROL4(ChromeUtilityMsg_RenderPDFPagesToMetafiles,
base::FilePath, // Base location for output metafile
printing::PdfRenderSettings, // PDF render settings
std::vector<printing::PageRange>)
-#endif
+#endif // OS_WIN
//------------------------------------------------------------------------------
// Utility process host messages:
@@ -131,7 +130,7 @@ IPC_MESSAGE_CONTROL1(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
std::string /* printer name */)
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
// Reply when the utility process has succeeded in rendering the PDF.
IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_Succeeded,
std::vector<printing::PageRange>, // Pages rendered
@@ -139,4 +138,4 @@ IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_Succeeded,
// Reply when an error occurred rendering the PDF.
IPC_MESSAGE_CONTROL0(ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed)
-#endif
+#endif // OS_WIN
diff --git a/chrome/common/print_messages.h b/chrome/common/print_messages.h
index 6653b21..fa86dbd 100644
--- a/chrome/common/print_messages.h
+++ b/chrome/common/print_messages.h
@@ -287,11 +287,6 @@ IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params)
// Page number.
IPC_STRUCT_MEMBER(int, page_number)
-#if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)
- // Shrink factor used to render this page.
- IPC_STRUCT_MEMBER(double, actual_shrink)
-#endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING
-
// The size of the page the page author specified.
IPC_STRUCT_MEMBER(gfx::Size, page_size)
diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn
index fef9507..0cb4606 100644
--- a/chrome/renderer/BUILD.gn
+++ b/chrome/renderer/BUILD.gn
@@ -154,13 +154,7 @@ static_library("renderer") {
}
# TODO(GYP)
- # ['win_pdf_metafile_for_printing==1', {
# 'sources': [
# 'renderer/printing/print_web_view_helper_pdf_win.cc',
# ],
- # }, {
- # 'sources': [
- # 'renderer/printing/print_web_view_helper_win.cc',
- # ],
- # }],
}
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index 6dd507e..27ea08f 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -1340,8 +1340,7 @@ void PrintWebViewHelper::FinishFramePrinting() {
prep_frame_view_.reset();
}
-#if defined(OS_MACOSX) || \
- (defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING))
+#if defined(OS_MACOSX)
bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
int page_count,
const gfx::Size& canvas_size) {
@@ -1366,7 +1365,7 @@ bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
return true;
}
-#endif // OS_MACOSX || !WIN_PDF_METAFILE_FOR_PRINTING
+#endif // OS_MACOSX
// static - Not anonymous so that platform implementations can use it.
void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
diff --git a/chrome/renderer/printing/print_web_view_helper.h b/chrome/renderer/printing/print_web_view_helper.h
index dd82d7e..53fde04 100644
--- a/chrome/renderer/printing/print_web_view_helper.h
+++ b/chrome/renderer/printing/print_web_view_helper.h
@@ -209,7 +209,7 @@ class PrintWebViewHelper
const gfx::Size& canvas_size,
blink::WebFrame* frame,
Metafile* metafile);
-#elif defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#elif defined(OS_WIN)
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
blink::WebFrame* frame,
@@ -227,16 +227,7 @@ class PrintWebViewHelper
const blink::WebNode& node);
// Platform specific helper function for rendering page(s) to |metafile|.
-#if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)
- void RenderPage(const PrintMsg_Print_Params& params,
- int page_number,
- blink::WebFrame* frame,
- bool is_preview,
- Metafile* metafile,
- double* scale_factor,
- gfx::Size* page_size_in_dpi,
- gfx::Rect* content_area_in_dpi);
-#elif defined(OS_MACOSX)
+#if defined(OS_MACOSX)
void RenderPage(const PrintMsg_Print_Params& params,
int page_number,
blink::WebFrame* frame,
@@ -244,7 +235,7 @@ class PrintWebViewHelper
Metafile* metafile,
gfx::Size* page_size,
gfx::Rect* content_rect);
-#endif // defined(OS_WIN)
+#endif // defined(OS_MACOSX)
// Renders page contents from |frame| to |content_area| of |canvas|.
// |page_number| is zero-based.
diff --git a/chrome/renderer/printing/print_web_view_helper_browsertest.cc b/chrome/renderer/printing/print_web_view_helper_browsertest.cc
index 936d770..fb46a5d 100644
--- a/chrome/renderer/printing/print_web_view_helper_browsertest.cc
+++ b/chrome/renderer/printing/print_web_view_helper_browsertest.cc
@@ -243,7 +243,7 @@ TEST_F(PrintWebViewHelperTest, OnPrintPages) {
VerifyPagesPrinted(true);
}
-#if (defined(OS_WIN) && !WIN_PDF_METAFILE_FOR_PRINTING) || defined(OS_MACOSX)
+#if defined(OS_MACOSX)
// TODO(estade): I don't think this test is worth porting to Linux. We will have
// to rip out and replace most of the IPC code if we ever plan to improve
// printing, and the comment below by sverrir suggests that it doesn't do much
@@ -284,7 +284,7 @@ TEST_F(PrintWebViewHelperTest, PrintWithIframe) {
EXPECT_NE(0, image1.size().width());
EXPECT_NE(0, image1.size().height());
}
-#endif
+#endif // OS_MACOSX
// Tests if we can print a page and verify its results.
// This test prints HTML pages into a pseudo printer and check their outputs,
@@ -330,7 +330,7 @@ const TestPageData kTestPages[] = {
// hooking up Cairo to read a pdf stream, or accessing the cairo surface in the
// metafile directly.
// Same for printing via PDF on Windows.
-#if (defined(OS_WIN) && !WIN_PDF_METAFILE_FOR_PRINTING) || defined(OS_MACOSX)
+#if defined(OS_MACOSX)
TEST_F(PrintWebViewHelperTest, PrintLayoutTest) {
bool baseline = false;
@@ -383,7 +383,7 @@ TEST_F(PrintWebViewHelperTest, PrintLayoutTest) {
}
}
}
-#endif
+#endif // OS_MACOSX
// These print preview tests do not work on Chrome OS yet.
#if !defined(OS_CHROMEOS)
diff --git a/chrome/renderer/printing/print_web_view_helper_win.cc b/chrome/renderer/printing/print_web_view_helper_win.cc
deleted file mode 100644
index 48d94a2..0000000
--- a/chrome/renderer/printing/print_web_view_helper_win.cc
+++ /dev/null
@@ -1,253 +0,0 @@
-// 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 "chrome/renderer/printing/print_web_view_helper.h"
-
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/metrics/histogram.h"
-#include "base/process/process_handle.h"
-#include "base/win/scoped_gdi_object.h"
-#include "base/win/scoped_hdc.h"
-#include "base/win/scoped_select_object.h"
-#include "chrome/common/print_messages.h"
-#include "printing/metafile.h"
-#include "printing/metafile_impl.h"
-#include "printing/metafile_skia_wrapper.h"
-#include "printing/page_size_margins.h"
-#include "printing/units.h"
-#include "skia/ext/platform_device.h"
-#include "skia/ext/refptr.h"
-#include "skia/ext/vector_canvas.h"
-#include "third_party/WebKit/public/web/WebLocalFrame.h"
-#include "ui/gfx/gdi_util.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/size.h"
-
-namespace printing {
-
-using blink::WebFrame;
-
-void PrintWebViewHelper::PrintPageInternal(
- const PrintMsg_PrintPage_Params& params,
- const gfx::Size& canvas_size,
- WebFrame* frame) {
- // Generate a memory-based metafile. It will use the current screen's DPI.
- // Each metafile contains a single page.
- scoped_ptr<NativeMetafile> metafile(new NativeMetafile);
- metafile->Init();
- DCHECK(metafile->context());
- skia::InitializeDC(metafile->context());
-
- int page_number = params.page_number;
-
- // Calculate the dpi adjustment.
- // Browser will render context using desired_dpi, so we need to calculate
- // adjustment factor to play content on the printer DC later during the
- // actual printing.
- double actual_shrink = static_cast<float>(params.params.desired_dpi /
- params.params.dpi);
- gfx::Size page_size_in_dpi;
- gfx::Rect content_area_in_dpi;
-
- // Render page for printing.
- RenderPage(params.params, page_number, frame, false, metafile.get(),
- &actual_shrink, &page_size_in_dpi, &content_area_in_dpi);
-
- // Close the device context to retrieve the compiled metafile.
- if (!metafile->FinishDocument())
- NOTREACHED();
-
- if (!params.params.supports_alpha_blend && metafile->IsAlphaBlendUsed()) {
- scoped_ptr<NativeMetafile> raster_metafile(
- metafile->RasterizeAlphaBlend());
- if (raster_metafile.get())
- metafile.swap(raster_metafile);
- }
-
- // Get the size of the compiled metafile.
- uint32 buf_size = metafile->GetDataSize();
- DCHECK_GT(buf_size, 128u);
-
- PrintHostMsg_DidPrintPage_Params page_params;
- page_params.data_size = buf_size;
- page_params.metafile_data_handle = NULL;
- page_params.page_number = page_number;
- page_params.document_cookie = params.params.document_cookie;
- page_params.actual_shrink = actual_shrink;
- page_params.page_size = page_size_in_dpi;
- page_params.content_area = content_area_in_dpi;
-
- if (!CopyMetafileDataToSharedMem(metafile.get(),
- &(page_params.metafile_data_handle))) {
- page_params.data_size = 0;
- }
-
- Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params));
-}
-
-bool PrintWebViewHelper::RenderPreviewPage(
- int page_number,
- const PrintMsg_Print_Params& print_params) {
- // Calculate the dpi adjustment.
- double actual_shrink = static_cast<float>(print_params.desired_dpi /
- print_params.dpi);
- scoped_ptr<Metafile> draft_metafile;
- Metafile* initial_render_metafile = print_preview_context_.metafile();
-
- if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) {
- draft_metafile.reset(new PreviewMetafile);
- initial_render_metafile = draft_metafile.get();
- }
-
- base::TimeTicks begin_time = base::TimeTicks::Now();
- RenderPage(print_params, page_number, print_preview_context_.prepared_frame(),
- true, initial_render_metafile, &actual_shrink, NULL, NULL);
- print_preview_context_.RenderedPreviewPage(
- base::TimeTicks::Now() - begin_time);
-
- if (draft_metafile.get()) {
- draft_metafile->FinishDocument();
- } else if (print_preview_context_.IsModifiable() &&
- print_preview_context_.generate_draft_pages()) {
- DCHECK(!draft_metafile.get());
- draft_metafile.reset(
- print_preview_context_.metafile()->GetMetafileForCurrentPage());
- }
- return PreviewPageRendered(page_number, draft_metafile.get());
-}
-
-void PrintWebViewHelper::RenderPage(
- const PrintMsg_Print_Params& params, int page_number, WebFrame* frame,
- bool is_preview, Metafile* metafile, double* actual_shrink,
- gfx::Size* page_size_in_dpi, gfx::Rect* content_area_in_dpi) {
- PageSizeMargins page_layout_in_points;
- double css_scale_factor = 1.0f;
- ComputePageLayoutInPointsForCss(frame, page_number, params,
- ignore_css_margins_, &css_scale_factor,
- &page_layout_in_points);
- gfx::Size page_size;
- gfx::Rect content_area;
- GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
- &content_area);
- int dpi = static_cast<int>(params.dpi);
- // Calculate the actual page size and content area in dpi.
- if (page_size_in_dpi) {
- *page_size_in_dpi = gfx::Size(
- static_cast<int>(ConvertUnitDouble(page_size.width(), kPointsPerInch,
- dpi)),
- static_cast<int>(ConvertUnitDouble(page_size.height(), kPointsPerInch,
- dpi)));
- }
-
- if (content_area_in_dpi) {
- *content_area_in_dpi = gfx::Rect(
- static_cast<int>(ConvertUnitDouble(content_area.x(), kPointsPerInch,
- dpi)),
- static_cast<int>(ConvertUnitDouble(content_area.y(), kPointsPerInch,
- dpi)),
- static_cast<int>(ConvertUnitDouble(content_area.width(), kPointsPerInch,
- dpi)),
- static_cast<int>(ConvertUnitDouble(content_area.height(),
- kPointsPerInch, dpi)));
- }
-
- if (!is_preview) {
- // Since WebKit extends the page width depending on the magical scale factor
- // we make sure the canvas covers the worst case scenario (x2.0 currently).
- // PrintContext will then set the correct clipping region.
- page_size = gfx::Size(
- static_cast<int>(page_layout_in_points.content_width *
- params.max_shrink),
- static_cast<int>(page_layout_in_points.content_height *
- params.max_shrink));
- }
-
- float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number);
- float scale_factor = css_scale_factor * webkit_page_shrink_factor;
-
- gfx::Rect canvas_area =
- params.display_header_footer ? gfx::Rect(page_size) : content_area;
-
- SkBaseDevice* device = metafile->StartPageForVectorCanvas(
- page_size, canvas_area, scale_factor);
- DCHECK(device);
- // The printPage method may take a reference to the canvas we pass down, so it
- // can't be a stack object.
- skia::RefPtr<skia::VectorCanvas> canvas =
- skia::AdoptRef(new skia::VectorCanvas(device));
-
- if (is_preview) {
- MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
- skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
- skia::SetIsPreviewMetafile(*canvas, is_preview);
- }
-
- if (params.display_header_footer) {
- // |page_number| is 0-based, so 1 is added.
- PrintHeaderAndFooter(canvas.get(),
- page_number + 1,
- print_preview_context_.total_page_count(),
- *frame,
- scale_factor,
- page_layout_in_points,
- params);
- }
-
- float webkit_scale_factor = RenderPageContent(frame, page_number, canvas_area,
- content_area, scale_factor,
- canvas.get());
-
- if (*actual_shrink <= 0 || webkit_scale_factor <= 0) {
- NOTREACHED() << "Printing page " << page_number << " failed.";
- } else {
- // While rendering certain plugins (PDF) to metafile, we might need to
- // set custom scale factor. Update |actual_shrink| with custom scale
- // if it is set on canvas.
- // TODO(gene): We should revisit this solution for the next versions.
- // Consider creating metafile of the right size (or resizable)
- // https://code.google.com/p/chromium/issues/detail?id=126037
- if (!MetafileSkiaWrapper::GetCustomScaleOnCanvas(
- *canvas, actual_shrink)) {
- // Update the dpi adjustment with the "page |actual_shrink|" calculated in
- // webkit.
- *actual_shrink /= (webkit_scale_factor * css_scale_factor);
- }
- }
-
- bool result = metafile->FinishPage();
- DCHECK(result);
-}
-
-bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
- Metafile* metafile, base::SharedMemoryHandle* shared_mem_handle) {
- uint32 buf_size = metafile->GetDataSize();
- base::SharedMemory shared_buf;
- if (buf_size >= kMetafileMaxSize) {
- NOTREACHED() << "Buffer too large: " << buf_size;
- return false;
- }
-
- // Allocate a shared memory buffer to hold the generated metafile data.
- if (!shared_buf.CreateAndMapAnonymous(buf_size)) {
- NOTREACHED() << "Buffer allocation failed";
- return false;
- }
-
- // Copy the bits into shared memory.
- if (!metafile->GetData(shared_buf.memory(), buf_size)) {
- NOTREACHED() << "GetData() failed";
- shared_buf.Unmap();
- return false;
- }
- shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
- shared_buf.Unmap();
-
- Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
- shared_mem_handle));
- return true;
-}
-
-} // namespace printing
diff --git a/chrome/service/service_utility_process_host.cc b/chrome/service/service_utility_process_host.cc
index c6ffead..d649ba74 100644
--- a/chrome/service/service_utility_process_host.cc
+++ b/chrome/service/service_utility_process_host.cc
@@ -230,7 +230,7 @@ void ServiceUtilityProcessHost::OnChildDisconnected() {
bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message)
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(
ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_Succeeded,
OnRenderPDFPagesToMetafilesSucceeded)
@@ -257,7 +257,7 @@ base::ProcessHandle ServiceUtilityProcessHost::GetHandle() const {
return handle_;
}
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafilesSucceeded(
const std::vector<printing::PageRange>& page_ranges,
double scale_factor) {
@@ -301,7 +301,7 @@ void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileFailed() {
FROM_HERE,
base::Bind(&Client::OnRenderPDFPagesToMetafileFailed, client_.get()));
}
-#endif // defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#endif // defined(OS_WIN)
void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded(
const std::string& printer_name,
diff --git a/chrome/utility/printing_handler.cc b/chrome/utility/printing_handler.cc
index 6ea0e95..f3552a0 100644
--- a/chrome/utility/printing_handler.cc
+++ b/chrome/utility/printing_handler.cc
@@ -259,10 +259,10 @@ void PrintingHandler::PreSandboxStartup() {
bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message)
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles,
OnRenderPDFPagesToMetafile)
-#endif
+#endif // OS_WIN
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToPWGRaster,
OnRenderPDFPagesToPWGRaster)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
@@ -274,7 +274,7 @@ bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
void PrintingHandler::OnRenderPDFPagesToMetafile(
IPC::PlatformFileForTransit pdf_transit,
const base::FilePath& metafile_path,
@@ -302,7 +302,7 @@ void PrintingHandler::OnRenderPDFPagesToMetafile(
}
ReleaseProcessIfNeeded();
}
-#endif
+#endif // OS_WIN
void PrintingHandler::OnRenderPDFPagesToPWGRaster(
IPC::PlatformFileForTransit pdf_transit,
@@ -320,7 +320,7 @@ void PrintingHandler::OnRenderPDFPagesToPWGRaster(
ReleaseProcessIfNeeded();
}
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
bool PrintingHandler::RenderPDFToWinMetafile(
base::File pdf_file,
const base::FilePath& metafile_path,
@@ -403,7 +403,7 @@ bool PrintingHandler::RenderPDFToWinMetafile(
}
return ret;
}
-#endif // defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#endif // OS_WIN
bool PrintingHandler::RenderPDFPagesToPWGRaster(
base::File pdf_file,
diff --git a/chrome/utility/printing_handler.h b/chrome/utility/printing_handler.h
index 805c1e3..4eecd78 100644
--- a/chrome/utility/printing_handler.h
+++ b/chrome/utility/printing_handler.h
@@ -33,20 +33,20 @@ class PrintingHandler : public UtilityMessageHandler {
private:
// IPC message handlers.
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
void OnRenderPDFPagesToMetafile(
IPC::PlatformFileForTransit pdf_transit,
const base::FilePath& metafile_path,
const printing::PdfRenderSettings& settings,
const std::vector<printing::PageRange>& page_ranges);
-#endif
+#endif // OS_WIN
void OnRenderPDFPagesToPWGRaster(
IPC::PlatformFileForTransit pdf_transit,
const printing::PdfRenderSettings& settings,
const printing::PwgRasterSettings& bitmap_settings,
IPC::PlatformFileForTransit bitmap_transit);
-#if defined(WIN_PDF_METAFILE_FOR_PRINTING)
+#if defined(OS_WIN)
// Helper method for Windows.
// |highest_rendered_page_number| is set to -1 on failure to render any page.
// |page_ranges| is both input and output. If supplied as input, only the
@@ -59,7 +59,7 @@ class PrintingHandler : public UtilityMessageHandler {
std::vector<printing::PageRange>* page_ranges,
int* highest_rendered_page_number,
double* scale_factor);
-#endif
+#endif // OS_WIN
bool RenderPDFPagesToPWGRaster(
base::File pdf_file,
diff --git a/content/renderer/pepper/pepper_plugin_instance_impl.cc b/content/renderer/pepper/pepper_plugin_instance_impl.cc
index b9170f4..8b03de0 100644
--- a/content/renderer/pepper/pepper_plugin_instance_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_instance_impl.cc
@@ -1750,10 +1750,9 @@ bool PepperPluginInstanceImpl::PrintPage(int page_number,
// The canvas only has a metafile on it for print preview.
bool save_for_later =
(printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL);
-#if defined(OS_MACOSX) || \
- (defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING))
+#if defined(OS_MACOSX)
save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas);
-#endif
+#endif // defined(OS_MACOSX)
if (save_for_later) {
ranges_.push_back(page_range);
canvas_ = skia::SharePtr(canvas);
diff --git a/printing/metafile_impl.h b/printing/metafile_impl.h
index 9fb2307..92bec72 100644
--- a/printing/metafile_impl.h
+++ b/printing/metafile_impl.h
@@ -7,19 +7,11 @@
#include "printing/pdf_metafile_skia.h"
-#if defined(OS_WIN)
-#include "printing/emf_win.h"
-#endif
-
namespace printing {
-#if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING)
-typedef Emf NativeMetafile;
-typedef PdfMetafileSkia PreviewMetafile;
-#else
+// TODO(vitalybuka) Remove following typedefs and replace with PdfMetafileSkia.
typedef PdfMetafileSkia NativeMetafile;
typedef PdfMetafileSkia PreviewMetafile;
-#endif
} // namespace printing