Bug 1588874 - Do not use preprocessing in nsSessionStore.js. r=IanN a=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Wed, 30 Oct 2019 19:27:49 +0100
changeset 32346 1fb6016c237d81d4b828b86692de1c504e728a76
parent 32345 6aa94e4ea6e19b458136a140d8c408e0e8d44911
child 32347 796708756db3d8c1779b88059a14340af1fa73f6
push id225
push userfrgrahl@gmx.net
push dateWed, 30 Oct 2019 18:44:45 +0000
treeherdercomm-esr60@4f5c19b9a6b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN
bugs1588874, 1228655
Bug 1588874 - Do not use preprocessing in nsSessionStore.js. r=IanN a=IanN Port Bug 1228655 "Replace #ifdefs in browser code by AppConstants".
suite/components/sessionstore/moz.build
suite/components/sessionstore/nsSessionStore.js
--- a/suite/components/sessionstore/moz.build
+++ b/suite/components/sessionstore/moz.build
@@ -11,13 +11,13 @@ XPIDL_SOURCES += [
 
 XPIDL_MODULE = 'suitecommon'
 
 EXTRA_COMPONENTS += [
     'nsSessionStartup.js',
     'nsSessionStartup.manifest',
 ]
 
-EXTRA_PP_COMPONENTS += [
+EXTRA_COMPONENTS += [
     'nsSessionStore.js',
 ]
 
 JAR_MANIFESTS += ['jar.mn']
--- a/suite/components/sessionstore/nsSessionStore.js
+++ b/suite/components/sessionstore/nsSessionStore.js
@@ -72,37 +72,31 @@ XXX keep these in sync with all the attr
 const CAPABILITIES = [
   "Subframes", "Plugins", "Javascript", "MetaRedirects", "Images",
   "DNSPrefetch", "Auth", "WindowControl"
 ];
 
 // These are tab events that we listen to.
 const TAB_EVENTS = ["TabOpen", "TabClose", "TabSelect", "TabShow", "TabHide"];
 
-#ifndef XP_WIN
-#define BROKEN_WM_Z_ORDER
-#endif
-
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 // debug.js adds NS_ASSERT. cf. bug 669196
 ChromeUtils.import("resource://gre/modules/debug.js");
 
-#ifdef MOZ_CRASH_REPORTER
-XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
-  "@mozilla.org/xre/app-info;1", "nsICrashReporter");
-#endif
-
 XPCOMUtils.defineLazyServiceGetter(this, "SecMan",
   "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager");
 XPCOMUtils.defineLazyServiceGetter(this, "gScreenManager",
   "@mozilla.org/gfx/screenmanager;1", "nsIScreenManager");
 XPCOMUtils.defineLazyServiceGetter(this, "uuidGenerator",
   "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator");
+
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+  "resource://gre/modules/AppConstants.jsm");
 ChromeUtils.defineModuleGetter(this, "Utils",
   "resource://gre/modules/sessionstore/Utils.jsm");
 
 function debug(aMsg) {
   Services.console.logStringMessage("SessionStore: " + aMsg);
 }
 
 /* :::::::: The Service ::::::::::::::: */
@@ -595,19 +589,17 @@ SessionStoreService.prototype = {
           closedWindowState = this._closedWindows[i];
           closedWindowIndex = i;
           break;
         }
       }
 
       if (closedWindowState) {
         let newWindowState;
-#ifndef XP_MACOSX
-        if (!this._doResumeSession()) {
-#endif
+        if (AppConstants.platform == "macosx" || !this._doResumeSession()) {
           // We want to split the window up into pinned tabs and unpinned tabs.
           // Pinned tabs should be restored. If there are any remaining tabs,
           // they should be added back to _closedWindows.
           // We'll cheat a little bit and reuse _prepDataForDeferredRestore
           // even though it wasn't built exactly for this.
           let [appTabsState, normalTabsState] =
             this._prepDataForDeferredRestore({ windows: [closedWindowState] });
 
@@ -621,26 +613,25 @@ SessionStoreService.prototype = {
           if (!normalTabsState.windows.length) {
             this._closedWindows.splice(closedWindowIndex, 1);
           }
           // Or update _closedWindows with the modified state
           else {
             delete normalTabsState.windows[0].__lastSessionWindowID;
             this._closedWindows[closedWindowIndex] = normalTabsState.windows[0];
           }
-#ifndef XP_MACOSX
         }
         else {
           // If we're just restoring the window, make sure it gets removed from
           // _closedWindows.
           this._closedWindows.splice(closedWindowIndex, 1);
           newWindowState = closedWindowState;
           delete newWindowState.hidden;
         }
-#endif
+
         if (newWindowState) {
           // Ensure that the window state isn't hidden
           this._restoreCount = 1;
           let state = { windows: [newWindowState] };
           this.restoreWindow(aWindow, state, this._isCmdLineEmpty(aWindow));
         }
       }
       // we actually restored the session just now.
@@ -2161,31 +2152,30 @@ SessionStoreService.prototype = {
         if (!winData.isPopup)
           nonPopupCount++;
       }
     }
 
     // shallow copy this._closedWindows to preserve current state
     let lastClosedWindowsCopy = this._closedWindows.slice();
 
-#ifndef XP_MACOSX
     // If no non-popup browser window remains open, return the state of the last
     // closed window(s). We only want to do this when we're actually "ending"
     // the session.
     //XXXzpao We should do this for _restoreLastWindow == true, but that has
     //        its own check for popups. c.f. bug 597619
-    if (nonPopupCount == 0 && lastClosedWindowsCopy.length > 0 &&
+    if (AppConstants.platform != "macosx" && 
+        nonPopupCount == 0 && lastClosedWindowsCopy.length > 0 &&
         this._loadState == STATE_QUITTING) {
       // prepend the last non-popup browser window, so that if the user loads more tabs
       // at startup we don't accidentally add them to a popup window
       do {
         total.unshift(lastClosedWindowsCopy.shift())
       } while (total[0].isPopup)
     }
-#endif
 
     if (activeWindow) {
       this.activeWindowSSiCache = activeWindow.__SSi || "";
     }
     ix = ids.indexOf(this.activeWindowSSiCache);
     // We don't want to restore focus to a minimized window.
     if (ix != -1 && total[ix].sizemode == "minimized")
       ix = -1;
@@ -3426,36 +3416,41 @@ SessionStoreService.prototype = {
    */
   _getMostRecentBrowserWindow: function sss_getMostRecentBrowserWindow() {
     var win = Services.wm.getMostRecentWindow("navigator:browser");
     if (!win)
       return null;
     if (!win.closed)
       return win;
 
-#ifdef BROKEN_WM_Z_ORDER
-    win = null;
-    var windowsEnum = Services.wm.getEnumerator("navigator:browser");
-    // this is oldest to newest, so this gets a bit ugly
-    while (windowsEnum.hasMoreElements()) {
-      let nextWin = windowsEnum.getNext();
-      if (!nextWin.closed)
-        win = nextWin;
+    let broken_wm_z_order =
+      AppConstants.platform != "macosx" && AppConstants.platform != "win";
+
+    if (broken_wm_z_order) {
+      win = null;
+      var windowsEnum = Services.wm.getEnumerator("navigator:browser");
+      // this is oldest to newest, so this gets a bit ugly
+      while (windowsEnum.hasMoreElements()) {
+        let nextWin = windowsEnum.getNext();
+        if (!nextWin.closed)
+          win = nextWin;
+      }
+      return win;
     }
-    return win;
-#else
+
     var windowsEnum =
       Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
+
     while (windowsEnum.hasMoreElements()) {
       win = windowsEnum.getNext();
       if (!win.closed)
         return win;
     }
+
     return null;
-#endif
   },
 
   /**
    * Calls onClose for windows that are determined to be closed but aren't
    * destroyed yet, which would otherwise cause getBrowserState and
    * setBrowserState to treat them as open windows.
    */
   _handleClosedWindows: function sss_handleClosedWindows() {
@@ -3604,33 +3599,39 @@ SessionStoreService.prototype = {
   _getURIFromString: function sss_getURIFromString(aString) {
     return Services.io.newURI(aString);
   },
 
   /**
    * Annotate a breakpad crash report with the currently selected tab's URL.
    */
   _updateCrashReportURL: function sss_updateCrashReportURL(aWindow) {
-#ifdef MOZ_CRASH_REPORTER
+
+     // If the crash reporter isn't built, we bail out.
+    if (!AppConstants.MOZ_CRASHREPORTER) {
+      return;
+    }
+
     try {
       var currentURI = aWindow.getBrowser().currentURI.clone();
       // if the current URI contains a username/password, remove it
       try {
         currentURI.userPass = "";
       }
       catch (ex) { } // ignore failures on about: URIs
 
-      CrashReporter.annotateCrashReport("URL", currentURI.spec);
+      Cc["@mozilla.org/xre/app-info;1"]
+        .getService(Ci.nsICrashReporter)
+        .annotateCrashReport("URL", currentURI.spec);
     }
     catch (ex) {
       // don't make noise when crashreporter is built but not enabled
       if (ex.result != Cr.NS_ERROR_NOT_INITIALIZED)
         debug(ex);
     }
-#endif
   },
 
   /**
    * @param aState is a session state
    * @param aRecentCrashes is the number of consecutive crashes
    * @returns whether a restore page will be needed for the session state
    */
   _needsRestorePage: function sss_needsRestorePage(aState, aRecentCrashes) {
@@ -3886,25 +3887,26 @@ SessionStoreService.prototype = {
    * where we don't have any non-popup windows on Windows and Linux. Then we must
    * resize such that we have at least one non-popup window.
    */
   _capClosedWindows : function sss_capClosedWindows() {
     let maxWindowsUndo = this._prefBranch.getIntPref("sessionstore.max_windows_undo");
     if (this._closedWindows.length <= maxWindowsUndo)
       return;
     let spliceTo = maxWindowsUndo;
-#ifndef XP_MACOSX
-    let normalWindowIndex = 0;
-    // try to find a non-popup window in this._closedWindows
-    while (normalWindowIndex < this._closedWindows.length &&
-           this._closedWindows[normalWindowIndex].isPopup)
-      normalWindowIndex++;
-    if (normalWindowIndex >= maxWindowsUndo)
-      spliceTo = normalWindowIndex + 1;
-#endif
+    if (AppConstants.platform != "macosx") {
+      let normalWindowIndex = 0;
+      // try to find a non-popup window in this._closedWindows
+      while (normalWindowIndex < this._closedWindows.length &&
+             this._closedWindows[normalWindowIndex].isPopup)
+        normalWindowIndex++;
+      if (normalWindowIndex >= maxWindowsUndo)
+        spliceTo = normalWindowIndex + 1;
+    }
+
     this._closedWindows.splice(spliceTo, this._closedWindows.length);
   },
 
   /**
    * Reset state to prepare for a new session state to be restored.
    */
   _resetRestoringState: function sss_initRestoringState() {
     this._tabsToRestore = { visible: [], hidden: [] };