Fix .9.8 bugs:
115180 - saving a complete page on top of an existing complete page messes up 116167 - "Save Image" uses POST method 116445 - gzip files expanded when downloaded via "save link as" 115181 - saving a file sometimes results in an unpopulated progress dialog that does not go away 42441 - Save as Plain Text 115148 - save as dialog does not remember last directory used 115440 - File/Save Page does not work for PDF files 116263 - "File Type" selection in Save Page dialog is not remembered 115395 - Save Page as full page mpg does not work 115210 - Save Page as for plain text is not intelligent 115087 - Doing save page on an image Document should not save image document HTML Nature of fixes described here: http://bugzilla.mozilla.org/show_bug.cgi?id=120174 r=law, sr=hewitt git-svn-id: svn://10.0.0.236/trunk@112294 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
5f33a51792
commit
28f877330a
@ -33,6 +33,7 @@ var dialog;
|
||||
var helperAppLoader;
|
||||
var webBrowserPersist;
|
||||
var persistArgs;
|
||||
const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
|
||||
|
||||
// random global variables...
|
||||
var completed = false;
|
||||
@ -79,7 +80,7 @@ var progressListener = {
|
||||
onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
|
||||
{
|
||||
|
||||
if (!gRestartChecked)
|
||||
if (!gRestartChecked)
|
||||
{
|
||||
gRestartChecked = true;
|
||||
try
|
||||
@ -302,9 +303,7 @@ function loadDialog()
|
||||
sourceUrl = persistArgs.source;
|
||||
}
|
||||
catch (e) {
|
||||
// must be an nsIFile
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
|
||||
sourceUrl = { spec: ioService.getURLSpecFromFile(persistArgs.source) };
|
||||
sourceUrl = { spec: persistArgs.source.URL };
|
||||
}
|
||||
|
||||
// When saving web pages, we don't need to do anything special to receive the time
|
||||
@ -342,6 +341,7 @@ function onLoad() {
|
||||
}
|
||||
catch (e) {
|
||||
webBrowserPersist = window.arguments[0].QueryInterface( Components.interfaces.nsIWebBrowserPersist );
|
||||
setTimeout("checkPersistComplete()", 100);
|
||||
}
|
||||
|
||||
if ( !helperAppLoader && !webBrowserPersist ) {
|
||||
@ -382,6 +382,14 @@ function onLoad() {
|
||||
|
||||
targetFile = persistArgs.target;
|
||||
|
||||
// If the code reaches this point, the user has agreed to replace existing files in the
|
||||
// file picker.
|
||||
const flags = nsIWBP.PERSIST_FLAGS_NO_CONVERSION | nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
|
||||
if (persistArgs.bypassCache)
|
||||
webBrowserPersist.persistFlags |= nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
|
||||
else
|
||||
webBrowserPersist.persistFlags |= nsIWBP.PERSIST_FLAGS_FROM_CACHE;
|
||||
|
||||
try {
|
||||
var uri = persistArgs.source.QueryInterface(Components.interfaces.nsIURI);
|
||||
webBrowserPersist.saveURI(uri, persistArgs.postData, targetFile);
|
||||
@ -389,23 +397,36 @@ function onLoad() {
|
||||
catch (e) {
|
||||
// Saving a Document, not a URI:
|
||||
|
||||
// Create the local directory into which to save associated files.
|
||||
const lfContractID = "@mozilla.org/file/local;1";
|
||||
const lfIID = Components.interfaces.nsILocalFile;
|
||||
var filesFolder = Components .classes[lfContractID].createInstance(lfIID);
|
||||
filesFolder.initWithUnicodePath(persistArgs.target.unicodePath);
|
||||
|
||||
var nameWithoutExtension = filesFolder.leafName;
|
||||
nameWithoutExtension = nameWithoutExtension.substring(0, nameWithoutExtension.lastIndexOf("."));
|
||||
var filesFolderLeafName = getString("filesFolder");
|
||||
filesFolderLeafName = filesFolderLeafName.replace(/\^BASE\^/, nameWithoutExtension);
|
||||
var filesFolder = null;
|
||||
if (persistArgs.contentType != "text/plain") {
|
||||
// Create the local directory into which to save associated files.
|
||||
const lfContractID = "@mozilla.org/file/local;1";
|
||||
const lfIID = Components.interfaces.nsILocalFile;
|
||||
filesFolder = Components .classes[lfContractID].createInstance(lfIID);
|
||||
filesFolder.initWithUnicodePath(persistArgs.target.unicodePath);
|
||||
|
||||
var nameWithoutExtension = filesFolder.leafName;
|
||||
nameWithoutExtension = nameWithoutExtension.substring(0, nameWithoutExtension.lastIndexOf("."));
|
||||
var filesFolderLeafName = getString("filesFolder");
|
||||
filesFolderLeafName = filesFolderLeafName.replace(/\^BASE\^/, nameWithoutExtension);
|
||||
|
||||
filesFolder.leafName = filesFolderLeafName;
|
||||
filesFolder.leafName = filesFolderLeafName;
|
||||
|
||||
if (!filesFolder.exists())
|
||||
filesFolder.create(lfIID.DIRECTORY_TYPE, 0755);
|
||||
}
|
||||
|
||||
var encodingFlags = 0;
|
||||
if (persistArgs.contentType == "text/plain") {
|
||||
encodingFlags |= nsIWBP.ENCODE_FLAGS_FORMATTED;
|
||||
encodingFlags |= nsIWBP.ENCODE_FLAGS_ABSOLUTE_LINKS;
|
||||
encodingFlags |= nsIWBP.ENCODE_FLAGS_NOFRAMES_CONTENT;
|
||||
}
|
||||
|
||||
if (!filesFolder.exists())
|
||||
filesFolder.create(lfIID.DIRECTORY_TYPE, 0755);
|
||||
const kWrapColumn = 80;
|
||||
|
||||
webBrowserPersist.saveDocument(persistArgs.source, targetFile, filesFolder, null, 0, 0);
|
||||
webBrowserPersist.saveDocument(persistArgs.source, targetFile, filesFolder,
|
||||
persistArgs.contentType, encodingFlags, kWrapColumn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,3 +579,13 @@ function doPauseButton() {
|
||||
dialog.request.suspend()
|
||||
}
|
||||
}
|
||||
|
||||
function checkPersistComplete()
|
||||
{
|
||||
const nsIWebBrowserPersist = Components.interfaces.nsIWebBrowserPersist;
|
||||
if (webBrowserPersist.currentState == nsIWebBrowserPersist.PERSIST_STATE_FINISHED) {
|
||||
dump("*** all done\n");
|
||||
processEndOfDownload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -141,22 +141,30 @@ function findParentNode(node, parentNode)
|
||||
// - A linked document using Save Link As...
|
||||
// - A linked document using shift-click Save Link As...
|
||||
//
|
||||
function saveURL(aURL, aFileName, aFilePickerTitleKey)
|
||||
function saveURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache)
|
||||
{
|
||||
saveInternal(aURL, null, aFileName, aFilePickerTitleKey);
|
||||
saveInternal(aURL, null, aFileName, aFilePickerTitleKey, aShouldBypassCache);
|
||||
}
|
||||
|
||||
function saveDocument(aDocument)
|
||||
{
|
||||
saveInternal(aDocument.location.href, aDocument);
|
||||
// In both cases here, we want to use cached data because the
|
||||
// document is currently visible.
|
||||
if (aDocument)
|
||||
saveInternal(aDocument.location.href, aDocument, false);
|
||||
else
|
||||
saveInternal(_content.location.href, null, false);
|
||||
}
|
||||
|
||||
function saveInternal(aURL, aDocument, aFileName, aFilePickerTitleKey)
|
||||
function saveInternal(aURL, aDocument,
|
||||
aFileName, aFilePickerTitleKey,
|
||||
aShouldBypassCache)
|
||||
{
|
||||
var data = {
|
||||
fileName: aFileName,
|
||||
filePickerTitle: aFilePickerTitleKey,
|
||||
document: aDocument
|
||||
document: aDocument,
|
||||
bypassCache: aShouldBypassCache
|
||||
};
|
||||
var sniffer = new nsHeaderSniffer(aURL, foundHeaderInfo, data);
|
||||
}
|
||||
@ -171,11 +179,30 @@ function foundHeaderInfo(aSniffer, aData)
|
||||
fp.init(window, bundle.GetStringFromName(titleKey),
|
||||
Components.interfaces.nsIFilePicker.modeSave);
|
||||
|
||||
var modeComplete = aData.document != null &&
|
||||
(contentType == "text/html" || contentType == "text/xml");
|
||||
appendFiltersForContentType(fp, aSniffer.contentType,
|
||||
modeComplete ? MODE_COMPLETE : MODE_FILEONLY);
|
||||
|
||||
var isDocument = aData.document != null && isDocumentType(contentType);
|
||||
appendFiltersForContentType(fp, aSniffer.contentType,
|
||||
isDocument ? MODE_COMPLETE : MODE_FILEONLY);
|
||||
|
||||
const prefSvcContractID = "@mozilla.org/preferences-service;1";
|
||||
const prefSvcIID = Components.interfaces.nsIPrefService;
|
||||
var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID).getBranch("browser.download");
|
||||
|
||||
const nsILocalFile = Components.interfaces.nsILocalFile;
|
||||
try {
|
||||
fp.displayDirectory = prefs.getComplexValue("dir", nsILocalFile);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
|
||||
if (isDocument) {
|
||||
try {
|
||||
fp.filterIndex = prefs.getIntPref("save_converter_index");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Determine what the 'default' string to display in the File Picker dialog
|
||||
// should be.
|
||||
var defaultFileName = getDefaultFileName(aData.fileName,
|
||||
@ -186,22 +213,25 @@ function foundHeaderInfo(aSniffer, aData)
|
||||
if (fp.show() == Components.interfaces.nsIFilePicker.returnCancel || !fp.file)
|
||||
return;
|
||||
|
||||
if (isDocument)
|
||||
prefs.setIntPref("save_converter_index", fp.filterIndex);
|
||||
var directory = fp.file.parent.QueryInterface(nsILocalFile);
|
||||
prefs.setComplexValue("dir", nsILocalFile, directory);
|
||||
|
||||
fp.file.leafName = validateFileName(fp.file.leafName);
|
||||
fp.file.leafName = getNormalizedLeafName(fp.file.leafName, contentType);
|
||||
|
||||
// XXX turn this on when Adam lands the ability to save as a specific content
|
||||
// type
|
||||
//var contentType = fp.filterIndex == 2 ? "text/unicode" : "text/html";
|
||||
var source = (aData.document && contentType == "text/html" &&
|
||||
fp.filterIndex == 0) ? aData.document : aSniffer.uri;
|
||||
// If we're saving a document, and are saving either in complete mode or
|
||||
// as converted text, pass the document to the web browser persist component.
|
||||
// If we're just saving the HTML (second option in the list), send only the URI.
|
||||
var source = (isDocument && fp.filterIndex != 1) ? aData.document : aSniffer.uri;
|
||||
|
||||
var persistArgs = {
|
||||
source : source,
|
||||
// XXX turn this on when Adam lands the ability to save as a specific content
|
||||
// type
|
||||
// contentType : fp.filterIndex == 2 ? "text/unicode" : "text/html";
|
||||
target : fp.file,
|
||||
postData : getPostData()
|
||||
source : source,
|
||||
contentType : (isDocument && fp.filterIndex == 2) ? "text/plain" : contentType,
|
||||
target : fp.file,
|
||||
postData : isDocument ? getPostData() : null,
|
||||
bypassCache : aData.bypassCache
|
||||
};
|
||||
|
||||
openDialog("chrome://global/content/nsProgressDlg.xul", "",
|
||||
@ -291,8 +321,7 @@ function appendFiltersForContentType(aFilePicker, aContentType, aSaveMode)
|
||||
if (aSaveMode == MODE_COMPLETE)
|
||||
aFilePicker.appendFilter(bundle.GetStringFromName("WebPageCompleteFilter"), "*.htm; *.html");
|
||||
aFilePicker.appendFilter(bundle.GetStringFromName("WebPageHTMLOnlyFilter"), "*.htm; *.html");
|
||||
// XXX waiting for fix for 110135 to land
|
||||
// aFilePicker.appendFilter(bundle.GetStringFromName("TextOnlyFilter"), "*.txt");
|
||||
aFilePicker.appendFilter(bundle.GetStringFromName("TextOnlyFilter"), "*.txt");
|
||||
break;
|
||||
default:
|
||||
var mimeInfo = getMIMEInfoForType(aContentType);
|
||||
@ -385,19 +414,19 @@ function getMIMEInfoForType(aMIMEType)
|
||||
|
||||
function getDefaultFileName(aDefaultFileName, aNameFromHeaders, aDocumentURI, aDocument)
|
||||
{
|
||||
if (aDefaultFileName)
|
||||
return validateFileName(aDefaultFileName); // 1) Use the caller-provided name, if any
|
||||
|
||||
if (aNameFromHeaders)
|
||||
return validateFileName(aNameFromHeaders); // 2) Use the name suggested by the HTTP headers
|
||||
|
||||
if (aDocument && aDocument.title != "")
|
||||
return validateFileName(aDocument.title) // 3) Use the document title
|
||||
return validateFileName(aNameFromHeaders); // 1) Use the name suggested by the HTTP headers
|
||||
|
||||
var url = aDocumentURI.QueryInterface(Components.interfaces.nsIURL);
|
||||
if (url.fileName != "")
|
||||
return url.fileName; // 4) Use the actual file name, if present
|
||||
return url.fileName; // 2) Use the actual file name, if present
|
||||
|
||||
if (aDocument && aDocument.title != "")
|
||||
return validateFileName(aDocument.title) // 3) Use the document title
|
||||
|
||||
if (aDefaultFileName)
|
||||
return validateFileName(aDefaultFileName); // 4) Use the caller-provided name, if any
|
||||
|
||||
return aDocumentURI.host; // 5) Use the host.
|
||||
}
|
||||
|
||||
@ -449,3 +478,14 @@ function getNormalizedLeafName(aFile, aContentType)
|
||||
return leafName;
|
||||
}
|
||||
|
||||
function isDocumentType(aContentType)
|
||||
{
|
||||
switch (aContentType) {
|
||||
case "text/html":
|
||||
case "text/xml":
|
||||
case "application/xhtml+xml":
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -471,11 +471,11 @@ nsContextMenu.prototype = {
|
||||
},
|
||||
// Save URL of clicked-on link.
|
||||
saveLink : function () {
|
||||
saveURL( this.linkURL(), this.linkText() );
|
||||
saveURL( this.linkURL(), this.linkText(), null, true );
|
||||
},
|
||||
// Save URL of clicked-on image.
|
||||
saveImage : function () {
|
||||
saveURL( this.imageURL, null, "SaveImageTitle" );
|
||||
saveURL( this.imageURL, null, "SaveImageTitle", false );
|
||||
},
|
||||
// Generate email address and put it on clipboard.
|
||||
copyEmail : function () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user