Bug 1588875 - Detect OS using AppConstants.platform. r=IanN

This commit is contained in:
Frank-Rainer Grahl 2019-10-30 19:04:34 +01:00
Родитель 36fa493ebe
Коммит 92b3d8d359
22 изменённых файлов: 83 добавлений и 47 удалений

Просмотреть файл

@ -6,6 +6,9 @@
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const {AeroPeek} = ChromeUtils.import("resource:///modules/WindowsPreviewPerTab.jsm");
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
NetUtil: "resource://gre/modules/NetUtil.jsm",
@ -2945,7 +2948,7 @@ function WindowIsClosing()
var numtabs = cn.length;
var reallyClose = true;
if (!gPrivate && !/Mac/.test(navigator.platform) && isClosingLastBrowser()) {
if (!gPrivate && AppConstants.platform != "macosx" && isClosingLastBrowser()) {
let closingCanceled = Cc["@mozilla.org/supports-PRBool;1"]
.createInstance(Ci.nsISupportsPRBool);
Services.obs.notifyObservers(closingCanceled, "browser-lastwindow-close-requested");

Просмотреть файл

@ -3,6 +3,10 @@
* 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/. */
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
function toggleTabsFromOtherComputers()
{
// enable/disable the Tabs From Other Computers menu
@ -135,7 +139,7 @@ function createHistoryMenuItem(aParent, aIndex, aEntry, aAnchor, aChecked)
menuitem.setAttribute("checked", "true");
}
if (!aChecked || /Mac/.test(navigator.platform))
if (!aChecked || AppConstants.platform == "macosx")
{
menuitem.className = "menuitem-iconic bookmark-item menuitem-with-favicon";
PlacesUtils.favicons.getFaviconURLForPage(aEntry.URI,

Просмотреть файл

@ -160,7 +160,7 @@
if (aEvent.altKey)
return;
if (/Mac/.test(navigator.platform)) {
if (AppConstants.platform == "macosx") {
if (!aEvent.metaKey)
return;
@ -175,8 +175,7 @@
aEvent.stopPropagation();
aEvent.preventDefault();
}
}
else {
} else {
if (aEvent.ctrlKey && !aEvent.shiftKey && !aEvent.metaKey &&
aEvent.keyCode == KeyEvent.DOM_VK_F4 &&
this.getStripVisibility()) {
@ -3049,7 +3048,7 @@
<constructor>
<![CDATA[
document.addEventListener("keypress", this._keyEventHandler);
this.arrowKeysShouldWrap = /Mac/.test(navigator.platform);
this.arrowKeysShouldWrap = AppConstants.platform == "macosx";
// Bail out early if we are in tabmail. See Bug 521803.
if (!this.mPanelContainer)
return;

Просмотреть файл

@ -756,7 +756,7 @@ function triggerSecondaryCommand(popup, index) {
});
// One down event to open the popup
EventUtils.synthesizeKey("VK_DOWN", { altKey: !navigator.platform.includes("Mac") });
EventUtils.synthesizeKey("VK_DOWN", { altKey: AppConstants.platform != "macosx" });
}
function loadURI(uri, callback) {

Просмотреть файл

@ -4,7 +4,7 @@ function test() {
/* This part tests accel keys, which are not implemented in Seamonkey yet.
* Commenting out for now ...
* var isLinux = navigator.platform.indexOf("Linux") == 0;
* var isLinux = AppConstants.platform == "linux";
* for (let i = 9; i >= 1; i--) {
* EventUtils.synthesizeKey(i.toString(), { altKey: isLinux, accelKey: !isLinux });
*

Просмотреть файл

@ -113,7 +113,7 @@ function test()
is(downloadView.rowCount, sites.length, "All downloads displayed");
// Select all downloads
var isMac = navigator.platform.search("Mac") == 0;
var isMac = AppConstants.platform == "macosx";
synthesizeKey("a", { metaKey: isMac, ctrlKey: !isMac }, win);
is(downloadView.selection.count, sites.length, "All downloads selected");

Просмотреть файл

@ -6,6 +6,9 @@
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
var {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const FEEDWRITER_CID = Components.ID("{49bb6593-3aff-4eb3-a068-2712c28bd58e}");
const FEEDWRITER_CONTRACTID = "@mozilla.org/browser/feeds/result-writer;1";
@ -580,14 +583,13 @@ FeedWriter.prototype = {
* @returns The display name of the application represented by the file.
*/
_getFileDisplayName: function getFileDisplayName(file) {
if ("nsILocalFileWin" in Ci &&
if (AppConstants.platform == "win" &&
file instanceof Ci.nsILocalFileWin) {
try {
return file.getVersionInfoField("FileDescription");
} catch (e) {}
}
else if ("nsILocalFileMac" in Ci &&
file instanceof Ci.nsILocalFileMac) {
} else if (AppConstants.platform == "macosx" &&
file instanceof Ci.nsILocalFileMac) {
try {
return file.bundleDisplayName;
} catch (e) {}

Просмотреть файл

@ -83,14 +83,13 @@ const kActionManageApp = -1;
// Utilities
function getFileDisplayName(aFile) {
if ("nsILocalFileWin" in Ci &&
if (AppConstants.platform == "win" &&
aFile instanceof Ci.nsILocalFileWin) {
try {
return aFile.getVersionInfoField("FileDescription");
} catch (e) {}
}
else if ("nsILocalFileMac" in Ci &&
aFile instanceof Ci.nsILocalFileMac) {
} else if (AppConstants.platform == "macosx" &&
aFile instanceof Ci.nsILocalFileMac) {
try {
return aFile.bundleDisplayName;
} catch (e) {}

Просмотреть файл

@ -6,6 +6,10 @@
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const {DownloadUtils} = ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
function Startup()
{
updateActualCacheSize();
@ -59,7 +63,7 @@ function ReadCacheFolder(aField)
if (file) {
aField.file = file;
aField.label = (/Mac/.test(navigator.platform)) ? file.leafName : file.path;
aField.label = AppConstants.platform == "macosx" ? file.leafName : file.path;
}
}

Просмотреть файл

@ -2,6 +2,10 @@
* 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/. */
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
var minMinValue;
var maxMinValue;
@ -78,7 +82,7 @@ function AdjustMinZoom()
*/
function updateHardwareAcceleration(aVal)
{
if (/^Win/.test(navigator.platform)) {
if (AppConstants.platform == "win") {
document.getElementById("gfx.direct2d.disabled").value = aVal;
}
}

Просмотреть файл

@ -3,14 +3,19 @@
* 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/. */
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const kTabToLinks = 4;
const kTabToForms = 2;
const kTabToTextboxes = 1;
function Startup()
{
if (/Mac/.test(navigator.platform))
if (AppConstants.platform == "macosx") {
document.getElementById("tabNavigationPrefs").setAttribute("hidden", true);
}
UpdateBrowseWithCaretItems();
}

Просмотреть файл

@ -181,10 +181,11 @@ var gEngineManagerDialog = {
return;
if (aEvent.keyCode == (AppConstants.platform == "macosx" ?
KeyEvent.DOM_VK_RETURN : KeyEvent.DOM_VK_F2))
if (tree.startEditing(gEngineView.selectedIndex,
tree.columns.engineKeyword))
aEvent.preventDefault();
KeyEvent.DOM_VK_RETURN : KeyEvent.DOM_VK_F2) &&
tree.startEditing(gEngineView.selectedIndex,
tree.columns.engineKeyword)) {
aEvent.preventDefault();
}
}
};

Просмотреть файл

@ -684,8 +684,9 @@
phase="capturing"
action="return this.openSearch();"/>
<handler event="keypress" keycode="VK_F4" phase="capturing"><![CDATA[
return /Mac/.test(navigator.platform) || this.openSearch();
<handler event="keypress" keycode="VK_F4" phase="capturing">
<![CDATA[
return (AppConstants.platform == "macosx") || this.openSearch()
]]></handler>
</handlers>
</binding>

Просмотреть файл

@ -4,6 +4,10 @@
* 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/. */
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
var gShell = Cc["@mozilla.org/suite/shell-service;1"]
.getService(Ci.nsIShellService);
@ -11,7 +15,7 @@ var gImage, gImageName, gPosition, gPicker, gDesktop;
function onLoad()
{
document.getElementById("itemsBox").hidden = /Mac/.test(navigator.platform);
document.getElementById("itemsBox").hidden = AppConstants.platform == "macosx";
gImage = window.arguments[0];
gImageName = window.arguments[1];
gPosition = document.getElementById("position");

Просмотреть файл

@ -80,7 +80,7 @@ function browserWindowsCount(expected, msg) {
function test() {
browserWindowsCount(1, "Only one browser window should be open initially");
if (navigator.platform.match(/Mac/)) {
if (AppConstants.platform == "macosx") {
todo(false, "Test disabled on MacOSX. (Bug 520787)");
return;
}
@ -426,7 +426,7 @@ function test() {
// Execution starts here
setupTestsuite();
if (navigator.platform.match(/Mac/)) {
if (AppConstants.platform == "macosx") {
// Mac tests
testMacNotifications(function () {
testNotificationCount(function () {

Просмотреть файл

@ -21,9 +21,9 @@ function test() {
return el.isPopup;
}).length;
let numNormal = ss.getClosedWindowCount() - numPopups;
// #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform
let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac
: expectedResults.other;
let oResults = AppConstants.platform == "macosx" ? expectedResults.mac
: expectedResults.other;
is(numPopups, oResults.popup,
"There were " + oResults.popup + " popup windows to repoen");
is(numNormal, oResults.normal,

Просмотреть файл

@ -2,6 +2,11 @@
* 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/. */
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
function browserWindowsCount() {
let count = 0;
let e = Services.wm.getEnumerator("navigator:browser");

Просмотреть файл

@ -1832,8 +1832,7 @@ function CheckValidEmailAddress(aTo, aCC, aBCC)
function SendMessage()
{
let sendInBackground = Services.prefs.getBoolPref("mailnews.sendInBackground");
if (sendInBackground && !/Mac/.test(navigator.platform))
{
if (sendInBackground && AppConstants.platform != "macosx") {
let enumerator = Services.wm.getEnumerator(null);
let count = 0;
while (enumerator.hasMoreElements() && count < 2)

Просмотреть файл

@ -5,6 +5,10 @@
// The contents of this file will be loaded into the scope of the object
// <prefpane id="notifications_pane">!
var {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
var gSoundUrlPref = null;
function Startup()
@ -23,15 +27,15 @@ function Startup()
// animate dock icon option currently available for Mac OSX only
var newMailNotificationBouncePref = document.getElementById("newMailNotificationBounceBox");
newMailNotificationBouncePref.hidden = !navigator.platform.startsWith("Mac");
newMailNotificationBouncePref.hidden = AppConstants.platform != "macosx";
// show tray icon option currently available for Windows only
var newMailNotificationTrayIconPref = document.getElementById("newMailNotificationTrayIconBox");
newMailNotificationTrayIconPref.hidden = !navigator.platform.startsWith("Win");
newMailNotificationTrayIconPref.hidden = AppConstants.platform != "win";
// use system alert option currently available for Linux only
var useSystemAlertPref = document.getElementById("useSystemAlertBox");
useSystemAlertPref.hidden = !navigator.platform.startsWith("Linux");
useSystemAlertPref.hidden = AppConstants.platform != "linux";
EnableAlert(document.getElementById("mail.biff.show_alert").value, false);
EnableTrayIcon(document.getElementById("mail.biff.show_tray_icon").value);
@ -44,8 +48,7 @@ function Startup()
function EnableAlert(aEnable, aFocus)
{
// switch off the balloon on Windows if the user wants regular alerts
if (aEnable && navigator.platform.startsWith("Win"))
{
if (aEnable && AppConstants.platform == "win") {
let balloonAlert = document.getElementById("mail.biff.show_balloon");
if (!balloonAlert.locked)
balloonAlert.value = false;
@ -66,8 +69,7 @@ function EnableTrayIcon(aEnable)
function ClearAlert(aEnable)
{
// switch off the regular alerts if the user wants the balloon
if (aEnable && navigator.platform.startsWith("Win"))
{
if (aEnable && AppConstants.platform == "win") {
let showAlert = document.getElementById("mail.biff.show_alert");
if (!showAlert.locked)
showAlert.value = false;

Просмотреть файл

@ -107,8 +107,9 @@ function setTitleFromFolder(msgfolder, subject)
}
}
if (!/Mac/.test(navigator.platform))
if (AppConstants.platform != "macosx") {
title += " - " + gBrandBundle.getString("brandShortName");
}
document.title = title;

Просмотреть файл

@ -488,8 +488,9 @@
if (switchToNewTab)
{
let docTitle = tabInfo.title;
if (!/Mac/.test(navigator.platform))
if (AppConstants.platform != "macosx") {
docTitle += " - " + gBrandBundle.getString("brandFullName");
}
document.title = docTitle;
// Update the toolbar status - we don't need to do menus as they
@ -635,8 +636,9 @@
}
let docTitle = tabInfo.title;
if (!/Mac/.test(navigator.platform))
if (AppConstants.platform != "macosx") {
docTitle += " - " + gBrandBundle.getString("brandFullName");
}
document.title = docTitle;
// Update the toolbar status - we don't need to do menus as they
@ -712,8 +714,9 @@
if (index == this.tabContainer.selectedIndex)
{
let docTitle = tabInfo.title;
if (!/Mac/.test(navigator.platform))
if (AppConstants.platform != "macosx") {
docTitle += " - " + gBrandBundle.getString("brandFullName");
}
document.title = docTitle;
// Update the toolbar status - we don't need to do menus as they

Просмотреть файл

@ -49,8 +49,8 @@ var Sanitizer = {
}
if (this._prefs.getBoolPref("promptOnSanitize")) {
// make this an app-modal window on Mac.
var win = "nsILocalFileMac" in Ci ? null
: aParentWindow;
let win = AppConstants.platform == "macosx" ? null : aParentWindow;
Services.ww.openWindow(win,
"chrome://communicator/content/sanitize.xul",
"Sanitize",