diff --git a/toolkit/components/viewsource/content/viewSourceUtils.js b/toolkit/components/viewsource/content/viewSourceUtils.js index eb2c1fef2844..709f0693bb03 100644 --- a/toolkit/components/viewsource/content/viewSourceUtils.js +++ b/toolkit/components/viewsource/content/viewSourceUtils.js @@ -119,10 +119,28 @@ var gViewSourceUtils = { webBrowserPersist.progressListener = this.viewSourceProgressListener; webBrowserPersist.saveURI(uri, null, null, null, null, file); - // register the file to be deleted on app exit - Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] - .getService(Components.interfaces.nsPIExternalAppLauncher) - .deleteTemporaryFileOnExit(file); + let fromPrivateWindow = false; + if (aDocument) { + try { + fromPrivateWindow = + aDocument.defaultView + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIWebNavigation) + .QueryInterface(Components.interfaces.nsILoadContext) + .usePrivateBrowsing; + } catch (e) { + } + } + + let helperService = Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] + .getService(Components.interfaces.nsPIExternalAppLauncher); + if (fromPrivateWindow) { + // register the file to be deleted when possible + helperService.deleteTemporaryPrivateFileWhenPossible(file); + } else { + // register the file to be deleted on app exit + helperService.deleteTemporaryFileOnExit(file); + } } else { // we'll use nsIWebPageDescriptor to get the source because it may // not have to refetch the file from the server @@ -264,10 +282,22 @@ var gViewSourceUtils = { coStream.close(); foStream.close(); - // register the file to be deleted on app exit - Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] - .getService(Components.interfaces.nsPIExternalAppLauncher) - .deleteTemporaryFileOnExit(this.file); + let fromPrivateWindow = + this.data.doc.defaultView + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIWebNavigation) + .QueryInterface(Components.interfaces.nsILoadContext) + .usePrivateBrowsing; + + let helperService = Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] + .getService(Components.interfaces.nsPIExternalAppLauncher); + if (fromPrivateWindow) { + // register the file to be deleted when possible + helperService.deleteTemporaryPrivateFileWhenPossible(this.file); + } else { + // register the file to be deleted on app exit + helperService.deleteTemporaryFileOnExit(this.file); + } } var editorArgs = gViewSourceUtils.buildEditorArgs(this.file.path,