diff --git a/browser/base/content/tabbrowser.xml b/browser/base/content/tabbrowser.xml index 1b8a8fe27f6a..610d2a8e5499 100644 --- a/browser/base/content/tabbrowser.xml +++ b/browser/base/content/tabbrowser.xml @@ -1513,6 +1513,136 @@ + null + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1583,55 +1713,23 @@ if (aOwner) t.owner = aOwner; - var b = document.createElementNS( - "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", - "browser"); - b.setAttribute("type", "content-targetable"); - b.setAttribute("message", "true"); - b.setAttribute("messagemanagergroup", "browsers"); - b.setAttribute("contextmenu", this.getAttribute("contentcontextmenu")); - b.setAttribute("tooltip", this.getAttribute("contenttooltip")); + let b; + let usingPreloadedContent = false; + let isPrivateWindow = PrivateBrowsingUtils.isWindowPrivate(window); - if (remote) - b.setAttribute("remote", "true"); - - if (window.gShowPageResizers && window.windowState == window.STATE_NORMAL) { - b.setAttribute("showresizer", "true"); + // If we open a new tab with the newtab URL, + // check if there is a preloaded browser ready. + if (aURI == BROWSER_NEW_TAB_URL && !isPrivateWindow) { + b = this._getPreloadedBrowser(); + usingPreloadedContent = !!b; } - if (this.hasAttribute("autocompletepopup")) - b.setAttribute("autocompletepopup", this.getAttribute("autocompletepopup")); - - if (this.hasAttribute("selectpopup")) - b.setAttribute("selectpopup", this.getAttribute("selectpopup")); - - b.setAttribute("autoscrollpopup", this._autoScrollPopup.id); - - // Create the browserStack container - var stack = document.createElementNS(NS_XUL, "stack"); - stack.className = "browserStack"; - stack.appendChild(b); - stack.setAttribute("flex", "1"); - - // Create the browserContainer - var browserContainer = document.createElementNS(NS_XUL, "vbox"); - browserContainer.className = "browserContainer"; - browserContainer.appendChild(stack); - browserContainer.setAttribute("flex", "1"); - - // Create the sidebar container - var browserSidebarContainer = document.createElementNS(NS_XUL, - "hbox"); - browserSidebarContainer.className = "browserSidebarContainer"; - browserSidebarContainer.appendChild(browserContainer); - browserSidebarContainer.setAttribute("flex", "1"); - - // Add the Message and the Browser to the box - var notificationbox = document.createElementNS(NS_XUL, - "notificationbox"); - notificationbox.setAttribute("flex", "1"); - notificationbox.appendChild(browserSidebarContainer); + if (!b) { + // No preloaded browser found, create one. + b = this._createBrowser({remote, uriIsAboutBlank}); + } + let notificationbox = this.getNotificationBox(b); var position = this.tabs.length - 1; var uniqueId = this._generateUniquePanelID(); notificationbox.id = uniqueId; @@ -1642,19 +1740,16 @@ t.lastAccessed = Date.now(); this.tabContainer._setPositionalAttributes(); - // Prevent the superfluous initial load of a blank document - // if we're going to load something other than about:blank. - if (!uriIsAboutBlank) { - b.setAttribute("nodefaultsrc", "true"); + // Inject the into the DOM if necessary. + if (!notificationbox.parentNode) { + // NB: this appendChild call causes us to run constructors for the + // browser element, which fires off a bunch of notifications. Some + // of those notifications can cause code to run that inspects our + // state, so it is important that the tab element is fully + // initialized by this point. + this.mPanelContainer.appendChild(notificationbox); } - // NB: this appendChild call causes us to run constructors for the - // browser element, which fires off a bunch of notifications. Some - // of those notifications can cause code to run that inspects our - // state, so it is important that the tab element is fully - // initialized by this point. - this.mPanelContainer.appendChild(notificationbox); - // We've waited until the tab is in the DOM to set the label. This // allows the TabLabelModified event to be properly dispatched. if (!aURI || isBlankPageURL(aURI)) { @@ -1677,16 +1772,9 @@ b.droppedLinkHandler = handleDroppedLink; - // If we just created a new tab that loads the default - // newtab url, swap in a preloaded page if possible. - // Do nothing if we're a private window. - let docShellsSwapped = false; - if (aURI == BROWSER_NEW_TAB_URL && - !PrivateBrowsingUtils.isWindowPrivate(window) && - !gMultiProcessBrowser) { - docShellsSwapped = gBrowserNewTabPreloader.newTab(t); - } else if (aURI == "about:customizing") { - docShellsSwapped = gCustomizationTabPreloader.newTab(t); + // Swap in a preloaded customize tab, if available. + if (aURI == "about:customizing") { + usingPreloadedContent = gCustomizationTabPreloader.newTab(t); } // Dispatch a new tab notification. We do this once we're @@ -1698,7 +1786,7 @@ // If we didn't swap docShells with a preloaded browser // then let's just continue loading the page normally. - if (!docShellsSwapped && !uriIsAboutBlank) { + if (!usingPreloadedContent && !uriIsAboutBlank) { // pretend the user typed this so it'll be available till // the document successfully loads if (aURI && gInitialPages.indexOf(aURI) == -1) @@ -4279,6 +4367,9 @@ // without any scrolling and when the tabbar has already // overflowed. this.mTabstrip._updateScrollButtonsDisabledState(); + + // Preload the next about:newtab if there isn't one already. + this.tabbrowser._createPreloadBrowser(); ]]> diff --git a/testing/mochitest/browser-test.js b/testing/mochitest/browser-test.js index a989d156c0f0..7c5816e4d225 100644 --- a/testing/mochitest/browser-test.js +++ b/testing/mochitest/browser-test.js @@ -505,6 +505,14 @@ Tester.prototype = { BackgroundPageThumbs._destroy(); BrowserNewTabPreloader.uninit(); + + // Destroy preloaded browsers. + if (gBrowser._preloadedBrowser) { + let browser = gBrowser._preloadedBrowser; + gBrowser._preloadedBrowser = null; + gBrowser.getNotificationBox(browser).remove(); + } + CustomizationTabPreloader.uninit(); SocialFlyout.unload(); SocialShare.uninit();