aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/MozDownload.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-05-07 21:32:54 +0800
committerChristian Persch <chpe@src.gnome.org>2004-05-07 21:32:54 +0800
commitbb74728ca89c5fefd999f86960c9a16db0e7e5c9 (patch)
treeb9708e6ee104340ff5ec123ae205d221fe5fa82a /embed/mozilla/MozDownload.cpp
parent0dcd33eacecfaa7c83f420e2c1eeda13fa7939e5 (diff)
downloadgsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.tar
gsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.tar.gz
gsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.tar.bz2
gsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.tar.lz
gsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.tar.xz
gsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.tar.zst
gsoc2013-epiphany-bb74728ca89c5fefd999f86960c9a16db0e7e5c9.zip
Merged nsIDownload API changes from HEAD.
2004-05-07 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: * embed/mozilla/EventContext.h: * embed/mozilla/FilePicker.cpp: * embed/mozilla/Makefile.am: * embed/mozilla/MozDownload.cpp: * embed/mozilla/MozDownload.h: * embed/mozilla/mozilla-download.cpp: * embed/mozilla/mozilla-embed-persist.cpp: Merged nsIDownload API changes from HEAD.
Diffstat (limited to 'embed/mozilla/MozDownload.cpp')
-rw-r--r--embed/mozilla/MozDownload.cpp78
1 files changed, 72 insertions, 6 deletions
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index 473d81cfd..d2354ecd9 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,18 @@ 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
+#if MOZILLA_SNAPSHOT < 16
MozDownload::InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName,
+#else
+MozDownload::InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName,
+#endif
nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist,
MozillaEmbedPersist *aEmbedPersist, PRInt32 aMaxSize)
{
@@ -92,10 +102,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 +169,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 +183,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 +351,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 +365,31 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
if we have to open the saved file */
if ((strcmp (NS_ConvertUCS2toUTF8 (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 +397,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 +535,18 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI
nsAutoString fileDisplayName;
inDestFile->GetLeafName(fileDisplayName);
+ #if MOZILLA_SNAPSHOT >= 16
+ nsCOMPtr<nsIURI> destURI;
+ NS_NewFileURI (getter_AddRefs(destURI), inDestFile);
+ #endif
+
MozDownload *downloader = new MozDownload ();
/* dlListener attaches to its progress dialog here, which gains ownership */
+ #if MOZILLA_SNAPSHOT < 16
rv = downloader->InitForEmbed (inOriginalURI, inDestFile, fileDisplayName.get(),
+ #else
+ rv = downloader->InitForEmbed (inOriginalURI, destURI, fileDisplayName.get(),
+ #endif
nsnull, timeNow, webPersist, embedPersist, aMaxSize);
NS_ENSURE_SUCCESS (rv, rv);