Bug 1486079 - create initial browser dynamically so we can set various attributes from the start, r=dao
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 28 Aug 2018 11:07:34 +0000
changeset 433528 05672d13ef56
parent 433527 58c2e6069684
child 433529 e417158d9456
push id34517
push useraciure@mozilla.com
push dateTue, 28 Aug 2018 21:56:57 +0000
treeherdermozilla-central@9494c03553b9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1486079
milestone63.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 1486079 - create initial browser dynamically so we can set various attributes from the start, r=dao Differential Revision: https://phabricator.services.mozilla.com/D4248
browser/base/content/browser.xul
browser/base/content/tabbrowser.js
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -629,16 +629,26 @@ xmlns="http://www.w3.org/1999/xhtml"
       <menuitem label="&selectAllCmd.label;"
                 accesskey="&selectAllCmd.accesskey;"
                 cmd="cmd_selectAll"/>
       <menuseparator/>
       <menuitem label="&syncSyncNowItem.label;"
                 accesskey="&syncSyncNowItem.accesskey;"
                 id="syncedTabsRefreshFilter"/>
     </menupopup>
+
+    <hbox id="statuspanel" inactive="true" layer="true">
+      <hbox id="statuspanel-inner">
+        <label id="statuspanel-label"
+               role="status"
+               aria-live="off"
+               flex="1"
+               crop="end"/>
+      </hbox>
+    </hbox>
   </popupset>
   <box id="appMenu-viewCache" hidden="true"/>
 
 <vbox id="titlebar">
   <hbox id="titlebar-content">
     <spacer id="titlebar-spacer" flex="1"/>
     <hbox id="titlebar-buttonbox-container">
       <hbox id="titlebar-buttonbox" class="titlebar-color">
@@ -1256,47 +1266,17 @@ xmlns="http://www.w3.org/1999/xhtml"
       </vbox>
 
       <splitter id="sidebar-splitter" class="chromeclass-extrachrome sidebar-splitter" hidden="true"/>
       <vbox id="appcontent" flex="1">
         <notificationbox id="high-priority-global-notificationbox" notificationside="top"/>
         <tabbox id="tabbrowser-tabbox"
                 flex="1" eventnode="document" tabcontainer="tabbrowser-tabs">
           <tabpanels id="tabbrowser-tabpanels"
-                     flex="1" class="plain" selectedIndex="0">
-            <notificationbox flex="1" notificationside="top">
-              <!-- Set large flex to allow the devtools toolbox to set a flex attribute.
-                   We don't want the toolbox to actually take up free space, but we do want it to collapse when the window shrinks, and with flex=0 it can't.
-                   When the toolbox is on the bottom it's a sibling of browserSidebarContainer,
-                   and when it's on the side it's a sibling of browserContainer.  -->
-              <hbox flex="10000" class="browserSidebarContainer">
-                <vbox flex="10000" class="browserContainer">
-                  <stack flex="1" class="browserStack">
-                    <browser id="tabbrowser-initialBrowser" type="content"
-                             message="true" messagemanagergroup="browsers"
-                             primary="true" blank="true"
-                             tooltip="aHTMLTooltip"
-                             contextmenu="contentAreaContextMenu"
-                             autocompletepopup="PopupAutoComplete"
-                             selectmenulist="ContentSelectDropdown"
-                             datetimepicker="DateTimePickerPanel"/>
-                  </stack>
-                  <hbox id="statuspanel" inactive="true" layer="true">
-                    <hbox id="statuspanel-inner">
-                      <label id="statuspanel-label"
-                             role="status"
-                             aria-live="off"
-                             flex="1"
-                             crop="end"/>
-                    </hbox>
-                  </hbox>
-                </vbox>
-              </hbox>
-            </notificationbox>
-          </tabpanels>
+                     flex="1" class="plain" selectedIndex="0"/>
         </tabbox>
       </vbox>
       <vbox id="browser-border-end" hidden="true" layer="true"/>
     </hbox>
 #include ../../components/customizableui/content/customizeMode.inc.xul
   </deck>
 
   <html:div id="fullscreen-warning" class="pointerlockfswarning" hidden="true">
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -277,59 +277,49 @@ window._gBrowser = {
   get selectedTab() {
     return this._selectedTab;
   },
 
   get selectedBrowser() {
     return this._selectedBrowser;
   },
 
-  get initialBrowser() {
-    delete this.initialBrowser;
-    return this.initialBrowser = document.getElementById("tabbrowser-initialBrowser");
-  },
-
   _setupInitialBrowserAndTab() {
-    let browser = this.initialBrowser;
-    this._selectedBrowser = browser;
-
-    browser.permanentKey = {};
+    // Bug 1362774 will adjust this to only set `uriIsAboutBlank` when
+    // necessary. For now, we always pass it.
+    let browser = this._createBrowser({uriIsAboutBlank: true});
+    browser.setAttribute("primary", "true");
+    browser.setAttribute("blank", "true");
     browser.droppedLinkHandler = handleDroppedLink;
     browser.loadURI = _loadURI.bind(null, browser);
 
+    let uniqueId = this._generateUniquePanelID();
+    let notificationbox = this.getNotificationBox(browser);
+    notificationbox.id = uniqueId;
+    this.tabpanels.appendChild(notificationbox);
+
+    let tab = this.tabs[0];
+    tab.linkedPanel = uniqueId;
+    this._selectedTab = tab;
+    this._selectedBrowser = browser;
+    tab.permanentKey = browser.permanentKey;
+    tab._tPos = 0;
+    tab._fullyOpen = true;
+    tab.linkedBrowser = browser;
+    this._tabForBrowser.set(browser, tab);
+
+    this._appendStatusPanel();
+
+    this.initialBrowser = browser;
+
     let autoScrollPopup = browser._createAutoScrollPopup();
     autoScrollPopup.id = "autoscroller";
     document.getElementById("mainPopupSet").appendChild(autoScrollPopup);
     browser.setAttribute("autoscrollpopup", autoScrollPopup.id);
-
-    this._defaultBrowserAttributes = {
-      autoscrollpopup: "",
-      contextmenu: "",
-      datetimepicker: "",
-      message: "",
-      messagemanagergroup: "",
-      selectmenulist: "",
-      tooltip: "",
-      type: "",
-    };
-    for (let attribute in this._defaultBrowserAttributes) {
-      this._defaultBrowserAttributes[attribute] = browser.getAttribute(attribute);
-    }
-
-    let tab = this.tabs[0];
-    this._selectedTab = tab;
-
-    let uniqueId = this._generateUniquePanelID();
-    this.tabpanels.children[0].id = uniqueId;
-    tab.linkedPanel = uniqueId;
-    tab.permanentKey = browser.permanentKey;
-    tab._tPos = 0;
-    tab._fullyOpen = true;
-    tab.linkedBrowser = browser;
-    this._tabForBrowser.set(browser, tab);
+    this._autoScrollPopup = autoScrollPopup;
 
     // Hook the browser up with a progress listener.
     let tabListener = new TabProgressListener(tab, browser, true, false);
     let filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
                   .createInstance(Ci.nsIWebProgress);
     filter.addProgressListener(tabListener, Ci.nsIWebProgress.NOTIFY_ALL);
     this._tabListeners.set(tab, tabListener);
     this._tabFilters.set(tab, filter);
@@ -1806,18 +1796,27 @@ window._gBrowser = {
     replayExecution,
     sameProcessAsFrameLoader,
     uriIsAboutBlank,
     userContextId,
   } = {}) {
     let b = document.createXULElement("browser");
     b.permanentKey = {};
 
-    for (let attribute in this._defaultBrowserAttributes) {
-      b.setAttribute(attribute, this._defaultBrowserAttributes[attribute]);
+    const defaultBrowserAttributes = {
+      contextmenu: "contentAreaContextMenu",
+      datetimepicker: "DateTimePickerPanel",
+      message: "true",
+      messagemanagergroup: "browsers",
+      selectmenulist: "ContentSelectDropdown",
+      tooltip: "aHTMLTooltip",
+      type: "content",
+    };
+    for (let attribute in defaultBrowserAttributes) {
+      b.setAttribute(attribute, defaultBrowserAttributes[attribute]);
     }
 
     if (userContextId) {
       b.setAttribute("usercontextid", userContextId);
     }
 
     if (remoteType) {
       b.setAttribute("remoteType", remoteType);
@@ -1837,16 +1836,20 @@ window._gBrowser = {
         throw new Error("Cannot set opener window on a remote browser!");
       }
       b.presetOpenerWindow(openerWindow);
     }
 
     if (!isPreloadBrowser) {
       b.setAttribute("autocompletepopup", "PopupAutoComplete");
     }
+    if (this._autoScrollPopup) {
+      b.setAttribute("autoscrollpopup", this._autoScrollPopup.id);
+    }
+
 
     /*
      * This attribute is meant to describe if the browser is the
      * preloaded browser. There are 2 defined states: "preloaded" or
      * "consumed". The order of events goes as follows:
      *   1. The preloaded browser is created and the 'preloadedState'
      *      attribute for that browser is set to "preloaded".
      *   2. When a new tab is opened and it is time to show that
@@ -1883,23 +1886,27 @@ window._gBrowser = {
     }
 
     // Create the browserStack container
     let stack = document.createXULElement("stack");
     stack.className = "browserStack";
     stack.appendChild(b);
     stack.setAttribute("flex", "1");
 
-    // Create the browserContainer
+    // We set large flex on both containers to allow the devtools toolbox to
+    // set a flex attribute. We don't want the toolbox to actually take up free
+    // space, but we do want it to collapse when the window shrinks, and with
+    // flex=0 it can't. When the toolbox is on the bottom it's a sibling of
+    // browserSidebarContainer, and when it's on the side it's a sibling of
+    // browserContainer.
     let browserContainer = document.createXULElement("vbox");
     browserContainer.className = "browserContainer";
     browserContainer.appendChild(stack);
     browserContainer.setAttribute("flex", "10000");
 
-    // Create the sidebar container
     let browserSidebarContainer = document.createXULElement("hbox");
     browserSidebarContainer.className = "browserSidebarContainer";
     browserSidebarContainer.appendChild(browserContainer);
     browserSidebarContainer.setAttribute("flex", "10000");
 
     // Add the Message and the Browser to the box
     let notificationbox = document.createXULElement("notificationbox");
     notificationbox.setAttribute("flex", "1");