Bug 1380377 part 1 - Change the way FX_NEW_WINDOW_MS is calculated. r?florian draft
authorEdouard Oger <eoger@fastmail.com>
Tue, 29 Aug 2017 16:14:18 -0400
changeset 655303 670133b6324a4c980aa045055e880ce03afbdf8b
parent 654398 3529b653ede26f990eb7320649015294ad0f8e76
child 655305 22c5e5742bb6a91304ebba659956c56b99bd585d
push id76820
push userbmo:eoger@fastmail.com
push dateTue, 29 Aug 2017 20:18:08 +0000
reviewersflorian
bugs1380377
milestone57.0a1
Bug 1380377 part 1 - Change the way FX_NEW_WINDOW_MS is calculated. r?florian MozReview-Commit-ID: KQ6aSkw423P
browser/base/content/browser.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4176,36 +4176,34 @@ function toOpenWindowByType(inType, uri,
   else
     window.open(uri, "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
 }
 
 function OpenBrowserWindow(options) {
   var telemetryObj = {};
   TelemetryStopwatch.start("FX_NEW_WINDOW_MS", telemetryObj);
 
-  function newDocumentShown(doc, topic, data) {
-    if (topic == "document-shown" &&
-        doc != document &&
-        doc.defaultView == win) {
-      Services.obs.removeObserver(newDocumentShown, "document-shown");
+  function mozAfterPaint(e) {
+    if (e.target.document != document &&
+        e.target.document.defaultView == win) {
+      win.removeEventListener("MozAfterPaint", mozAfterPaint);
       Services.obs.removeObserver(windowClosed, "domwindowclosed");
       TelemetryStopwatch.finish("FX_NEW_WINDOW_MS", telemetryObj);
     }
   }
 
   function windowClosed(subject) {
     if (subject == win) {
-      Services.obs.removeObserver(newDocumentShown, "document-shown");
+      win.removeEventListener("MozAfterPaint", mozAfterPaint);
       Services.obs.removeObserver(windowClosed, "domwindowclosed");
     }
   }
 
-  // Make sure to remove the 'document-shown' observer in case the window
+  // Make sure to remove the 'MozAfterPaint' observer in case the window
   // is being closed right after it was opened to avoid leaking.
-  Services.obs.addObserver(newDocumentShown, "document-shown");
   Services.obs.addObserver(windowClosed, "domwindowclosed");
 
   var handler = Components.classes["@mozilla.org/browser/clh;1"]
                           .getService(Components.interfaces.nsIBrowserHandler);
   var defaultArgs = handler.defaultArgs;
   var wintype = document.documentElement.getAttribute("windowtype");
 
   var extraFeatures = "";
@@ -4242,16 +4240,18 @@ function OpenBrowserWindow(options) {
 
     // we should "inherit" the charset menu setting in a new window
     win = window.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no" + extraFeatures, defaultArgs, charsetArg);
   } else {
     // forget about the charset information.
     win = window.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no" + extraFeatures, defaultArgs);
   }
 
+  win.addEventListener("MozAfterPaint", mozAfterPaint);
+
   return win;
 }
 
 /**
  * Update the global flag that tracks whether or not any edit UI (the Edit menu,
  * edit-related items in the context menu, and edit-related toolbar buttons
  * is visible, then update the edit commands' enabled state accordingly.  We use
  * this flag to skip updating the edit commands on focus or selection changes