Backed out changeset dd417504346b (bug 1114594) for crashes.

CLOSED TREE
This commit is contained in:
Ryan VanderMeulen 2015-01-27 15:17:39 -05:00
parent 41b0c63db4
commit 9f10340a50
10 changed files with 92 additions and 9 deletions

View File

@ -33,6 +33,14 @@ HelperAppLauncherDialog.prototype = {
aLauncher.saveToDisk(null, false);
},
promptForSaveToFile: function(aLauncher,
aContext,
aDefaultFile,
aSuggestedFileExt,
aForcePrompt) {
throw Cr.NS_ERROR_NOT_AVAILABLE;
},
promptForSaveToFileAsync: function(aLauncher,
aContext,
aDefaultFile,

View File

@ -138,6 +138,10 @@ HelperAppLauncherDialog.prototype = {
messageContainer.appendChild(fragment);
},
promptForSaveToFile: function hald_promptForSaveToFile(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) {
throw new Components.Exception("Async version must be used", Cr.NS_ERROR_NOT_AVAILABLE);
},
promptForSaveToFileAsync: function hald_promptForSaveToFileAsync(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) {
let file = null;
let prefs = Services.prefs;

View File

@ -236,6 +236,11 @@ HelperAppLauncherDialog.prototype = {
Services.prefs.clearUserPref(this._getPrefName(mime));
},
promptForSaveToFile: function () {
throw new Components.Exception("Async version must be used",
Cr.NS_ERROR_NOT_AVAILABLE);
},
promptForSaveToFileAsync: function (aLauncher, aContext, aDefaultFile,
aSuggestedFileExt, aForcePrompt) {
Task.spawn(function* () {

View File

@ -15,7 +15,9 @@ HelperAppDlg.prototype = {
show: function (launcher, ctx, reason) {
launcher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToDisk;
launcher.launchWithApplication(null, false);
}
},
promptForSaveToFile: function (launcher, ctx, defaultFile, suggestedExtension, forcePrompt) { }
}

View File

@ -793,6 +793,15 @@ add_task(function test_common_initialize()
createInstance: function (aOuter, aIid) {
return {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]),
promptForSaveToFile: function (aLauncher, aWindowContext,
aDefaultFileName,
aSuggestedFileExtension,
aForcePrompt)
{
throw new Components.Exception(
"Synchronous promptForSaveToFile not implemented.",
Cr.NS_ERROR_NOT_AVAILABLE);
},
promptForSaveToFileAsync: function (aLauncher, aWindowContext,
aDefaultFileName,
aSuggestedFileExtension,

View File

@ -195,6 +195,22 @@ nsUnknownContentTypeDialog.prototype = {
bundle.GetStringFromName("badPermissions"));
},
// promptForSaveToFile: Display file picker dialog and return selected file.
// This is called by the External Helper App Service
// after the ucth dialog calls |saveToDisk| with a null
// target filename (no target, therefore user must pick).
//
// Alternatively, if the user has selected to have all
// files download to a specific location, return that
// location and don't ask via the dialog.
//
// Note - this function is called without a dialog, so it cannot access any part
// of the dialog XUL as other functions on this object do.
promptForSaveToFile: function(aLauncher, aContext, aDefaultFile, aSuggestedFileExtension, aForcePrompt) {
throw new Components.Exception("Async version must be used", Components.results.NS_ERROR_NOT_AVAILABLE);
},
promptForSaveToFileAsync: function(aLauncher, aContext, aDefaultFile, aSuggestedFileExtension, aForcePrompt) {
var result = null;

View File

@ -2237,16 +2237,24 @@ void nsExternalAppHandler::RequestSaveDestination(const nsAFlatString &aDefaultF
// picker is up would cause Cancel() to be called, and the dialog would be
// released, which would release this object too, which would crash.
// See Bug 249143
nsIFile* fileToUse;
nsRefPtr<nsExternalAppHandler> kungFuDeathGrip(this);
nsCOMPtr<nsIHelperAppLauncherDialog> dlg(mDialog);
rv = mDialog->PromptForSaveToFile(this,
GetDialogParent(),
aDefaultFile.get(),
aFileExtension.get(),
mForceSave, &fileToUse);
rv = mDialog->PromptForSaveToFileAsync(this,
GetDialogParent(),
aDefaultFile.get(),
aFileExtension.get(),
mForceSave);
if (NS_FAILED(rv)) {
Cancel(NS_BINDING_ABORTED);
if (rv == NS_ERROR_NOT_AVAILABLE) {
// we need to use the async version -> nsIHelperAppLauncherDialog.promptForSaveToFileAsync.
rv = mDialog->PromptForSaveToFileAsync(this,
GetDialogParent(),
aDefaultFile.get(),
aFileExtension.get(),
mForceSave);
} else {
SaveDestinationAvailable(rv == NS_OK ? fileToUse : nullptr);
}
}

View File

@ -57,6 +57,32 @@ interface nsIHelperAppLauncherDialog : nsISupports {
in nsISupports aWindowContext,
in unsigned long aReason);
/**
* Invoke a save-to-file dialog instead of the full fledged helper app dialog.
* Returns the a nsIFile for the file name/location selected.
*
* @param aLauncher
* A nsIHelperAppLauncher to be invoked when a file is selected.
* @param aWindowContext
* Window associated with action.
* @param aDefaultFileName
* Default file name to provide (can be null)
* @param aSuggestedFileExtension
* Sugested file extension
* @param aForcePrompt
* Set to true to force prompting the user for thet file
* name/location, otherwise perferences may control if the user is
* prompted.
*
* @throws NS_ERROR_NOT_AVAILABLE if the async version of this function
* should be used.
*/
nsIFile promptForSaveToFile(in nsIHelperAppLauncher aLauncher,
in nsISupports aWindowContext,
in wstring aDefaultFileName,
in wstring aSuggestedFileExtension,
in boolean aForcePrompt);
/**
* Async invoke a save-to-file dialog instead of the full fledged helper app
* dialog. When the file is chosen (or the dialog is closed), the callback

View File

@ -84,6 +84,9 @@ function load() {
"The filename should be correctly sanitized");
gCallback();
},
promptForSaveToFile: function(aLauncher, aWindowContext, aDefaultFileName, aSuggestedFileExtension, aForcePrompt) {
return null;
},
QueryInterface: function(aIID) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (aIID.equals(SpecialPowers.Ci.nsISupports) ||

View File

@ -61,7 +61,9 @@ HelperAppDlg.prototype = {
show: function (launcher, ctx, reason, usePrivateUI) {
launcher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToFile;
launcher.launchWithApplication(null, false);
}
},
promptForSaveToFile: function (launcher, ctx, defaultFile, suggestedExtension, forcePrompt) { }
}
// Stolen from XPCOMUtils, since this handy function is not public there