aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/MozDownload.cpp
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2004-04-27 17:07:36 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2004-04-27 17:07:36 +0800
commit6fadfbe07379b55695a43687c6b7d935bff80133 (patch)
tree0e9c207847091df0505b4e08caca7e0d899f2a31 /embed/mozilla/MozDownload.cpp
parente88e7018c298131a4024415d0a2dbff9b7046960 (diff)
downloadgsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.tar
gsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.tar.gz
gsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.tar.bz2
gsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.tar.lz
gsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.tar.xz
gsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.tar.zst
gsoc2013-epiphany-6fadfbe07379b55695a43687c6b7d935bff80133.zip
Nice mess of defines to support 1.8a. Damn.
2004-04-27 Marco Pesenti Gritti <marco@gnome.org> * configure.in: * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: * embed/mozilla/EphyHeaderSniffer.cpp: * embed/mozilla/EventContext.h: * embed/mozilla/FilePicker.cpp: * embed/mozilla/MozDownload.cpp: * embed/mozilla/MozDownload.h: * embed/mozilla/mozilla-download.cpp: * embed/mozilla/mozilla-embed-persist.cpp: Nice mess of defines to support 1.8a. Damn.
Diffstat (limited to 'embed/mozilla/MozDownload.cpp')
-rw-r--r--embed/mozilla/MozDownload.cpp72
1 files changed, 64 insertions, 8 deletions
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index 722e7d8a5..2dd99e98d 100644
--- a/embed/mozilla/MozDownload.cpp
+++ b/embed/mozilla/MozDownload.cpp
@@ -60,7 +60,9 @@
#include "nsDirectoryServiceUtils.h"
#include "nsIRequest.h"
#include "nsIMIMEInfo.h"
+#include "nsIFileURL.h"
#include "netCore.h"
+#include "nsNetUtil.h"
const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
@@ -80,10 +82,14 @@ MozDownload::~MozDownload()
NS_ASSERTION (!mEphyDownload, "MozillaDownload still alive!");
}
+#if MOZILLA_SNAPSHOT < 16
NS_IMPL_ISUPPORTS2(MozDownload, nsIDownload, nsIWebProgressListener)
+#else
+NS_IMPL_ISUPPORTS3(MozDownload, nsIDownload, nsITransfer, nsIWebProgressListener)
+#endif
NS_IMETHODIMP
-MozDownload::InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName,
+MozDownload::InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName,
nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist,
MozillaEmbedPersist *aEmbedPersist, PRInt32 aMaxSize)
{
@@ -92,10 +98,16 @@ MozDownload::InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, const PRUnich
return Init (aSource, aTarget, aDisplayName, aMIMEInfo, startTime, aPersist);
}
-/* void init (in nsIURI aSource, in nsILocalFile aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsIWebBrowserPersist aPersist); */
+/* void init (in nsIURI aSource, in nsIURI aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsIWebBrowserPersist aPersist); */
+#if MOZILLA_SNAPSHOT < 16
NS_IMETHODIMP
MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName,
- nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist)
+ nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist)
+#else
+NS_IMETHODIMP
+MozDownload::Init(nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName,
+ nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist)
+#endif
{
PRBool addToView = PR_TRUE;
nsresult rv;
@@ -153,8 +165,13 @@ MozDownload::GetSource(nsIURI **aSource)
return NS_OK;
}
+#if MOZILLA_SNAPSHOT < 16
NS_IMETHODIMP
MozDownload::GetTarget(nsILocalFile **aTarget)
+#else
+NS_IMETHODIMP
+MozDownload::GetTarget(nsIURI **aTarget)
+#endif
{
NS_ENSURE_ARG_POINTER(aTarget);
NS_IF_ADDREF(*aTarget = mDestination);
@@ -162,6 +179,23 @@ MozDownload::GetTarget(nsILocalFile **aTarget)
return NS_OK;
}
+#if MOZILLA_SNAPSHOT > 15
+NS_IMETHODIMP
+MozDownload::GetTargetFile (nsILocalFile** aTargetFile)
+{
+ nsresult rv;
+
+ nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mDestination, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ nsCOMPtr<nsIFile> file;
+ rv = fileURL->GetFile(getter_AddRefs(file));
+ if (NS_SUCCEEDED(rv))
+ rv = CallQueryInterface(file, aTargetFile);
+ return rv;
+}
+#endif
+
NS_IMETHODIMP
MozDownload::GetPersist(nsIWebBrowserPersist **aPersist)
{
@@ -313,8 +347,8 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
else if (NS_SUCCEEDED (aStatus))
{
GnomeVFSMimeApplication *helperApp;
- char *mimeType;
-
+#if MOZILLA_SNAPSHOT < 16
+ char *mimeType;
rv = mMIMEInfo->GetMIMEType (&mimeType);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
@@ -327,13 +361,31 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
if we have to open the saved file */
if ((strcmp (NS_ConvertUTF16toUTF8 (description).get(), "gnome-default") == 0) &&
helperApp)
+#else
+ nsCAutoString mimeType;
+ rv = mMIMEInfo->GetMIMEType (mimeType);
+ NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
+
+ helperApp = gnome_vfs_mime_get_default_application (mimeType.get());
+
+ nsAutoString description;
+ mMIMEInfo->GetApplicationDescription (description);
+
+ /* HACK we use the application description to decide
+ if we have to open the saved file */
+ if ((strcmp (NS_ConvertUCS2toUTF8 (description).get(), "gnome-default") == 0) &&
+ helperApp)
+#endif
{
GList *params = NULL;
char *param;
nsCAutoString aDest;
+#if MOZILLA_SNAPSHOT < 16
mDestination->GetNativePath (aDest);
-
+#else
+ mDestination->GetSpec (aDest);
+#endif
param = gnome_vfs_make_uri_canonical (aDest.get ());
params = g_list_append (params, param);
gnome_vfs_mime_application_launch (helperApp, params);
@@ -341,9 +393,10 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
g_list_free (params);
}
-
+#if MOZILLA_SNAPSHOT < 16
nsMemory::Free (mimeType);
nsMemory::Free (description);
+#endif
gnome_vfs_mime_application_free (helperApp);
}
}
@@ -478,9 +531,12 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI
nsAutoString fileDisplayName;
inDestFile->GetLeafName(fileDisplayName);
+ nsCOMPtr<nsIURI> destURI;
+ NS_NewFileURI (getter_AddRefs(destURI), inDestFile);
+
MozDownload *downloader = new MozDownload ();
/* dlListener attaches to its progress dialog here, which gains ownership */
- rv = downloader->InitForEmbed (inOriginalURI, inDestFile, fileDisplayName.get(),
+ rv = downloader->InitForEmbed (inOriginalURI, destURI, fileDisplayName.get(),
nsnull, timeNow, webPersist, embedPersist, aMaxSize);
NS_ENSURE_SUCCESS (rv, rv);