Bug 1197974 - Don't exit Gecko on Android even if there's no window; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 18 Sep 2015 09:17:10 -0400
changeset 297546 007b7970b6c8e67cdfe88e0a1f75f9e7b6735ce6
parent 297545 5e86358d4ec223fbaa00177add41c9f33055f827
child 297547 e13fd468953ba2cbcecb0b272cecba8256d3daa8
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1197974
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1197974 - Don't exit Gecko on Android even if there's no window; r=snorp Gecko on Android follows the Android app model where it never stops until it is killed by the system or told explicitly to quit. Therefore, we should exit Gecko when there is no window or the last window is closed.
widget/android/nsAppShell.cpp
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -23,16 +23,17 @@
 #include "nsIDOMClientRect.h"
 #include "nsIDOMWakeLockListener.h"
 #include "nsIPowerManagerService.h"
 #include "nsINetworkLinkService.h"
 #include "nsISpeculativeConnect.h"
 #include "nsIURIFixup.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsCDefaultURIFixup.h"
+#include "nsToolkitCompsCID.h"
 
 #include "mozilla/HangMonitor.h"
 #include "mozilla/Services.h"
 #include "mozilla/unused.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Hal.h"
 #include "prenv.h"
 
@@ -270,28 +271,42 @@ nsAppShell::Observe(nsISupports* aSubjec
                     const char* aTopic,
                     const char16_t* aData)
 {
     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.
         mObserversHash.Clear();
         return nsBaseAppShell::Observe(aSubject, aTopic, aData);
+
     } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) &&
                aData &&
                nsDependentString(aData).Equals(NS_LITERAL_STRING(PREFNAME_COALESCE_TOUCHES))) {
         mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
         return NS_OK;
+
     } else if (!strcmp(aTopic, "browser-delayed-startup-finished")) {
         NS_CreateServicesFromCategory("browser-delayed-startup-finished", nullptr,
                                       "browser-delayed-startup-finished");
+
     } else if (!strcmp(aTopic, "profile-do-change")) {
         if (jni::IsAvailable()) {
             widget::GeckoThread::SetState(
                     widget::GeckoThread::State::PROFILE_READY());
+
+            // Gecko on Android follows the Android app model where it never
+            // stops until it is killed by the system or told explicitly to
+            // quit. Therefore, we should *not* exit Gecko when there is no
+            // window or the last window is closed. nsIAppStartup::Quit will
+            // still force Gecko to exit.
+            nsCOMPtr<nsIAppStartup> appStartup =
+                do_GetService(NS_APPSTARTUP_CONTRACTID);
+            if (appStartup) {
+                appStartup->EnterLastWindowClosingSurvivalArea();
+            }
         }
         nsCOMPtr<nsIObserverService> obsServ =
             mozilla::services::GetObserverService();
         if (obsServ) {
             obsServ->RemoveObserver(this, "profile-do-change");
         }
     }
     return NS_OK;