Bug 1523944: Fix shutdown leak related to macOS TouchBar support. r=mstange
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Wed, 13 Feb 2019 14:16:39 -0500
changeset 458861 69e057ca6ad85a14aa07f388a5b6d44d3fc9f32d
parent 458860 fbe70e26f7ffef954345336933b4419952506b46
child 458862 f405cc68a129277e3532d364f09134ddf3238175
push id111895
push userspohl@mozilla.com
push dateWed, 13 Feb 2019 19:16:58 +0000
treeherdermozilla-inbound@69e057ca6ad8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1523944
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1523944: Fix shutdown leak related to macOS TouchBar support. r=mstange
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
widget/cocoa/nsTouchBar.h
widget/cocoa/nsTouchBar.mm
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -81,16 +81,18 @@ typedef struct _nsCocoaWindowList {
 
 - (void)disableSetNeedsDisplay;
 - (void)enableSetNeedsDisplay;
 
 - (NSRect)getAndResetNativeDirtyRect;
 
 - (void)setUseMenuStyle:(BOOL)aValue;
 
+- (void)releaseJSObjects;
+
 @end
 
 @interface NSWindow (Undocumented)
 
 // If a window has been explicitly removed from the "window cache" (to
 // deactivate it), it's sometimes necessary to "reset" it to reactivate it
 // (and put it back in the "window cache").  One way to do this, which Apple
 // often uses, is to set the "window number" to '-1' and then back to its
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -160,16 +160,17 @@ nsCocoaWindow::nsCocoaWindow()
   }
 }
 
 void nsCocoaWindow::DestroyNativeWindow() {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   if (!mWindow) return;
 
+  [mWindow releaseJSObjects];
   // We want to unhook the delegate here because we don't want events
   // sent to it after this object has been destroyed.
   [mWindow setDelegate:nil];
   [mWindow close];
   mWindow = nil;
   [mDelegate autorelease];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
@@ -3116,16 +3117,20 @@ static const NSString* kStateCollectionB
     retval = [NSArray arrayWithArray:holder];
   }
 
   return retval;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
+- (void)releaseJSObjects {
+  [mTouchBar releaseJSObjects];
+}
+
 @end
 
 // This class allows us to exercise control over the window's title bar. This
 // allows for a "unified toolbar" look without having to extend the content
 // area into the title bar.
 //
 // Drawing the unified gradient in the titlebar and the toolbar works like this:
 // 1) In the style sheet we set the toolbar's -moz-appearance to toolbar.
--- a/widget/cocoa/nsTouchBar.h
+++ b/widget/cocoa/nsTouchBar.h
@@ -168,11 +168,13 @@ typedef NSString* NSTouchBarItemIdentifi
                             sharingServicesForItems:(NSArray*)aItems
                             proposedSharingServices:(NSArray<NSSharingService*>*)aProposedServices;
 
 /**
  * Retrieves TouchBarInput icons.
  */
 + (NSImage*)getTouchBarIconNamed:(NSString*)aImageName;
 
+- (void)releaseJSObjects;
+
 @end  // nsTouchBar
 
 #endif  // nsTouchBar_h_
--- a/widget/cocoa/nsTouchBar.mm
+++ b/widget/cocoa/nsTouchBar.mm
@@ -187,16 +187,20 @@ static char sIdentifierAssociationKey;
   if (!input) {
     return;
   }
 
   nsCOMPtr<nsITouchBarInputCallback> callback = [input callback];
   callback->OnCommand();
 }
 
+- (void)releaseJSObjects {
+  mTouchBarHelper = nil;
+}
+
 #pragma mark - TouchBar Utilities
 
 + (NSImage*)getTouchBarIconNamed:(NSString*)aImageName {
   nsCOMPtr<nsIFile> resDir;
   nsAutoCString resPath;
   NSString* pathToImage;
 
   nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(resDir));