summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-26 00:28:36 +0000
committerdpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-26 00:28:36 +0000
commit67c5be79a53904e4ab5a6617bf9cbad9f7f5de6f (patch)
treed3d8e5c52a081276c4e7e5a44f77cc8d49a70c21
parent70ce2ea6a9312b849f9909b26d52c147e6033e38 (diff)
downloadchromium_src-67c5be79a53904e4ab5a6617bf9cbad9f7f5de6f.zip
chromium_src-67c5be79a53904e4ab5a6617bf9cbad9f7f5de6f.tar.gz
chromium_src-67c5be79a53904e4ab5a6617bf9cbad9f7f5de6f.tar.bz2
Adding CreateFromData to NativeMetafileFactory
Also making Create method calling Init on the metafile before returning it. Usually clients of the NativeMetafileFactory call Create and the Init or InitFromData on the object to initialize it. Now the returned object will already be initialized. BUG=NONE TEST=NONE Review URL: http://codereview.chromium.org/6696076 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79475 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/mock_printer.cc5
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc2
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm4
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc3
-rw-r--r--printing/image.cc6
-rw-r--r--printing/native_metafile_factory.cc21
-rw-r--r--printing/native_metafile_factory.h14
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc7
8 files changed, 46 insertions, 16 deletions
diff --git a/chrome/renderer/mock_printer.cc b/chrome/renderer/mock_printer.cc
index 5b46804..a4efbfe 100644
--- a/chrome/renderer/mock_printer.cc
+++ b/chrome/renderer/mock_printer.cc
@@ -138,8 +138,9 @@ void MockPrinter::PrintPage(const PrintHostMsg_DidPrintPage_Params& params) {
#endif
metafile_data.Map(params.data_size);
scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
- metafile->InitFromData(metafile_data.memory(), params.data_size);
+ printing::NativeMetafileFactory::CreateFromData(metafile_data.memory(),
+ params.data_size));
+ CHECK(metafile.get());
printing::Image image(*metafile);
MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(),
params.data_size,
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 98a2f80..5c466e9 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -172,8 +172,6 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
if (!*page_count)
return false;
- metafile->Init();
-
PrintMsg_PrintPage_Params page_params;
page_params.params = printParams;
const gfx::Size& canvas_size = prep_frame_view.GetPrintCanvasSize();
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index 2ef74d3..83e1f1f 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -20,7 +20,7 @@ void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params,
WebFrame* frame) {
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
- if (!metafile->Init())
+ if(!metafile.get())
return;
float scale_factor = frame->getPrintPageShrink(params.page_number);
@@ -67,7 +67,7 @@ void PrintWebViewHelper::CreatePreviewDocument(
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
- if (!metafile->Init())
+ if(!metafile.get())
return;
float scale_factor = frame->getPrintPageShrink(0);
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index f733062..840e5fb 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -73,7 +73,6 @@ void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params,
// Each metafile contains a single page.
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
- metafile->Init();
DCHECK(metafile->context());
skia::PlatformDevice::InitializeDC(metafile->context());
@@ -140,7 +139,6 @@ void PrintWebViewHelper::CreatePreviewDocument(
// http://code.google.com/p/chromium/issues/detail?id=62889
scoped_ptr<printing::NativeMetafile> metafile(
printing::NativeMetafileFactory::Create());
- metafile->Init();
DCHECK(metafile->context());
skia::PlatformDevice::InitializeDC(metafile->context());
@@ -260,7 +258,6 @@ void PrintWebViewHelper::RenderPage(
HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
FillRect(bitmap_dc, &rect, whiteBrush);
- metafile2->Init();
HDC hdc = metafile2->context();
DCHECK(hdc);
skia::PlatformDevice::InitializeDC(hdc);
diff --git a/printing/image.cc b/printing/image.cc
index 2f5d7e3..87a6f7e 100644
--- a/printing/image.cc
+++ b/printing/image.cc
@@ -147,8 +147,10 @@ bool Image::LoadPng(const std::string& compressed) {
bool Image::LoadMetafile(const std::string& data) {
DCHECK(!data.empty());
scoped_ptr<NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
- metafile->InitFromData(data.data(), data.size());
+ printing::NativeMetafileFactory::CreateFromData(data.data(),
+ data.size()));
+ if(!metafile.get())
+ return false;
return LoadMetafile(*metafile);
}
diff --git a/printing/native_metafile_factory.cc b/printing/native_metafile_factory.cc
index f971452..f31994b 100644
--- a/printing/native_metafile_factory.cc
+++ b/printing/native_metafile_factory.cc
@@ -4,6 +4,8 @@
#include "printing/native_metafile_factory.h"
+#include "base/scoped_ptr.h"
+
#if defined(OS_WIN)
#include "printing/emf_win.h"
#elif defined(OS_MACOSX)
@@ -15,7 +17,24 @@
namespace printing {
// static
-printing::NativeMetafile* NativeMetafileFactory::Create() {
+NativeMetafile* NativeMetafileFactory::Create() {
+ scoped_ptr<NativeMetafile> metafile(CreateNewMetafile());
+ if (!metafile->Init())
+ return NULL;
+ return metafile.release();
+}
+
+// static
+NativeMetafile* NativeMetafileFactory::CreateFromData(
+ const void* src_buffer, uint32 src_buffer_size) {
+ scoped_ptr<NativeMetafile> metafile(CreateNewMetafile());
+ if (!metafile->InitFromData(src_buffer, src_buffer_size))
+ return NULL;
+ return metafile.release();
+}
+
+// static
+NativeMetafile* NativeMetafileFactory::CreateNewMetafile(){
#if defined(OS_WIN)
return new printing::Emf;
#elif defined(OS_MACOSX)
diff --git a/printing/native_metafile_factory.h b/printing/native_metafile_factory.h
index b13f17a..610970f 100644
--- a/printing/native_metafile_factory.h
+++ b/printing/native_metafile_factory.h
@@ -17,11 +17,23 @@ namespace printing {
class NativeMetafileFactory {
public:
// This method returns a pointer to the appropriate NativeMetafile object
- // according to the platform.
+ // according to the platform. The metafile is already initialized by invoking
+ // Init() on it. NULL is returned if Init() fails.
static printing::NativeMetafile* Create();
+ // This method returns a pointer to the appropriate NativeMetafile object
+ // according to the platform. The metafile is already initialized by invoking
+ // InitFromData(src_buffer,_buffer_size) on it. NULL is returned if
+ // InitiFromData() fails.
+ static printing::NativeMetafile* CreateFromData(const void* src_buffer,
+ uint32 src_buffer_size);
+
private:
NativeMetafileFactory();
+
+ // Retrieves a new uninitialized metafile.
+ static NativeMetafile* CreateNewMetafile();
+
DISALLOW_COPY_AND_ASSIGN(NativeMetafileFactory);
};
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index d6a1da0..a665285 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -1187,10 +1187,11 @@ bool PluginInstance::PrintPDFOutput(PP_Resource print_output,
if (metafile)
ret = metafile->InitFromData(buffer->mapped_buffer(), buffer->size());
#elif defined(OS_MACOSX)
- scoped_ptr<printing::NativeMetafile> metafile(
- printing::NativeMetafileFactory::Create());
// Create a PDF metafile and render from there into the passed in context.
- if (metafile->InitFromData(buffer->mapped_buffer(), buffer->size())) {
+ scoped_ptr<printing::NativeMetafile> metafile(
+ printing::NativeMetafileFactory::CreateFromData(buffer->mapped_buffer(),
+ buffer->size()));
+ if (metafile.get() != NULL) {
// Flip the transform.
CGContextSaveGState(canvas);
CGContextTranslateCTM(canvas, 0,