| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 params->margin_left = static_cast<int>(0.25 * dpi); | 33 params->margin_left = static_cast<int>(0.25 * dpi); |
| 34 params->margin_top = static_cast<int>(0.25 * dpi); | 34 params->margin_top = static_cast<int>(0.25 * dpi); |
| 35 } else if (margins_type == printing::CUSTOM_MARGINS) { | 35 } else if (margins_type == printing::CUSTOM_MARGINS) { |
| 36 params->content_size.SetSize(static_cast<int>((7.9 * dpi)), | 36 params->content_size.SetSize(static_cast<int>((7.9 * dpi)), |
| 37 static_cast<int>((10.4 * dpi))); | 37 static_cast<int>((10.4 * dpi))); |
| 38 params->margin_left = static_cast<int>(0.30 * dpi); | 38 params->margin_left = static_cast<int>(0.30 * dpi); |
| 39 params->margin_top = static_cast<int>(0.30 * dpi); | 39 params->margin_top = static_cast<int>(0.30 * dpi); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // end | 43 } // namespace |
| 44 | 44 |
| 45 MockPrinterPage::MockPrinterPage(const void* source_data, | 45 MockPrinterPage::MockPrinterPage(const void* source_data, |
| 46 uint32 source_size, | 46 uint32 source_size, |
| 47 const printing::Image& image) | 47 const printing::Image& image) |
| 48 : source_size_(source_size), | 48 : source_size_(source_size), |
| 49 image_(image) { | 49 image_(image) { |
| 50 // Create copies of the source data | 50 // Create copies of the source data |
| 51 source_data_.reset(new uint8[source_size]); | 51 source_data_.reset(new uint8[source_size]); |
| 52 if (source_data_.get()) | 52 if (source_data_.get()) |
| 53 memcpy(source_data_.get(), source_data, source_size); | 53 memcpy(source_data_.get(), source_data, source_size); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 #if defined(OS_MACOSX) | 219 #if defined(OS_MACOSX) |
| 220 printing::PdfMetafileCg metafile; | 220 printing::PdfMetafileCg metafile; |
| 221 #else | 221 #else |
| 222 printing::NativeMetafile metafile; | 222 printing::NativeMetafile metafile; |
| 223 #endif | 223 #endif |
| 224 metafile.InitFromData(metafile_data.memory(), params.data_size); | 224 metafile.InitFromData(metafile_data.memory(), params.data_size); |
| 225 printing::Image image(metafile); | 225 printing::Image image(metafile); |
| 226 MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(), | 226 MockPrinterPage* page_data = new MockPrinterPage(metafile_data.memory(), |
| 227 params.data_size, | 227 params.data_size, |
| 228 image); | 228 image); |
| 229 if (!page_data) { | |
| 230 printer_status_ = PRINTER_ERROR; | |
| 231 return; | |
| 232 } | |
| 233 | |
| 234 scoped_refptr<MockPrinterPage> page(page_data); | 229 scoped_refptr<MockPrinterPage> page(page_data); |
| 235 pages_.push_back(page); | 230 pages_.push_back(page); |
| 236 #endif | 231 #endif |
| 237 | 232 |
| 238 // We finish printing a printing job. | 233 // We finish printing a printing job. |
| 239 // Reset the job status and the printer status. | 234 // Reset the job status and the printer status. |
| 240 ++page_number_; | 235 ++page_number_; |
| 241 if (number_pages_ == page_number_) | 236 if (number_pages_ == page_number_) |
| 242 ResetPrinter(); | 237 ResetPrinter(); |
| 243 } | 238 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 params->margin_top = margin_top_; | 309 params->margin_top = margin_top_; |
| 315 params->is_first_request = is_first_request_; | 310 params->is_first_request = is_first_request_; |
| 316 params->print_scaling_option = print_scaling_option_; | 311 params->print_scaling_option = print_scaling_option_; |
| 317 params->print_to_pdf = print_to_pdf_; | 312 params->print_to_pdf = print_to_pdf_; |
| 318 params->preview_request_id = preview_request_id_; | 313 params->preview_request_id = preview_request_id_; |
| 319 params->display_header_footer = display_header_footer_; | 314 params->display_header_footer = display_header_footer_; |
| 320 params->date = date_; | 315 params->date = date_; |
| 321 params->title = title_; | 316 params->title = title_; |
| 322 params->url = url_; | 317 params->url = url_; |
| 323 } | 318 } |
| OLD | NEW |