Bug 1142542 - Use AppConstants in browser/modules (r=gavin)
authorBill McCloskey <billm@mozilla.com>
Thu, 12 Mar 2015 08:25:32 -0700
changeset 233562 56da5d401fe2b13af17c353350ea3729d8018419
parent 233561 f0f3cba361d1cc2ae315b440ba9c7fe05275eff4
child 233563 5c8eccfa028dab4a080f352809ae58f89f8bf826
push id28417
push userryanvm@gmail.com
push dateFri, 13 Mar 2015 19:52:44 +0000
treeherdermozilla-central@977add19414a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs1142542
milestone39.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 1142542 - Use AppConstants in browser/modules (r=gavin)
browser/modules/AboutHome.jsm
browser/modules/PluginContent.jsm
browser/modules/RecentWindow.jsm
browser/modules/moz.build
browser/modules/webrtcUI.jsm
toolkit/modules/AppConstants.jsm
--- a/browser/modules/AboutHome.jsm
+++ b/browser/modules/AboutHome.jsm
@@ -8,16 +8,18 @@ let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 
 this.EXPORTED_SYMBOLS = [ "AboutHomeUtils", "AboutHome" ];
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+  "resource://gre/modules/AppConstants.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
   "resource://gre/modules/FxAccounts.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
   "resource://gre/modules/Promise.jsm");
 
 // Url to fetch snippets, in the urlFormatter service format.
@@ -45,20 +47,20 @@ this.AboutHomeUtils = {
     try {
       return !Services.prefs.getBoolPref("browser.rights.override");
     } catch (e) { }
     // Ditto, for the legacy EULA pref.
     try {
       return !Services.prefs.getBoolPref("browser.EULA.override");
     } catch (e) { }
 
-#ifndef MOZILLA_OFFICIAL
-    // Non-official builds shouldn't show the notification.
-    return false;
-#endif
+    if (!AppConstants.MOZILLA_OFFICIAL) {
+      // Non-official builds shouldn't show the notification.
+      return false;
+    }
 
     // Look to see if the user has seen the current version or not.
     var currentVersion = Services.prefs.getIntPref("browser.rights.version");
     try {
       return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
     } catch (e) { }
 
     // Legacy: If the user accepted a EULA, we won't annoy them with the
@@ -188,19 +190,20 @@ let AboutHome = {
         }
 
         Services.search.init(function(status) {
           if (!Components.isSuccessCode(status)) {
             return;
           }
 
           let engine = Services.search.currentEngine;
-#ifdef MOZ_SERVICES_HEALTHREPORT
-          window.BrowserSearch.recordSearchInHealthReport(engine, "abouthome", data.selection);
-#endif
+          if (AppConstants.MOZ_SERVICES_HEALTHREPORT) {
+            window.BrowserSearch.recordSearchInHealthReport(engine, "abouthome", data.selection);
+          }
+
           // Trigger a search through nsISearchEngine.getSubmission()
           let submission = engine.getSubmission(data.searchTerms, null, "homepage");
           let where = data.useNewTab ? "tab" : "current";
           window.openUILinkIn(submission.uri.spec, where, false,
                               submission.postData);
 
           // Used for testing
           let mm = aMessage.target.messageManager;
--- a/browser/modules/PluginContent.jsm
+++ b/browser/modules/PluginContent.jsm
@@ -1,12 +1,11 @@
-# -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 let Cc = Components.classes;
 let Ci = Components.interfaces;
 let Cu = Components.utils;
 
 this.EXPORTED_SYMBOLS = [ "PluginContent" ];
@@ -16,16 +15,19 @@ Cu.import("resource://gre/modules/Servic
 Cu.import("resource://gre/modules/Timer.jsm");
 Cu.import("resource://gre/modules/BrowserUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "gNavigatorBundle", function() {
   const url = "chrome://browser/locale/browser.properties";
   return Services.strings.createBundle(url);
 });
 
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+  "resource://gre/modules/AppConstants.jsm");
+
 this.PluginContent = function (global) {
   this.init(global);
 }
 
 PluginContent.prototype = {
   init: function (global) {
     this.global = global;
     // Need to hold onto the content window or else it'll get destroyed
@@ -512,34 +514,35 @@ PluginContent.prototype = {
       objLoadingContent.cancelPlayPreview();
   },
 
   // Forward a link click callback to the chrome process.
   forwardCallback: function (name) {
     this.global.sendAsyncMessage("PluginContent:LinkClickCallback", { name: name });
   },
 
-#ifdef MOZ_CRASHREPORTER
   submitReport: function submitReport(pluginDumpID, browserDumpID, plugin) {
+    if (!AppConstants.MOZ_CRASHREPORTER) {
+      return;
+    }
     let keyVals = {};
     if (plugin) {
       let userComment = this.getPluginUI(plugin, "submitComment").value.trim();
       if (userComment)
         keyVals.PluginUserComment = userComment;
       if (this.getPluginUI(plugin, "submitURLOptIn").checked)
         keyVals.PluginContentURL = plugin.ownerDocument.URL;
     }
 
     this.global.sendAsyncMessage("PluginContent:SubmitReport", {
       pluginDumpID: pluginDumpID,
       browserDumpID: browserDumpID,
       keyVals: keyVals,
     });
   },
-#endif
 
   reloadPage: function () {
     this.global.content.location.reload();
   },
 
   // Event listener for click-to-play plugins.
   _handleClickToPlayEvent: function (plugin) {
     let doc = plugin.ownerDocument;
@@ -880,17 +883,16 @@ PluginContent.prototype = {
         return;
       }
       // doPrompt is specific to the crashed plugin overlay, and
       // therefore is not applicable for window-global plugins.
       doPrompt = false;
     }
 
     let status;
-#ifdef MOZ_CRASHREPORTER
     // Determine which message to show regarding crash reports.
     if (submittedReport) { // submitReports && !doPrompt, handled in observer
       status = "submitted";
     }
     else if (!submitReports && !doPrompt) {
       status = "noSubmit";
     }
     else if (!pluginDumpID) {
@@ -906,17 +908,17 @@ PluginContent.prototype = {
     // This can happen if the plugin is killed from the task manager.
     if (!pluginDumpID) {
         status = "noReport";
     }
 
     // If we're showing the link to manually trigger report submission, we'll
     // want to be able to update all the instances of the UI for this crash to
     // show an updated message when a report is submitted.
-    if (doPrompt) {
+    if (AppConstants.MOZ_CRASHREPORTER && doPrompt) {
       let observer = {
         QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                                Ci.nsISupportsWeakReference]),
         observe : (subject, topic, data) => {
           let propertyBag = subject;
           if (!(propertyBag instanceof Ci.nsIPropertyBag2))
             return;
           // Ignore notifications for other crashes.
@@ -935,17 +937,16 @@ PluginContent.prototype = {
       Services.obs.addObserver(observer, "crash-report-status", true);
       // ...alas, now we need something to hold a strong reference to prevent
       // it from being GC. But I don't want to manually manage the reference's
       // lifetime (which should be no greater than the page).
       // Clever solution? Use a closue with an event listener on the document.
       // When the doc goes away, so do the listener references and the closure.
       doc.addEventListener("mozCleverClosureHack", observer, false);
     }
-#endif
 
     let isShowing = false;
 
     if (plugin) {
       // If there's no plugin (an <object> or <embed> element), this call is
       // for a window-global plugin. In this case, there's no overlay to show.
       isShowing = _setUpPluginOverlay.call(this, plugin, doPrompt);
     }
--- a/browser/modules/RecentWindow.jsm
+++ b/browser/modules/RecentWindow.jsm
@@ -3,25 +3,20 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 this.EXPORTED_SYMBOLS = ["RecentWindow"];
 
 const Cu = Components.utils;
 
+Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
-#ifdef XP_UNIX
-#ifndef XP_MACOSX
-#define BROKEN_WM_Z_ORDER
-#endif
-#endif
-
 this.RecentWindow = {
   /*
    * Get the most recent browser window.
    *
    * @param aOptions an object accepting the arguments for the search.
    *        * private: true to restrict the search to private windows
    *            only, false to restrict the search to non-private only.
    *            Omit the property to search in both groups.
@@ -36,35 +31,38 @@ this.RecentWindow = {
     function isSuitableBrowserWindow(win) {
       return (!win.closed &&
               (allowPopups || win.toolbar.visible) &&
               (!checkPrivacy ||
                PrivateBrowsingUtils.permanentPrivateBrowsing ||
                PrivateBrowsingUtils.isWindowPrivate(win) == aOptions.private));
     }
 
-#ifdef BROKEN_WM_Z_ORDER
-    let win = Services.wm.getMostRecentWindow("navigator:browser");
+    let broken_wm_z_order =
+      AppConstants.platform != "macosx" && AppConstants.platform != "win";
+
+    if (broken_wm_z_order) {
+      let win = Services.wm.getMostRecentWindow("navigator:browser");
 
-    // if we're lucky, this isn't a popup, and we can just return this
-    if (win && !isSuitableBrowserWindow(win)) {
-      win = null;
-      let windowList = Services.wm.getEnumerator("navigator:browser");
-      // this is oldest to newest, so this gets a bit ugly
+      // if we're lucky, this isn't a popup, and we can just return this
+      if (win && !isSuitableBrowserWindow(win)) {
+        win = null;
+        let windowList = Services.wm.getEnumerator("navigator:browser");
+        // this is oldest to newest, so this gets a bit ugly
+        while (windowList.hasMoreElements()) {
+          let nextWin = windowList.getNext();
+          if (isSuitableBrowserWindow(nextWin))
+            win = nextWin;
+        }
+      }
+      return win;
+    } else {
+      let windowList = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
       while (windowList.hasMoreElements()) {
-        let nextWin = windowList.getNext();
-        if (isSuitableBrowserWindow(nextWin))
-          win = nextWin;
+        let win = windowList.getNext();
+        if (isSuitableBrowserWindow(win))
+          return win;
       }
+      return null;
     }
-    return win;
-#else
-    let windowList = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
-    while (windowList.hasMoreElements()) {
-      let win = windowList.getNext();
-      if (isSuitableBrowserWindow(win))
-        return win;
-    }
-    return null;
-#endif
   }
 };
 
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -6,16 +6,17 @@
 
 BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
 XPCSHELL_TESTS_MANIFESTS += [
     'test/unit/social/xpcshell.ini',
     'test/xpcshell/xpcshell.ini',
 ]
 
 EXTRA_JS_MODULES += [
+    'AboutHome.jsm',
     'BrowserUITelemetry.jsm',
     'CastingApps.jsm',
     'Chat.jsm',
     'ContentClick.jsm',
     'ContentLinkHandler.jsm',
     'ContentObservers.jsm',
     'ContentSearch.jsm',
     'ContentWebRTC.jsm',
@@ -24,43 +25,39 @@ EXTRA_JS_MODULES += [
     'E10SUtils.jsm',
     'Feeds.jsm',
     'FormSubmitObserver.jsm',
     'FormValidationHandler.jsm',
     'HiddenFrame.jsm',
     'NetworkPrioritizer.jsm',
     'offlineAppCache.jsm',
     'PanelFrame.jsm',
+    'PluginContent.jsm',
     'ProcessHangMonitor.jsm',
     'ReaderParent.jsm',
+    'RecentWindow.jsm',
     'RemotePrompt.jsm',
     'SelfSupportBackend.jsm',
     'SitePermissions.jsm',
     'Social.jsm',
     'TabCrashReporter.jsm',
     'WebappManager.jsm',
+    'webrtcUI.jsm',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     EXTRA_JS_MODULES += [
         'Windows8WindowFrameColor.jsm',
         'WindowsJumpLists.jsm',
         'WindowsPreviewPerTab.jsm',
     ]
 
 if CONFIG['NIGHTLY_BUILD']:
     EXTRA_JS_MODULES += [
         'SignInToWebsite.jsm',
     ]
 
-EXTRA_PP_JS_MODULES += [
-    'AboutHome.jsm',
-    'PluginContent.jsm',
-    'RecentWindow.jsm',
-    'webrtcUI.jsm',
-]
-
 EXTRA_PP_COMPONENTS += [
     'browsermodules.manifest',
 ]
 
 if CONFIG['MOZILLA_OFFICIAL']:
     DEFINES['MOZILLA_OFFICIAL'] = 1
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -8,16 +8,18 @@ this.EXPORTED_SYMBOLS = ["webrtcUI"];
 
 const Cu = Components.utils;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+                                  "resource://gre/modules/AppConstants.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
                                   "resource://gre/modules/PluralForm.jsm");
 
 this.webrtcUI = {
   init: function () {
     Services.obs.addObserver(maybeAddMenuIndicator, "browser-delayed-startup-finished", false);
 
     let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
@@ -85,29 +87,27 @@ this.webrtcUI = {
       browserWindow.gBrowser.selectedTab = aActiveStream.tab;
     } else {
       aActiveStream.browser.focus();
     }
     browserWindow.focus();
     let PopupNotifications = browserWindow.PopupNotifications;
     let notif = PopupNotifications.getNotification("webRTC-sharing" + aType,
                                                    aActiveStream.browser);
-#ifdef XP_MACOSX
-    if (!Services.focus.activeWindow) {
+    if (AppConstants.platform == "macosx" && !Services.focus.activeWindow) {
       browserWindow.addEventListener("activate", function onActivate() {
         browserWindow.removeEventListener("activate", onActivate);
         Services.tm.mainThread.dispatch(function() {
           notif.reshow();
         }, Ci.nsIThread.DISPATCH_NORMAL);
       });
       Cc["@mozilla.org/widget/macdocksupport;1"].getService(Ci.nsIMacDockSupport)
         .activateApplication(true);
       return;
     }
-#endif
     notif.reshow();
   },
 
   updateMainActionLabel: function(aMenuList) {
     let type = aMenuList.selectedItem.getAttribute("devicetype");
     let document = aMenuList.ownerDocument;
     document.getElementById("webRTC-all-windows-shared").hidden = type != "Screen";
 
@@ -456,22 +456,23 @@ function removePrompt(aBrowser, aCallId)
   let chromeWin = aBrowser.ownerDocument.defaultView;
   let notification =
     chromeWin.PopupNotifications.getNotification("webRTC-shareDevices", aBrowser);
   if (notification && notification.callID == aCallId)
     notification.remove();
 }
 
 function getGlobalIndicator() {
-#ifndef XP_MACOSX
-  const INDICATOR_CHROME_URI = "chrome://browser/content/webrtcIndicator.xul";
-  const features = "chrome,dialog=yes,titlebar=no,popup=yes";
+  if (AppConstants.platform != "macosx") {
+    const INDICATOR_CHROME_URI = "chrome://browser/content/webrtcIndicator.xul";
+    const features = "chrome,dialog=yes,titlebar=no,popup=yes";
 
-  return Services.ww.openWindow(null, INDICATOR_CHROME_URI, "_blank", features, []);
-#else
+    return Services.ww.openWindow(null, INDICATOR_CHROME_URI, "_blank", features, []);
+  }
+
   let indicator = {
     _camera: null,
     _microphone: null,
     _screen: null,
 
     _hiddenDoc: Cc["@mozilla.org/appshell/appShellService;1"]
                   .getService(Ci.nsIAppShellService)
                   .hiddenDOMWindow.document,
@@ -588,17 +589,16 @@ function getGlobalIndicator() {
       this._setIndicatorState("Camera", false);
       this._setIndicatorState("Microphone", false);
       this._setIndicatorState("Screen", false);
     }
   };
 
   indicator.updateIndicatorState();
   return indicator;
-#endif
 }
 
 function onTabSharingMenuPopupShowing(e) {
   let streams = webrtcUI.getActiveStreams(true, true, true);
   for (let streamInfo of streams) {
     let stringName = "getUserMedia.sharingMenu";
     let types = streamInfo.types;
     if (types.camera)
@@ -645,39 +645,41 @@ function showOrCreateMenuForWindow(aWind
   let document = aWindow.document;
   let menu = document.getElementById("tabSharingMenu");
   if (!menu) {
     let stringBundle = aWindow.gNavigatorBundle;
     menu = document.createElement("menu");
     menu.id = "tabSharingMenu";
     let labelStringId = "getUserMedia.sharingMenu.label";
     menu.setAttribute("label", stringBundle.getString(labelStringId));
-#ifdef XP_MACOSX
-    let container = document.getElementById("windowPopup");
-    let insertionPoint = document.getElementById("sep-window-list");
-    let separator = document.createElement("menuseparator");
-    separator.id = "tabSharingSeparator";
-    container.insertBefore(separator, insertionPoint);
-#else
-    let accesskeyStringId = "getUserMedia.sharingMenu.accesskey";
-    menu.setAttribute("accesskey", stringBundle.getString(accesskeyStringId));
-    let container = document.getElementById("main-menubar");
-    let insertionPoint = document.getElementById("helpMenu");
-#endif
+
+    let container, insertionPoint;
+    if (AppConstants.platform == "macosx") {
+      container = document.getElementById("windowPopup");
+      insertionPoint = document.getElementById("sep-window-list");
+      let separator = document.createElement("menuseparator");
+      separator.id = "tabSharingSeparator";
+      container.insertBefore(separator, insertionPoint);
+    } else {
+      let accesskeyStringId = "getUserMedia.sharingMenu.accesskey";
+      menu.setAttribute("accesskey", stringBundle.getString(accesskeyStringId));
+      container = document.getElementById("main-menubar");
+      insertionPoint = document.getElementById("helpMenu");
+    }
     let popup = document.createElement("menupopup");
     popup.id = "tabSharingMenuPopup";
     popup.addEventListener("popupshowing", onTabSharingMenuPopupShowing);
     popup.addEventListener("popuphiding", onTabSharingMenuPopupHiding);
     menu.appendChild(popup);
     container.insertBefore(menu, insertionPoint);
   } else {
     menu.hidden = false;
-#ifdef XP_MACOSX
-    document.getElementById("tabSharingSeparator").hidden = false;
-#endif
+    if (AppConstants.platform == "macosx") {
+      document.getElementById("tabSharingSeparator").hidden = false;
+    }
   }
 }
 
 function maybeAddMenuIndicator(window) {
   if (webrtcUI.showGlobalIndicator) {
     showOrCreateMenuForWindow(window);
   }
 }
@@ -696,22 +698,22 @@ function updateIndicators(data) {
     if (webrtcUI.showGlobalIndicator) {
       showOrCreateMenuForWindow(chromeWin);
     } else {
       let doc = chromeWin.document;
       let existingMenu = doc.getElementById("tabSharingMenu");
       if (existingMenu) {
         existingMenu.hidden = true;
       }
-#ifdef XP_MACOSX
-      let separator = doc.getElementById("tabSharingSeparator");
-      if (separator) {
-        separator.hidden = true;
+      if (AppConstants.platform == "macosx") {
+        let separator = doc.getElementById("tabSharingSeparator");
+        if (separator) {
+          separator.hidden = true;
+        }
       }
-#endif
     }
   }
 
   if (webrtcUI.showGlobalIndicator) {
     if (!gIndicatorWindow)
       gIndicatorWindow = getGlobalIndicator();
     else
       gIndicatorWindow.updateIndicatorState();
--- a/toolkit/modules/AppConstants.jsm
+++ b/toolkit/modules/AppConstants.jsm
@@ -79,12 +79,36 @@ let AppConstants = Object.freeze({
 
   MOZ_WEBRTC:
 #ifdef MOZ_WEBRTC
   true,
 #else
   false,
 #endif
 
+  platform:
+#ifdef MOZ_WIDGET_GTK
+  "linux",
+#elif MOZ_WIDGET_QT
+  "linux",
+#elif XP_WIN
+  "win",
+#elif XP_MACOSX
+  "macosx",
+#elif MOZ_WIDGET_ANDROID
+  "android",
+#elif MOZ_WIDGET_GONK
+  "gonk",
+#else
+  "other",
+#endif
+
+  MOZ_CRASHREPORTER:
+#ifdef MOZ_CRASHREPORTER
+  true,
+#else
+  false,
+#endif
+
   MOZ_APP_VERSION: "@MOZ_APP_VERSION@",
 
   ANDROID_PACKAGE_NAME: "@ANDROID_PACKAGE_NAME@",
 });