Bug 1585217 - Make the layout debugger with -autoclose handle content process crashes. r=heycam
☠☠ backed out by 407a7003cd13 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 01 Oct 2019 14:23:12 +0000
changeset 495798 3f8c2c77cd630d9bf06d0b769a6fd99980576ad1
parent 495797 046a8c9987d95355780330e6c9a66523b8a5e235
child 495799 24a4aba3f466b35a78b0ece6b9f1bef2ad7a7890
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,