OLD | NEW |
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 "printing/pdf_metafile_cg_mac.h" | 5 #include "printing/pdf_metafile_cg_mac.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/mac_util.h" |
9 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/sys_info.h" | |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
15 | 15 |
16 using base::mac::ScopedCFTypeRef; | 16 using base::mac::ScopedCFTypeRef; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // What is up with this ugly hack? <http://crbug.com/64641>, that's what. | 20 // What is up with this ugly hack? <http://crbug.com/64641>, that's what. |
21 // The bug: Printing certain PDFs crashes. The cause: When printing, the | 21 // The bug: Printing certain PDFs crashes. The cause: When printing, the |
22 // renderer process assembles pages one at a time, in PDF format, to send to the | 22 // renderer process assembles pages one at a time, in PDF format, to send to the |
23 // browser process. When printing a PDF, the PDF plugin returns output in PDF | 23 // browser process. When printing a PDF, the PDF plugin returns output in PDF |
24 // format. There is a bug in 10.5 and 10.6 (<rdar://9018916>, | 24 // format. There is a bug in 10.5 and 10.6 (<rdar://9018916>, |
25 // <http://www.openradar.me/9018916>) where reference counting is broken when | 25 // <http://www.openradar.me/9018916>) where reference counting is broken when |
26 // drawing certain PDFs into PDF contexts. So at the high-level, a PdfMetafileCg | 26 // drawing certain PDFs into PDF contexts. So at the high-level, a PdfMetafileCg |
27 // is used to hold the destination context, and then about five layers down on | 27 // is used to hold the destination context, and then about five layers down on |
28 // the callstack, a PdfMetafileCg is used to hold the source PDF. If the source | 28 // the callstack, a PdfMetafileCg is used to hold the source PDF. If the source |
29 // PDF is drawn into the destination PDF context and then released, accessing | 29 // PDF is drawn into the destination PDF context and then released, accessing |
30 // the destination PDF context will crash. So the outermost instantiation of | 30 // the destination PDF context will crash. So the outermost instantiation of |
31 // PdfMetafileCg creates a pool for deeper instantiations to dump their used | 31 // PdfMetafileCg creates a pool for deeper instantiations to dump their used |
32 // PDFs into rather than releasing them. When the top-level PDF is closed, then | 32 // PDFs into rather than releasing them. When the top-level PDF is closed, then |
33 // it's safe to clear the pool. A thread local is used to allow this to work in | 33 // it's safe to clear the pool. A thread local is used to allow this to work in |
34 // single-process mode. TODO(avi): This Apple bug appears fixed in 10.7; when | 34 // single-process mode. TODO(avi): This Apple bug appears fixed in 10.7; when |
35 // 10.7 is the minimum required version for Chromium, remove this hack. | 35 // 10.7 is the minimum required version for Chromium, remove this hack. |
36 | 36 |
37 base::ThreadLocalPointer<struct __CFSet> thread_pdf_docs; | 37 base::ThreadLocalPointer<struct __CFSet> thread_pdf_docs; |
38 | 38 |
39 bool PDFBugFixed() { | 39 bool PDFBugFixed() { |
40 int32 major_version; | 40 return base::mac::IsOSLionOrLater(); |
41 int32 minor_version; | |
42 int32 bugfix_version; | |
43 base::SysInfo::OperatingSystemVersionNumbers(&major_version, | |
44 &minor_version, | |
45 &bugfix_version); | |
46 return | |
47 major_version > 10 || (major_version == 10 && minor_version >= 7); | |
48 } | 41 } |
49 | 42 |
50 } // namespace | 43 } // namespace |
51 | 44 |
52 namespace printing { | 45 namespace printing { |
53 | 46 |
54 PdfMetafileCg::PdfMetafileCg() | 47 PdfMetafileCg::PdfMetafileCg() |
55 : page_is_open_(false), | 48 : page_is_open_(false), |
56 thread_pdf_docs_owned_(false) { | 49 thread_pdf_docs_owned_(false) { |
57 static bool bug_fixed = PDFBugFixed(); | 50 static bool bug_fixed = PDFBugFixed(); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 296 |
304 if (!pdf_doc_.get()) { | 297 if (!pdf_doc_.get()) { |
305 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 298 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
306 CGDataProviderCreateWithCFData(pdf_data_)); | 299 CGDataProviderCreateWithCFData(pdf_data_)); |
307 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 300 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
308 } | 301 } |
309 return pdf_doc_.get(); | 302 return pdf_doc_.get(); |
310 } | 303 } |
311 | 304 |
312 } // namespace printing | 305 } // namespace printing |
OLD | NEW |