Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: chrome/renderer/mock_printer.cc

Issue 6826027: Connect the right metafiles for print preview on Linux and Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile problems Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/common_param_traits_unittest.cc ('k') | chrome/renderer/print_web_view_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/mock_printer.h" 5 #include "chrome/renderer/mock_printer.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/shared_memory.h" 8 #include "base/shared_memory.h"
9 #include "chrome/common/print_messages.h" 9 #include "chrome/common/print_messages.h"
10 #include "ipc/ipc_message_utils.h" 10 #include "ipc/ipc_message_utils.h"
11 #include "printing/native_metafile_factory.h" 11 #include "printing/metafile_impl.h"
12 #include "printing/native_metafile.h"
13 #include "printing/units.h" 12 #include "printing/units.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 MockPrinterPage::MockPrinterPage(const void* source_data, 15 MockPrinterPage::MockPrinterPage(const void* source_data,
17 uint32 source_size, 16 uint32 source_size,
18 const printing::Image& image) 17 const printing::Image& image)
19 : source_size_(source_size), 18 : source_size_(source_size),
20 image_(image) { 19 image_(image) {
21 // Create copies of the source data 20 // Create copies of the source data
22 source_data_.reset(new uint8[source_size]); 21 source_data_.reset(new uint8[source_size]);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // We duplicate the given file handle when creating a base::SharedMemory 129 // We duplicate the given file handle when creating a base::SharedMemory
131 // instance so that its destructor closes the copy. 130 // instance so that its destructor closes the copy.
132 EXPECT_GT(params.data_size, 0U); 131 EXPECT_GT(params.data_size, 0U);
133 #if defined(OS_WIN) 132 #if defined(OS_WIN)
134 base::SharedMemory metafile_data(params.metafile_data_handle, true, 133 base::SharedMemory metafile_data(params.metafile_data_handle, true,
135 GetCurrentProcess()); 134 GetCurrentProcess());
136 #elif defined(OS_MACOSX) 135 #elif defined(OS_MACOSX)
137 base::SharedMemory metafile_data(params.metafile_data_handle, true); 136 base::SharedMemory metafile_data(params.metafile_data_handle, true);
138 #endif 137 #endif
139 metafile_data.Map(params.data_size); 138 metafile_data.Map(params.data_size);
140 scoped_ptr<printing::NativeMetafile> metafile( 139 printing::NativeMetafile metafile;
141 printing::NativeMetafileFactory::CreateFromData(metafile_data.memory(), 140 metafile.InitFromData(metafile_data.memory(), params.data_size);
142 params.data_size)); 141 printing::Image image(metafile);
143 CHECK(metafile.get());
144 printing::Image image(*metafile);
145 MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(), 142 MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(),
146 params.data_size, 143 params.data_size,
147 image); 144 image);
148 if (!page_data) { 145 if (!page_data) {
149 printer_status_ = PRINTER_ERROR; 146 printer_status_ = PRINTER_ERROR;
150 return; 147 return;
151 } 148 }
152 149
153 scoped_refptr<MockPrinterPage> page(page_data); 150 scoped_refptr<MockPrinterPage> page(page_data);
154 pages_.push_back(page); 151 pages_.push_back(page);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (printer_status_ != PRINTER_READY || page >= pages_.size()) 207 if (printer_status_ != PRINTER_READY || page >= pages_.size())
211 return false; 208 return false;
212 209
213 pages_[page]->image().SaveToPng(filepath); 210 pages_[page]->image().SaveToPng(filepath);
214 return true; 211 return true;
215 } 212 }
216 213
217 int MockPrinter::CreateDocumentCookie() { 214 int MockPrinter::CreateDocumentCookie() {
218 return ++current_document_cookie_; 215 return ++current_document_cookie_;
219 } 216 }
OLDNEW
« no previous file with comments | « chrome/common/common_param_traits_unittest.cc ('k') | chrome/renderer/print_web_view_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698