2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef downloadproxy___h___
|
|
|
|
#define downloadproxy___h___
|
|
|
|
|
|
|
|
#include "nsIDownloadManager.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIMIMEInfo.h"
|
|
|
|
#include "nsIFileURL.h"
|
2007-08-27 17:10:25 -07:00
|
|
|
#include "nsIDownloadManagerUI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define PREF_BDM_SHOWWHENSTARTING "browser.download.manager.showWhenStarting"
|
2007-08-27 17:10:25 -07:00
|
|
|
#define PREF_BDM_FOCUSWHENSTARTING "browser.download.manager.focusWhenStarting"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-21 17:03:33 -07:00
|
|
|
class nsDownloadProxy : public nsITransfer
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
nsDownloadProxy() { }
|
|
|
|
virtual ~nsDownloadProxy() { }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHODIMP Init(nsIURI* aSource,
|
|
|
|
nsIURI* aTarget,
|
|
|
|
const nsAString& aDisplayName,
|
|
|
|
nsIMIMEInfo *aMIMEInfo,
|
|
|
|
PRTime aStartTime,
|
|
|
|
nsILocalFile* aTempFile,
|
|
|
|
nsICancelable* aCancelable) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDownloadManager> dm = do_GetService("@mozilla.org/download-manager;1", &rv);
|
2007-05-21 17:03:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = dm->AddDownload(nsIDownloadManager::DOWNLOAD_TYPE_DOWNLOAD, aSource,
|
2007-07-22 10:24:03 -07:00
|
|
|
aTarget, aDisplayName, aMIMEInfo, aStartTime,
|
|
|
|
aTempFile, aCancelable, getter_AddRefs(mInner));
|
2007-05-21 17:03:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv);
|
2007-05-21 17:03:33 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool showDM = true;
|
2007-05-21 17:03:33 -07:00
|
|
|
if (branch)
|
2008-03-21 17:23:45 -07:00
|
|
|
branch->GetBoolPref(PREF_BDM_SHOWWHENSTARTING, &showDM);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-26 08:51:38 -07:00
|
|
|
if (showDM) {
|
2007-05-21 17:03:33 -07:00
|
|
|
PRUint32 id;
|
|
|
|
mInner->GetId(&id);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-27 17:10:25 -07:00
|
|
|
nsCOMPtr<nsIDownloadManagerUI> dmui =
|
|
|
|
do_GetService("@mozilla.org/download-manager-ui;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool visible;
|
2007-08-27 17:10:25 -07:00
|
|
|
rv = dmui->GetVisible(&visible);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool focusWhenStarting = true;
|
2007-08-27 17:10:25 -07:00
|
|
|
if (branch)
|
2010-05-01 06:55:00 -07:00
|
|
|
(void)branch->GetBoolPref(PREF_BDM_FOCUSWHENSTARTING, &focusWhenStarting);
|
2007-08-27 17:10:25 -07:00
|
|
|
|
2010-05-01 06:55:00 -07:00
|
|
|
if (visible && !focusWhenStarting)
|
|
|
|
return NS_OK;
|
2007-08-27 17:10:25 -07:00
|
|
|
|
2008-04-02 20:05:22 -07:00
|
|
|
return dmui->Show(nsnull, id, nsIDownloadManagerUI::REASON_NEW_DOWNLOAD);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnStateChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, PRUint32 aStateFlags,
|
|
|
|
PRUint32 aStatus)
|
|
|
|
{
|
2008-03-27 14:00:20 -07:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_NOT_INITIALIZED);
|
2007-06-27 14:08:31 -07:00
|
|
|
return mInner->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnStatusChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest, nsresult aStatus,
|
|
|
|
const PRUnichar *aMessage)
|
|
|
|
{
|
2008-03-27 14:00:20 -07:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_NOT_INITIALIZED);
|
2007-06-27 14:08:31 -07:00
|
|
|
return mInner->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnLocationChange(nsIWebProgress *aWebProgress,
|
2011-11-10 06:01:11 -08:00
|
|
|
nsIRequest *aRequest, nsIURI *aLocation,
|
|
|
|
PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-27 14:00:20 -07:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_NOT_INITIALIZED);
|
2011-11-10 06:01:11 -08:00
|
|
|
return mInner->OnLocationChange(aWebProgress, aRequest, aLocation, aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnProgressChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt32 aCurSelfProgress,
|
|
|
|
PRInt32 aMaxSelfProgress,
|
|
|
|
PRInt32 aCurTotalProgress,
|
|
|
|
PRInt32 aMaxTotalProgress)
|
|
|
|
{
|
2008-03-27 14:00:20 -07:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_NOT_INITIALIZED);
|
2007-06-27 14:08:31 -07:00
|
|
|
return mInner->OnProgressChange(aWebProgress, aRequest,
|
|
|
|
aCurSelfProgress,
|
|
|
|
aMaxSelfProgress,
|
|
|
|
aCurTotalProgress,
|
|
|
|
aMaxTotalProgress);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnProgressChange64(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
|
|
|
PRInt64 aCurSelfProgress,
|
|
|
|
PRInt64 aMaxSelfProgress,
|
|
|
|
PRInt64 aCurTotalProgress,
|
|
|
|
PRInt64 aMaxTotalProgress)
|
|
|
|
{
|
2008-03-27 14:00:20 -07:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_NOT_INITIALIZED);
|
2007-06-27 14:08:31 -07:00
|
|
|
return mInner->OnProgressChange64(aWebProgress, aRequest,
|
|
|
|
aCurSelfProgress,
|
|
|
|
aMaxSelfProgress,
|
|
|
|
aCurTotalProgress,
|
|
|
|
aMaxTotalProgress);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnRefreshAttempted(nsIWebProgress *aWebProgress,
|
|
|
|
nsIURI *aUri,
|
|
|
|
PRInt32 aDelay,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSameUri,
|
|
|
|
bool *allowRefresh)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*allowRefresh = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnSecurityChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest, PRUint32 aState)
|
|
|
|
{
|
2008-03-27 14:00:20 -07:00
|
|
|
NS_ENSURE_TRUE(mInner, NS_ERROR_NOT_INITIALIZED);
|
2007-06-27 14:08:31 -07:00
|
|
|
return mInner->OnSecurityChange(aWebProgress, aRequest, aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDownload> mInner;
|
|
|
|
};
|
|
|
|
|
2007-05-21 17:03:33 -07:00
|
|
|
NS_IMPL_ISUPPORTS3(nsDownloadProxy, nsITransfer,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWebProgressListener, nsIWebProgressListener2)
|
|
|
|
|
|
|
|
#endif
|