Commit a1bec15b authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Wrap showing the system print dialog in a CATransaction completion block to fix a crash.

Bug: 849538
Change-Id: Ib04c020dbc50aae398255654f5404fd8904a5326
Reviewed-on: https://chromium-review.googlesource.com/1092232Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565684}
parent c344f85d
...@@ -112,6 +112,7 @@ component("printing") { ...@@ -112,6 +112,7 @@ component("printing") {
} }
libs = [ libs = [
"AppKit.framework", "AppKit.framework",
"QuartzCore.framework",
"ApplicationServices.framework", "ApplicationServices.framework",
"CoreFoundation.framework", "CoreFoundation.framework",
"CoreGraphics.framework", "CoreGraphics.framework",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "printing/printing_context_mac.h" #include "printing/printing_context_mac.h"
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import <QuartzCore/QuartzCore.h>
#import <iomanip> #import <iomanip>
#import <numeric> #import <numeric>
...@@ -121,15 +122,23 @@ void PrintingContextMac::AskUserForSettings(int max_pages, ...@@ -121,15 +122,23 @@ void PrintingContextMac::AskUserForSettings(int max_pages,
// TODO(stuartmorgan): We really want a tab sheet here, not a modal window. // TODO(stuartmorgan): We really want a tab sheet here, not a modal window.
// Will require restructuring the PrintingContext API to use a callback. // Will require restructuring the PrintingContext API to use a callback.
NSInteger selection = [panel runModalWithPrintInfo:printInfo];
if (selection == NSOKButton) { // This function may be called in the middle of a CATransaction, where
print_info_.reset([[panel printInfo] retain]); // running a modal panel is forbidden. That situation isn't ideal, but from
settings_.set_ranges(GetPageRangesFromPrintInfo()); // this code's POV the right answer is to defer running the panel until after
InitPrintSettingsFromPrintInfo(); // the current transaction. See https://crbug.com/849538.
std::move(callback).Run(OK); __block auto block_callback = std::move(callback);
} else { [CATransaction setCompletionBlock:^{
std::move(callback).Run(CANCEL); NSInteger selection = [panel runModalWithPrintInfo:printInfo];
} if (selection == NSOKButton) {
print_info_.reset([[panel printInfo] retain]);
settings_.set_ranges(GetPageRangesFromPrintInfo());
InitPrintSettingsFromPrintInfo();
std::move(block_callback).Run(OK);
} else {
std::move(block_callback).Run(CANCEL);
}
}];
} }
gfx::Size PrintingContextMac::GetPdfPaperSizeDeviceUnits() { gfx::Size PrintingContextMac::GetPdfPaperSizeDeviceUnits() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment