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/printing_context_mac.h" | 5 #include "printing/printing_context_mac.h" |
6 | 6 |
7 #import <ApplicationServices/ApplicationServices.h> | 7 #import <ApplicationServices/ApplicationServices.h> |
8 #import <AppKit/AppKit.h> | 8 #import <AppKit/AppKit.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/mac/scoped_nsexception_enabler.h" | |
12 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "printing/print_settings_initializer_mac.h" | 15 #include "printing/print_settings_initializer_mac.h" |
15 | 16 |
16 static const CFStringRef kColorModel = CFSTR("ColorModel"); | 17 static const CFStringRef kColorModel = CFSTR("ColorModel"); |
17 static const CFStringRef kGrayColor = CFSTR("Gray"); | 18 static const CFStringRef kGrayColor = CFSTR("Gray"); |
18 | 19 |
19 namespace printing { | 20 namespace printing { |
20 | 21 |
21 // static | 22 // static |
22 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 23 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
23 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); | 24 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); |
24 } | 25 } |
25 | 26 |
26 PrintingContextMac::PrintingContextMac(const std::string& app_locale) | 27 PrintingContextMac::PrintingContextMac(const std::string& app_locale) |
27 : PrintingContext(app_locale), | 28 : PrintingContext(app_locale), |
28 context_(NULL) { | 29 context_(NULL) { |
29 } | 30 } |
30 | 31 |
31 PrintingContextMac::~PrintingContextMac() { | 32 PrintingContextMac::~PrintingContextMac() { |
32 ReleaseContext(); | 33 ReleaseContext(); |
33 } | 34 } |
34 | 35 |
35 void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, | 36 void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, |
36 int max_pages, | 37 int max_pages, |
37 bool has_selection, | 38 bool has_selection, |
38 PrintSettingsCallback* callback) { | 39 PrintSettingsCallback* callback) { |
40 // Third-party print drivers seem to be an area prone to raising exceptions. | |
41 // This will allow exceptions to be raised, but does not handle them. | |
stuartmorgan
2011/05/17 18:52:14
I don't understand. Why would we *deliberately* al
Scott Hess - ex-Googler
2011/05/17 19:34:40
The primary benefit of making NSExceptions fatal i
| |
42 // TODO(shess): Some experimentation indicates that uncaught exceptions can | |
43 // leave the print panel up, and any use after the exception will almost | |
44 // certainly crash on access to zombie objects, but simply _catching_ the | |
45 // exception doesn't resolve the problem, because you cannot easily dismiss | |
46 // the print panel from code. This situation doesn't seem right, to me. | |
47 base::mac::ScopedNSExceptionEnabler enabler(true); | |
48 | |
39 DCHECK([NSThread isMainThread]); | 49 DCHECK([NSThread isMainThread]); |
40 | 50 |
41 // We deliberately don't feed max_pages into the dialog, because setting | 51 // We deliberately don't feed max_pages into the dialog, because setting |
42 // NSPrintLastPage makes the print dialog pre-select the option to only print | 52 // NSPrintLastPage makes the print dialog pre-select the option to only print |
43 // a range. | 53 // a range. |
44 | 54 |
45 // TODO(stuartmorgan): implement 'print selection only' (probably requires | 55 // TODO(stuartmorgan): implement 'print selection only' (probably requires |
46 // adding a new custom view to the panel on 10.5; 10.6 has | 56 // adding a new custom view to the panel on 10.5; 10.6 has |
47 // NSPrintPanelShowsPrintSelection). | 57 // NSPrintPanelShowsPrintSelection). |
48 NSPrintPanel* panel = [NSPrintPanel printPanel]; | 58 NSPrintPanel* panel = [NSPrintPanel printPanel]; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 void PrintingContextMac::ReleaseContext() { | 365 void PrintingContextMac::ReleaseContext() { |
356 print_info_.reset(); | 366 print_info_.reset(); |
357 context_ = NULL; | 367 context_ = NULL; |
358 } | 368 } |
359 | 369 |
360 gfx::NativeDrawingContext PrintingContextMac::context() const { | 370 gfx::NativeDrawingContext PrintingContextMac::context() const { |
361 return context_; | 371 return context_; |
362 } | 372 } |
363 | 373 |
364 } // namespace printing | 374 } // namespace printing |
OLD | NEW |