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

Hopefully work around an MD downloads crash by suppressing zero-size drag components.

Chrome is experiencing crashes like this when a download is dragged:

> [Uncaught NSException] CALayerInvalidGeometry reason CALayer position
> contains NaN: [nan nan]

They started when I touched the dragging code at r545861 and, based on
some research, the probable cause is a zero-size component. I haven't
been able to trigger this locally so I'm guarding both of them.

Bug: 826632
Change-Id: I0e7c7acdd5a84dca8f0771aafab58987553b10e9
Reviewed-on: https://chromium-review.googlesource.com/1008502Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549973}
parent 3d350b77
......@@ -648,24 +648,36 @@ NSTextField* MakeLabel(
downloadPath_.value())]]
autorelease];
draggingItem.imageComponentsProvider = ^{
NSDraggingImageComponent* imageComponent =
[[[NSDraggingImageComponent alloc]
initWithKey:NSDraggingImageComponentIconKey] autorelease];
NSImage* image = imageView_.image;
imageComponent.contents = image;
imageComponent.frame = imageRect;
NSDraggingImageComponent* labelComponent =
[[[NSDraggingImageComponent alloc]
initWithKey:NSDraggingImageComponentLabelKey] autorelease];
labelComponent.contents = [NSImage imageWithSize:labelRect.size
flipped:NO
drawingHandler:^(NSRect rect) {
[filename drawAtPoint:NSZeroPoint];
return YES;
}];
labelComponent.frame = labelRect;
return @[ imageComponent, labelComponent ];
// If either component is zero sized (which shouldn't generally happen, but
// apparently can… maybe a missing icon or empty string title?), omit it,
// else the dragging session will create layers with NaN components and
// crash.
auto* components = [NSMutableArray<NSDraggingImageComponent*> array];
if (imageRect.size.width != 0 && imageRect.size.height != 0) {
NSDraggingImageComponent* imageComponent =
[[[NSDraggingImageComponent alloc]
initWithKey:NSDraggingImageComponentIconKey] autorelease];
NSImage* image = imageView_.image;
imageComponent.contents = image;
imageComponent.frame = imageRect;
[components addObject:imageComponent];
}
if (labelRect.size.width != 0 && labelRect.size.height != 0) {
NSDraggingImageComponent* labelComponent =
[[[NSDraggingImageComponent alloc]
initWithKey:NSDraggingImageComponentLabelKey] autorelease];
labelComponent.contents = [NSImage imageWithSize:labelRect.size
flipped:NO
drawingHandler:^(NSRect rect) {
[filename drawAtPoint:NSZeroPoint];
return YES;
}];
labelComponent.frame = labelRect;
[components addObject:labelComponent];
}
return components;
};
[self beginDraggingSessionWithItems:@[ draggingItem ]
event:event
......
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