From 9095136a9ea233cd541c30a83a6db127fc6d6235 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 26 Apr 2004 19:27:51 +0000 Subject: Fix encoding of saved content; fixes bug #141050. 2004-04-26 Marco Pesenti Gritti * embed/mozilla/MozDownload.cpp: Fix encoding of saved content; fixes bug #141050. --- embed/mozilla/MozDownload.cpp | 57 +++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'embed/mozilla/MozDownload.cpp') diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index e548dd86b..722e7d8a5 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -465,7 +465,7 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI EmbedPersistFlags ephy_flags; ephy_flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (embedPersist)); - PRBool isHTML = (domDocument && contentType && + PRBool isHTML = (contentType && (strcmp (contentType, "text/html") == 0 || strcmp (contentType, "text/xml") == 0 || strcmp (contentType, "application/xhtml+xml") == 0)); @@ -486,7 +486,7 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES; - if (!isHTML) + if (!domDocument && !isHTML && !(ephy_flags & EMBED_PERSIST_COPY_PAGE)) { flags |= nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION; } @@ -496,51 +496,40 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI } webPersist->SetPersistFlags(flags); - if (!isHTML || ephy_flags & EMBED_PERSIST_COPY_PAGE) + if (!domDocument || !isHTML || ephy_flags & EMBED_PERSIST_COPY_PAGE) { rv = webPersist->SaveURI (sourceURI, aCacheKey, nsnull, postData, nsnull, inDestFile); } else { - if (!domDocument) return rv; /* should never happen */ - PRInt32 encodingFlags = 0; nsCOMPtr filesFolder; - if (!contentType || strcmp (contentType, "text/plain") != 0) - { - /** - * Construct a directory path to hold the associated files; mozilla - * will create the directory as needed. - */ - - filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); - nsAutoString unicodePath; - inDestFile->GetPath(unicodePath); - filesFolder->InitWithPath(unicodePath); - - nsAutoString leafName; - filesFolder->GetLeafName(leafName); - nsAutoString nameMinusExt(leafName); - PRInt32 index = nameMinusExt.RFind("."); - if (index >= 0) - { - nameMinusExt.Left(nameMinusExt, index); - } + /** + * Construct a directory path to hold the associated files; mozilla + * will create the directory as needed. + */ - nameMinusExt += NS_LITERAL_STRING (" "); - nameMinusExt += NS_ConvertUTF8toUTF16 (_("Files")); - - filesFolder->SetLeafName(nameMinusExt); - } - else + filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); + nsAutoString unicodePath; + inDestFile->GetPath(unicodePath); + filesFolder->InitWithPath(unicodePath); + + nsAutoString leafName; + filesFolder->GetLeafName(leafName); + nsAutoString nameMinusExt(leafName); + PRInt32 index = nameMinusExt.RFind("."); + if (index >= 0) { - encodingFlags |= nsIWebBrowserPersist::ENCODE_FLAGS_FORMATTED | - nsIWebBrowserPersist::ENCODE_FLAGS_ABSOLUTE_LINKS | - nsIWebBrowserPersist::ENCODE_FLAGS_NOFRAMES_CONTENT; + nameMinusExt.Left(nameMinusExt, index); } + nameMinusExt += NS_LITERAL_STRING (" "); + nameMinusExt += NS_ConvertUTF8toUTF16 (_("Files")); + + filesFolder->SetLeafName(nameMinusExt); + rv = webPersist->SaveDocument (domDocument, inDestFile, filesFolder, contentType, encodingFlags, 80); } -- cgit v1.2.3