Bug 408605 - Preference to control cross-session download behaviour. Patch by graememcc <graememcc_firefox@graeme-online.co.uk>. r=sdwilsh, a=schrep

This commit is contained in:
sdwilsh%shawnwilsher.com 2008-01-26 21:11:31 +00:00
Родитель d2aea36bed
Коммит f099385f75
3 изменённых файлов: 54 добавлений и 5 удалений

Просмотреть файл

@ -217,6 +217,7 @@ pref("browser.download.manager.openDelay", 0);
pref("browser.download.manager.focusWhenStarting", false);
pref("browser.download.manager.flashCount", 2);
pref("browser.download.manager.addToRecentDocs", true);
pref("browser.download.manager.quitBehavior", 0);
// search engines URL
pref("browser.search.searchEnginesURL", "https://%LOCALE%.add-ons.mozilla.com/%LOCALE%/firefox/%VERSION%/search-engines/");

Просмотреть файл

@ -25,6 +25,7 @@
* Shawn Wilsher <me@shawnwilsher.com>
* Srirang G Doddihal <brahmana@doddihal.com>
* Edward Lee <edward.lee@engineering.uiuc.edu>
* Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -92,6 +93,7 @@
#define PREF_BDM_SHOWALERTONCOMPLETE "browser.download.manager.showAlertOnComplete"
#define PREF_BDM_SHOWALERTINTERVAL "browser.download.manager.showAlertInterval"
#define PREF_BDM_RETENTION "browser.download.manager.retention"
#define PREF_BDM_QUITBEHAVIOR "browser.download.manager.quitBehavior"
#define PREF_BDM_CLOSEWHENDONE "browser.download.manager.closeWhenDone"
#define PREF_BDM_ADDTORECENTDOCS "browser.download.manager.addToRecentDocs"
#define PREF_BH_DELETETEMPFILEONEXIT "browser.helperApps.deleteTempFileOnExit"
@ -214,7 +216,7 @@ nsDownloadManager::RemoveAllDownloads()
nsRefPtr<nsDownload> dl = mCurrentDownloads[0];
nsresult result;
if (dl->IsPaused())
if (dl->IsPaused() && GetQuitBehavior() != QUIT_AND_CANCEL)
result = mCurrentDownloads.RemoveObject(dl);
else
result = CancelDownload(dl->mID);
@ -896,6 +898,28 @@ nsDownloadManager::GetRetentionBehavior()
return val;
}
enum nsDownloadManager::QuitBehavior
nsDownloadManager::GetQuitBehavior()
{
// We use 0 as the default, which is "remember and resume the download"
nsresult rv;
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, QUIT_AND_RESUME);
PRInt32 val;
rv = pref->GetIntPref(PREF_BDM_QUITBEHAVIOR, &val);
NS_ENSURE_SUCCESS(rv, QUIT_AND_RESUME);
switch (val) {
case 1:
return QUIT_AND_PAUSE;
case 2:
return QUIT_AND_CANCEL;
default:
return QUIT_AND_RESUME;
}
}
nsresult
nsDownloadManager::GetDownloadFromDB(PRUint32 aID, nsDownload **retVal)
{
@ -1630,14 +1654,17 @@ nsDownloadManager::Observe(nsISupports *aSubject,
if (dl2)
return CancelDownload(id);
} else if (strcmp(aTopic, "quit-application") == 0) {
// Try to pause all downloads and mark them as auto-resume
(void)PauseAllDownloads(PR_TRUE);
// Try to pause all downloads and, if appropriate, mark them as auto-resume
// unless user has specified that downloads should be canceled
enum QuitBehavior behavior = GetQuitBehavior();
if (behavior != QUIT_AND_CANCEL)
(void)PauseAllDownloads(PRBool(behavior != QUIT_AND_PAUSE));
// Remove downloads to break cycles and cancel downloads
(void)RemoveAllDownloads();
// Now that active downloads have been canceled, remove all downloads if
// the user's retention policy specifies it.
// Now that active downloads have been canceled, remove all completed or
// aborted downloads if the user's retention policy specifies it.
if (GetRetentionBehavior() == 1)
CleanUp();
} else if (strcmp(aTopic, "quit-application-requested") == 0 &&

Просмотреть файл

@ -197,6 +197,27 @@ protected:
PRInt32 GetRetentionBehavior();
/**
* Type to indicate possible behaviors for active downloads across sessions.
*
* Possible values are:
* QUIT_AND_RESUME - downloads should be auto-resumed
* QUIT_AND_PAUSE - downloads should be paused
* QUIT_AND_CANCEL - downloads should be cancelled
*/
enum QuitBehavior {
QUIT_AND_RESUME = 0,
QUIT_AND_PAUSE = 1,
QUIT_AND_CANCEL = 2
};
/**
* Indicates user-set behavior for active downloads across sessions,
*
* @return value of user-set pref for active download behavior
*/
enum QuitBehavior GetQuitBehavior();
private:
nsCOMArray<nsIDownloadProgressListener> mListeners;
nsCOMPtr<nsIStringBundle> mBundle;