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/file_util.h" | |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/numerics/safe_conversions.h" | |
11 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/printing/print_job.h" | 18 #include "chrome/browser/printing/print_job.h" |
17 #include "chrome/browser/printing/print_job_manager.h" | 19 #include "chrome/browser/printing/print_job_manager.h" |
18 #include "chrome/browser/printing/printer_query.h" | 20 #include "chrome/browser/printing/printer_query.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/simple_message_box.h" | 22 #include "chrome/browser/ui/simple_message_box.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
43 #if defined(WIN_PDF_METAFILE_FOR_PRINTING) | 45 #if defined(WIN_PDF_METAFILE_FOR_PRINTING) |
44 #include "base/memory/ref_counted.h" | 46 #include "base/memory/ref_counted.h" |
45 #include "base/memory/ref_counted_memory.h" | 47 #include "base/memory/ref_counted_memory.h" |
46 #include "chrome/browser/printing/pdf_to_emf_converter.h" | 48 #include "chrome/browser/printing/pdf_to_emf_converter.h" |
47 #include "printing/pdf_render_settings.h" | 49 #include "printing/pdf_render_settings.h" |
48 #endif | 50 #endif |
49 | 51 |
50 using base::TimeDelta; | 52 using base::TimeDelta; |
51 using content::BrowserThread; | 53 using content::BrowserThread; |
52 | 54 |
55 namespace printing { | |
56 | |
57 namespace { | |
58 | |
53 #if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING) | 59 #if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING) |
54 // Limits memory usage by raster to 64 MiB. | 60 // Limits memory usage by raster to 64 MiB. |
55 const int kMaxRasterSizeInPixels = 16*1024*1024; | 61 const int kMaxRasterSizeInPixels = 16*1024*1024; |
56 #endif | 62 #endif |
57 | 63 |
58 namespace printing { | 64 #if defined(WIN_PDF_METAFILE_FOR_PRINTING) |
65 void WriteBytesOnFileThread(const base::FilePath& path, | |
66 const base::RefCountedMemory* deta) { | |
67 base::WriteFile(path, | |
68 reinterpret_cast<const char*>(deta->front()), | |
69 base::checked_cast<int>(deta->size())); | |
70 } | |
71 #endif // WIN_PDF_METAFILE_FOR_PRINTING | |
72 | |
73 } // namespace | |
59 | 74 |
60 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) | 75 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) |
61 : content::WebContentsObserver(web_contents), | 76 : content::WebContentsObserver(web_contents), |
62 number_pages_(0), | 77 number_pages_(0), |
63 printing_succeeded_(false), | 78 printing_succeeded_(false), |
64 inside_inner_message_loop_(false), | 79 inside_inner_message_loop_(false), |
65 cookie_(0), | 80 cookie_(0), |
66 queue_(g_browser_process->print_job_manager()->queue()) { | 81 queue_(g_browser_process->print_job_manager()->queue()) { |
67 DCHECK(queue_); | 82 DCHECK(queue_); |
68 #if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \ | 83 #if (defined(OS_POSIX) && !defined(OS_MACOSX)) || \ |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 TerminatePrintJob(true); | 228 TerminatePrintJob(true); |
214 web_contents()->Stop(); | 229 web_contents()->Stop(); |
215 return; | 230 return; |
216 } | 231 } |
217 } | 232 } |
218 #endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING | 233 #endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING |
219 | 234 |
220 #if !defined(WIN_PDF_METAFILE_FOR_PRINTING) | 235 #if !defined(WIN_PDF_METAFILE_FOR_PRINTING) |
221 // Update the rendered document. It will send notifications to the listener. | 236 // Update the rendered document. It will send notifications to the listener. |
222 document->SetPage(params.page_number, | 237 document->SetPage(params.page_number, |
223 metafile.release(), | 238 metafile.release(), |
224 params.actual_shrink, | 239 params.actual_shrink, |
225 params.page_size, | 240 params.page_size, |
226 params.content_area); | 241 params.content_area); |
227 | 242 |
228 ShouldQuitFromInnerMessageLoop(); | 243 ShouldQuitFromInnerMessageLoop(); |
229 #else | 244 #else |
230 if (metafile_must_be_valid) { | 245 if (metafile_must_be_valid) { |
231 scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes( | 246 scoped_refptr<base::RefCountedBytes> bytes = new base::RefCountedBytes( |
232 reinterpret_cast<const unsigned char*>(shared_buf.memory()), | 247 reinterpret_cast<const unsigned char*>(shared_buf.memory()), |
233 params.data_size); | 248 params.data_size); |
234 | 249 |
250 base::FilePath debug_dump_path = | |
251 PrintedDocument::CreateDebugDumpPath(document->name(), "pdf"); | |
252 if (!debug_dump_path.empty()) { | |
253 BrowserThread::PostTask( | |
254 BrowserThread::FILE, | |
255 FROM_HERE, | |
256 base::Bind(&WriteBytesOnFileThread, debug_dump_path, bytes)); | |
Lei Zhang
2014/06/11 20:03:05
You can probably Bind() to &base::WriteFile with I
Vitaly Buka (NO REVIEWS)
2014/06/11 21:32:57
Moved writing into document.
| |
257 } | |
Noam Samuel
2014/06/11 18:35:23
Does this only dump PDFS on Windows? Maybe it make
Vitaly Buka (NO REVIEWS)
2014/06/11 21:32:57
Other platforms dumped pdfs inside of SetPage abov
| |
258 | |
235 if (!pdf_to_emf_converter_) | 259 if (!pdf_to_emf_converter_) |
236 pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault(); | 260 pdf_to_emf_converter_ = PdfToEmfConverter::CreateDefault(); |
237 | 261 |
238 const int kPrinterDpi = 600; | 262 const int kPrinterDpi = 600; |
239 pdf_to_emf_converter_->Start( | 263 pdf_to_emf_converter_->Start( |
240 bytes, | 264 bytes, |
241 printing::PdfRenderSettings(params.content_area, kPrinterDpi, false), | 265 printing::PdfRenderSettings(params.content_area, kPrinterDpi, false), |
242 base::Bind(&PrintViewManagerBase::OnPdfToEmfConverted, | 266 base::Bind(&PrintViewManagerBase::OnPdfToEmfConverted, |
243 base::Unretained(this), | 267 base::Unretained(this), |
244 params)); | 268 params)); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 scoped_refptr<printing::PrinterQuery> printer_query; | 612 scoped_refptr<printing::PrinterQuery> printer_query; |
589 printer_query = queue_->PopPrinterQuery(cookie); | 613 printer_query = queue_->PopPrinterQuery(cookie); |
590 if (!printer_query) | 614 if (!printer_query) |
591 return; | 615 return; |
592 BrowserThread::PostTask( | 616 BrowserThread::PostTask( |
593 BrowserThread::IO, FROM_HERE, | 617 BrowserThread::IO, FROM_HERE, |
594 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 618 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
595 } | 619 } |
596 | 620 |
597 } // namespace printing | 621 } // namespace printing |
OLD | NEW |