diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index fa159243e1f..6186a7712c9 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -69,7 +69,7 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); -static PRBool gEnumeratingDownloads = PR_FALSE; +static PRBool gStoppingDownloads = PR_FALSE; #define DOWNLOAD_MANAGER_FE_URL "chrome://mozapps/content/downloads/downloads.xul" #define DOWNLOAD_MANAGER_BUNDLE "chrome://mozapps/locale/downloads/downloads.properties" @@ -266,7 +266,7 @@ nsDownloadManager::DownloadEnded(const PRUnichar* aPath, const PRUnichar* aMessa nsDownload* download = NS_STATIC_CAST(nsDownload*, mCurrDownloads.Get(&key)); NS_RELEASE(download); - if (!gEnumeratingDownloads) + if (!gStoppingDownloads) mCurrDownloads.Remove(&key); } @@ -1169,7 +1169,7 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn } } else if (nsCRT::strcmp(aTopic, "quit-application") == 0 && mCurrDownloads.Count()) { - gEnumeratingDownloads = PR_TRUE; + gStoppingDownloads = PR_TRUE; mCurrDownloads.Enumerate(CancelAllDownloads, this); // Download Manager is shutting down! Tell the XPInstallManager to stop @@ -1249,9 +1249,14 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn PRBool data; cancelDownloads->GetData(&data); if (!data) { - gEnumeratingDownloads = PR_TRUE; + gStoppingDownloads = PR_TRUE; + + // Network is going down! Tell the XPInstallManager to stop + // transferring any files that may have been being downloaded. + gObserverService->NotifyObservers(mXPIProgress, "xpinstall-progress", NS_LITERAL_STRING("cancel").get()); + mCurrDownloads.Enumerate(CancelAllDownloads, this); - gEnumeratingDownloads = PR_FALSE; + gStoppingDownloads = PR_FALSE; } } return NS_OK; @@ -1440,19 +1445,21 @@ nsXPIProgressListener::OnStateChange(PRUint32 aIndex, PRInt16 aState, PRInt32 aV // Close now, if we're allowed to. gObserverService->NotifyObservers(nsnull, "xpinstall-dialog-close", nsnull); - nsCOMPtr sbs(do_GetService("@mozilla.org/intl/stringbundle;1")); - nsCOMPtr brandBundle, xpinstallBundle; - sbs->CreateBundle("chrome://global/locale/brand.properties", getter_AddRefs(brandBundle)); - sbs->CreateBundle("chrome://mozapps/locale/xpinstall/xpinstallConfirm.properties", getter_AddRefs(xpinstallBundle)); + if (!gStoppingDownloads) { + nsCOMPtr sbs(do_GetService("@mozilla.org/intl/stringbundle;1")); + nsCOMPtr 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)); + 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 ps(do_GetService("@mozilla.org/embedcomp/prompt-service;1")); - ps->Alert(nsnull, title, message); + nsCOMPtr ps(do_GetService("@mozilla.org/embedcomp/prompt-service;1")); + ps->Alert(nsnull, title, message); + } break; } diff --git a/toolkit/mozapps/downloads/content/downloads.js b/toolkit/mozapps/downloads/content/downloads.js index 18d3cf0803a..89a7728e3fd 100644 --- a/toolkit/mozapps/downloads/content/downloads.js +++ b/toolkit/mozapps/downloads/content/downloads.js @@ -530,7 +530,9 @@ var XPInstallDownloadManager = { var certName = aParams.GetString(i++); } - aObserver.observe(xpinstallManager.xpiProgress, "xpinstall-progress", "open"); + var observerService = Components.classes[kObserverServiceProgID] + .getService(Components.interfaces.nsIObserverService); + observerService.notifyObservers(xpinstallManager.xpiProgress, "xpinstall-progress", "open"); } }