Bug 1262946 - Don't focus the initial browser of a new window until it has painted. r?Gijs draft
authorMike Conley <mconley@mozilla.com>
Thu, 07 Apr 2016 11:42:17 -0400
changeset 348551 fab011f4b5acab0acea8b541d19f0a0adb04bfb6
parent 348506 b6683e141c47c022598c0caac3ea8ba8c6236d42
child 517872 a806ae73d32ab9c6954c67a01790215784240d46
push id14850
push usermconley@mozilla.com
push dateThu, 07 Apr 2016 19:00:42 +0000
reviewersGijs
bugs1262946
milestone48.0a1
Bug 1262946 - Don't focus the initial browser of a new window until it has painted. r?Gijs This is in order to optimize the critical path (the presenting of content to the user). If we don't wait until the content has been presented for the tab switch, then we run the risk of causing the content to send sync IPC messages for IME up to the parent, which slows down the rendering of the content. MozReview-Commit-ID: 6nuomVwGOVp
browser/base/content/browser.js
toolkit/content/browser-child.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1178,17 +1178,24 @@ var gBrowserInit = {
     Services.telemetry.getHistogramById("E10S_WINDOW").add(gMultiProcessBrowser);
 
     SidebarUI.startDelayedLoad();
 
     UpdateUrlbarSearchSplitterState();
 
     if (!(isBlankPageURL(uriToLoad) || uriToLoad == "about:privatebrowsing") ||
         !focusAndSelectUrlBar()) {
-      gBrowser.selectedBrowser.focus();
+      let activeElement = document.activeElement;
+      let mm = window.messageManager;
+      mm.addMessageListener("Browser:FirstPaint", function onFirstPaint() {
+        mm.removeMessageListener("Browser:FirstPaint", onFirstPaint);
+        if (document.activeElement == activeElement) {
+          gBrowser.selectedBrowser.focus();
+        }
+      });
     }
 
     // Enable/Disable auto-hide tabbar
     gBrowser.tabContainer.updateVisibility();
 
     BookmarkingUI.init();
 
     gPrefService.addObserver(gHomeButton.prefDomain, gHomeButton, false);
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -634,8 +634,13 @@ var outerWindowID = content.QueryInterfa
                            .outerWindowID;
 sendAsyncMessage("Browser:Init", {outerWindowID: outerWindowID});
 addMessageListener("Browser:InitReceived", function onInitReceived(msg) {
   removeMessageListener("Browser:InitReceived", onInitReceived);
   if (msg.data.initPopup) {
     AutoCompletePopup.init();
   }
 });
+
+addEventListener("MozAfterPaint", function onFirstPaint() {
+  removeEventListener("MozAfterPaint", onFirstPaint);
+  sendAsyncMessage("Browser:FirstPaint");
+});