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") {
}
libs = [
"AppKit.framework",
"QuartzCore.framework",
"ApplicationServices.framework",
"CoreFoundation.framework",
"CoreGraphics.framework",
......
......@@ -5,6 +5,7 @@
#include "printing/printing_context_mac.h"
#import <AppKit/AppKit.h>
#import <QuartzCore/QuartzCore.h>
#import <iomanip>
#import <numeric>
......@@ -121,15 +122,23 @@ void PrintingContextMac::AskUserForSettings(int max_pages,
// TODO(stuartmorgan): We really want a tab sheet here, not a modal window.
// Will require restructuring the PrintingContext API to use a callback.
NSInteger selection = [panel runModalWithPrintInfo:printInfo];
if (selection == NSOKButton) {
print_info_.reset([[panel printInfo] retain]);
settings_.set_ranges(GetPageRangesFromPrintInfo());
InitPrintSettingsFromPrintInfo();
std::move(callback).Run(OK);
} else {
std::move(callback).Run(CANCEL);
}
// This function may be called in the middle of a CATransaction, where
// running a modal panel is forbidden. That situation isn't ideal, but from
// this code's POV the right answer is to defer running the panel until after
// the current transaction. See https://crbug.com/849538.
__block auto block_callback = std::move(callback);
[CATransaction setCompletionBlock:^{
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() {
......
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