Index: embed/mozilla/mozilla-embed-persist.cpp
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/mozilla-embed-persist.cpp,v
retrieving revision 1.36
diff -u -p -U8 -r1.36 mozilla-embed-persist.cpp
--- embed/mozilla/mozilla-embed-persist.cpp	3 May 2004 13:18:49 -0000	1.36
+++ embed/mozilla/mozilla-embed-persist.cpp	3 May 2004 14:38:46 -0000
@@ -223,36 +223,38 @@ impl_save (EphyEmbedPersist *persist)
                 	browser->GetTargetDocument (getter_AddRefs(DOMDocument));
 		}
         	NS_ENSURE_TRUE (DOMDocument, FALSE);
 	}
 
 
 	/* Get the current page descriptor */
 	nsCOMPtr<nsISupports> pageDescriptor;
-	if (flags & EMBED_PERSIST_COPY_PAGE)
+	if (browser)
 	{
 	        browser->GetPageDescriptor(getter_AddRefs(pageDescriptor));
-		NS_ENSURE_TRUE (pageDescriptor, FALSE);
 	}
 
+	NS_ENSURE_TRUE (!(flags & EMBED_PERSIST_COPY_PAGE) || pageDescriptor, FALSE);
+
+
 	if (filename == NULL)
 	{
 		/* Create an header sniffer and do the save */
 		nsCOMPtr<nsIWebBrowserPersist> webPersist =
 			MOZILLA_EMBED_PERSIST (persist)->priv->mPersist;
 		NS_ENSURE_TRUE (webPersist, FALSE);
 
 		EphyHeaderSniffer* sniffer = new EphyHeaderSniffer
 			(webPersist, MOZILLA_EMBED_PERSIST (persist),
-			 tmpFile, inURI, DOMDocument, postData);
+			 tmpFile, inURI, DOMDocument, postData, pageDescriptor);
 		if (!sniffer) return FALSE;
  
 		webPersist->SetProgressListener(sniffer);
-		rv = webPersist->SaveURI(inURI, nsnull, nsnull, nsnull, nsnull, tmpFile);
+		rv = webPersist->SaveURI(inURI, pageDescriptor, nsnull, nsnull, nsnull, tmpFile);
 		if (NS_FAILED (rv)) return FALSE;
 	}
 	else
 	{
 		/* Filename to save to */
 		nsCOMPtr<nsILocalFile> destFile;
 		NS_NewNativeLocalFile (nsDependentCString(filename),
 				       PR_TRUE, getter_AddRefs(destFile));
Index: embed/mozilla/EphyHeaderSniffer.h
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyHeaderSniffer.h,v
retrieving revision 1.10
diff -u -p -U8 -r1.10 EphyHeaderSniffer.h
--- embed/mozilla/EphyHeaderSniffer.h	29 Apr 2004 10:41:10 -0000	1.10
+++ embed/mozilla/EphyHeaderSniffer.h	3 May 2004 14:38:46 -0000
@@ -55,17 +55,18 @@
 #endif
 
 class EphyHeaderSniffer : public nsIWebProgressListener,
 			  public nsIAuthPrompt
 {
 public:
 	EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist,
 		           nsIFile* aFile, nsIURI* aURL,
-                           nsIDOMDocument* aDocument, nsIInputStream* aPostData);
+                           nsIDOMDocument* aDocument, nsIInputStream* aPostData,
+			   nsISupports *aCacheKey);
 	virtual ~EphyHeaderSniffer ();
 
 	NS_DECL_ISUPPORTS
 	NS_DECL_NSIWEBPROGRESSLISTENER
 	NS_DECL_NSIAUTHPROMPT
 
 	nsresult InitiateDownload (nsILocalFile *aDestFile);
 
@@ -76,13 +77,14 @@ protected:
 private:
 	nsIWebBrowserPersist*      mPersist; /* Weak. It owns us as a listener. */
 	MozillaEmbedPersist       *mEmbedPersist;
 	nsCOMPtr<nsIFile>          mTmpFile;
 	nsCOMPtr<nsIURI>           mURL;
 	nsCOMPtr<nsIURI>           mOriginalURI;
 	nsCOMPtr<nsIDOMDocument>   mDocument;
 	nsCOMPtr<nsIInputStream>   mPostData;
+	nsCOMPtr<nsISupports>	   mCacheKey;
 	nsCString                  mContentType;
 	nsCString                  mContentDisposition;
 	nsCOMPtr<nsIPromptService> mPrompt;
 };
 
Index: embed/mozilla/EphyHeaderSniffer.cpp
===================================================================
RCS file: /cvs/gnome/epiphany/embed/mozilla/EphyHeaderSniffer.cpp,v
retrieving revision 1.30
diff -u -p -U8 -r1.30 EphyHeaderSniffer.cpp
--- embed/mozilla/EphyHeaderSniffer.cpp	29 Apr 2004 22:34:32 -0000	1.30
+++ embed/mozilla/EphyHeaderSniffer.cpp	3 May 2004 14:38:46 -0000
@@ -68,24 +68,26 @@
 #include <nsIDownload.h>
 #include <nsIMIMEHeaderParam.h>
 
 #ifdef ALLOW_PRIVATE_STRINGS
 #include <nsReadableUtils.h>
 #endif
 
 EphyHeaderSniffer::EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist,
-		nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData)
+		nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData,
+		nsISupports *aCacheKey)
 : mPersist(aPersist)
 , mEmbedPersist(aEmbedPersist)
 , mTmpFile(aFile)
 , mURL(aURL)
 , mOriginalURI(nsnull)
 , mDocument(aDocument)
 , mPostData(aPostData)
+, mCacheKey(aCacheKey)
 {
 	mPrompt = do_GetService("@mozilla.org/embedcomp/prompt-service;1");
 
 	LOG ("EphyHeaderSniffer ctor (%p)", this)
 }
 
 EphyHeaderSniffer::~EphyHeaderSniffer()
 {
@@ -367,17 +370,17 @@ nsresult EphyHeaderSniffer::PerformSave 
 }
 
 nsresult EphyHeaderSniffer::InitiateDownload (nsILocalFile *aDestFile)
 {
 	LOG ("Initiating download")
 
 	return InitiateMozillaDownload (mDocument, mURL, aDestFile,
 					mContentType.get(), mOriginalURI, mEmbedPersist,
-					mPostData, nsnull, -1);
+					mPostData, mCacheKey, -1);
 }
 
 NS_IMETHODIMP EphyHeaderSniffer::Prompt (const PRUnichar *dialogTitle, const PRUnichar *text,
 				         const PRUnichar *passwordRealm, PRUint32 savePassword,
 				         const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval)
 {
 	if (defaultText) *result = ToNewUnicode(nsDependentString(defaultText));
 
