More changes for 214260... place xpinstall progress listener in download manager service so that it doesn't get killed when the manager window closes.

This commit is contained in:
ben%bengoodger.com 2003-12-09 05:55:09 +00:00
Родитель 799cdf28cb
Коммит b5e0adcf2e
8 изменённых файлов: 340 добавлений и 117 удалений

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

@ -53,6 +53,7 @@ REQUIRES = \
necko \
windowwatcher \
uriloader \
xpinstall \
$(NULL)
ifeq ($(OS_ARCH),WINNT)

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

@ -29,6 +29,7 @@ include $(DEPTH)/config/autoconf.mk
MODULE = downloads
XPIDLSRCS = nsIDownloadManager.idl \
nsIXPInstallManagerUI.idl \
nsIDownloadProgressListener.idl \
include $(topsrcdir)/config/rules.mk

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

@ -53,6 +53,13 @@ interface nsISupportsArray;
[scriptable, uuid(9be66cc0-1dd1-11b2-8617-e3a3ed26e3b0)]
interface nsIDownloadManager : nsISupports {
// Download States
const short DOWNLOAD_NOTSTARTED = -1;
const short DOWNLOAD_DOWNLOADING = 0;
const short DOWNLOAD_FINISHED = 1;
const short DOWNLOAD_FAILED = 2;
const short DOWNLOAD_CANCELED = 3;
const short DOWNLOAD_PAUSED = 4;
// Methods called by clients to carry out various managing functions

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

@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com>
*
* 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
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Keeps track of ongoing downloads, in the form of nsIDownload's.
#include "nsISupports.idl"
interface nsIXPIProgressDialog;
interface nsIDownload;
[scriptable, uuid(087f52a4-8fd8-40ab-ae52-c3e161810141)]
interface nsIXPInstallManagerUI : nsISupports {
// Install States
const short INSTALL_DOWNLOADING = 5;
const short INSTALL_INSTALLING = 6;
const short INSTALL_FINISHED = 7;
void addDownload(in nsIDownload aDownload);
readonly attribute nsIXPIProgressDialog xpiProgress;
readonly attribute boolean hasActiveXPIOperations;
};

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

@ -45,6 +45,7 @@ REQUIRES = xpcom \
appshell \
dom \
toolkitcomps \
xpinstall \
$(NULL)
ifeq ($(OS_ARCH),WINNT)

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

@ -131,6 +131,11 @@ nsDownloadManager::~nsDownloadManager()
NS_RELEASE(gRDFService);
NS_RELEASE(gObserverService);
if (mXPIProgress) {
delete mXPIProgress;
mXPIProgress = nsnull;
}
}
PRInt32 PR_CALLBACK nsDownloadManager::CancelAllDownloads(nsHashKey* aKey, void* aData, void* aClosure)
@ -143,7 +148,7 @@ PRInt32 PR_CALLBACK nsDownloadManager::CancelAllDownloads(nsHashKey* aKey, void*
DownloadState state;
NS_STATIC_CAST(nsDownload*, aData)->GetDownloadState(&state);
if (state == NOTSTARTED || state == DOWNLOADING || state == PAUSED)
if (IsInProgress(state))
manager->CancelDownload(key->GetString());
else
NS_STATIC_CAST(nsDownloadManager*, aClosure)->DownloadEnded(key->GetString(), nsnull);
@ -320,14 +325,6 @@ nsDownloadManager::GetInternalListener(nsIDownloadProgressListener** aListener)
return NS_OK;
}
nsresult
nsDownloadManager::GetDataSource(nsIRDFDataSource** aDataSource)
{
*aDataSource = mDataSource;
NS_IF_ADDREF(*aDataSource);
return NS_OK;
}
NS_IMETHODIMP
nsDownloadManager::GetActiveDownloadCount(PRInt32* aResult)
{
@ -366,9 +363,12 @@ nsDownloadManager::SaveState()
nsCOMPtr<nsIRDFResource> res;
nsCOMPtr<nsIRDFInt> intLiteral;
DownloadState states[] = { DOWNLOADING, PAUSED };
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_DOWNLOADING,
nsIDownloadManager::DOWNLOAD_PAUSED,
nsIXPInstallManagerUI::INSTALL_DOWNLOADING,
nsIXPInstallManagerUI::INSTALL_INSTALLING };
for (int i = 0; i < 2; ++i) {
for (int i = 0; i < 4; ++i) {
gRDFService->GetIntLiteral(states[i], getter_AddRefs(intLiteral));
nsCOMPtr<nsISimpleEnumerator> downloads;
nsresult rv = mDataSource->GetSources(gNC_DownloadState, intLiteral, PR_TRUE, getter_AddRefs(downloads));
@ -580,7 +580,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
// Assert download state information (NOTSTARTED, since it's just now being added)
nsCOMPtr<nsIRDFInt> intLiteral;
gRDFService->GetIntLiteral(NOTSTARTED, getter_AddRefs(intLiteral));
gRDFService->GetIntLiteral(nsIDownloadManager::DOWNLOAD_NOTSTARTED, getter_AddRefs(intLiteral));
mDataSource->GetTarget(downloadRes, gNC_DownloadState, PR_TRUE, getter_AddRefs(node));
if (node)
rv = mDataSource->Change(downloadRes, gNC_DownloadState, node, intLiteral);
@ -647,10 +647,10 @@ nsDownloadManager::CancelDownload(const PRUnichar* aPath)
return NS_ERROR_FAILURE;
// Don't cancel if download is already finished
if (internalDownload->mDownloadState == FINISHED)
if (CompletedSuccessfully(internalDownload->mDownloadState))
return NS_OK;
internalDownload->SetDownloadState(CANCELED);
internalDownload->SetDownloadState(nsIDownloadManager::DOWNLOAD_CANCELED);
// if a persist was provided, we can do the cancel ourselves.
nsCOMPtr<nsIWebBrowserPersist> persist;
@ -793,9 +793,12 @@ nsDownloadManager::CleanUp()
// 1). First, clean out the usual suspects - downloads that are
// finished, failed or canceled.
DownloadState states[] = { FINISHED, FAILED, CANCELED };
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED,
nsIDownloadManager::DOWNLOAD_FAILED,
nsIDownloadManager::DOWNLOAD_CANCELED,
nsIXPInstallManagerUI::INSTALL_FINISHED };
for (int i = 0; i < 3; ++i) {
for (int i = 0; i < 4; ++i) {
gRDFService->GetIntLiteral(states[i], getter_AddRefs(intLiteral));
nsresult rv = mDataSource->GetSources(gNC_DownloadState, intLiteral, PR_TRUE, getter_AddRefs(downloads));
if (NS_FAILED(rv)) return rv;
@ -829,9 +832,12 @@ nsDownloadManager::GetCanCleanUp(PRBool* aResult)
// 1). Downloads that can be cleaned up include those that are finished,
// failed or canceled.
DownloadState states[] = { FINISHED, FAILED, CANCELED };
DownloadState states[] = { nsIDownloadManager::DOWNLOAD_FINISHED,
nsIDownloadManager::DOWNLOAD_FAILED,
nsIDownloadManager::DOWNLOAD_CANCELED,
nsIXPInstallManagerUI::INSTALL_FINISHED };
for (int i = 0; i < 3; ++i) {
for (int i = 0; i < 4; ++i) {
gRDFService->GetIntLiteral(states[i], getter_AddRefs(intLiteral));
mDataSource->GetSource(gNC_DownloadState, intLiteral, PR_TRUE, getter_AddRefs(downloadRes));
@ -962,7 +968,7 @@ nsDownloadManager::PauseResumeDownload(const PRUnichar* aPath, PRBool aPause)
// Update download state in the DataSource
nsCOMPtr<nsIRDFInt> intLiteral;
gRDFService->GetIntLiteral(aPause ? PAUSED : DOWNLOADING, getter_AddRefs(intLiteral));
gRDFService->GetIntLiteral(aPause ? nsIDownloadManager::DOWNLOAD_PAUSED : nsIDownloadManager::DOWNLOAD_DOWNLOADING, getter_AddRefs(intLiteral));
nsCOMPtr<nsIRDFResource> res;
gRDFService->GetUnicodeResource(nsDependentString(aPath), getter_AddRefs(res));
@ -1280,6 +1286,34 @@ nsDownloadManager::ConfirmCancelDownloads(PRInt32 aCount, nsISupportsPRBool* aCa
}
}
///////////////////////////////////////////////////////////////////////////////
// nsIXPInstallManagerUI
NS_IMETHODIMP
nsDownloadManager::GetXpiProgress(nsIXPIProgressDialog** aProgress)
{
*aProgress = mXPIProgress;
NS_IF_ADDREF(*aProgress);
return NS_OK;
}
NS_IMETHODIMP
nsDownloadManager::AddDownload(nsIDownload* aDownload)
{
if (!mXPIProgress)
mXPIProgress = new nsXPIProgressListener();
mXPIProgress->AddDownload(aDownload);
return NS_OK;
}
NS_IMETHODIMP
nsDownloadManager::GetHasActiveXPIOperations(PRBool* aHasOps)
{
*aHasOps = !mXPIProgress ? PR_FALSE : mXPIProgress->HasActiveXPIOperations();
return NS_OK;
}
#ifdef XP_WIN
///////////////////////////////////////////////////////////////////////////////
// nsIAlertListener
@ -1305,12 +1339,140 @@ nsDownloadManager::OnAlertClickCallback(const PRUnichar* aAlertCookie)
}
#endif
///////////////////////////////////////////////////////////////////////////////
// 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();
mDownloadManager = nsnull;
}
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));
nsDownload* dl = NS_REINTERPRET_CAST(nsDownload*, wpl.get());
switch (aState) {
case nsIXPIProgressDialog::DOWNLOAD_START:
wpl->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_START, 0);
dl->SetDownloadState(nsIXPInstallManagerUI::INSTALL_DOWNLOADING);
AssertProgressInfoForDownload(dl);
break;
case nsIXPIProgressDialog::DOWNLOAD_DONE:
break;
case nsIXPIProgressDialog::INSTALL_START:
dl->SetDownloadState(nsIXPInstallManagerUI::INSTALL_INSTALLING);
AssertProgressInfoForDownload(dl);
break;
case nsIXPIProgressDialog::INSTALL_DONE:
wpl->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP, 0);
dl->SetDownloadState(nsIXPInstallManagerUI::INSTALL_FINISHED);
AssertProgressInfoForDownload(dl);
// Now, remove it from our internal bookkeeping list.
RemoveDownloadAtIndex(aIndex);
break;
case nsIXPIProgressDialog::DIALOG_CLOSE:
// Close now, if we're allowed to.
gObserverService->NotifyObservers(nsnull, "xpinstall-dialog-close", nsnull);
nsCOMPtr<nsIStringBundleService> sbs(do_GetService("@mozilla.org/intl/stringbundle;1"));
nsCOMPtr<nsIStringBundle> brandBundle, xpinstallBundle;
sbs->CreateBundle("chrome://global/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("@mozilla.org/embedcomp/prompt-service;1"));
ps->Alert(nsnull, title, message);
break;
}
return NS_OK;
}
NS_IMETHODIMP
nsXPIProgressListener::OnProgress(PRUint32 aIndex, PRUint32 aValue, PRUint32 aMaxValue)
{
nsCOMPtr<nsIWebProgressListener> wpl(do_QueryElementAt(mDownloads, aIndex));
return wpl->OnProgressChange(nsnull, nsnull, 0, 0, aValue, aMaxValue);
}
void
nsXPIProgressListener::AssertProgressInfoForDownload(nsDownload* aDownload)
{
nsCOMPtr<nsILocalFile> target;
aDownload->GetTarget(getter_AddRefs(target));
nsAutoString path;
target->GetPath(path);
mDownloadManager->AssertProgressInfoFor(path.get());
};
///////////////////////////////////////////////////////////////////////////////
// nsDownload
NS_IMPL_ISUPPORTS2(nsDownload, nsIDownload, nsIWebProgressListener)
nsDownload::nsDownload():mDownloadState(NOTSTARTED),
nsDownload::nsDownload():mDownloadState(nsIDownloadManager::DOWNLOAD_NOTSTARTED),
mPercentComplete(0),
mCurrBytes(0),
mMaxBytes(0),
@ -1441,12 +1603,12 @@ nsDownload::OnProgressChange(nsIWebProgress *aWebProgress,
mLastUpdate = now;
if (mDownloadState == NOTSTARTED) {
if (mDownloadState == nsIDownloadManager::DOWNLOAD_NOTSTARTED) {
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_FAILED(rv)) return rv;
mDownloadState = DOWNLOADING;
mDownloadState = nsIDownloadManager::DOWNLOAD_DOWNLOADING;
mDownloadManager->DownloadStarted(path.get());
}
@ -1483,7 +1645,7 @@ nsDownload::OnStatusChange(nsIWebProgress *aWebProgress,
const PRUnichar *aMessage)
{
if (NS_FAILED(aStatus)) {
mDownloadState = FAILED;
mDownloadState = nsIDownloadManager::DOWNLOAD_FAILED;
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_SUCCEEDED(rv)) {
@ -1534,8 +1696,12 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
// that will close and call CancelDownload if it was the last open window.
nsresult rv = NS_OK;
if (aStateFlags & STATE_STOP) {
if (mDownloadState == DOWNLOADING || mDownloadState == NOTSTARTED) {
mDownloadState = FINISHED;
if (nsDownloadManager::IsInFinalStage(mDownloadState)) {
if (mDownloadState != nsIXPInstallManagerUI::INSTALL_INSTALLING)
mDownloadState = nsIDownloadManager::DOWNLOAD_FINISHED;
else
mDownloadState = nsIXPInstallManagerUI::INSTALL_FINISHED;
// Files less than 1Kb shouldn't show up as 0Kb.
if (mMaxBytes==0)
mMaxBytes = 1;
@ -1646,7 +1812,7 @@ nsDownload::SetDisplayName(const PRUnichar* aDisplayName)
mDisplayName = aDisplayName;
nsCOMPtr<nsIRDFDataSource> ds;
mDownloadManager->GetDataSource(getter_AddRefs(ds));
mDownloadManager->GetDatasource(getter_AddRefs(ds));
nsCOMPtr<nsIRDFLiteral> nameLiteral;
nsCOMPtr<nsIRDFResource> res;
@ -1750,11 +1916,11 @@ nsDownload::Pause(PRBool aPaused)
if (mRequest) {
if (aPaused) {
mRequest->Suspend();
mDownloadState = PAUSED;
mDownloadState = nsIDownloadManager::DOWNLOAD_PAUSED;
}
else {
mRequest->Resume();
mDownloadState = DOWNLOADING;
mDownloadState = nsIDownloadManager::DOWNLOAD_DOWNLOADING;
}
}
}

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

@ -41,6 +41,7 @@
#define downloadmanager___h___
#include "nsIDownloadManager.h"
#include "nsIXPInstallManagerUI.h"
#include "nsIDownloadProgressListener.h"
#include "nsIDownload.h"
#include "nsIRDFDataSource.h"
@ -50,6 +51,7 @@
#include "nsIDOMEventListener.h"
#include "nsIRDFContainerUtils.h"
#include "nsIWebProgressListener.h"
#include "nsIXPIProgressDialog.h"
#include "nsIURI.h"
#include "nsIWebBrowserPersist.h"
#include "nsILocalFile.h"
@ -65,9 +67,13 @@
#include "nsIAlertsService.h"
#endif
enum DownloadState { NOTSTARTED = -1, DOWNLOADING, FINISHED, FAILED, CANCELED, PAUSED };
typedef PRInt16 DownloadState;
class nsXPIProgressListener;
class nsDownload;
class nsDownloadManager : public nsIDownloadManager,
public nsIXPInstallManagerUI,
public nsIObserver
#ifdef XP_WIN
, public nsIAlertListener
@ -76,6 +82,7 @@ class nsDownloadManager : public nsIDownloadManager,
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOWNLOADMANAGER
NS_DECL_NSIXPINSTALLMANAGERUI
NS_DECL_NSIOBSERVER
#ifdef XP_WIN
NS_DECL_NSIALERTLISTENER
@ -90,12 +97,14 @@ public:
static PRInt32 PR_CALLBACK BuildActiveDownloadsList(nsHashKey* aKey, void* aData, void* aClosure);
nsresult DownloadEnded(const PRUnichar* aPersistentDescriptor, const PRUnichar* aMessage);
public:
nsresult AssertProgressInfoFor(const PRUnichar* aPersistentDescriptor);
protected:
nsresult GetDownloadsContainer(nsIRDFContainer** aResult);
nsresult GetProfileDownloadsFileURL(nsCString& aDownloadsFileURL);
nsresult GetDataSource(nsIRDFDataSource** aDataSource);
nsresult DownloadStarted(const PRUnichar* aPersistentDescriptor);
nsresult AssertProgressInfoFor(const PRUnichar* aPersistentDescriptor);
nsresult GetInternalListener(nsIDownloadProgressListener** aListener);
nsresult PauseResumeDownload(const PRUnichar* aPath, PRBool aPause);
nsresult RemoveDownload(nsIRDFResource* aDownload);
@ -113,6 +122,28 @@ protected:
PRBool NeedsUIUpdate() { return mListener != nsnull; }
PRInt32 GetRetentionBehavior();
static PRBool IsInFinalStage(DownloadState aState)
{
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING ||
aState == nsIXPInstallManagerUI::INSTALL_INSTALLING;
};
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;
};
static PRBool CompletedSuccessfully(DownloadState aState)
{
return aState == nsIDownloadManager::DOWNLOAD_FINISHED ||
aState == nsIXPInstallManagerUI::INSTALL_FINISHED;
};
private:
nsCOMPtr<nsIDownloadProgressListener> mListener;
nsCOMPtr<nsIRDFDataSource> mDataSource;
@ -123,9 +154,34 @@ private:
PRInt32 mBatches;
nsHashtable mCurrDownloads;
nsXPIProgressListener* mXPIProgress;
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);
inline void AssertProgressInfoForDownload(nsDownload* aDownload);
private:
nsDownloadManager* mDownloadManager;
nsCOMPtr<nsISupportsArray> mDownloads;
};
class nsDownload : public nsIDownload,
public nsIWebProgressListener
{
@ -137,6 +193,10 @@ public:
nsDownload();
virtual ~nsDownload();
public:
nsresult GetDownloadState(DownloadState* aState);
nsresult SetDownloadState(DownloadState aState);
protected:
nsresult SetDownloadManager(nsDownloadManager* aDownloadManager);
nsresult SetDialogListener(nsIWebProgressListener* aInternalListener);
@ -147,8 +207,6 @@ protected:
nsresult SetTarget(nsILocalFile* aTarget);
nsresult SetSource(nsIURI* aSource);
nsresult GetTransferInformation(PRInt32* aCurr, PRInt32* aMax);
nsresult GetDownloadState(DownloadState* aState);
nsresult SetDownloadState(DownloadState aState);
nsresult SetMIMEInfo(nsIMIMEInfo* aMIMEInfo);
nsresult SetStartTime(PRInt64 aStartTime);

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

@ -205,7 +205,12 @@ var gDownloadObserver = {
var installObserver = windowArgs.QueryElementAt(1, Components.interfaces.nsISupportsInterfacePointer);
installObserver = installObserver.data.QueryInterface(Components.interfaces.nsIObserver);
XPInstallDownloadManager.addDownloads(params, installObserver);
break;
break;
case "xpinstall-dialog-close":
var mgr = gDownloadManager.QueryInterface(Components.interfaces.nsIXPInstallManagerUI);
gCanAutoClose = mgr.hasActiveXPIOperations;
autoClose();
break;
}
}
};
@ -434,16 +439,18 @@ function Startup()
observerService.addObserver(gDownloadObserver, "dl-done", false);
observerService.addObserver(gDownloadObserver, "dl-cancel", false);
observerService.addObserver(gDownloadObserver, "dl-failed", false);
observerService.addObserver(gDownloadObserver, "dl-start", 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);
gCanAutoClose = false;
XPInstallDownloadManager.addDownloads(params, installObserver);
var mgr = gDownloadManager.QueryInterface(Components.interfaces.nsIXPInstallManagerUI);
gCanAutoClose = mgr.hasActiveXPIOperations;
}
catch (e) { }
}
@ -479,16 +486,6 @@ function Shutdown()
// XPInstall
var XPInstallDownloadManager = {
_XPInstallDownloads: [],
_XPInstallProgressListener: null,
init: function ()
{
this._XPInstallProgressListener = new XPInstallProgressListener(this._XPInstallDownloads);
},
addDownloads: function (aParams, aObserver)
{
var numXPInstallItems = aParams.GetInt(1);
@ -498,6 +495,8 @@ var XPInstallDownloadManager = {
var mimeService = Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"].getService(Components.interfaces.nsIMIMEService);
var xpinstallManager = gDownloadManager.QueryInterface(Components.interfaces.nsIXPInstallManagerUI);
var xpiString = "";
for (var i = 0; i < numXPInstallItems;) {
// Pretty Name
@ -520,86 +519,16 @@ var XPInstallDownloadManager = {
var mimeInfo = mimeService.getFromTypeAndExtension(null, url.fileExtension);
var download = gDownloadManager.addDownload(uri, localTarget, displayName, mimeInfo, 0, null);
this._XPInstallDownloads.push(download);
xpinstallManager.addDownload(download);
// Advance the enumerator
var certName = aParams.GetString(i++);
}
// Store the list of things we're downloading so we can reinitialize the FE
// properly if the window is closed and then reopened.
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var str = Components.classes["@mozilla.org/pref-localizedstring;1"].createInstance(Components.interfaces.nsIPrefLocalizedString);
str.data = xpiString;
pref.setComplexValue(PREF_BDM_CLOSEWHENDONE, Components.interfaces.nsIPrefLocalizedString, str);
aObserver.observe(this._XPInstallProgressListener, "xpinstall-progress", "open");
aObserver.observe(xpinstallManager.xpiProgress, "xpinstall-progress", "open");
}
}
function XPInstallProgressListener(aDownloads)
{
this._XPInstallDownloads = aDownloads;
}
// implements nsIXPIProgressDialog
XPInstallProgressListener.prototype = {
onStateChange: function (aIndex, aState, aValue)
{
const nsIXPIPD = Components.interfaces.nsIXPIProgressDialog;
const nsIWPL = Components.interfaces.nsIWebProgressListener;
var wpl = this._XPInstallDownloads[aIndex].QueryInterface(nsIWPL);
switch (aState) {
case nsIXPIPD.DOWNLOAD_START:
wpl.onStateChange(null, null, nsIWPL.STATE_START, 0);
break;
case nsIXPIPD.DOWNLOAD_DONE:
break;
case nsIXPIPD.INSTALL_START:
break;
case nsIXPIPD.INSTALL_DONE:
wpl.onStateChange(null, null, nsIWPL.STATE_STOP, 0);
break;
case nsIXPIPD.DIALOG_CLOSE:
// Close now, if we're allowed to.
gCanAutoClose = true;
var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
var brandBundle = sbs.createBundle("chrome://global/locale/brand.properties");
var xpinstallBundle = sbs.createBundle("chrome://mozapps/locale/xpinstall/xpinstallConfirm.properties");
var brandShortName = brandBundle.GetStringFromName("brandShortName");
var message = xpinstallBundle.formatStringFromName("installComplete", [brandShortName], 1);
var title = xpinstallBundle.GetStringFromName("installCompleteTitle");
var promptSvc = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
promptSvc.alert(null, title, message);
autoClose();
break;
}
},
onProgress: function (aIndex, aValue, aMaxValue)
{
const nsIWPL = Components.interfaces.nsIWebProgressListener;
var wpl = this._XPInstallDownloads[aIndex].QueryInterface(nsIWPL);
wpl.onProgressChange(null, null, 0, 0, aValue, aMaxValue);
},
QueryInterface: function( iid )
{
if (!iid.equals(Components.interfaces.nsISupports) &&
!iid.equals(Components.interfaces.nsIXPIProgressDialog))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
///////////////////////////////////////////////////////////////////////////////
// View Context Menus
var gContextMenus = [