Bug 1543813: Fix a race condition that can lead to a crash when using the color picker on macOS. r=mstange

Differential Revision: https://phabricator.services.mozilla.com/D71045
This commit is contained in:
Stephen A Pohl 2020-05-27 22:07:45 +00:00
Родитель fbcafaf7ae
Коммит e3c972281a
1 изменённых файлов: 16 добавлений и 4 удалений

Просмотреть файл

@ -37,6 +37,7 @@ static unsigned int HexStrToInt(NSString* str) {
- (void)open:(NSColor*)aInitialColor title:(NSString*)aTitle;
- (void)colorChanged:(NSColorPanel*)aPanel;
- (void)windowWillClose:(NSNotification*)aNotification;
- (void)close;
@end
@implementation NSColorPanelWrapper
@ -58,28 +59,38 @@ static unsigned int HexStrToInt(NSString* str) {
}
- (void)colorChanged:(NSColorPanel*)aPanel {
if (!mColorPicker) {
return;
}
mColorPicker->Update([mColorPanel color]);
}
- (void)windowWillClose:(NSNotification*)aNotification {
if (!mColorPicker) {
return;
}
mColorPicker->Done();
}
- (void)dealloc {
- (void)close {
[mColorPanel setTarget:nil];
[mColorPanel setAction:nil];
[mColorPanel setDelegate:nil];
mColorPanel = nil;
mColorPicker = nullptr;
[super dealloc];
}
@end
NS_IMPL_ISUPPORTS(nsColorPicker, nsIColorPicker)
nsColorPicker::~nsColorPicker() {}
nsColorPicker::~nsColorPicker() {
if (mColorPanelWrapper) {
[mColorPanelWrapper close];
[mColorPanelWrapper release];
mColorPanelWrapper = nullptr;
}
}
NS_IMETHODIMP
nsColorPicker::Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
@ -136,6 +147,7 @@ void nsColorPicker::Update(NSColor* aColor) {
}
void nsColorPicker::Done() {
[mColorPanelWrapper close];
[mColorPanelWrapper release];
mColorPanelWrapper = nullptr;
mCallback->Done(EmptyString());