Bug 1588084 - Add null-checking to isUrlbarFocused to avoid crashes on window shutdown. r=mikedeboer
authorharry <htwyford@mozilla.com>
Fri, 11 Oct 2019 13:35:04 +0000
changeset 497265 6f13ec193094a7c7507edd8df79fdb0e1c985c40
parent 497264 f3f4aa35d46eef4077f94447ee163b42f7670d9a
child 497266 454751fb75a275c397e37706546990f01d936bab
push id36681
push usercbrindusan@mozilla.com
push dateFri, 11 Oct 2019 21:50:12 +0000
treeherdermozilla-central@c5e6477c3a24 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1588084
milestone71.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 1588084 - Add null-checking to isUrlbarFocused to avoid crashes on window shutdown. r=mikedeboer Differential Revision: https://phabricator.services.mozilla.com/D48966
browser/components/touchbar/MacTouchBar.js
widget/cocoa/nsTouchBar.mm
--- a/browser/components/touchbar/MacTouchBar.js
+++ b/browser/components/touchbar/MacTouchBar.js
@@ -288,16 +288,19 @@ class TouchBarHelper {
     return layoutItems;
   }
 
   static get window() {
     return BrowserWindowTracker.getTopWindow();
   }
 
   get isUrlbarFocused() {
+    if (!TouchBarHelper.window || !TouchBarHelper.window.gURLBar) {
+      return false;
+    }
     return TouchBarHelper.window.gURLBar.focused;
   }
 
   static get baseWindow() {
     return TouchBarHelper.window.docShell.treeOwner.QueryInterface(
       Ci.nsIBaseWindow
     );
   }
--- a/widget/cocoa/nsTouchBar.mm
+++ b/widget/cocoa/nsTouchBar.mm
@@ -357,16 +357,21 @@ static const uint32_t kInputIconSize = 1
   } else if ([aInput title]) {
     aPopoverItem.collapsedRepresentationLabel = [aInput title];
   } else {
     aPopoverItem.collapsedRepresentation = nil;
   }
 
   // Special handling to show/hide the search popover if the Urlbar is focused.
   if ([[aInput nativeIdentifier] isEqualToString:SearchPopoverIdentifier]) {
+    // We can reach this code during window shutdown. We only want to toggle
+    // showPopover if we are in a normal running state.
+    if (!mTouchBarHelper) {
+      return;
+    }
     bool urlbarIsFocused = false;
     mTouchBarHelper->GetIsUrlbarFocused(&urlbarIsFocused);
     if (urlbarIsFocused) {
       [aPopoverItem showPopover:self];
     }
   }
 }