Bug 1442938: Nil-check the title in nsCocoaWindow::importState / exportState. r?mstange draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 03 Mar 2018 18:47:41 +0100
changeset 762950 ca12095970a89598c06d8e81edb70cec515acc03
parent 762948 8c1a6a3a23ef7aeed25565c152a4834bfecab931
push id101290
push userbmo:emilio@crisal.io
push dateSun, 04 Mar 2018 00:47:16 +0000
reviewersmstange
bugs1442938, 1439875
milestone60.0a1
Bug 1442938: Nil-check the title in nsCocoaWindow::importState / exportState. r?mstange Looking at the docs for [NSWindow title] I don't think it's supposed to return nil under any circumstances... But it does in our automation, for some reason, with the patches for bug 1439875 which make our fullscreen code run a bit earlier. MozReview-Commit-ID: AX4qzjzsqST
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -3219,28 +3219,32 @@ static const NSString* kStateTitleKey = 
 static const NSString* kStateDrawsContentsIntoWindowFrameKey = @"drawsContentsIntoWindowFrame";
 static const NSString* kStateActiveTitlebarColorKey = @"activeTitlebarColor";
 static const NSString* kStateInactiveTitlebarColorKey = @"inactiveTitlebarColor";
 static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
 static const NSString* kStateCollectionBehavior = @"collectionBehavior";
 
 - (void)importState:(NSDictionary*)aState
 {
-  [self setTitle:[aState objectForKey:kStateTitleKey]];
+  if (NSString* title = [aState objectForKey:kStateTitleKey]) {
+    [self setTitle:title];
+  }
   [self setDrawsContentsIntoWindowFrame:[[aState objectForKey:kStateDrawsContentsIntoWindowFrameKey] boolValue]];
   [self setTitlebarColor:[aState objectForKey:kStateActiveTitlebarColorKey] forActiveWindow:YES];
   [self setTitlebarColor:[aState objectForKey:kStateInactiveTitlebarColorKey] forActiveWindow:NO];
   [self setShowsToolbarButton:[[aState objectForKey:kStateShowsToolbarButton] boolValue]];
   [self setCollectionBehavior:[[aState objectForKey:kStateCollectionBehavior] unsignedIntValue]];
 }
 
 - (NSMutableDictionary*)exportState
 {
   NSMutableDictionary* state = [NSMutableDictionary dictionaryWithCapacity:10];
-  [state setObject:[self title] forKey:kStateTitleKey];
+  if (NSString* title = [self title]) {
+    [state setObject:title forKey:kStateTitleKey];
+  }
   [state setObject:[NSNumber numberWithBool:[self drawsContentsIntoWindowFrame]]
             forKey:kStateDrawsContentsIntoWindowFrameKey];
   NSColor* activeTitlebarColor = [self titlebarColorForActiveWindow:YES];
   if (activeTitlebarColor) {
     [state setObject:activeTitlebarColor forKey:kStateActiveTitlebarColorKey];
   }
   NSColor* inactiveTitlebarColor = [self titlebarColorForActiveWindow:NO];
   if (inactiveTitlebarColor) {