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
--- 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");
+});