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

Side by Side Diff: printing/pdf_metafile_cg_mac.cc

Issue 7144007: Improve and unify Mac OS X run-time version checks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 | « media/audio/mac/audio_manager_mac.cc ('k') | third_party/apple_apsl/CFBase.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 "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() {
40 int32 major_version;
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 }
49
50 } // namespace 39 } // namespace
51 40
52 namespace printing { 41 namespace printing {
53 42
54 PdfMetafileCg::PdfMetafileCg() 43 PdfMetafileCg::PdfMetafileCg()
55 : page_is_open_(false), 44 : page_is_open_(false),
56 thread_pdf_docs_owned_(false) { 45 thread_pdf_docs_owned_(false) {
57 static bool bug_fixed = PDFBugFixed(); 46 if (!thread_pdf_docs.Get() && base::mac::IsOSSnowLeopardOrEarlier()) {
58 if (!thread_pdf_docs.Get() && !bug_fixed) {
59 thread_pdf_docs_owned_ = true; 47 thread_pdf_docs_owned_ = true;
60 thread_pdf_docs.Set(CFSetCreateMutable(kCFAllocatorDefault, 48 thread_pdf_docs.Set(CFSetCreateMutable(kCFAllocatorDefault,
61 0, 49 0,
62 &kCFTypeSetCallBacks)); 50 &kCFTypeSetCallBacks));
63 } 51 }
64 } 52 }
65 53
66 PdfMetafileCg::~PdfMetafileCg() { 54 PdfMetafileCg::~PdfMetafileCg() {
67 DCHECK(CalledOnValidThread()); 55 DCHECK(CalledOnValidThread());
68 if (pdf_doc_ && thread_pdf_docs.Get()) { 56 if (pdf_doc_ && thread_pdf_docs.Get()) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 291
304 if (!pdf_doc_.get()) { 292 if (!pdf_doc_.get()) {
305 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( 293 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider(
306 CGDataProviderCreateWithCFData(pdf_data_)); 294 CGDataProviderCreateWithCFData(pdf_data_));
307 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); 295 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider));
308 } 296 }
309 return pdf_doc_.get(); 297 return pdf_doc_.get();
310 } 298 }
311 299
312 } // namespace printing 300 } // namespace printing
OLDNEW
« no previous file with comments | « media/audio/mac/audio_manager_mac.cc ('k') | third_party/apple_apsl/CFBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698