summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka <vitalybuka@chromium.org>2014-09-12 02:19:59 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-12 09:28:05 +0000
commit5d1290581ae0d39d5c640c1f95ba298946515dbe (patch)
tree370d078537161b95c196d42a121ff0ede1d2f547
parent07d6071e18c1fa48a7667c1ca78a64573dd4c849 (diff)
downloadchromium_src-5d1290581ae0d39d5c640c1f95ba298946515dbe.zip
chromium_src-5d1290581ae0d39d5c640c1f95ba298946515dbe.tar.gz
chromium_src-5d1290581ae0d39d5c640c1f95ba298946515dbe.tar.bz2
Extracted MetafilePlayer interface from printing::MetafilePlayer.
Removed some unused code. Updated interfaces from plain pointers to scoped_ptr<> SaveTo(base::FilePath) replaced with SaveTo(base::File). BUG=408184 TBR=sgurun@chromium.org Review URL: https://codereview.chromium.org/568633002 Cr-Commit-Position: refs/heads/master@{#294556}
-rw-r--r--android_webview/renderer/print_web_view_helper_linux.cc4
-rw-r--r--chrome/browser/printing/pdf_to_emf_converter.cc2
-rw-r--r--chrome/browser/printing/pdf_to_emf_converter.h11
-rw-r--r--chrome/browser/printing/print_view_manager_base.cc6
-rw-r--r--chrome/browser/printing/print_view_manager_base.h4
-rw-r--r--chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc38
-rw-r--r--chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h4
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_handler.cc4
-rw-r--r--chrome/renderer/printing/print_web_view_helper_linux.cc4
-rw-r--r--chrome/renderer/printing/print_web_view_helper_mac.mm4
-rw-r--r--chrome/renderer/printing/print_web_view_helper_pdf_win.cc4
-rw-r--r--chrome/service/cloud_print/print_system_win.cc2
-rw-r--r--chrome/service/service_utility_process_host.h4
-rw-r--r--printing/BUILD.gn1
-rw-r--r--printing/emf_win.cc41
-rw-r--r--printing/emf_win.h21
-rw-r--r--printing/emf_win_unittest.cc12
-rw-r--r--printing/metafile.cc49
-rw-r--r--printing/metafile.h88
-rw-r--r--printing/pdf_metafile_cg_mac.cc13
-rw-r--r--printing/pdf_metafile_cg_mac.h3
-rw-r--r--printing/pdf_metafile_skia.cc63
-rw-r--r--printing/pdf_metafile_skia.h14
-rw-r--r--printing/print_dialog_gtk_interface.h4
-rw-r--r--printing/printed_document.cc34
-rw-r--r--printing/printed_document.h9
-rw-r--r--printing/printed_document_linux.cc4
-rw-r--r--printing/printed_document_mac.cc2
-rw-r--r--printing/printed_page.cc6
-rw-r--r--printing/printed_page.h6
-rw-r--r--printing/printed_page_unittest.cc31
-rw-r--r--printing/printing.gyp1
-rw-r--r--printing/printing_context_linux.cc3
-rw-r--r--printing/printing_context_linux.h4
34 files changed, 237 insertions, 263 deletions
diff --git a/android_webview/renderer/print_web_view_helper_linux.cc b/android_webview/renderer/print_web_view_helper_linux.cc
index 0229837..6895b25 100644
--- a/android_webview/renderer/print_web_view_helper_linux.cc
+++ b/android_webview/renderer/print_web_view_helper_linux.cc
@@ -52,8 +52,8 @@ bool PrintWebViewHelper::RenderPreviewPage(
} else if (print_preview_context_.IsModifiable() &&
print_preview_context_.generate_draft_pages()) {
DCHECK(!draft_metafile.get());
- draft_metafile.reset(
- print_preview_context_.metafile()->GetMetafileForCurrentPage());
+ draft_metafile =
+ print_preview_context_.metafile()->GetMetafileForCurrentPage();
}
return PreviewPageRendered(page_number, draft_metafile.get());
}
diff --git a/chrome/browser/printing/pdf_to_emf_converter.cc b/chrome/browser/printing/pdf_to_emf_converter.cc
index ad99e3a..f0a8bab 100644
--- a/chrome/browser/printing/pdf_to_emf_converter.cc
+++ b/chrome/browser/printing/pdf_to_emf_converter.cc
@@ -284,7 +284,7 @@ void PdfToEmfUtilityProcessHostClient::RunCallbackOnUIThread(
const std::vector<printing::PageRange>& page_ranges,
double scale_factor) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- ScopedVector<Metafile> pages;
+ ScopedVector<MetafilePlayer> pages;
std::vector<printing::PageRange>::const_iterator iter;
for (iter = page_ranges.begin(); iter != page_ranges.end(); ++iter) {
for (int page_number = iter->from; page_number <= iter->to; ++page_number) {
diff --git a/chrome/browser/printing/pdf_to_emf_converter.h b/chrome/browser/printing/pdf_to_emf_converter.h
index 0ad5a1a..ca7adc4 100644
--- a/chrome/browser/printing/pdf_to_emf_converter.h
+++ b/chrome/browser/printing/pdf_to_emf_converter.h
@@ -14,19 +14,16 @@ class FilePath;
}
namespace printing {
-class PdfRenderSettings;
-}
-namespace printing {
-
-class Metafile;
+class MetafilePlayer;
+class PdfRenderSettings;
class PdfToEmfConverter {
public:
// Callback for when the PDF is converted to an EMF.
// Takes ownership of metafiles.
- typedef base::Callback<
- void(double /*scale_factor*/, ScopedVector<Metafile>* /*emf_files*/)>
+ typedef base::Callback<void(double /*scale_factor*/,
+ ScopedVector<MetafilePlayer>* /*emf_files*/)>
ResultCallback;
virtual ~PdfToEmfConverter() {}
diff --git a/chrome/browser/printing/print_view_manager_base.cc b/chrome/browser/printing/print_view_manager_base.cc
index 45f34df..a888fd4 100644
--- a/chrome/browser/printing/print_view_manager_base.cc
+++ b/chrome/browser/printing/print_view_manager_base.cc
@@ -130,7 +130,7 @@ void PrintViewManagerBase::OnDidGetDocumentCookie(int cookie) {
void PrintViewManagerBase::OnPdfToEmfConverted(
const PrintHostMsg_DidPrintPage_Params& params,
double scale_factor,
- ScopedVector<Metafile>* emf_files) {
+ ScopedVector<MetafilePlayer>* emf_files) {
if (!print_job_.get())
return;
@@ -148,7 +148,7 @@ void PrintViewManagerBase::OnPdfToEmfConverted(
for (size_t i = 0; i < emf_files->size(); ++i) {
// Update the rendered document. It will send notifications to the listener.
document->SetPage(i,
- (*emf_files)[i],
+ make_scoped_ptr((*emf_files)[i]),
scale_factor,
params.page_size,
params.content_area);
@@ -200,7 +200,7 @@ void PrintViewManagerBase::OnDidPrintPage(
#if !defined(OS_WIN)
// Update the rendered document. It will send notifications to the listener.
document->SetPage(params.page_number,
- metafile.release(),
+ metafile.PassAs<MetafilePlayer>(),
params.page_size,
params.content_area);
diff --git a/chrome/browser/printing/print_view_manager_base.h b/chrome/browser/printing/print_view_manager_base.h
index 0a8c5e5..048a4ef 100644
--- a/chrome/browser/printing/print_view_manager_base.h
+++ b/chrome/browser/printing/print_view_manager_base.h
@@ -23,7 +23,7 @@ class RenderViewHost;
namespace printing {
class JobEventDetails;
-class Metafile;
+class MetafilePlayer;
class PdfToEmfConverter;
class PrintJob;
class PrintJobWorkerOwner;
@@ -138,7 +138,7 @@ class PrintViewManagerBase : public content::NotificationObserver,
// Called on completion of converting the pdf to emf.
void OnPdfToEmfConverted(const PrintHostMsg_DidPrintPage_Params& params,
double scale_factor,
- ScopedVector<Metafile>* emf_files);
+ ScopedVector<MetafilePlayer>* emf_files);
#endif // OS_WIN
content::NotificationRegistrar registrar_;
diff --git a/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc b/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc
index 8f1cdb5..e050372 100644
--- a/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc
+++ b/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc
@@ -361,8 +361,8 @@ void PrintDialogGtk2::ShowDialog(
gtk_window_present_with_time(GTK_WINDOW(dialog_), time);
}
-void PrintDialogGtk2::PrintDocument(const printing::Metafile* metafile,
- const base::string16& document_name) {
+void PrintDialogGtk2::PrintDocument(const printing::MetafilePlayer& metafile,
+ const base::string16& document_name) {
// This runs on the print worker thread, does not block the UI thread.
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -370,28 +370,30 @@ void PrintDialogGtk2::PrintDocument(const printing::Metafile* metafile,
// this dialog.
AddRef();
- bool error = false;
- if (!base::CreateTemporaryFile(&path_to_pdf_)) {
- LOG(ERROR) << "Creating temporary file failed";
- error = true;
- }
+ bool success = base::CreateTemporaryFile(&path_to_pdf_);
- if (!error && !metafile->SaveTo(path_to_pdf_)) {
- LOG(ERROR) << "Saving metafile failed";
- base::DeleteFile(path_to_pdf_, false);
- error = true;
+ if (success) {
+ base::File file;
+ file.Initialize(path_to_pdf_,
+ base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+ success = metafile.SaveTo(&file);
+ file.Close();
+ if (!success)
+ base::DeleteFile(path_to_pdf_, false);
}
- if (error) {
+ if (!success) {
+ LOG(ERROR) << "Saving metafile failed";
// Matches AddRef() above.
Release();
- } else {
- // No errors, continue printing.
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&PrintDialogGtk2::SendDocumentToPrinter, this,
- document_name));
+ return;
}
+
+ // No errors, continue printing.
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&PrintDialogGtk2::SendDocumentToPrinter, this, document_name));
}
void PrintDialogGtk2::AddRefToDialog() {
diff --git a/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h b/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h
index ecbb6ec..6c5ad43 100644
--- a/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h
+++ b/chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h
@@ -19,7 +19,7 @@
#include "ui/aura/window_observer.h"
namespace printing {
-class Metafile;
+class MetafilePlayer;
class PrintSettings;
}
@@ -43,7 +43,7 @@ class PrintDialogGtk2
gfx::NativeView parent_view,
bool has_selection,
const PrintingContextLinux::PrintSettingsCallback& callback) OVERRIDE;
- virtual void PrintDocument(const printing::Metafile* metafile,
+ virtual void PrintDocument(const printing::MetafilePlayer& metafile,
const base::string16& document_name) OVERRIDE;
virtual void AddRefToDialog() OVERRIDE;
virtual void ReleaseDialog() OVERRIDE;
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index 06894a4..2b3ac6b 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -246,7 +246,9 @@ void PrintToPdfCallback(const scoped_refptr<base::RefCountedBytes>& data,
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
printing::PdfMetafileSkia metafile;
metafile.InitFromData(static_cast<const void*>(data->front()), data->size());
- metafile.SaveTo(path);
+ base::File file(path,
+ base::File::FLAG_CREATE_ALWAYS || base::File::FLAG_WRITE);
+ metafile.SaveTo(&file);
if (!pdf_file_saved_closure.is_null())
pdf_file_saved_closure.Run();
}
diff --git a/chrome/renderer/printing/print_web_view_helper_linux.cc b/chrome/renderer/printing/print_web_view_helper_linux.cc
index 3d8fb47..edd4eee 100644
--- a/chrome/renderer/printing/print_web_view_helper_linux.cc
+++ b/chrome/renderer/printing/print_web_view_helper_linux.cc
@@ -50,8 +50,8 @@ bool PrintWebViewHelper::RenderPreviewPage(
} else if (print_preview_context_.IsModifiable() &&
print_preview_context_.generate_draft_pages()) {
DCHECK(!draft_metafile.get());
- draft_metafile.reset(
- print_preview_context_.metafile()->GetMetafileForCurrentPage());
+ draft_metafile =
+ print_preview_context_.metafile()->GetMetafileForCurrentPage();
}
return PreviewPageRendered(page_number, draft_metafile.get());
}
diff --git a/chrome/renderer/printing/print_web_view_helper_mac.mm b/chrome/renderer/printing/print_web_view_helper_mac.mm
index c5e6b9f..7747623 100644
--- a/chrome/renderer/printing/print_web_view_helper_mac.mm
+++ b/chrome/renderer/printing/print_web_view_helper_mac.mm
@@ -86,8 +86,8 @@ bool PrintWebViewHelper::RenderPreviewPage(
if (print_preview_context_.IsModifiable() &&
print_preview_context_.generate_draft_pages()) {
DCHECK(!draft_metafile.get());
- draft_metafile.reset(
- print_preview_context_.metafile()->GetMetafileForCurrentPage());
+ draft_metafile =
+ print_preview_context_.metafile()->GetMetafileForCurrentPage();
}
}
return PreviewPageRendered(page_number, draft_metafile.get());
diff --git a/chrome/renderer/printing/print_web_view_helper_pdf_win.cc b/chrome/renderer/printing/print_web_view_helper_pdf_win.cc
index d0b7621..5a7a249 100644
--- a/chrome/renderer/printing/print_web_view_helper_pdf_win.cc
+++ b/chrome/renderer/printing/print_web_view_helper_pdf_win.cc
@@ -49,8 +49,8 @@ bool PrintWebViewHelper::RenderPreviewPage(
} else if (print_preview_context_.IsModifiable() &&
print_preview_context_.generate_draft_pages()) {
DCHECK(!draft_metafile.get());
- draft_metafile.reset(
- print_preview_context_.metafile()->GetMetafileForCurrentPage());
+ draft_metafile =
+ print_preview_context_.metafile()->GetMetafileForCurrentPage();
}
return PreviewPageRendered(page_number, draft_metafile.get());
}
diff --git a/chrome/service/cloud_print/print_system_win.cc b/chrome/service/cloud_print/print_system_win.cc
index f5e615e..7d252be 100644
--- a/chrome/service/cloud_print/print_system_win.cc
+++ b/chrome/service/cloud_print/print_system_win.cc
@@ -336,7 +336,7 @@ class JobSpoolerWin : public PrintSystem::JobSpooler {
// ServiceUtilityProcessHost::Client implementation.
virtual void OnRenderPDFPagesToMetafileSucceeded(
- const printing::Emf& metafile,
+ const printing::MetafilePlayer& metafile,
int highest_rendered_page_number,
double scale_factor) OVERRIDE {
PreparePageDCForPrinting(printer_dc_.Get(), scale_factor);
diff --git a/chrome/service/service_utility_process_host.h b/chrome/service/service_utility_process_host.h
index ac37bdb..9ad97dd 100644
--- a/chrome/service/service_utility_process_host.h
+++ b/chrome/service/service_utility_process_host.h
@@ -30,7 +30,7 @@ class ChildProcessHost;
}
namespace printing {
-class Emf;
+class MetafilePlayer;
struct PageRange;
struct PrinterCapsAndDefaults;
struct PrinterSemanticCapsAndDefaults;
@@ -54,7 +54,7 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
// Called when at least one page in the specified PDF has been rendered
// successfully into |metafile|.
virtual void OnRenderPDFPagesToMetafileSucceeded(
- const printing::Emf& metafile,
+ const printing::MetafilePlayer& metafile,
int highest_rendered_page_number,
double scale_factor) {}
// Called when no page in the passed in PDF could be rendered.
diff --git a/printing/BUILD.gn b/printing/BUILD.gn
index 2a0d2b5..a1ef97d 100644
--- a/printing/BUILD.gn
+++ b/printing/BUILD.gn
@@ -28,6 +28,7 @@ component("printing") {
"image_linux.cc",
"image_mac.cc",
"image_win.cc",
+ "metafile.cc",
"metafile.h",
"metafile_skia_wrapper.cc",
"metafile_skia_wrapper.h",
diff --git a/printing/emf_win.cc b/printing/emf_win.cc
index b6c9b4f..5497495a 100644
--- a/printing/emf_win.cc
+++ b/printing/emf_win.cc
@@ -4,6 +4,7 @@
#include "printing/emf_win.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -273,38 +274,6 @@ bool Emf::GetData(void* buffer, uint32 size) const {
return size2 == size && size2 != 0;
}
-bool Emf::GetDataAsVector(std::vector<uint8>* buffer) const {
- uint32 size = GetDataSize();
- if (!size)
- return false;
-
- buffer->resize(size);
- if (!GetData(&buffer->front(), size))
- return false;
- return true;
-}
-
-bool Emf::SaveTo(const base::FilePath& file_path) const {
- HANDLE file = CreateFile(file_path.value().c_str(), GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
- CREATE_ALWAYS, 0, NULL);
- if (file == INVALID_HANDLE_VALUE)
- return false;
-
- bool success = false;
- std::vector<uint8> buffer;
- if (GetDataAsVector(&buffer)) {
- DWORD written = 0;
- if (WriteFile(file, &*buffer.begin(), static_cast<DWORD>(buffer.size()),
- &written, NULL) &&
- written == buffer.size()) {
- success = true;
- }
- }
- CloseHandle(file);
- return success;
-}
-
int CALLBACK Emf::SafePlaybackProc(HDC hdc,
HANDLETABLE* handle_table,
const ENHMETARECORD* record,
@@ -606,7 +575,7 @@ bool Emf::IsAlphaBlendUsed() const {
return result;
}
-Emf* Emf::RasterizeMetafile(int raster_area_in_pixels) const {
+scoped_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const {
gfx::Rect page_bounds = GetPageBounds(1);
gfx::Size page_size(page_bounds.size());
if (page_size.GetArea() <= 0) {
@@ -648,10 +617,10 @@ Emf* Emf::RasterizeMetafile(int raster_area_in_pixels) const {
result->FinishPage();
result->FinishDocument();
- return result.release();
+ return result.Pass();
}
-Emf* Emf::RasterizeAlphaBlend() const {
+scoped_ptr<Emf> Emf::RasterizeAlphaBlend() const {
gfx::Rect page_bounds = GetPageBounds(1);
if (page_bounds.size().GetArea() <= 0) {
NOTREACHED() << "Metafile is empty";
@@ -676,7 +645,7 @@ Emf* Emf::RasterizeAlphaBlend() const {
result->FinishDocument();
- return result.release();
+ return result.Pass();
}
diff --git a/printing/emf_win.h b/printing/emf_win.h
index e31e204..f759300 100644
--- a/printing/emf_win.h
+++ b/printing/emf_win.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
+#include "base/memory/scoped_ptr.h"
#include "printing/metafile.h"
namespace base {
@@ -47,10 +48,10 @@ class PRINTING_EXPORT Emf : public Metafile {
// Generates a new metafile that will record every GDI command, and will
// be saved to |metafile_path|.
- virtual bool InitToFile(const base::FilePath& metafile_path);
+ bool InitToFile(const base::FilePath& metafile_path);
// Initializes the Emf with the data in |metafile_path|.
- virtual bool InitFromFile(const base::FilePath& metafile_path);
+ bool InitFromFile(const base::FilePath& metafile_path);
// Metafile methods.
virtual bool Init() OVERRIDE;
@@ -73,11 +74,6 @@ class PRINTING_EXPORT Emf : public Metafile {
virtual uint32 GetDataSize() const OVERRIDE;
virtual bool GetData(void* buffer, uint32 size) const OVERRIDE;
- // Saves the EMF data to a file as-is. It is recommended to use the .emf file
- // extension but it is not enforced. This function synchronously writes to the
- // file. For testing only.
- virtual bool SaveTo(const base::FilePath& file_path) const OVERRIDE;
-
// Should be passed to Playback to keep the exact same size.
virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE;
@@ -92,29 +88,24 @@ class PRINTING_EXPORT Emf : public Metafile {
virtual bool Playback(HDC hdc, const RECT* rect) const OVERRIDE;
virtual bool SafePlayback(HDC hdc) const OVERRIDE;
- virtual HENHMETAFILE emf() const OVERRIDE {
- return emf_;
- }
+ HENHMETAFILE emf() const { return emf_; }
// Returns true if metafile contains alpha blend.
bool IsAlphaBlendUsed() const;
// Returns new metafile with only bitmap created by playback of the current
// metafile. Returns NULL if fails.
- Emf* RasterizeMetafile(int raster_area_in_pixels) const;
+ scoped_ptr<Emf> RasterizeMetafile(int raster_area_in_pixels) const;
// Returns new metafile where AlphaBlend replaced by bitmaps. Returns NULL
// if fails.
- Emf* RasterizeAlphaBlend() const;
+ scoped_ptr<Emf> RasterizeAlphaBlend() const;
private:
FRIEND_TEST_ALL_PREFIXES(EmfTest, DC);
FRIEND_TEST_ALL_PREFIXES(EmfPrintingTest, PageBreak);
FRIEND_TEST_ALL_PREFIXES(EmfTest, FileBackedEmf);
- // Retrieves the underlying data stream. It is a helper function.
- bool GetDataAsVector(std::vector<uint8>* buffer) const;
-
// Playbacks safely one EMF record.
static int CALLBACK SafePlaybackProc(HDC hdc,
HANDLETABLE* handle_table,
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index ad4d8c3..451a532 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -52,7 +52,7 @@ const uint32 EMF_HEADER_SIZE = 128;
TEST(EmfTest, DC) {
// Simplest use case.
uint32 size;
- std::vector<BYTE> data;
+ std::vector<char> data;
{
Emf emf;
EXPECT_TRUE(emf.Init());
@@ -134,7 +134,7 @@ TEST_F(EmfPrintingTest, PageBreak) {
if (!dc.Get())
return;
uint32 size;
- std::vector<BYTE> data;
+ std::vector<char> data;
{
Emf emf;
EXPECT_TRUE(emf.Init());
@@ -179,7 +179,7 @@ TEST(EmfTest, FileBackedEmf) {
EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(),
&metafile_path));
uint32 size;
- std::vector<BYTE> data;
+ std::vector<char> data;
{
Emf emf;
EXPECT_TRUE(emf.InitToFile(metafile_path));
@@ -221,12 +221,12 @@ TEST(EmfTest, RasterizeMetafile) {
// Just 1px bitmap but should be stretched to the same bounds.
EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
- raster.reset(emf.RasterizeMetafile(20));
+ raster = emf.RasterizeMetafile(20);
EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
- raster.reset(emf.RasterizeMetafile(16*1024*1024));
+ raster = emf.RasterizeMetafile(16 * 1024 * 1024);
// Expected size about 64MB.
- EXPECT_LE(abs(int(raster->GetDataSize()) - 64*1024*1024), 1024*1024);
+ EXPECT_LE(abs(int(raster->GetDataSize()) - 64 * 1024 * 1024), 1024 * 1024);
// Bounds should still be the same.
EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
}
diff --git a/printing/metafile.cc b/printing/metafile.cc
new file mode 100644
index 0000000..ece61df
--- /dev/null
+++ b/printing/metafile.cc
@@ -0,0 +1,49 @@
+// Copyright 2014 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 "printing/metafile.h"
+
+#include <vector>
+
+#include "base/files/file.h"
+#include "base/numerics/safe_conversions.h"
+
+namespace printing {
+
+MetafilePlayer::MetafilePlayer() {
+}
+
+MetafilePlayer::~MetafilePlayer() {
+}
+
+Metafile::Metafile() {
+}
+
+Metafile::~Metafile() {
+}
+
+bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
+ buffer->resize(GetDataSize());
+ if (buffer->empty())
+ return false;
+ return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size()));
+}
+
+bool Metafile::SaveTo(base::File* file) const {
+ if (!file->IsValid())
+ return false;
+
+ std::vector<char> buffer;
+ if (!GetDataAsVector(&buffer))
+ return false;
+
+ int size = base::checked_cast<int>(buffer.size());
+ if (file->WriteAtCurrentPos(&buffer[0], size) != size) {
+ DLOG(ERROR) << "Failed to save file.";
+ return false;
+ }
+ return true;
+}
+
+} // namespace printing
diff --git a/printing/metafile.h b/printing/metafile.h
index 5f771e5f..af0b2372 100644
--- a/printing/metafile.h
+++ b/printing/metafile.h
@@ -5,6 +5,8 @@
#ifndef PRINTING_METAFILE_H_
#define PRINTING_METAFILE_H_
+#include <vector>
+
#include "base/basictypes.h"
#include "build/build_config.h"
#include "printing/printing_export.h"
@@ -19,7 +21,7 @@
#endif
namespace base {
-class FilePath;
+class File;
}
namespace gfx {
@@ -29,17 +31,10 @@ class Size;
class SkBaseDevice;
-#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
-namespace base {
-struct FileDescriptor;
-}
-#endif
-
namespace printing {
-// This class creates a graphics context that renders into a data stream
-// (usually PDF or EMF).
-class PRINTING_EXPORT Metafile {
+// This class plays metafiles from data stream (usually PDF or EMF).
+class PRINTING_EXPORT MetafilePlayer {
public:
#if defined(OS_MACOSX)
// |shrink_to_fit| specifies whether the output should be shrunk to fit a
@@ -71,8 +66,40 @@ class PRINTING_EXPORT Metafile {
bool autorotate;
};
#endif // defined(OS_MACOSX)
+ MetafilePlayer();
+ virtual ~MetafilePlayer();
+
+#if defined(OS_WIN)
+ // The slow version of Playback(). It enumerates all the records and play them
+ // back in the HDC. The trick is that it skip over the records known to have
+ // issue with some printers. See Emf::Record::SafePlayback implementation for
+ // details.
+ virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const = 0;
+
+#elif defined(OS_MACOSX)
+ // Renders the given page into |rect| in the given context.
+ // Pages use a 1-based index. The rendering uses the arguments in
+ // |params| to determine scaling, translation, and rotation.
+ virtual bool RenderPage(unsigned int page_number,
+ gfx::NativeDrawingContext context,
+ const CGRect rect,
+ const MacRenderPageParams& params) const = 0;
+#endif // if defined(OS_WIN)
+
+ // Saves the underlying data to the given file. This function should ONLY be
+ // called after the metafile is closed. Returns true if writing succeeded.
+ virtual bool SaveTo(base::File* file) const = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MetafilePlayer);
+};
- virtual ~Metafile() {}
+// This class creates a graphics context that renders into a data stream
+// (usually PDF or EMF).
+class PRINTING_EXPORT Metafile : public MetafilePlayer {
+ public:
+ Metafile();
+ virtual ~Metafile();
// Initializes a fresh new metafile for rendering. Returns false on failure.
// Note: It should only be called from within the renderer process to allocate
@@ -87,10 +114,9 @@ class PRINTING_EXPORT Metafile {
// This method calls StartPage and then returns an appropriate
// VectorPlatformDevice implementation bound to the context created by
// StartPage or NULL on error.
- virtual SkBaseDevice* StartPageForVectorCanvas(
- const gfx::Size& page_size,
- const gfx::Rect& content_area,
- const float& scale_factor) = 0;
+ virtual SkBaseDevice* StartPageForVectorCanvas(const gfx::Size& page_size,
+ const gfx::Rect& content_area,
+ const float& scale_factor) = 0;
// Prepares a context for rendering a new page with the given |page_size|,
// |content_area| and a |scale_factor| to use for the drawing. The units are
@@ -117,15 +143,9 @@ class PRINTING_EXPORT Metafile {
// Returns true if the copy succeeds.
virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
- // Saves the underlying data to the given file. This function should ONLY be
- // called after the metafile is closed. Returns true if writing succeeded.
- virtual bool SaveTo(const base::FilePath& file_path) const = 0;
-
- // Returns the bounds of the given page. Pages use a 1-based index.
virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
virtual unsigned int GetPageCount() const = 0;
- // Get the context for rendering to the PDF.
virtual gfx::NativeDrawingContext context() const = 0;
#if defined(OS_WIN)
@@ -139,28 +159,14 @@ class PRINTING_EXPORT Metafile {
// it requires user intervention.
virtual bool Playback(gfx::NativeDrawingContext hdc,
const RECT* rect) const = 0;
+#endif // OS_WIN
- // The slow version of Playback(). It enumerates all the records and play them
- // back in the HDC. The trick is that it skip over the records known to have
- // issue with some printers. See Emf::Record::SafePlayback implementation for
- // details.
- virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const = 0;
+ bool GetDataAsVector(std::vector<char>* buffer) const;
- virtual HENHMETAFILE emf() const = 0;
-#elif defined(OS_MACOSX)
- // Renders the given page into |rect| in the given context.
- // Pages use a 1-based index. The rendering uses the arguments in
- // |params| to determine scaling, translation, and rotation.
- virtual bool RenderPage(unsigned int page_number,
- gfx::NativeDrawingContext context,
- const CGRect rect,
- const MacRenderPageParams& params) const = 0;
-#elif defined(OS_CHROMEOS) || defined(OS_ANDROID)
- // Saves the underlying data to the file associated with fd. This function
- // should ONLY be called after the metafile is closed.
- // Returns true if writing succeeded.
- virtual bool SaveToFD(const base::FileDescriptor& fd) const = 0;
-#endif // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+ virtual bool SaveTo(base::File* file) const OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Metafile);
};
} // namespace printing
diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc
index 8668738..47915d1 100644
--- a/printing/pdf_metafile_cg_mac.cc
+++ b/printing/pdf_metafile_cg_mac.cc
@@ -286,19 +286,6 @@ bool PdfMetafileCg::GetData(void* dst_buffer, uint32 dst_buffer_size) const {
return true;
}
-bool PdfMetafileCg::SaveTo(const base::FilePath& file_path) const {
- DCHECK(pdf_data_.get());
- DCHECK(!context_.get());
-
- std::string path_string = file_path.value();
- ScopedCFTypeRef<CFURLRef> path_url(CFURLCreateFromFileSystemRepresentation(
- kCFAllocatorDefault, reinterpret_cast<const UInt8*>(path_string.c_str()),
- path_string.length(), false));
- SInt32 error_code;
- CFURLWriteDataAndPropertiesToResource(path_url, pdf_data_, NULL, &error_code);
- return error_code == 0;
-}
-
CGContextRef PdfMetafileCg::context() const {
return context_.get();
}
diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h
index 331129a..98c8ea4 100644
--- a/printing/pdf_metafile_cg_mac.h
+++ b/printing/pdf_metafile_cg_mac.h
@@ -49,9 +49,6 @@ class PRINTING_EXPORT PdfMetafileCg : public Metafile {
virtual uint32 GetDataSize() const OVERRIDE;
virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const OVERRIDE;
- // For testing purposes only.
- virtual bool SaveTo(const base::FilePath& file_path) const OVERRIDE;
-
virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE;
virtual unsigned int GetPageCount() const OVERRIDE;
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
index 899232d..36a42d9 100644
--- a/printing/pdf_metafile_skia.cc
+++ b/printing/pdf_metafile_skia.cc
@@ -128,18 +128,6 @@ bool PdfMetafileSkia::GetData(void* dst_buffer,
return true;
}
-bool PdfMetafileSkia::SaveTo(const base::FilePath& file_path) const {
- DCHECK_GT(data_->pdf_stream_.getOffset(), 0U);
- SkAutoDataUnref data(data_->pdf_stream_.copyToData());
- if (base::WriteFile(file_path,
- reinterpret_cast<const char*>(data->data()),
- GetDataSize()) != static_cast<int>(GetDataSize())) {
- DLOG(ERROR) << "Failed to save file " << file_path.value().c_str();
- return false;
- }
- return true;
-}
-
gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const {
// TODO(vandebo) add a method to get the page size for a given page to
// SkPDFDocument.
@@ -170,10 +158,6 @@ bool PdfMetafileSkia::SafePlayback(gfx::NativeDrawingContext hdc) const {
return false;
}
-HENHMETAFILE PdfMetafileSkia::emf() const {
- NOTREACHED();
- return NULL;
-}
#elif defined(OS_MACOSX)
/* TODO(caryclark): The set up of PluginInstance::PrintPDFOutput may result in
rasterized output. Even if that flow uses PdfMetafileCg::RenderPage,
@@ -203,23 +187,15 @@ bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {
DLOG(ERROR) << "Invalid file descriptor!";
return false;
}
-
- bool result = true;
+ base::File file(fd.fd);
SkAutoDataUnref data(data_->pdf_stream_.copyToData());
- if (base::WriteFileDescriptor(fd.fd,
- reinterpret_cast<const char*>(data->data()),
- GetDataSize()) !=
- static_cast<int>(GetDataSize())) {
- DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
- result = false;
- }
+ bool result =
+ file.WriteAtCurrentPos(reinterpret_cast<const char*>(data->data()),
+ GetDataSize()) == static_cast<int>(GetDataSize());
+ DLOG_IF(ERROR, !result) << "Failed to save file with fd " << fd.fd;
- if (fd.auto_close) {
- if (IGNORE_EINTR(close(fd.fd)) < 0) {
- DPLOG(WARNING) << "close";
- result = false;
- }
- }
+ if (!fd.auto_close)
+ file.TakePlatformFile();
return result;
}
#endif
@@ -229,23 +205,26 @@ PdfMetafileSkia::PdfMetafileSkia()
page_outstanding_(false) {
}
-PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
+scoped_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage() {
+ scoped_ptr<PdfMetafileSkia> metafile;
SkPDFDocument pdf_doc(SkPDFDocument::kDraftMode_Flags);
- SkDynamicMemoryWStream pdf_stream;
if (!pdf_doc.appendPage(data_->current_page_.get()))
- return NULL;
+ return metafile.Pass();
+ SkDynamicMemoryWStream pdf_stream;
if (!pdf_doc.emitPDF(&pdf_stream))
- return NULL;
+ return metafile.Pass();
- SkAutoDataUnref data(pdf_stream.copyToData());
- if (data->size() == 0)
- return NULL;
+ SkAutoDataUnref data_copy(pdf_stream.copyToData());
+ if (data_copy->size() == 0)
+ return scoped_ptr<PdfMetafileSkia>();
- PdfMetafileSkia* metafile = new PdfMetafileSkia;
- metafile->InitFromData(data->bytes(),
- base::checked_cast<uint32>(data->size()));
- return metafile;
+ metafile.reset(new PdfMetafileSkia);
+ if (!metafile->InitFromData(data_copy->bytes(),
+ base::checked_cast<uint32>(data_copy->size()))) {
+ metafile.reset();
+ }
+ return metafile.Pass();
}
} // namespace printing
diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h
index b44133f..f46fd3c 100644
--- a/printing/pdf_metafile_skia.h
+++ b/printing/pdf_metafile_skia.h
@@ -15,6 +15,12 @@
#include <windows.h>
#endif
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
+namespace base {
+struct FileDescriptor;
+}
+#endif
+
namespace printing {
struct PdfMetafileSkiaData;
@@ -44,8 +50,6 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
virtual uint32 GetDataSize() const OVERRIDE;
virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const OVERRIDE;
- virtual bool SaveTo(const base::FilePath& file_path) const OVERRIDE;
-
virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE;
virtual unsigned int GetPageCount() const OVERRIDE;
@@ -55,7 +59,6 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
virtual bool Playback(gfx::NativeDrawingContext hdc,
const RECT* rect) const OVERRIDE;
virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const OVERRIDE;
- virtual HENHMETAFILE emf() const OVERRIDE;
#elif defined(OS_MACOSX)
virtual bool RenderPage(unsigned int page_number,
gfx::NativeDrawingContext context,
@@ -64,11 +67,12 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
#endif
#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
- virtual bool SaveToFD(const base::FileDescriptor& fd) const OVERRIDE;
+ // TODO(vitalybuka): replace with SaveTo().
+ bool SaveToFD(const base::FileDescriptor& fd) const;
#endif // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
// Return a new metafile containing just the current page in draft mode.
- PdfMetafileSkia* GetMetafileForCurrentPage();
+ scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage();
private:
scoped_ptr<PdfMetafileSkiaData> data_;
diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h
index e06e43e..5c47b28 100644
--- a/printing/print_dialog_gtk_interface.h
+++ b/printing/print_dialog_gtk_interface.h
@@ -11,7 +11,7 @@
namespace printing {
-class Metafile;
+class MetafilePlayer;
class PrintSettings;
// An interface for GTK printing dialogs. Classes that live outside of
@@ -36,7 +36,7 @@ class PrintDialogGtkInterface {
// Prints the document named |document_name| contained in |metafile|.
// Called from the print worker thread. Once called, the
// PrintDialogGtkInterface instance should not be reused.
- virtual void PrintDocument(const Metafile* metafile,
+ virtual void PrintDocument(const MetafilePlayer& metafile,
const base::string16& document_name) = 0;
// Same as AddRef/Release, but with different names since
diff --git a/printing/printed_document.cc b/printing/printed_document.cc
index f1b507d..63fce8f 100644
--- a/printing/printed_document.cc
+++ b/printing/printed_document.cc
@@ -48,13 +48,15 @@ void DebugDumpPageTask(const base::string16& doc_name,
base::string16 filename = doc_name;
filename +=
base::ASCIIToUTF16(base::StringPrintf("_%04d", page->page_number()));
+ base::FilePath file_path =
#if defined(OS_WIN)
- page->metafile()->SaveTo(PrintedDocument::CreateDebugDumpPath(
- filename, FILE_PATH_LITERAL(".emf")));
+ PrintedDocument::CreateDebugDumpPath(filename, FILE_PATH_LITERAL(".emf"));
#else // OS_WIN
- page->metafile()->SaveTo(PrintedDocument::CreateDebugDumpPath(
- filename, FILE_PATH_LITERAL(".pdf")));
+ PrintedDocument::CreateDebugDumpPath(filename, FILE_PATH_LITERAL(".pdf"));
#endif // OS_WIN
+ base::File file(file_path,
+ base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
+ page->metafile()->SaveTo(&file);
}
void DebugDumpDataTask(const base::string16& doc_name,
@@ -109,7 +111,7 @@ PrintedDocument::~PrintedDocument() {
}
void PrintedDocument::SetPage(int page_number,
- Metafile* metafile,
+ scoped_ptr<MetafilePlayer> metafile,
#if defined(OS_WIN)
double shrink,
#endif // OS_WIN
@@ -118,7 +120,7 @@ void PrintedDocument::SetPage(int page_number,
// Notice the page_number + 1, the reason is that this is the value that will
// be shown. Users dislike 0-based counting.
scoped_refptr<PrintedPage> page(
- new PrintedPage(page_number + 1, metafile, paper_size, page_rect));
+ new PrintedPage(page_number + 1, metafile.Pass(), paper_size, page_rect));
#if defined(OS_WIN)
page->set_shrink_factor(shrink);
#endif // OS_WIN
@@ -177,26 +179,6 @@ void PrintedDocument::DisconnectSource() {
mutable_.source_ = NULL;
}
-uint32 PrintedDocument::MemoryUsage() const {
- std::vector< scoped_refptr<PrintedPage> > pages_copy;
- {
- base::AutoLock lock(lock_);
- pages_copy.reserve(mutable_.pages_.size());
- PrintedPages::const_iterator end = mutable_.pages_.end();
- for (PrintedPages::const_iterator itr = mutable_.pages_.begin();
- itr != end; ++itr) {
- if (itr->second.get()) {
- pages_copy.push_back(itr->second);
- }
- }
- }
- uint32 total = 0;
- for (size_t i = 0; i < pages_copy.size(); ++i) {
- total += pages_copy[i]->metafile()->GetDataSize();
- }
- return total;
-}
-
void PrintedDocument::set_page_count(int max_page) {
base::AutoLock lock(lock_);
DCHECK_EQ(0, mutable_.page_count_);
diff --git a/printing/printed_document.h b/printing/printed_document.h
index 4d0e41e..47c9ec7 100644
--- a/printing/printed_document.h
+++ b/printing/printed_document.h
@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/synchronization/lock.h"
#include "printing/print_settings.h"
@@ -21,7 +22,7 @@ class TaskRunner;
namespace printing {
-class Metafile;
+class MetafilePlayer;
class PrintedPage;
class PrintedPagesSource;
class PrintingContext;
@@ -45,7 +46,7 @@ class PRINTING_EXPORT PrintedDocument
// Sets a page's data. 0-based. Takes metafile ownership.
// Note: locks for a short amount of time.
void SetPage(int page_number,
- Metafile* metafile,
+ scoped_ptr<MetafilePlayer> metafile,
#if defined(OS_WIN)
double shrink,
#endif // OS_WIN
@@ -76,10 +77,6 @@ class PRINTING_EXPORT PrintedDocument
// the source is being destroyed.
void DisconnectSource();
- // Retrieves the current memory usage of the renderer pages.
- // Note: locks for a short amount of time.
- uint32 MemoryUsage() const;
-
// Sets the number of pages in the document to be rendered. Can only be set
// once.
// Note: locks for a short amount of time.
diff --git a/printing/printed_document_linux.cc b/printing/printed_document_linux.cc
index a800307..a104171 100644
--- a/printing/printed_document_linux.cc
+++ b/printing/printed_document_linux.cc
@@ -27,8 +27,8 @@ void PrintedDocument::RenderPrintedPage(
{
base::AutoLock lock(lock_);
if (page.page_number() - 1 == mutable_.first_page) {
- static_cast<PrintingContextLinux*>(context)->PrintDocument(
- page.metafile());
+ static_cast<PrintingContextLinux*>(context)
+ ->PrintDocument(*page.metafile());
}
}
}
diff --git a/printing/printed_document_mac.cc b/printing/printed_document_mac.cc
index cc671e1..3710d62 100644
--- a/printing/printed_document_mac.cc
+++ b/printing/printed_document_mac.cc
@@ -29,7 +29,7 @@ void PrintedDocument::RenderPrintedPage(
gfx::Rect content_area;
page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area);
- const Metafile* metafile = page.metafile();
+ const MetafilePlayer* metafile = page.metafile();
// Each Metafile is a one-page PDF, and pages use 1-based indexing.
const int page_number = 1;
struct Metafile::MacRenderPageParams params;
diff --git a/printing/printed_page.cc b/printing/printed_page.cc
index 19b9fd3..998f8be 100644
--- a/printing/printed_page.cc
+++ b/printing/printed_page.cc
@@ -7,11 +7,11 @@
namespace printing {
PrintedPage::PrintedPage(int page_number,
- Metafile* metafile,
+ scoped_ptr<MetafilePlayer> metafile,
const gfx::Size& page_size,
const gfx::Rect& page_content_rect)
: page_number_(page_number),
- metafile_(metafile),
+ metafile_(metafile.Pass()),
#if defined(OS_WIN)
shrink_factor_(0.0f),
#endif // OS_WIN
@@ -22,7 +22,7 @@ PrintedPage::PrintedPage(int page_number,
PrintedPage::~PrintedPage() {
}
-const Metafile* PrintedPage::metafile() const {
+const MetafilePlayer* PrintedPage::metafile() const {
return metafile_.get();
}
diff --git a/printing/printed_page.h b/printing/printed_page.h
index a1adfa4..0859502 100644
--- a/printing/printed_page.h
+++ b/printing/printed_page.h
@@ -23,13 +23,13 @@ class PRINTING_EXPORT PrintedPage
: public base::RefCountedThreadSafe<PrintedPage> {
public:
PrintedPage(int page_number,
- Metafile* metafile,
+ scoped_ptr<MetafilePlayer> metafile,
const gfx::Size& page_size,
const gfx::Rect& page_content_rect);
// Getters
int page_number() const { return page_number_; }
- const Metafile* metafile() const;
+ const MetafilePlayer* metafile() const;
const gfx::Size& page_size() const { return page_size_; }
const gfx::Rect& page_content_rect() const { return page_content_rect_; }
#if defined(OS_WIN)
@@ -53,7 +53,7 @@ class PRINTING_EXPORT PrintedPage
const int page_number_;
// Actual paint data.
- const scoped_ptr<Metafile> metafile_;
+ const scoped_ptr<MetafilePlayer> metafile_;
#if defined(OS_WIN)
// Shrink done in comparison to desired_dpi.
diff --git a/printing/printed_page_unittest.cc b/printing/printed_page_unittest.cc
index d37d93a..795afe4 100644
--- a/printing/printed_page_unittest.cc
+++ b/printing/printed_page_unittest.cc
@@ -12,8 +12,10 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) {
gfx::Rect page_content;
// No centering.
- page = new PrintedPage(
- 1, NULL, gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100));
+ page = new PrintedPage(1,
+ scoped_ptr<MetafilePlayer>(),
+ gfx::Size(1200, 1200),
+ gfx::Rect(0, 0, 400, 1100));
page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
EXPECT_EQ(0, page_content.x());
EXPECT_EQ(0, page_content.y());
@@ -21,8 +23,10 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) {
EXPECT_EQ(1100, page_content.height());
// X centered.
- page = new PrintedPage(
- 1, NULL, gfx::Size(500, 1200), gfx::Rect(0, 0, 400, 1100));
+ page = new PrintedPage(1,
+ scoped_ptr<MetafilePlayer>(),
+ gfx::Size(500, 1200),
+ gfx::Rect(0, 0, 400, 1100));
page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
EXPECT_EQ(250, page_content.x());
EXPECT_EQ(0, page_content.y());
@@ -30,8 +34,10 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) {
EXPECT_EQ(1100, page_content.height());
// Y centered.
- page = new PrintedPage(
- 1, NULL, gfx::Size(1200, 500), gfx::Rect(0, 0, 400, 1100));
+ page = new PrintedPage(1,
+ scoped_ptr<MetafilePlayer>(),
+ gfx::Size(1200, 500),
+ gfx::Rect(0, 0, 400, 1100));
page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
EXPECT_EQ(0, page_content.x());
EXPECT_EQ(250, page_content.y());
@@ -39,8 +45,10 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) {
EXPECT_EQ(1100, page_content.height());
// Both X and Y centered.
- page =
- new PrintedPage(1, NULL, gfx::Size(500, 500), gfx::Rect(0, 0, 400, 1100));
+ page = new PrintedPage(1,
+ scoped_ptr<MetafilePlayer>(),
+ gfx::Size(500, 500),
+ gfx::Rect(0, 0, 400, 1100));
page->GetCenteredPageContentRect(gfx::Size(1000, 1000), &page_content);
EXPECT_EQ(250, page_content.x());
EXPECT_EQ(250, page_content.y());
@@ -50,8 +58,11 @@ TEST(PrintedPageTest, GetCenteredPageContentRect) {
#if defined(OS_WIN)
TEST(PrintedPageTest, Shrink) {
- scoped_refptr<PrintedPage> page = new PrintedPage(
- 1, NULL, gfx::Size(1200, 1200), gfx::Rect(0, 0, 400, 1100));
+ scoped_refptr<PrintedPage> page =
+ new PrintedPage(1,
+ scoped_ptr<MetafilePlayer>(),
+ gfx::Size(1200, 1200),
+ gfx::Rect(0, 0, 400, 1100));
EXPECT_EQ(0.0f, page->shrink_factor());
page->set_shrink_factor(0.2f);
EXPECT_EQ(0.2f, page->shrink_factor());
diff --git a/printing/printing.gyp b/printing/printing.gyp
index 43f903d..48e289a 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -44,6 +44,7 @@
'image_linux.cc',
'image_mac.cc',
'image_win.cc',
+ 'metafile.cc',
'metafile.h',
'metafile_skia_wrapper.cc',
'metafile_skia_wrapper.h',
diff --git a/printing/printing_context_linux.cc b/printing/printing_context_linux.cc
index 926d4e2..8e23577 100644
--- a/printing/printing_context_linux.cc
+++ b/printing/printing_context_linux.cc
@@ -59,9 +59,8 @@ void PrintingContextLinux::SetPdfPaperSizeFunction(
get_pdf_paper_size_ = get_pdf_paper_size;
}
-void PrintingContextLinux::PrintDocument(const Metafile* metafile) {
+void PrintingContextLinux::PrintDocument(const MetafilePlayer& metafile) {
DCHECK(print_dialog_);
- DCHECK(metafile);
print_dialog_->PrintDocument(metafile, document_name_);
}
diff --git a/printing/printing_context_linux.h b/printing/printing_context_linux.h
index af59806..ca7085a 100644
--- a/printing/printing_context_linux.h
+++ b/printing/printing_context_linux.h
@@ -15,7 +15,7 @@ class DictionaryValue;
namespace printing {
-class Metafile;
+class MetafilePlayer;
class PrintDialogGtkInterface;
// PrintingContext with optional native UI for print dialog and pdf_paper_size.
@@ -34,7 +34,7 @@ class PRINTING_EXPORT PrintingContextLinux : public PrintingContext {
gfx::Size (*get_pdf_paper_size)(PrintingContextLinux* context));
// Prints the document contained in |metafile|.
- void PrintDocument(const Metafile* metafile);
+ void PrintDocument(const MetafilePlayer& metafile);
// PrintingContext implementation.
virtual void AskUserForSettings(