aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/MozDownload.cpp
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@src.gnome.org>2004-06-04 02:51:32 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2004-06-04 02:51:32 +0800
commitb774b547788b74884b9eb690c548a6016e714023 (patch)
tree72b9df09c0fc257169b3e9b9cbdc349e56a63101 /embed/mozilla/MozDownload.cpp
parentb699b40d663955560655271f7645ae277e6076c8 (diff)
downloadgsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar
gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.gz
gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.bz2
gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.lz
gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.xz
gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.zst
gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.zip
merge mozilla-embed-strings branch
Diffstat (limited to 'embed/mozilla/MozDownload.cpp')
-rw-r--r--embed/mozilla/MozDownload.cpp120
1 files changed, 48 insertions, 72 deletions
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index b50161c38..cd836599b 100644
--- a/embed/mozilla/MozDownload.cpp
+++ b/embed/mozilla/MozDownload.cpp
@@ -45,21 +45,21 @@
#include "config.h"
#endif
-#include "MozDownload.h"
+#include "mozilla-version.h"
+
#include "mozilla-download.h"
#include "eel-gconf-extensions.h"
#include "ephy-prefs.h"
#include "ephy-file-helpers.h"
#include "ephy-debug.h"
+#include "MozDownload.h"
+#include "EphyUtils.h"
#include <libgnomevfs/gnome-vfs-utils.h>
#include <glib/gi18n.h>
#include <nsIFileURL.h>
-
-#ifdef ALLOW_PRIVATE_STRINGS
-#include "nsNetUtil.h"
-#endif
+#include <nsEmbedString.h>
const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
@@ -79,18 +79,10 @@ 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)
{
@@ -100,15 +92,9 @@ MozDownload::InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aD
}
/* 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)
-#else
NS_IMETHODIMP
MozDownload::Init(nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName,
nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist)
-#endif
{
PRBool addToView = PR_TRUE;
@@ -165,13 +151,8 @@ 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);
@@ -179,7 +160,6 @@ MozDownload::GetTarget(nsIURI **aTarget)
return NS_OK;
}
-#if MOZILLA_SNAPSHOT > 15
NS_IMETHODIMP
MozDownload::GetTargetFile (nsILocalFile** aTargetFile)
{
@@ -194,7 +174,6 @@ MozDownload::GetTargetFile (nsILocalFile** aTargetFile)
rv = CallQueryInterface(file, aTargetFile);
return rv;
}
-#endif
NS_IMETHODIMP
MozDownload::GetPersist(nsIWebBrowserPersist **aPersist)
@@ -347,45 +326,49 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
else if (NS_SUCCEEDED (aStatus))
{
GnomeVFSMimeApplication *helperApp;
-#if MOZILLA_SNAPSHOT < 18
- char *mimeType;
- rv = mMIMEInfo->GetMIMEType (&mimeType);
+#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)
+ nsEmbedCString mimeType;
+ rv = mMIMEInfo->GetMIMEType (mimeType);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
- helperApp = gnome_vfs_mime_get_default_application (mimeType);
+ helperApp = gnome_vfs_mime_get_default_application (mimeType.get());
- PRUnichar *description;
- mMIMEInfo->GetApplicationDescription (&description);
+ nsEmbedString description;
+ mMIMEInfo->GetApplicationDescription (description);
+
+ nsEmbedCString cDesc;
+ NS_UTF16ToCString (description, NS_CSTRING_ENCODING_UTF8, cDesc);
/* HACK we use the application description to decide
if we have to open the saved file */
- if ((strcmp (NS_ConvertUTF16toUTF8 (description).get(), "gnome-default") == 0) &&
+ if ((strcmp (cDesc.get(), "gnome-default") == 0) &&
helperApp)
#else
- nsCAutoString mimeType;
- rv = mMIMEInfo->GetMIMEType (mimeType);
+ char *mimeType;
+ rv = mMIMEInfo->GetMIMEType (&mimeType);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
- helperApp = gnome_vfs_mime_get_default_application (mimeType.get());
+ helperApp = gnome_vfs_mime_get_default_application (mimeType);
- nsAutoString description;
- mMIMEInfo->GetApplicationDescription (description);
+ PRUnichar *description;
+ mMIMEInfo->GetApplicationDescription (&description);
+
+ nsEmbedCString cDesc;
+ NS_UTF16ToCString (nsEmbedString(description),
+ NS_CSTRING_ENCODING_UTF8, cDesc);
/* 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) &&
+ if (strcmp (cDesc.get(), "gnome-default") == 0 &&
helperApp)
#endif
{
GList *params = NULL;
char *param;
- nsCAutoString aDest;
+ nsEmbedCString 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);
@@ -393,10 +376,7 @@ 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);
}
}
@@ -528,21 +508,19 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI
PRInt64 timeNow = PR_Now();
- nsAutoString fileDisplayName;
+ nsEmbedString fileDisplayName;
inDestFile->GetLeafName(fileDisplayName);
- #if MOZILLA_SNAPSHOT >= 16
+ nsCOMPtr<nsIIOService> ioService;
+ rv = EphyUtils::GetIOService (getter_AddRefs (ioService));
+ NS_ENSURE_SUCCESS (rv, rv);
+
nsCOMPtr<nsIURI> destURI;
- NS_NewFileURI (getter_AddRefs(destURI), inDestFile);
- #endif
+ ioService->NewFileURI (inDestFile, getter_AddRefs(destURI));
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);
@@ -573,24 +551,22 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI
* 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)
+ nsEmbedCString cPath;
+ inDestFile->GetNativePath (cPath);
+
+ GString *path = g_string_new (cPath.get());
+ char *dot_pos = strchr (path->str, '.');
+ if (dot_pos)
{
- nameMinusExt.Left(nameMinusExt, index);
+ g_string_truncate (path, dot_pos - path->str);
}
+ g_string_append (path, " ");
+ g_string_append (path, _("Files"));
+
+ filesFolder = do_CreateInstance ("@mozilla.org/file/local;1");
+ filesFolder->InitWithNativePath (nsEmbedCString(path->str));
- nameMinusExt += NS_LITERAL_STRING (" ");
- nameMinusExt += NS_ConvertUTF8toUTF16 (_("Files"));
-
- filesFolder->SetLeafName(nameMinusExt);
+ g_string_free (path, TRUE);
rv = webPersist->SaveDocument (domDocument, inDestFile, filesFolder,
contentType, encodingFlags, 80);
@@ -684,7 +660,7 @@ nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval)
}
nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
- destFile->InitWithNativePath (nsDependentCString (path));
+ destFile->InitWithNativePath (nsEmbedCString (path));
g_free (path);
NS_IF_ADDREF (*_retval = destFile);