Registered a nsITransfer for opening documents after downloading.
parent
5ff6ba45d4
commit
2e65e2ca1d
@ -0,0 +1,117 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <nsStringAPI.h>
|
||||
|
||||
#include "sugar-browser-chandler.h"
|
||||
|
||||
#include "SugarDownload.h"
|
||||
|
||||
GSugarDownload::GSugarDownload()
|
||||
{
|
||||
}
|
||||
|
||||
GSugarDownload::~GSugarDownload()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3 (GSugarDownload,
|
||||
nsIWebProgressListener,
|
||||
nsIWebProgressListener2,
|
||||
nsITransfer)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::Init (nsIURI *aSource,
|
||||
nsIURI *aTarget,
|
||||
const nsAString &aDisplayName,
|
||||
nsIMIMEInfo *aMIMEInfo,
|
||||
PRTime aStartTime,
|
||||
nsILocalFile *aTempFile,
|
||||
nsICancelable *aCancelable)
|
||||
{
|
||||
FILE *file = fopen("/home/tomeu/file.txt","a+");
|
||||
fprintf(file,"%s\n","GSugarDownload::Init");
|
||||
fclose(file);
|
||||
|
||||
mSource = aSource;
|
||||
mTarget = aTarget;
|
||||
mMIMEInfo = aMIMEInfo;
|
||||
mTempFile = aTempFile;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
||||
PRUint32 aStateFlags, nsresult aStatus)
|
||||
{
|
||||
nsCString url;
|
||||
nsCString mimeType;
|
||||
nsCString tmpFileName;
|
||||
|
||||
if ((((aStateFlags & STATE_IS_REQUEST) &&
|
||||
(aStateFlags & STATE_IS_NETWORK) &&
|
||||
(aStateFlags & STATE_STOP)) ||
|
||||
aStateFlags == STATE_STOP) &&
|
||||
NS_SUCCEEDED (aStatus)) {
|
||||
|
||||
mMIMEInfo->GetMIMEType(mimeType);
|
||||
mSource->GetSpec(url);
|
||||
mTempFile->GetNativeLeafName(tmpFileName);
|
||||
|
||||
// FIXME: Hack. Mozilla adds a .part to the file name. Must exist a better/simpler way.
|
||||
// FIXME: Also creates a nice memory leak.
|
||||
char *tmpFileName_striped = (char*)malloc(strlen(tmpFileName.get()));
|
||||
strncpy(tmpFileName_striped, tmpFileName.get(), strlen(tmpFileName.get()) - 5);
|
||||
|
||||
SugarBrowserChandler *browser_chandler = sugar_get_browser_chandler();
|
||||
sugar_browser_chandler_handle_content(browser_chandler,
|
||||
url.get(),
|
||||
mimeType.get(),
|
||||
tmpFileName_striped);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnProgressChange (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return OnProgressChange64 (aWebProgress, aRequest,
|
||||
aCurSelfProgress, aMaxSelfProgress,
|
||||
aCurTotalProgress, aMaxTotalProgress);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnProgressChange64 (nsIWebProgress *aWebProgress,
|
||||
nsIRequest *aRequest,
|
||||
PRInt64 aCurSelfProgress,
|
||||
PRInt64 aMaxSelfProgress,
|
||||
PRInt64 aCurTotalProgress,
|
||||
PRInt64 aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnLocationChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnStatusChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest,
|
||||
nsresult aStatus, const PRUnichar *aMessage)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GSugarDownload::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
#ifndef SugarDownload_h__
|
||||
#define SugarDownload_h__
|
||||
|
||||
#include <nsCOMPtr.h>
|
||||
#include <nsIInterfaceRequestor.h>
|
||||
#include <nsITransfer.h>
|
||||
#include <nsIWebProgressListener.h>
|
||||
#include <nsIMIMEInfo.h>
|
||||
#include <nsIURL.h>
|
||||
#include <nsILocalFile.h>
|
||||
|
||||
#define G_SUGARDOWNLOAD_CID \
|
||||
{ /* b1813bbe-6518-11db-967e-00e08161165f */ \
|
||||
0xb1813bbe, \
|
||||
0x6518, \
|
||||
0x11db, \
|
||||
{0x96, 0x7e, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
|
||||
}
|
||||
|
||||
class GSugarDownload : public nsITransfer
|
||||
{
|
||||
public:
|
||||
GSugarDownload();
|
||||
virtual ~GSugarDownload();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER2
|
||||
NS_DECL_NSITRANSFER
|
||||
|
||||
protected:
|
||||
nsIURI *mSource;
|
||||
nsIURI *mTarget;
|
||||
nsIMIMEInfo *mMIMEInfo;
|
||||
nsILocalFile *mTempFile;
|
||||
};
|
||||
|
||||
#endif // SugarDownload_h__
|
@ -1,3 +1,3 @@
|
||||
VOID:OBJECT,STRING,LONG,LONG
|
||||
VOID:OBJECT,LONG
|
||||
VOID:STRING,STRING,STRING,STRING
|
||||
VOID:STRING,STRING,STRING
|
||||
|
Loading…
Reference in New Issue