Bug 1659758 - Null-check event target in nsDocShellTreeOwner::AddChromeListeners. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 24 Aug 2020 23:51:26 +0000
changeset 545879 062c7597ed2ce74f4da348b8d869b421c3d03f12
parent 545878 ef8a093c01aafed9d2d6fbf535ce4aea60bccf29
child 545880 21925e313c1f26f67f8eda2c4f754aa0f102844b
push id37729
push userccoroiu@mozilla.com
push dateTue, 25 Aug 2020 09:46:22 +0000
treeherdermozilla-central@e9ff11c7fe04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1659758
milestone82.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 1659758 - Null-check event target in nsDocShellTreeOwner::AddChromeListeners. r=smaug 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) {