OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/printing/print_view_manager_base.h" | 5 #include "chrome/browser/printing/print_view_manager_base.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #if defined(WIN_PDF_METAFILE_FOR_PRINTING) | 43 #if defined(WIN_PDF_METAFILE_FOR_PRINTING) |
44 #include "base/memory/ref_counted.h" | 44 #include "base/memory/ref_counted.h" |
45 #include "base/memory/ref_counted_memory.h" | 45 #include "base/memory/ref_counted_memory.h" |
46 #include "chrome/browser/printing/pdf_to_emf_converter.h" | 46 #include "chrome/browser/printing/pdf_to_emf_converter.h" |
47 #include "printing/pdf_render_settings.h" | 47 #include "printing/pdf_render_settings.h" |
48 #endif | 48 #endif |
49 | 49 |
50 using base::TimeDelta; | 50 using base::TimeDelta; |
51 using content::BrowserThread; | 51 using content::BrowserThread; |
52 | 52 |
| 53 namespace printing { |
| 54 |
| 55 namespace { |
| 56 |
53 #if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING) | 57 #if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING) |
54 // Limits memory usage by raster to 64 MiB. | 58 // Limits memory usage by raster to 64 MiB. |
55 const int kMaxRasterSizeInPixels = 16*1024*1024; | 59 const int kMaxRasterSizeInPixels = 16*1024*1024; |
56 #endif | 60 #endif |
57 | 61 |
58 namespace printing { | 62 } // namespace |
59 | 63 |
60 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) | 64 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) |
61 : content::WebContentsObserver(web_contents), | 65 : content::WebContentsObserver(web_contents), |
62 number_pages_(0), | 66 number_pages_(0), |
63 printing_succeeded_(false), | 67 printing_succeeded_(false), |
64 inside_inner_message_loop_(false), | 68 inside_inner_message_loop_(false), |
65 cookie_(0), | 69 cookie_(0), |
66 queue_(g_browser_process->print_job_manager()->queue()) { | 70 queue_(g_browser_process->print_job_manager()->queue()) { |
67 DCHECK(queue_); | 71 DCHECK(queue_); |
68 #if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \ | 72 #if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \ |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 TerminatePrintJob(true); | 217 TerminatePrintJob(true); |
214 web_contents()->Stop(); | 218 web_contents()->Stop(); |
215 return; | 219 return; |
216 } | 220 } |
217 } | 221 } |
218 #endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING | 222 #endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING |
219 | 223 |
220 #if !defined(WIN_PDF_METAFILE_FOR_PRINTING) | 224 #if !defined(WIN_PDF_METAFILE_FOR_PRINTING) |
221 // Update the rendered document. It will send notifications to the listener. | 225 // Update the rendered document. It will send notifications to the listener. |
222 document->SetPage(params.page_number, | 226 document->SetPage(params.page_number, |
223 metafile.release(), | 227 metafile.release(), |
224 params.actual_shrink, | 228 params.actual_shrink, |
225 params.page_size, | 229 params.page_size, |
226 params.content_area); | 230 params.content_area); |
227 | 231 |
228 ShouldQuitFromInnerMessageLoop(); | 232 ShouldQuitFromInnerMessageLoop(); |
229 #else | 233 #else |
230 if (metafile_must_be_valid) { | 234 if (metafile_must_be_valid) { |
231 scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes( | 235 scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes( |
232 reinterpret_cast<const unsigned char*>(shared_buf.memory()), | 236 reinterpret_cast<const unsigned char*>(shared_buf.memory()), |
233 params.data_size); | 237 params.data_size); |
234 | 238 |
| 239 document->DebugDumpData(bytes, "pdf"); |
| 240 |
235 if (!pdf_to_emf_converter_) | 241 if (!pdf_to_emf_converter_) |
236 pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault(); | 242 pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault(); |
237 | 243 |
238 const int kPrinterDpi = 600; | 244 const int kPrinterDpi = 600; |
239 pdf_to_emf_converter_->Start( | 245 pdf_to_emf_converter_->Start( |
240 bytes, | 246 bytes, |
241 printing::PdfRenderSettings(params.content_area, kPrinterDpi, false), | 247 printing::PdfRenderSettings(params.content_area, kPrinterDpi, false), |
242 base::Bind(&PrintViewManagerBase::OnPdfToEmfConverted, | 248 base::Bind(&PrintViewManagerBase::OnPdfToEmfConverted, |
243 base::Unretained(this), | 249 base::Unretained(this), |
244 params)); | 250 params)); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 scoped_refptr<printing::PrinterQuery> printer_query; | 594 scoped_refptr<printing::PrinterQuery> printer_query; |
589 printer_query = queue_->PopPrinterQuery(cookie); | 595 printer_query = queue_->PopPrinterQuery(cookie); |
590 if (!printer_query) | 596 if (!printer_query) |
591 return; | 597 return; |
592 BrowserThread::PostTask( | 598 BrowserThread::PostTask( |
593 BrowserThread::IO, FROM_HERE, | 599 BrowserThread::IO, FROM_HERE, |
594 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 600 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
595 } | 601 } |
596 | 602 |
597 } // namespace printing | 603 } // namespace printing |
OLD | NEW |