summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-02-06 06:32:11 -0500
committerMatt A. Tobin <email@mattatobin.com>2020-02-06 06:32:11 -0500
commit2e6782afb5a340c777d3dab1c5e82f3e4af06ad2 (patch)
tree1fbc79ca6b9dc0a6dd05650ceab92e2de8bdd38a /toolkit
parent758618b6054d9332a8a0bd79f73623abfd5e1d3c (diff)
downloaduxp-2e6782afb5a340c777d3dab1c5e82f3e4af06ad2.tar.gz
Issue #65 - Remove AppConstants from toolkit/mozapps/downloads
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm68
-rw-r--r--toolkit/mozapps/downloads/content/downloads.js30
-rw-r--r--toolkit/mozapps/downloads/jar.mn2
-rw-r--r--toolkit/mozapps/downloads/moz.build3
-rw-r--r--toolkit/mozapps/downloads/nsHelperAppDlg.js176
5 files changed, 141 insertions, 138 deletions
diff --git a/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm b/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm
index bccbeda567..e015ded2a1 100644
--- a/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm
+++ b/toolkit/mozapps/downloads/DownloadTaskbarProgress.jsm
@@ -16,7 +16,6 @@ const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");
@@ -177,33 +176,33 @@ var DownloadTaskbarProgressUpdater =
*/
_setActiveWindow: function DTPU_setActiveWindow(aWindow, aIsDownloadWindow)
{
- if (AppConstants.platform == "win") {
- // Clear out the taskbar for the old active window. (If there was no active
- // window, this is a no-op.)
- this._clearTaskbar();
-
- this._activeWindowIsDownloadWindow = aIsDownloadWindow;
- if (aWindow) {
- // Get the taskbar progress for this window
- let docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIWebNavigation).
- QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
- QueryInterface(Ci.nsIInterfaceRequestor).
- getInterface(Ci.nsIXULWindow).docShell;
- let taskbarProgress = this._taskbar.getTaskbarProgress(docShell);
- this._activeTaskbarProgress = taskbarProgress;
-
- this._updateTaskbar();
- // _onActiveWindowUnload is idempotent, so we don't need to check whether
- // we've already set this before or not.
- aWindow.addEventListener("unload", function () {
- DownloadTaskbarProgressUpdater._onActiveWindowUnload(taskbarProgress);
- }, false);
- }
- else {
- this._activeTaskbarProgress = null;
- }
+#ifdef XP_WIN
+ // Clear out the taskbar for the old active window. (If there was no active
+ // window, this is a no-op.)
+ this._clearTaskbar();
+
+ this._activeWindowIsDownloadWindow = aIsDownloadWindow;
+ if (aWindow) {
+ // Get the taskbar progress for this window
+ let docShell = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIWebNavigation).
+ QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
+ QueryInterface(Ci.nsIInterfaceRequestor).
+ getInterface(Ci.nsIXULWindow).docShell;
+ let taskbarProgress = this._taskbar.getTaskbarProgress(docShell);
+ this._activeTaskbarProgress = taskbarProgress;
+
+ this._updateTaskbar();
+ // _onActiveWindowUnload is idempotent, so we don't need to check whether
+ // we've already set this before or not.
+ aWindow.addEventListener("unload", function () {
+ DownloadTaskbarProgressUpdater._onActiveWindowUnload(taskbarProgress);
+ }, false);
+ }
+ else {
+ this._activeTaskbarProgress = null;
}
+#endif
},
// / Current state displayed on the active window's taskbar item
@@ -213,14 +212,15 @@ var DownloadTaskbarProgressUpdater =
_shouldSetState: function DTPU_shouldSetState()
{
- if (AppConstants.platform == "win") {
- // If the active window is not the download manager window, set the state
- // only if it is normal or indeterminate.
- return this._activeWindowIsDownloadWindow ||
- (this._taskbarState == Ci.nsITaskbarProgress.STATE_NORMAL ||
- this._taskbarState == Ci.nsITaskbarProgress.STATE_INDETERMINATE);
- }
+#ifdef XP_WIN
+ // If the active window is not the download manager window, set the state
+ // only if it is normal or indeterminate.
+ return this._activeWindowIsDownloadWindow ||
+ (this._taskbarState == Ci.nsITaskbarProgress.STATE_NORMAL ||
+ this._taskbarState == Ci.nsITaskbarProgress.STATE_INDETERMINATE);
+#else
return true;
+#endif
},
/**
diff --git a/toolkit/mozapps/downloads/content/downloads.js b/toolkit/mozapps/downloads/content/downloads.js
index 2fdb19a743..66230592ff 100644
--- a/toolkit/mozapps/downloads/content/downloads.js
+++ b/toolkit/mozapps/downloads/content/downloads.js
@@ -19,7 +19,6 @@ var Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm");
@@ -253,18 +252,18 @@ function openDownload(aDownload)
dontAsk = !pref.getBoolPref(PREF_BDM_CONFIRMOPENEXE);
} catch (e) { }
- if (AppConstants.platform == "win") {
- // On Vista and above, we rely on native security prompting for
- // downloaded content unless it's disabled.
- try {
- var sysInfo = Cc["@mozilla.org/system-info;1"].
- getService(Ci.nsIPropertyBag2);
- if (parseFloat(sysInfo.getProperty("version")) >= 6 &&
- pref.getBoolPref(PREF_BDM_SCANWHENDONE)) {
- dontAsk = true;
- }
- } catch (ex) { }
- }
+#ifdef XP_WIN
+ // On Vista and above, we rely on native security prompting for
+ // downloaded content unless it's disabled.
+ try {
+ var sysInfo = Cc["@mozilla.org/system-info;1"].
+ getService(Ci.nsIPropertyBag2);
+ if (parseFloat(sysInfo.getProperty("version")) >= 6 &&
+ pref.getBoolPref(PREF_BDM_SCANWHENDONE)) {
+ dontAsk = true;
+ }
+ } catch (ex) { }
+#endif
if (!dontAsk) {
var strings = document.getElementById("downloadStrings");
@@ -478,10 +477,11 @@ var gDownloadObserver = {
removeFromView(dl);
break;
case "browser-lastwindow-close-granted":
- if (AppConstants.platform != "macosx" &&
- gDownloadManager.activeDownloadCount == 0) {
+#ifndef XP_MACOSX
+ if (gDownloadManager.activeDownloadCount == 0) {
setTimeout(gCloseDownloadManager, 0);
}
+#endif
break;
}
}
diff --git a/toolkit/mozapps/downloads/jar.mn b/toolkit/mozapps/downloads/jar.mn
index eb761b0d99..29a3d0ee24 100644
--- a/toolkit/mozapps/downloads/jar.mn
+++ b/toolkit/mozapps/downloads/jar.mn
@@ -6,7 +6,7 @@ toolkit.jar:
% content mozapps %content/mozapps/
* content/mozapps/downloads/unknownContentType.xul (content/unknownContentType.xul)
* content/mozapps/downloads/downloads.xul (content/downloads.xul)
- content/mozapps/downloads/downloads.js (content/downloads.js)
+* content/mozapps/downloads/downloads.js (content/downloads.js)
content/mozapps/downloads/DownloadProgressListener.js (content/DownloadProgressListener.js)
content/mozapps/downloads/downloads.css (content/downloads.css)
content/mozapps/downloads/download.xml (content/download.xml)
diff --git a/toolkit/mozapps/downloads/moz.build b/toolkit/mozapps/downloads/moz.build
index 1850ea7ded..9ad0814750 100644
--- a/toolkit/mozapps/downloads/moz.build
+++ b/toolkit/mozapps/downloads/moz.build
@@ -17,8 +17,9 @@ EXTRA_PP_COMPONENTS += [
EXTRA_JS_MODULES += [
'DownloadLastDir.jsm',
'DownloadPaths.jsm',
- 'DownloadTaskbarProgress.jsm',
'DownloadUtils.jsm',
]
+EXTRA_PP_JS_MODULES += ['DownloadTaskbarProgress.jsm']
+
JAR_MANIFESTS += ['jar.mn'] \ No newline at end of file
diff --git a/toolkit/mozapps/downloads/nsHelperAppDlg.js b/toolkit/mozapps/downloads/nsHelperAppDlg.js
index 27c0fede0b..243db1c2fd 100644
--- a/toolkit/mozapps/downloads/nsHelperAppDlg.js
+++ b/toolkit/mozapps/downloads/nsHelperAppDlg.js
@@ -4,7 +4,6 @@
const {utils: Cu, interfaces: Ci, classes: Cc, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EnableDelayHelper",
"resource://gre/modules/SharedPromptUtils.jsm");
@@ -408,22 +407,22 @@ nsUnknownContentTypeDialog.prototype = {
// is now caught properly in the caller of validateLeafName.
var createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
- if (AppConstants.platform == "win") {
- let ext;
- try {
- // We can fail here if there's no primary extension set
- ext = "." + this.mLauncher.MIMEInfo.primaryExtension;
- } catch (e) { }
-
- // Append a file extension if it's an executable that doesn't have one
- // but make sure we actually have an extension to add
- let leaf = createdFile.leafName;
- if (ext && leaf.slice(-ext.length) != ext && createdFile.isExecutable()) {
- createdFile.remove(false);
- aLocalFolder.leafName = leaf + ext;
- createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
- }
+#ifdef XP_WIN
+ let ext;
+ try {
+ // We can fail here if there's no primary extension set
+ ext = "." + this.mLauncher.MIMEInfo.primaryExtension;
+ } catch (e) { }
+
+ // Append a file extension if it's an executable that doesn't have one
+ // but make sure we actually have an extension to add
+ let leaf = createdFile.leafName;
+ if (ext && leaf.slice(-ext.length) != ext && createdFile.isExecutable()) {
+ createdFile.remove(false);
+ aLocalFolder.leafName = leaf + ext;
+ createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
}
+#endif
return createdFile;
},
@@ -639,22 +638,22 @@ nsUnknownContentTypeDialog.prototype = {
// Returns true if opening the default application makes sense.
openWithDefaultOK: function() {
- // The checking is different on Windows...
- if (AppConstants.platform == "win") {
- // Windows presents some special cases.
- // We need to prevent use of "system default" when the file is
- // executable (so the user doesn't launch nasty programs downloaded
- // from the web), and, enable use of "system default" if it isn't
- // executable (because we will prompt the user for the default app
- // in that case).
-
- // Default is Ok if the file isn't executable (and vice-versa).
- return !this.mLauncher.targetFileIsExecutable;
- }
+#ifdef XP_WIN
+ // Windows presents some special cases.
+ // We need to prevent use of "system default" when the file is
+ // executable (so the user doesn't launch nasty programs downloaded
+ // from the web), and, enable use of "system default" if it isn't
+ // executable (because we will prompt the user for the default app
+ // in that case).
+
+ // Default is Ok if the file isn't executable (and vice-versa).
+ return !this.mLauncher.targetFileIsExecutable;
+#else
// On other platforms, default is Ok if there is a default app.
// Note that nsIMIMEInfo providers need to ensure that this holds true
// on each platform.
return this.mLauncher.MIMEInfo.hasDefaultHandler;
+#endif
},
// Set "default" application description field.
@@ -675,10 +674,11 @@ nsUnknownContentTypeDialog.prototype = {
// getPath:
getPath: function (aFile) {
- if (AppConstants.platform == "macosx") {
- return aFile.leafName || aFile.path;
- }
+#ifdef XP_MACOSX
+ return aFile.leafName || aFile.path;
+#else
return aFile.path;
+#endif
},
// initAppAndSaveToDiskValues:
@@ -980,19 +980,20 @@ nsUnknownContentTypeDialog.prototype = {
// Retrieve the pretty description from the file
getFileDisplayName: function getFileDisplayName(file)
{
- if (AppConstants.platform == "win") {
- if (file instanceof Components.interfaces.nsILocalFileWin) {
- try {
- return file.getVersionInfoField("FileDescription");
- } catch (e) {}
- }
- } else if (AppConstants.platform == "macosx") {
- if (file instanceof Components.interfaces.nsILocalFileMac) {
- try {
- return file.bundleDisplayName;
- } catch (e) {}
- }
+#ifdef XP_WIN
+ if (file instanceof Components.interfaces.nsILocalFileWin) {
+ try {
+ return file.getVersionInfoField("FileDescription");
+ } catch (e) {}
+ }
+#elifdef XP_MACOSX
+ if (file instanceof Components.interfaces.nsILocalFileMac) {
+ try {
+ return file.bundleDisplayName;
+ } catch (e) {}
}
+#endif
+
return file.leafName;
},
@@ -1006,10 +1007,11 @@ nsUnknownContentTypeDialog.prototype = {
var otherHandler = this.dialogElement("otherHandler");
otherHandler.removeAttribute("hidden");
otherHandler.setAttribute("path", this.getPath(this.chosenApp.executable));
- if (AppConstants.platform == "win")
- otherHandler.label = this.getFileDisplayName(this.chosenApp.executable);
- else
- otherHandler.label = this.chosenApp.name;
+#ifdef XP_WIN
+ otherHandler.label = this.getFileDisplayName(this.chosenApp.executable);
+#else
+ otherHandler.label = this.chosenApp.name;
+#endif
this.dialogElement("openHandler").selectedIndex = 1;
this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler");
@@ -1025,50 +1027,49 @@ nsUnknownContentTypeDialog.prototype = {
},
// chooseApp: Open file picker and prompt user for application.
chooseApp: function() {
- if (AppConstants.platform == "win") {
- // Protect against the lack of an extension
- var fileExtension = "";
- try {
- fileExtension = this.mLauncher.MIMEInfo.primaryExtension;
- } catch(ex) {
- }
+#ifdef XP_WIN
+ // Protect against the lack of an extension
+ var fileExtension = "";
+ try {
+ fileExtension = this.mLauncher.MIMEInfo.primaryExtension;
+ } catch(ex) {
+ }
- // Try to use the pretty description of the type, if one is available.
- var typeString = this.mLauncher.MIMEInfo.description;
-
- if (!typeString) {
- // If there is none, use the extension to
- // identify the file, e.g. "ZIP file"
- if (fileExtension) {
- typeString =
- this.dialogElement("strings").
- getFormattedString("fileType", [fileExtension.toUpperCase()]);
- } else {
- // If we can't even do that, just give up and show the MIME type.
- typeString = this.mLauncher.MIMEInfo.MIMEType;
- }
+ // Try to use the pretty description of the type, if one is available.
+ var typeString = this.mLauncher.MIMEInfo.description;
+
+ if (!typeString) {
+ // If there is none, use the extension to
+ // identify the file, e.g. "ZIP file"
+ if (fileExtension) {
+ typeString =
+ this.dialogElement("strings").
+ getFormattedString("fileType", [fileExtension.toUpperCase()]);
+ } else {
+ // If we can't even do that, just give up and show the MIME type.
+ typeString = this.mLauncher.MIMEInfo.MIMEType;
}
+ }
- var params = {};
- params.title =
- this.dialogElement("strings").getString("chooseAppFilePickerTitle");
- params.description = typeString;
- params.filename = this.mLauncher.suggestedFileName;
- params.mimeInfo = this.mLauncher.MIMEInfo;
- params.handlerApp = null;
-
- this.mDialog.openDialog("chrome://global/content/appPicker.xul", null,
- "chrome,modal,centerscreen,titlebar,dialog=yes",
- params);
-
- if (params.handlerApp &&
- params.handlerApp.executable &&
- params.handlerApp.executable.isFile()) {
- // Remember the file they chose to run.
- this.chosenApp = params.handlerApp;
- }
+ var params = {};
+ params.title =
+ this.dialogElement("strings").getString("chooseAppFilePickerTitle");
+ params.description = typeString;
+ params.filename = this.mLauncher.suggestedFileName;
+ params.mimeInfo = this.mLauncher.MIMEInfo;
+ params.handlerApp = null;
+
+ this.mDialog.openDialog("chrome://global/content/appPicker.xul", null,
+ "chrome,modal,centerscreen,titlebar,dialog=yes",
+ params);
+
+ if (params.handlerApp &&
+ params.handlerApp.executable &&
+ params.handlerApp.executable.isFile()) {
+ // Remember the file they chose to run.
+ this.chosenApp = params.handlerApp;
}
- else {
+#else
#if MOZ_WIDGET_GTK == 3
var nsIApplicationChooser = Components.interfaces.nsIApplicationChooser;
var appChooser = Components.classes["@mozilla.org/applicationchooser;1"]
@@ -1103,6 +1104,7 @@ nsUnknownContentTypeDialog.prototype = {
this.chosenApp = localHandlerApp;
}
#endif // MOZ_WIDGET_GTK == 3
+#endif // XP_WIN
}
this.finishChooseApp();
},