Bug 1659758 - Null-check event target in nsDocShellTreeOwner::AddChromeListeners. r=smaug, a=RyanVM
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 24 Aug 2020 23:51:26 +0000
changeset 610468 57fc01dc4a01228c72dfc88c6be980184ea8e089
parent 610467 e2d32da01d2d2d3e02cc20d57913861e0d7a5b87
child 610469 0a5771b2f85819eb02e4490f6fc73e5e6405194c
push id13581
push userryanvm@gmail.com
push dateTue, 25 Aug 2020 17:28:28 +0000
treeherdermozilla-beta@0a5771b2f858 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, RyanVM
bugs1659758
milestone81.0
Bug 1659758 - Null-check event target in nsDocShellTreeOwner::AddChromeListeners. r=smaug, a=RyanVM Tentative fix (though crash is long-standing), so no test :/ Differential Revision: https://phabricator.services.mozilla.com/D88090
docshell/base/nsDocShellTreeOwner.cpp
--- a/docshell/base/nsDocShellTreeOwner.cpp
+++ b/docshell/base/nsDocShellTreeOwner.cpp
@@ -797,26 +797,28 @@ nsDocShellTreeOwner::AddChromeListeners(
         do_QueryInterface(webBrowserChrome));
     if (tooltipListener) {
       mChromeTooltipListener =
           new ChromeTooltipListener(mWebBrowser, webBrowserChrome);
       rv = mChromeTooltipListener->AddChromeListeners();
     }
   }
 
-  // register dragover and drop event listeners with the listener manager
   nsCOMPtr<EventTarget> target;
   GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
 
-  EventListenerManager* elmP = target->GetOrCreateListenerManager();
-  if (elmP) {
-    elmP->AddEventListenerByType(this, u"dragover"_ns,
-                                 TrustedEventsAtSystemGroupBubble());
-    elmP->AddEventListenerByType(this, u"drop"_ns,
-                                 TrustedEventsAtSystemGroupBubble());
+  // register dragover and drop event listeners with the listener manager
+  MOZ_ASSERT(target, "how does this happen? (see bug 1659758)");
+  if (target) {
+    if (EventListenerManager* elmP = target->GetOrCreateListenerManager()) {
+      elmP->AddEventListenerByType(this, u"dragover"_ns,
+                                   TrustedEventsAtSystemGroupBubble());
+      elmP->AddEventListenerByType(this, u"drop"_ns,
+                                   TrustedEventsAtSystemGroupBubble());
+    }
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
 nsDocShellTreeOwner::RemoveChromeListeners() {
   if (mChromeTooltipListener) {