Bug 1585217 - Make the layout debugger with -autoclose handle content process crashes. r=heycam
☠☠ backed out by 38fa2d18cb78 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 01 Oct 2019 02:17:48 +0000
changeset 495768 f5716082ad9c229a0ebd7ea8c905f0129dd5fdfc
parent 495767 2064b2f611472097f893fe7083471e957bc21e79
child 495769 38fa2d18cb78c1795640a8978ae1eff44c782d57
push id114140
push userdvarga@mozilla.com
push dateWed, 02 Oct 2019 18:04:51 +0000
treeherdermozilla-inbound@32eb0ea893f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1585217
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 1585217 - Make the layout debugger with -autoclose handle content process crashes. r=heycam This means that you can use it as a very light-weight crashtest harness by using: MOZ_GDB_SLEEP=0 ./mach run -layoutdebug <file> -autoclose Right now we just never exit otherwise. Differential Revision: https://phabricator.services.mozilla.com/D47715
layout/tools/layout-debug/ui/content/layoutdebug.js
--- a/layout/tools/layout-debug/ui/content/layoutdebug.js
+++ b/layout/tools/layout-debug/ui/content/layoutdebug.js
@@ -136,16 +136,61 @@ for (let [name, pref] of Object.entries(
 }
 
 for (let name of COMMANDS) {
   Debugger.prototype[name] = function() {
     this._sendMessage(name);
   };
 }
 
+const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+
+function autoCloseIfNeeded(aCrash) {
+  if (!gArgs.autoclose) {
+    return;
+  }
+  setTimeout(function() {
+    if (aCrash) {
+      let browser = document.createElementNS(XUL_NS, "browser");
+      // FIXME(emilio): we could use gBrowser if we bothered get the process switches right.
+      //
+      // Doesn't seem worth for this particular case.
+      document.documentElement.appendChild(browser);
+      browser.loadURI("about:crashparent", {
+        triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
+      });
+      return;
+    }
+    if (gArgs.profile && Services.profiler) {
+      dumpProfile();
+    } else {
+      Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
+    }
+  }, gArgs.delay * 1000);
+}
+
+const TabCrashedObserver = {
+  observe(subject, topic, data) {
+    switch (topic) {
+      case "ipc:content-shutdown":
+        subject.QueryInterface(Ci.nsIPropertyBag2);
+        if (!subject.get("abnormal")) {
+          return;
+        }
+        break;
+      case "oop-frameloader-crashed":
+        break;
+    }
+    autoCloseIfNeeded(true);
+  }
+};
+
+Services.obs.addObserver(TabCrashedObserver, "ipc:content-shutdown");
+Services.obs.addObserver(TabCrashedObserver, "oop-frameloader-crashed");
+
 function nsLDBBrowserContentListener() {
   this.init();
 }
 
 nsLDBBrowserContentListener.prototype = {
   init: function() {
     this.mStatusText = document.getElementById("status-text");
     this.mForwardButton = document.getElementById("forward-button");
@@ -169,29 +214,24 @@ nsLDBBrowserContentListener.prototype = 
       this.setButtonEnabled(this.mForwardButton, gBrowser.canGoForward);
       this.setButtonEnabled(this.mBackButton, gBrowser.canGoBack);
       this.mStatusText.value = "loading...";
       this.mLoading = true;
     } else if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
       this.setButtonEnabled(this.mStopButton, false);
       this.mStatusText.value = gURLBar.value + " loaded";
       this.mLoading = false;
-      if (gArgs.autoclose && gBrowser.currentURI.spec != "about:blank") {
+
+      if (gBrowser.currentURI.spec != "about:blank") {
         // We check for about:blank just to avoid one or two STATE_STOP
         // notifications that occur before the loadURI() call completes.
         // This does mean that --autoclose doesn't work when the URL on
         // the command line is about:blank (or not specified), but that's
         // not a big deal.
-        setTimeout(function() {
-          if (gArgs.profile && Services.profiler) {
-            dumpProfile();
-          } else {
-            Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
-          }
-        }, gArgs.delay * 1000);
+        autoCloseIfNeeded(false);
       }
     }
   },
 
   onProgressChange: function(
     aWebProgress,
     aRequest,
     aCurSelfProgress,