зеркало из https://github.com/mozilla/pjs.git
Bug 383224 - Remove XPInstall bits from the Download Manager. r=enndeakin, r=mano
This commit is contained in:
Родитель
8d9933853d
Коммит
18f56597d0
|
@ -45,8 +45,8 @@ include $(DEPTH)/config/autoconf.mk
|
|||
MODULE = downloads
|
||||
|
||||
XPIDLSRCS = nsIDownloadManager.idl \
|
||||
nsIXPInstallManagerUI.idl \
|
||||
nsIDownloadProgressListener.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ static PRInt32 gRefCnt = 0;
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsDownloadManager
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsDownloadManager, nsIDownloadManager, nsIXPInstallManagerUI, nsIObserver)
|
||||
NS_IMPL_ISUPPORTS2(nsDownloadManager, nsIDownloadManager, nsIObserver)
|
||||
|
||||
nsDownloadManager::~nsDownloadManager()
|
||||
{
|
||||
|
@ -527,29 +527,6 @@ nsDownloadManager::GetDownloadFromDB(PRUint32 aID, nsDownload **retVal)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDownloadManager::AddToCurrentDownloads(nsDownload *aDl)
|
||||
{
|
||||
// If this is an install operation, ensure we have a progress listener for the
|
||||
// install and track this download separately.
|
||||
if (aDl->mDownloadType == nsIXPInstallManagerUI::DOWNLOAD_TYPE_INSTALL) {
|
||||
if (!mXPIProgress) {
|
||||
mXPIProgress = new nsXPIProgressListener(this);
|
||||
if (!mXPIProgress)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsIXPIProgressDialog *dialog = mXPIProgress.get();
|
||||
nsXPIProgressListener *listener = NS_STATIC_CAST(nsXPIProgressListener*,
|
||||
dialog);
|
||||
listener->AddDownload(aDl);
|
||||
}
|
||||
|
||||
mCurrentDownloads.AppendObject(aDl);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIDownloadManager
|
||||
|
||||
|
@ -768,18 +745,16 @@ nsDownloadManager::CleanUp()
|
|||
{
|
||||
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED,
|
||||
nsIDownloadManager::DOWNLOAD_FAILED,
|
||||
nsIDownloadManager::DOWNLOAD_CANCELED,
|
||||
nsIXPInstallManagerUI::INSTALL_FINISHED };
|
||||
nsIDownloadManager::DOWNLOAD_CANCELED };
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_downloads "
|
||||
"WHERE state = ?1 "
|
||||
"OR state = ?2 "
|
||||
"OR state = ?3 "
|
||||
"OR state = ?4"), getter_AddRefs(stmt));
|
||||
"OR state = ?3"), getter_AddRefs(stmt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
for (PRUint32 i = 0; i < 4; ++i) {
|
||||
for (PRUint32 i = 0; i < 3; ++i) {
|
||||
rv = stmt->BindInt32Parameter(i, states[i]);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
@ -794,8 +769,7 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult)
|
|||
|
||||
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED,
|
||||
nsIDownloadManager::DOWNLOAD_FAILED,
|
||||
nsIDownloadManager::DOWNLOAD_CANCELED,
|
||||
nsIXPInstallManagerUI::INSTALL_FINISHED };
|
||||
nsIDownloadManager::DOWNLOAD_CANCELED };
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
|
@ -803,10 +777,9 @@ nsDownloadManager::GetCanCleanUp(PRBool *aResult)
|
|||
"FROM moz_downloads "
|
||||
"WHERE state = ?1 "
|
||||
"OR state = ?2 "
|
||||
"OR state = ?3 "
|
||||
"OR state = ?4"), getter_AddRefs(stmt));
|
||||
"OR state = ?3"), getter_AddRefs(stmt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
for (PRUint32 i = 0; i < 4; ++i) {
|
||||
for (PRUint32 i = 0; i < 3; ++i) {
|
||||
rv = stmt->BindInt32Parameter(i, states[i]);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
@ -1055,15 +1028,9 @@ nsDownloadManager::Observe(nsISupports *aSubject,
|
|||
} else if (strcmp(aTopic, "quit-application") == 0) {
|
||||
gStoppingDownloads = PR_TRUE;
|
||||
|
||||
if (currDownloadCount) {
|
||||
if (currDownloadCount)
|
||||
CancelAllDownloads();
|
||||
|
||||
// Download Manager is shutting down! Tell the XPInstallManager to stop
|
||||
// transferring any files that may have been being downloaded.
|
||||
mObserverService->NotifyObservers(mXPIProgress, "xpinstall-progress",
|
||||
NS_LITERAL_STRING("cancel").get());
|
||||
}
|
||||
|
||||
// Now that active downloads have been canceled, remove all downloads if
|
||||
// the user's retention policy specifies it.
|
||||
if (GetRetentionBehavior() == 1)
|
||||
|
@ -1095,19 +1062,6 @@ nsDownloadManager::Observe(nsISupports *aSubject,
|
|||
NS_LITERAL_STRING("offlineCancelDownloadsAlertMsgMultiple").get(),
|
||||
NS_LITERAL_STRING("offlineCancelDownloadsAlertMsg").get(),
|
||||
NS_LITERAL_STRING("dontGoOfflineButton").get());
|
||||
PRBool data;
|
||||
cancelDownloads->GetData(&data);
|
||||
if (!data) {
|
||||
gStoppingDownloads = PR_TRUE;
|
||||
|
||||
// Network is going down! Tell the XPInstallManager to stop
|
||||
// transferring any files that may have been being downloaded.
|
||||
mObserverService->NotifyObservers(mXPIProgress, "xpinstall-progress",
|
||||
NS_LITERAL_STRING("cancel").get());
|
||||
|
||||
CancelAllDownloads();
|
||||
gStoppingDownloads = PR_FALSE;
|
||||
}
|
||||
} else if (strcmp(aTopic, "alertclickcallback") == 0) {
|
||||
// Attempt to locate a browser window to parent the download manager to
|
||||
nsCOMPtr<nsIWindowMediator> wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
|
||||
|
@ -1171,154 +1125,6 @@ nsDownloadManager::ConfirmCancelDownloads(PRInt32 aCount,
|
|||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIXPInstallManagerUI
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetXpiProgress(nsIXPIProgressDialog** aProgress)
|
||||
{
|
||||
*aProgress = mXPIProgress;
|
||||
NS_IF_ADDREF(*aProgress);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownloadManager::GetHasActiveXPIOperations(PRBool* aHasOps)
|
||||
{
|
||||
nsIXPIProgressDialog* dialog = mXPIProgress.get();
|
||||
nsXPIProgressListener* listener = NS_STATIC_CAST(nsXPIProgressListener*, dialog);
|
||||
*aHasOps = !mXPIProgress ? PR_FALSE : listener->HasActiveXPIOperations();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIProgressListener
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsXPIProgressListener, nsIXPIProgressDialog)
|
||||
|
||||
nsXPIProgressListener::nsXPIProgressListener(nsDownloadManager* aDownloadManager)
|
||||
{
|
||||
NS_NewISupportsArray(getter_AddRefs(mDownloads));
|
||||
|
||||
mDownloadManager = aDownloadManager;
|
||||
}
|
||||
|
||||
nsXPIProgressListener::~nsXPIProgressListener()
|
||||
{
|
||||
// Release any remaining references to objects held by the downloads array
|
||||
mDownloads->Clear();
|
||||
}
|
||||
|
||||
void
|
||||
nsXPIProgressListener::AddDownload(nsIDownload* aDownload)
|
||||
{
|
||||
PRUint32 cnt;
|
||||
mDownloads->Count(&cnt);
|
||||
PRBool foundMatch = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIURI> uri1, uri2;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsCOMPtr<nsIDownload> download(do_QueryElementAt(mDownloads, i));
|
||||
download->GetSource(getter_AddRefs(uri1));
|
||||
aDownload->GetSource(getter_AddRefs(uri2));
|
||||
|
||||
uri1->Equals(uri2, &foundMatch);
|
||||
if (foundMatch)
|
||||
break;
|
||||
}
|
||||
if (!foundMatch)
|
||||
mDownloads->AppendElement(aDownload);
|
||||
}
|
||||
|
||||
void
|
||||
nsXPIProgressListener::RemoveDownloadAtIndex(PRUint32 aIndex)
|
||||
{
|
||||
mDownloads->RemoveElementAt(aIndex);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsXPIProgressListener::HasActiveXPIOperations()
|
||||
{
|
||||
PRUint32 count;
|
||||
mDownloads->Count(&count);
|
||||
return count != 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIXPIProgressDialog
|
||||
NS_IMETHODIMP
|
||||
nsXPIProgressListener::OnStateChange(PRUint32 aIndex, PRInt16 aState, PRInt32 aValue)
|
||||
{
|
||||
nsCOMPtr<nsIWebProgressListener> wpl(do_QueryElementAt(mDownloads, aIndex));
|
||||
nsIWebProgressListener* temp = wpl.get();
|
||||
nsDownload* dl = NS_STATIC_CAST(nsDownload*, temp);
|
||||
// Sometimes we get XPInstall progress notifications after everything is done, and there's
|
||||
// no more active downloads... this null check is to prevent a crash in this case.
|
||||
if (!dl)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIObserverService> os;
|
||||
|
||||
DownloadState newState = aState;
|
||||
switch (aState) {
|
||||
case nsIXPIProgressDialog::DOWNLOAD_START:
|
||||
wpl->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_START, 0);
|
||||
|
||||
newState = nsIXPInstallManagerUI::INSTALL_DOWNLOADING;
|
||||
|
||||
os = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (os)
|
||||
os->NotifyObservers(dl, "dl-start", nsnull);
|
||||
break;
|
||||
case nsIXPIProgressDialog::DOWNLOAD_DONE:
|
||||
break;
|
||||
case nsIXPIProgressDialog::INSTALL_START:
|
||||
newState = nsIXPInstallManagerUI::INSTALL_INSTALLING;
|
||||
break;
|
||||
case nsIXPIProgressDialog::INSTALL_DONE:
|
||||
wpl->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
|
||||
|
||||
newState = nsIXPInstallManagerUI::INSTALL_FINISHED;
|
||||
|
||||
// Now, remove it from our internal bookkeeping list.
|
||||
RemoveDownloadAtIndex(aIndex);
|
||||
break;
|
||||
case nsIXPIProgressDialog::DIALOG_CLOSE:
|
||||
// Close now, if we're allowed to.
|
||||
os = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (os)
|
||||
os->NotifyObservers(nsnull, "xpinstall-dialog-close", nsnull);
|
||||
|
||||
if (!gStoppingDownloads) {
|
||||
nsCOMPtr<nsIStringBundleService> sbs(do_GetService("@mozilla.org/intl/stringbundle;1"));
|
||||
nsCOMPtr<nsIStringBundle> brandBundle, xpinstallBundle;
|
||||
sbs->CreateBundle("chrome://branding/locale/brand.properties", getter_AddRefs(brandBundle));
|
||||
sbs->CreateBundle("chrome://mozapps/locale/xpinstall/xpinstallConfirm.properties", getter_AddRefs(xpinstallBundle));
|
||||
|
||||
nsXPIDLString brandShortName, message, title;
|
||||
brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(brandShortName));
|
||||
const PRUnichar* strings[1] = { brandShortName.get() };
|
||||
xpinstallBundle->FormatStringFromName(NS_LITERAL_STRING("installComplete").get(), strings, 1, getter_Copies(message));
|
||||
xpinstallBundle->GetStringFromName(NS_LITERAL_STRING("installCompleteTitle").get(), getter_Copies(title));
|
||||
|
||||
nsCOMPtr<nsIPromptService> ps(do_GetService(NS_PROMPTSERVICE_CONTRACTID));
|
||||
ps->Alert(nsnull, title, message);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return dl->SetState(newState);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPIProgressListener::OnProgress(PRUint32 aIndex, PRUint64 aValue, PRUint64 aMaxValue)
|
||||
{
|
||||
nsCOMPtr<nsIWebProgressListener2> wpl(do_QueryElementAt(mDownloads, aIndex));
|
||||
if (wpl)
|
||||
return wpl->OnProgressChange64(nsnull, nsnull, 0, 0, aValue, aMaxValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsDownload
|
||||
|
||||
|
|
|
@ -42,14 +42,12 @@
|
|||
#define downloadmanager___h___
|
||||
|
||||
#include "nsIDownloadManager.h"
|
||||
#include "nsIXPInstallManagerUI.h"
|
||||
#include "nsIDownloadProgressListener.h"
|
||||
#include "nsIDownload.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIWebProgressListener2.h"
|
||||
#include "nsIXPIProgressDialog.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIWebBrowserPersist.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
@ -75,13 +73,11 @@ class nsXPIProgressListener;
|
|||
class nsDownload;
|
||||
|
||||
class nsDownloadManager : public nsIDownloadManager,
|
||||
public nsIXPInstallManagerUI,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOWNLOADMANAGER
|
||||
NS_DECL_NSIXPINSTALLMANAGERUI
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsresult Init();
|
||||
|
@ -97,7 +93,15 @@ protected:
|
|||
nsresult CreateTable();
|
||||
nsresult ImportDownloadHistory();
|
||||
nsresult GetDownloadFromDB(PRUint32 aID, nsDownload **retVal);
|
||||
nsresult AddToCurrentDownloads(nsDownload *aDl);
|
||||
|
||||
inline nsresult AddToCurrentDownloads(nsDownload *aDl)
|
||||
{
|
||||
if (!mCurrentDownloads.AppendObject(aDl))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a download with the specified information to the DB.
|
||||
|
@ -158,28 +162,23 @@ protected:
|
|||
static PRBool IsInFinalStage(DownloadState aState)
|
||||
{
|
||||
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
|
||||
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING ||
|
||||
aState == nsIXPInstallManagerUI::INSTALL_INSTALLING;
|
||||
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING;
|
||||
}
|
||||
|
||||
static PRBool IsInProgress(DownloadState aState)
|
||||
{
|
||||
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
|
||||
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING ||
|
||||
aState == nsIDownloadManager::DOWNLOAD_PAUSED ||
|
||||
aState == nsIXPInstallManagerUI::INSTALL_DOWNLOADING ||
|
||||
aState == nsIXPInstallManagerUI::INSTALL_INSTALLING;
|
||||
aState == nsIDownloadManager::DOWNLOAD_PAUSED;
|
||||
}
|
||||
|
||||
static PRBool CompletedSuccessfully(DownloadState aState)
|
||||
{
|
||||
return aState == nsIDownloadManager::DOWNLOAD_FINISHED ||
|
||||
aState == nsIXPInstallManagerUI::INSTALL_FINISHED;
|
||||
return aState == nsIDownloadManager::DOWNLOAD_FINISHED;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMArray<nsIDownloadProgressListener> mListeners;
|
||||
nsCOMPtr<nsIXPIProgressDialog> mXPIProgress;
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
nsCOMPtr<nsITimer> mDMOpenTimer;
|
||||
nsCOMPtr<mozIStorageConnection> mDBConn;
|
||||
|
@ -189,28 +188,6 @@ private:
|
|||
friend class nsDownload;
|
||||
};
|
||||
|
||||
class nsXPIProgressListener : public nsIXPIProgressDialog
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIXPIPROGRESSDIALOG
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsXPIProgressListener() { }
|
||||
nsXPIProgressListener(nsDownloadManager* aManager);
|
||||
virtual ~nsXPIProgressListener();
|
||||
|
||||
void AddDownload(nsIDownload* aDownload);
|
||||
|
||||
PRBool HasActiveXPIOperations();
|
||||
|
||||
protected:
|
||||
void RemoveDownloadAtIndex(PRUint32 aIndex);
|
||||
|
||||
private:
|
||||
nsDownloadManager* mDownloadManager;
|
||||
nsCOMPtr<nsISupportsArray> mDownloads;
|
||||
};
|
||||
|
||||
class nsDownload : public nsIDownload
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -403,60 +403,6 @@
|
|||
</content>
|
||||
</binding>
|
||||
|
||||
<binding id="install-downloading" extends="chrome://mozapps/content/downloads/download.xml#download-downloading">
|
||||
<content>
|
||||
<xul:hbox flex="1" class="downloadContentBox" xbl:inherits="animated,animated-temp">
|
||||
<xul:vbox pack="start">
|
||||
<xul:image class="downloadTypeIcon" validate="always" style="width: 32px; max-width: 32px; height: 32px; max-height: 32px;" xbl:inherits="src=image"/>
|
||||
</xul:vbox>
|
||||
<xul:vbox flex="1">
|
||||
<xul:hbox flex="1">
|
||||
<xul:vbox flex="1">
|
||||
<xul:label xbl:inherits="value=target" crop="center"/>
|
||||
<xul:progressmeter mode="normal" value="0" flex="1"
|
||||
xbl:inherits="value=progress,mode=progressmode"/>
|
||||
</xul:vbox>
|
||||
</xul:hbox>
|
||||
<xul:hbox align="center">
|
||||
<xul:label xbl:inherits="value=status" flex="1" crop="right"/>
|
||||
</xul:hbox>
|
||||
</xul:vbox>
|
||||
</xul:hbox>
|
||||
</content>
|
||||
</binding>
|
||||
|
||||
<binding id="install-installing" extends="chrome://mozapps/content/downloads/download.xml#download-base">
|
||||
<content>
|
||||
<xul:hbox flex="1">
|
||||
<xul:vbox pack="start">
|
||||
<xul:image class="downloadTypeIcon" validate="always" style="width: 32px; max-width: 32px; height: 32px; max-height: 32px;" xbl:inherits="src=image"/>
|
||||
</xul:vbox>
|
||||
<xul:vbox pack="start" flex="1">
|
||||
<xul:label xbl:inherits="value=target" crop="center"/>
|
||||
<xul:label value="&installing.label;"/>
|
||||
</xul:vbox>
|
||||
</xul:hbox>
|
||||
</content>
|
||||
</binding>
|
||||
|
||||
<binding id="install-done" extends="chrome://mozapps/content/downloads/download.xml#download-base">
|
||||
<content>
|
||||
<xul:hbox flex="1">
|
||||
<xul:vbox pack="start">
|
||||
<xul:image class="downloadTypeIcon" validate="always" style="width: 32px; max-width: 32px; height: 32px; max-height: 32px;" xbl:inherits="src=image"/>
|
||||
</xul:vbox>
|
||||
<xul:vbox pack="start" flex="1">
|
||||
<xul:label xbl:inherits="value=target" crop="center"/>
|
||||
<xul:label value="&done.label;"/>
|
||||
</xul:vbox>
|
||||
<xul:vbox pack="start">
|
||||
<xul:label value="&cmd.remove.label;" class="text-link"
|
||||
onclick="this.parentNode.parentNode.parentNode.fireEvent('remove');"/>
|
||||
</xul:vbox>
|
||||
</xul:hbox>
|
||||
</content>
|
||||
</binding>
|
||||
|
||||
<binding id="download-view">
|
||||
<implementation>
|
||||
<field name="_selected">null</field>
|
||||
|
|
|
@ -23,18 +23,6 @@ download[state="4"] {
|
|||
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#download-paused');
|
||||
}
|
||||
|
||||
download[state="5"] {
|
||||
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#install-downloading');
|
||||
}
|
||||
|
||||
download[state="6"] {
|
||||
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#install-installing');
|
||||
}
|
||||
|
||||
download[state="7"] {
|
||||
-moz-binding: url('chrome://mozapps/content/downloads/download.xml#install-done');
|
||||
}
|
||||
|
||||
/* Only focus links in the selected item*/
|
||||
download:not([selected="true"]) .text-link {
|
||||
-moz-user-focus: none;
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
const kObserverServiceProgID = "@mozilla.org/observer-service;1";
|
||||
const kDlmgrContractID = "@mozilla.org/download-manager;1";
|
||||
const nsIDownloadManager = Components.interfaces.nsIDownloadManager;
|
||||
const nsIXPInstallManagerUI = Components.interfaces.nsIXPInstallManagerUI;
|
||||
const PREF_BDM_CLOSEWHENDONE = "browser.download.manager.closeWhenDone";
|
||||
const PREF_BDM_ALERTONEXEOPEN = "browser.download.manager.alertOnEXEOpen";
|
||||
const PREF_BDM_RETENTION = "browser.download.manager.retention";
|
||||
|
@ -63,14 +62,6 @@ var gDownloadsView = null;
|
|||
var gUserInterfered = false;
|
||||
var gActiveDownloads = [];
|
||||
|
||||
// This variable exists because for XPInstalls, we don't want to close the
|
||||
// download manager until the XPInstallManager sends the DIALOG_CLOSE status
|
||||
// message. Setting this variable to false when the downloads window is
|
||||
// opened by the xpinstall manager prevents the window from being closed after
|
||||
// each download completes (because xpinstall downloads are done sequentially,
|
||||
// not concurrently)
|
||||
var gCanAutoClose = true;
|
||||
|
||||
// If the user has interacted with the window in a significant way, we should
|
||||
// not auto-close the window. Tough UI decisions about what is "significant."
|
||||
var gUserInteracted = false;
|
||||
|
@ -168,7 +159,7 @@ function autoRemoveAndClose(aDownload)
|
|||
var autoClose = pref.getBoolPref(PREF_BDM_CLOSEWHENDONE);
|
||||
if (autoClose && (!window.opener ||
|
||||
window.opener.location.href == window.location.href) &&
|
||||
gCanAutoClose && !gUserInteracted) {
|
||||
!gUserInteracted) {
|
||||
gCloseDownloadManager();
|
||||
return true;
|
||||
}
|
||||
|
@ -223,21 +214,6 @@ var gDownloadObserver = {
|
|||
// switch view to it
|
||||
gDownloadsView.selectedIndex = 0;
|
||||
break;
|
||||
case "xpinstall-download-started":
|
||||
var windowArgs = aSubject.QueryInterface(Components.interfaces.nsISupportsArray);
|
||||
var params = windowArgs.QueryElementAt(0, Components.interfaces.nsISupportsInterfacePointer);
|
||||
params = params.data.QueryInterface(Components.interfaces.nsIDialogParamBlock);
|
||||
var installObserver = windowArgs.QueryElementAt(1, Components.interfaces.nsISupportsInterfacePointer);
|
||||
installObserver = installObserver.data.QueryInterface(Components.interfaces.nsIObserver);
|
||||
XPInstallDownloadManager.addDownloads(params, installObserver);
|
||||
break;
|
||||
case "xpinstall-dialog-close":
|
||||
if ("gDownloadManager" in window) {
|
||||
var mgr = gDownloadManager.QueryInterface(Components.interfaces.nsIXPInstallManagerUI);
|
||||
gCanAutoClose = mgr.hasActiveXPIOperations;
|
||||
autoRemoveAndClose();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -550,21 +526,7 @@ function Startup()
|
|||
observerService.addObserver(gDownloadObserver, "dl-cancel", false);
|
||||
observerService.addObserver(gDownloadObserver, "dl-failed", false);
|
||||
observerService.addObserver(gDownloadObserver, "dl-start", false);
|
||||
observerService.addObserver(gDownloadObserver, "xpinstall-download-started", false);
|
||||
observerService.addObserver(gDownloadObserver, "xpinstall-dialog-close", false);
|
||||
|
||||
// Now look and see if we're being opened by XPInstall
|
||||
if ("arguments" in window) {
|
||||
try {
|
||||
var params = window.arguments[0].QueryInterface(Components.interfaces.nsIDialogParamBlock);
|
||||
var installObserver = window.arguments[1].QueryInterface(Components.interfaces.nsIObserver);
|
||||
XPInstallDownloadManager.addDownloads(params, installObserver);
|
||||
var mgr = gDownloadManager.QueryInterface(Components.interfaces.nsIXPInstallManagerUI);
|
||||
gCanAutoClose = mgr.hasActiveXPIOperations;
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
|
||||
// This is for the "Clean Up" button, which requires there to be
|
||||
// non-active downloads before it can be enabled.
|
||||
gDownloadsView.controllers.appendController(gDownloadViewController);
|
||||
|
@ -588,68 +550,6 @@ function Shutdown()
|
|||
observerService.removeObserver(gDownloadObserver, "dl-cancel");
|
||||
observerService.removeObserver(gDownloadObserver, "dl-failed");
|
||||
observerService.removeObserver(gDownloadObserver, "dl-start");
|
||||
observerService.removeObserver(gDownloadObserver, "xpinstall-download-started");
|
||||
observerService.removeObserver(gDownloadObserver, "xpinstall-dialog-close");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// XPInstall
|
||||
|
||||
var XPInstallDownloadManager = {
|
||||
addDownloads: function (aParams, aObserver)
|
||||
{
|
||||
var numXPInstallItems = aParams.GetInt(1);
|
||||
|
||||
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
|
||||
var tempDir = fileLocator.get("TmpD", Components.interfaces.nsIFile);
|
||||
|
||||
var mimeService = Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Components.interfaces.nsIMIMEService);
|
||||
|
||||
var IOService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
var xpinstallManager = gDownloadManager.QueryInterface(Components.interfaces.nsIXPInstallManagerUI);
|
||||
|
||||
var xpiString = "";
|
||||
|
||||
for (var i = 0; i < numXPInstallItems;) {
|
||||
// Pretty Name
|
||||
var displayName = aParams.GetString(i++);
|
||||
|
||||
// URI
|
||||
var uri = IOService.newURI(aParams.GetString(i++), null, null);
|
||||
|
||||
var iconURL = aParams.GetString(i++);
|
||||
|
||||
// Local File Target
|
||||
var url = uri.QueryInterface(Components.interfaces.nsIURL);
|
||||
var localTarget = tempDir.clone();
|
||||
localTarget.append(url.fileName);
|
||||
|
||||
xpiString += localTarget.path + ",";
|
||||
|
||||
// MIME Info
|
||||
var mimeInfo = null;
|
||||
try {
|
||||
mimeInfo = mimeService.getFromTypeAndExtension(null, url.fileExtension);
|
||||
}
|
||||
catch (e) { }
|
||||
|
||||
if (!iconURL)
|
||||
iconURL = "chrome://mozapps/skin/xpinstall/xpinstallItemGeneric.png";
|
||||
|
||||
var targetUrl = makeFileURI(localTarget);
|
||||
var download = gDownloadManager.addDownload(Components.interfaces.nsIXPInstallManagerUI.DOWNLOAD_TYPE_INSTALL,
|
||||
uri, targetUrl, displayName, iconURL, mimeInfo, 0, null);
|
||||
|
||||
// Advance the enumerator
|
||||
var certName = aParams.GetString(i++);
|
||||
}
|
||||
|
||||
var observerService = Components.classes[kObserverServiceProgID]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
observerService.notifyObservers(xpinstallManager.xpiProgress, "xpinstall-progress", "open");
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -745,9 +645,7 @@ var gDownloadViewController = {
|
|||
|
||||
if (state != nsIDownloadManager.DOWNLOAD_NOTSTARTED &&
|
||||
state != nsIDownloadManager.DOWNLOAD_DOWNLOADING &&
|
||||
state != nsIDownloadManager.DOWNLOAD_PAUSED &&
|
||||
state != nsIXPInstallManagerUI.INSTALL_DOWNLOADING &&
|
||||
state != nsIXPInstallManagerUI.INSTALL_INSTALLING)
|
||||
state != nsIDownloadManager.DOWNLOAD_PAUSED)
|
||||
gDownloadsView.removeChild(gDownloadsView.children[i]);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче