Bug 1211919 - Allow quitting when asked explicitly; r=snorp

Right now we don't allow quitting Fennec when the last nsWindow closes
(e.g. when the last GeckoView is destroyed) because we want to keep the
Gecko thread running throughout the app process lifetime. However, when
we are asked to quit explicitly through nsIAppStartup::Quit, we should
release the hold on nsAppStartup and allow quitting to continue.
This commit is contained in:
Jim Chen 2015-10-15 15:49:48 -04:00
Родитель 00126a9fa0
Коммит 13b339824b
1 изменённых файлов: 21 добавлений и 1 удалений

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

@ -255,6 +255,7 @@ nsAppShell::Init()
if (obsServ) {
obsServ->AddObserver(this, "browser-delayed-startup-finished", false);
obsServ->AddObserver(this, "profile-after-change", false);
obsServ->AddObserver(this, "quit-application-granted", false);
obsServ->AddObserver(this, "xpcom-shutdown", false);
}
@ -271,6 +272,8 @@ nsAppShell::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData)
{
bool removeObserver = false;
if (!strcmp(aTopic, "xpcom-shutdown")) {
// We need to ensure no observers stick around after XPCOM shuts down
// or we'll see crashes, as the app shell outlives XPConnect.
@ -303,10 +306,27 @@ nsAppShell::Observe(nsISupports* aSubject,
appStartup->EnterLastWindowClosingSurvivalArea();
}
}
removeObserver = true;
} else if (!strcmp(aTopic, "quit-application-granted")) {
if (jni::IsAvailable()) {
// We are told explicitly to quit, perhaps due to
// nsIAppStartup::Quit being called. We should release our hold on
// nsIAppStartup and let it continue to quit.
nsCOMPtr<nsIAppStartup> appStartup =
do_GetService(NS_APPSTARTUP_CONTRACTID);
if (appStartup) {
appStartup->ExitLastWindowClosingSurvivalArea();
}
}
removeObserver = true;
}
if (removeObserver) {
nsCOMPtr<nsIObserverService> obsServ =
mozilla::services::GetObserverService();
if (obsServ) {
obsServ->RemoveObserver(this, "profile-after-change");
obsServ->RemoveObserver(this, aTopic);
}
}
return NS_OK;