Issue #65 - Remove AppConstants from toolkit/mozapps/downloads

This commit is contained in:
Matt A. Tobin 2020-02-06 06:32:11 -05:00 • committed by Roy Tam
commit f1210b0d9a
5 changed files with 141 additions and 138 deletions

View file

@ -16,7 +16,6 @@ const Cu = Components.utils;
const Cr = Components.results; const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Services", XPCOMUtils.defineLazyModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm"); "resource://gre/modules/Services.jsm");
@ -177,7 +176,7 @@ var DownloadTaskbarProgressUpdater =
*/ */
_setActiveWindow: function DTPU_setActiveWindow(aWindow, aIsDownloadWindow) _setActiveWindow: function DTPU_setActiveWindow(aWindow, aIsDownloadWindow)
{ {
if (AppConstants.platform == "win") { #ifdef XP_WIN
// Clear out the taskbar for the old active window. (If there was no active // Clear out the taskbar for the old active window. (If there was no active
// window, this is a no-op.) // window, this is a no-op.)
this._clearTaskbar(); this._clearTaskbar();
@ -203,7 +202,7 @@ var DownloadTaskbarProgressUpdater =
else { else {
this._activeTaskbarProgress = null; this._activeTaskbarProgress = null;
} }
} #endif
}, },
// / Current state displayed on the active window's taskbar item // / Current state displayed on the active window's taskbar item
@ -213,14 +212,15 @@ var DownloadTaskbarProgressUpdater =
_shouldSetState: function DTPU_shouldSetState() _shouldSetState: function DTPU_shouldSetState()
{ {
if (AppConstants.platform == "win") { #ifdef XP_WIN
// If the active window is not the download manager window, set the state // If the active window is not the download manager window, set the state
// only if it is normal or indeterminate. // only if it is normal or indeterminate.
return this._activeWindowIsDownloadWindow || return this._activeWindowIsDownloadWindow ||
(this._taskbarState == Ci.nsITaskbarProgress.STATE_NORMAL || (this._taskbarState == Ci.nsITaskbarProgress.STATE_NORMAL ||
this._taskbarState == Ci.nsITaskbarProgress.STATE_INDETERMINATE); this._taskbarState == Ci.nsITaskbarProgress.STATE_INDETERMINATE);
} #else
return true; return true;
#endif
}, },
/** /**

View file

@ -19,7 +19,6 @@ var Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/DownloadUtils.jsm"); Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm"); "resource://gre/modules/PluralForm.jsm");
@ -253,7 +252,7 @@ function openDownload(aDownload)
dontAsk = !pref.getBoolPref(PREF_BDM_CONFIRMOPENEXE); dontAsk = !pref.getBoolPref(PREF_BDM_CONFIRMOPENEXE);
} catch (e) { } } catch (e) { }
if (AppConstants.platform == "win") { #ifdef XP_WIN
// On Vista and above, we rely on native security prompting for // On Vista and above, we rely on native security prompting for
// downloaded content unless it's disabled. // downloaded content unless it's disabled.
try { try {
@ -264,7 +263,7 @@ function openDownload(aDownload)
dontAsk = true; dontAsk = true;
} }
} catch (ex) { } } catch (ex) { }
} #endif
if (!dontAsk) { if (!dontAsk) {
var strings = document.getElementById("downloadStrings"); var strings = document.getElementById("downloadStrings");
@ -478,10 +477,11 @@ var gDownloadObserver = {
removeFromView(dl); removeFromView(dl);
break; break;
case "browser-lastwindow-close-granted": case "browser-lastwindow-close-granted":
if (AppConstants.platform != "macosx" && #ifndef XP_MACOSX
gDownloadManager.activeDownloadCount == 0) { if (gDownloadManager.activeDownloadCount == 0) {
setTimeout(gCloseDownloadManager, 0); setTimeout(gCloseDownloadManager, 0);
} }
#endif
break; break;
} }
} }

View file

@ -6,7 +6,7 @@ toolkit.jar:
% content mozapps %content/mozapps/ % content mozapps %content/mozapps/
* content/mozapps/downloads/unknownContentType.xul (content/unknownContentType.xul) * content/mozapps/downloads/unknownContentType.xul (content/unknownContentType.xul)
* content/mozapps/downloads/downloads.xul (content/downloads.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/DownloadProgressListener.js (content/DownloadProgressListener.js)
content/mozapps/downloads/downloads.css (content/downloads.css) content/mozapps/downloads/downloads.css (content/downloads.css)
content/mozapps/downloads/download.xml (content/download.xml) content/mozapps/downloads/download.xml (content/download.xml)

View file

@ -17,8 +17,9 @@ EXTRA_PP_COMPONENTS += [
EXTRA_JS_MODULES += [ EXTRA_JS_MODULES += [
'DownloadLastDir.jsm', 'DownloadLastDir.jsm',
'DownloadPaths.jsm', 'DownloadPaths.jsm',
'DownloadTaskbarProgress.jsm',
'DownloadUtils.jsm', 'DownloadUtils.jsm',
] ]
EXTRA_PP_JS_MODULES += ['DownloadTaskbarProgress.jsm']
JAR_MANIFESTS += ['jar.mn'] JAR_MANIFESTS += ['jar.mn']

View file

@ -4,7 +4,6 @@
const {utils: Cu, interfaces: Ci, classes: Cc, results: Cr} = Components; const {utils: Cu, interfaces: Ci, classes: Cc, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EnableDelayHelper", XPCOMUtils.defineLazyModuleGetter(this, "EnableDelayHelper",
"resource://gre/modules/SharedPromptUtils.jsm"); "resource://gre/modules/SharedPromptUtils.jsm");
@ -408,7 +407,7 @@ nsUnknownContentTypeDialog.prototype = {
// is now caught properly in the caller of validateLeafName. // is now caught properly in the caller of validateLeafName.
var createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder); var createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
if (AppConstants.platform == "win") { #ifdef XP_WIN
let ext; let ext;
try { try {
// We can fail here if there's no primary extension set // We can fail here if there's no primary extension set
@ -423,7 +422,7 @@ nsUnknownContentTypeDialog.prototype = {
aLocalFolder.leafName = leaf + ext; aLocalFolder.leafName = leaf + ext;
createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder); createdFile = DownloadPaths.createNiceUniqueFile(aLocalFolder);
} }
} #endif
return createdFile; return createdFile;
}, },
@ -639,8 +638,7 @@ nsUnknownContentTypeDialog.prototype = {
// Returns true if opening the default application makes sense. // Returns true if opening the default application makes sense.
openWithDefaultOK: function() { openWithDefaultOK: function() {
// The checking is different on Windows... #ifdef XP_WIN
if (AppConstants.platform == "win") {
// Windows presents some special cases. // Windows presents some special cases.
// We need to prevent use of "system default" when the file is // We need to prevent use of "system default" when the file is
// executable (so the user doesn't launch nasty programs downloaded // executable (so the user doesn't launch nasty programs downloaded
@ -650,11 +648,12 @@ nsUnknownContentTypeDialog.prototype = {
// Default is Ok if the file isn't executable (and vice-versa). // Default is Ok if the file isn't executable (and vice-versa).
return !this.mLauncher.targetFileIsExecutable; return !this.mLauncher.targetFileIsExecutable;
} #else
// On other platforms, default is Ok if there is a default app. // On other platforms, default is Ok if there is a default app.
// Note that nsIMIMEInfo providers need to ensure that this holds true // Note that nsIMIMEInfo providers need to ensure that this holds true
// on each platform. // on each platform.
return this.mLauncher.MIMEInfo.hasDefaultHandler; return this.mLauncher.MIMEInfo.hasDefaultHandler;
#endif
}, },
// Set "default" application description field. // Set "default" application description field.
@ -675,10 +674,11 @@ nsUnknownContentTypeDialog.prototype = {
// getPath: // getPath:
getPath: function (aFile) { getPath: function (aFile) {
if (AppConstants.platform == "macosx") { #ifdef XP_MACOSX
return aFile.leafName || aFile.path; return aFile.leafName || aFile.path;
} #else
return aFile.path; return aFile.path;
#endif
}, },
// initAppAndSaveToDiskValues: // initAppAndSaveToDiskValues:
@ -980,19 +980,20 @@ nsUnknownContentTypeDialog.prototype = {
// Retrieve the pretty description from the file // Retrieve the pretty description from the file
getFileDisplayName: function getFileDisplayName(file) getFileDisplayName: function getFileDisplayName(file)
{ {
if (AppConstants.platform == "win") { #ifdef XP_WIN
if (file instanceof Components.interfaces.nsILocalFileWin) { if (file instanceof Components.interfaces.nsILocalFileWin) {
try { try {
return file.getVersionInfoField("FileDescription"); return file.getVersionInfoField("FileDescription");
} catch (e) {} } catch (e) {}
} }
} else if (AppConstants.platform == "macosx") { #elifdef XP_MACOSX
if (file instanceof Components.interfaces.nsILocalFileMac) { if (file instanceof Components.interfaces.nsILocalFileMac) {
try { try {
return file.bundleDisplayName; return file.bundleDisplayName;
} catch (e) {} } catch (e) {}
} }
} #endif
return file.leafName; return file.leafName;
}, },
@ -1006,10 +1007,11 @@ nsUnknownContentTypeDialog.prototype = {
var otherHandler = this.dialogElement("otherHandler"); var otherHandler = this.dialogElement("otherHandler");
otherHandler.removeAttribute("hidden"); otherHandler.removeAttribute("hidden");
otherHandler.setAttribute("path", this.getPath(this.chosenApp.executable)); otherHandler.setAttribute("path", this.getPath(this.chosenApp.executable));
if (AppConstants.platform == "win") #ifdef XP_WIN
otherHandler.label = this.getFileDisplayName(this.chosenApp.executable); otherHandler.label = this.getFileDisplayName(this.chosenApp.executable);
else #else
otherHandler.label = this.chosenApp.name; otherHandler.label = this.chosenApp.name;
#endif
this.dialogElement("openHandler").selectedIndex = 1; this.dialogElement("openHandler").selectedIndex = 1;
this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler"); this.dialogElement("openHandler").setAttribute("lastSelectedItemID", "otherHandler");
@ -1025,7 +1027,7 @@ nsUnknownContentTypeDialog.prototype = {
}, },
// chooseApp: Open file picker and prompt user for application. // chooseApp: Open file picker and prompt user for application.
chooseApp: function() { chooseApp: function() {
if (AppConstants.platform == "win") { #ifdef XP_WIN
// Protect against the lack of an extension // Protect against the lack of an extension
var fileExtension = ""; var fileExtension = "";
try { try {
@ -1067,8 +1069,7 @@ nsUnknownContentTypeDialog.prototype = {
// Remember the file they chose to run. // Remember the file they chose to run.
this.chosenApp = params.handlerApp; this.chosenApp = params.handlerApp;
} }
} #else
else {
#if MOZ_WIDGET_GTK == 3 #if MOZ_WIDGET_GTK == 3
var nsIApplicationChooser = Components.interfaces.nsIApplicationChooser; var nsIApplicationChooser = Components.interfaces.nsIApplicationChooser;
var appChooser = Components.classes["@mozilla.org/applicationchooser;1"] var appChooser = Components.classes["@mozilla.org/applicationchooser;1"]
@ -1103,6 +1104,7 @@ nsUnknownContentTypeDialog.prototype = {
this.chosenApp = localHandlerApp; this.chosenApp = localHandlerApp;
} }
#endif // MOZ_WIDGET_GTK == 3 #endif // MOZ_WIDGET_GTK == 3
#endif // XP_WIN
} }
this.finishChooseApp(); this.finishChooseApp();
}, },