Bug 950241 - Update app runners last run settings to support desktop updating from metro. r=bbondy, a=lsblakk
authorJim Mathies <jmathies@mozilla.com>
Thu, 30 Jan 2014 13:32:49 -0600
changeset 176264 138ec444b4e3b18eb3036cbb61c1cb0c034dc690
parent 176263 5d2ffbeb04f7d73db1db35e0274b96f14d62087b
child 176265 870cd04b8bfd29a6471a8db68eafadaf8765a833
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy, lsblakk
bugs950241
milestone28.0
Bug 950241 - Update app runners last run settings to support desktop updating from metro. r=bbondy, a=lsblakk
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2790,16 +2790,48 @@ static DWORD InitDwriteBG(LPVOID lpdwThr
   return 0;
 }
 #endif
 
 #ifdef USE_GLX_TEST
 bool fire_glxtest_process();
 #endif
 
+#if defined(XP_WIN) && defined(MOZ_METRO)
+#ifndef AHE_TYPE
+enum AHE_TYPE {
+  AHE_DESKTOP = 0,
+  AHE_IMMERSIVE = 1
+};
+#endif
+
+/*
+ * The Windows launcher uses this value to decide what front end ui
+ * to launch. We always launch the same ui unless the user
+ * specifically asks to switch. Update the value on every startup
+ * based on the environment requested.
+ */
+void
+SetLastWinRunType(AHE_TYPE aType)
+{
+  HKEY key;
+  LONG result = RegOpenKeyExW(HKEY_CURRENT_USER,
+                              L"SOFTWARE\\Mozilla\\Firefox",
+                              0, KEY_WRITE, &key);
+  if (result != ERROR_SUCCESS) {
+    return;
+  }
+  DWORD value = (DWORD)aType;
+  result = RegSetValueEx(key, L"MetroLastAHE", 0, REG_DWORD,
+                         reinterpret_cast<LPBYTE>(&value),
+                         sizeof(DWORD));
+  RegCloseKey(key);
+}
+#endif // defined(XP_WIN) && defined(MOZ_METRO)
+
 #include "GeckoProfiler.h"
 
 // Encapsulates startup and shutdown state for XRE_main
 class XREMain
 {
 public:
   XREMain() :
     mScopedXPCom(nullptr)
@@ -2883,16 +2915,29 @@ XREMain::XRE_mainInit(bool* aExitFlag)
   // don't want the user to see its crashes. That's the whole reason for
   // doing this in a separate process.
   if (fire_glxtest_process()) {
     *aExitFlag = true;
     return 0;
   }
 #endif
 
+#if defined(XP_WIN) && defined(MOZ_METRO)
+  // Don't remove this arg, we want to pass it on to nsUpdateDriver 
+  if (CheckArg("metro-update", false, nullptr, false) == ARG_FOUND ||
+      XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
+    // If we're doing a restart update that was initiated from metro land,
+    // we'll be running desktop to handle the actual update. Request that
+    // after the restart we launch into metro.
+    SetLastWinRunType(AHE_IMMERSIVE);
+  } else {
+    SetLastWinRunType(AHE_DESKTOP);
+  }
+#endif
+
   SetupErrorHandling(gArgv[0]);
 
 #ifdef CAIRO_HAS_DWRITE_FONT
   {
     // Bug 602792 - when DWriteCreateFactory is called the dwrite client dll
     // starts the FntCache service if it isn't already running (it's set
     // to manual startup by default in Windows 7 RTM).  Subsequent DirectWrite
     // calls cause the IDWriteFactory object to communicate with the FntCache
@@ -3619,16 +3664,22 @@ XREMain::XRE_mainStartup(bool* aExitFlag
                  gRestartArgc,
                  gRestartArgv,
                  mAppData->version);
   if (EnvHasValue("MOZ_PROCESS_UPDATES")) {
     SaveToEnv("MOZ_PROCESS_UPDATES=");
     *aExitFlag = true;
     return 0;
   }
+#if defined(XP_WIN) && defined(MOZ_METRO)
+  if (CheckArg("metro-update", false) == ARG_FOUND) {
+    *aExitFlag = true;
+    return 0;
+  }
+#endif
 #endif
 
   rv = NS_NewToolkitProfileService(getter_AddRefs(mProfileSvc));
   if (rv == NS_ERROR_FILE_ACCESS_DENIED) {
     PR_fprintf(PR_STDERR, "Error: Access was denied while trying to open files in " \
                 "your profile directory.\n");
   }
   if (NS_FAILED(rv)) {
@@ -4217,46 +4268,16 @@ public:
   ~WinRTInitWrapper() {
     if (SUCCEEDED(mResult)) {
       ::RoUninitialize();
     }
   }
   HRESULT mResult;
 };
 
-#ifndef AHE_TYPE
-enum AHE_TYPE {
-  AHE_DESKTOP = 0,
-  AHE_IMMERSIVE = 1
-};
-#endif
-
-/*
- * The Windows launcher uses this value to decide what front end ui
- * to launch. We always launch the same ui unless the user
- * specifically asks to switch. Update the value on every startup
- * based on the environment requested.
- */
-void
-SetLastWinRunType(AHE_TYPE aType)
-{
-  HKEY key;
-  LONG result = RegOpenKeyExW(HKEY_CURRENT_USER,
-                              L"SOFTWARE\\Mozilla\\Firefox",
-                              0, KEY_WRITE, &key);
-  if (result != ERROR_SUCCESS) {
-    return;
-  }
-  DWORD value = (DWORD)aType;
-  result = RegSetValueEx(key, L"MetroLastAHE", 0, REG_DWORD,
-                         reinterpret_cast<LPBYTE>(&value),
-                         sizeof(DWORD));
-  RegCloseKey(key);
-}
-
 int
 XRE_mainMetro(int argc, char* argv[], const nsXREAppData* aAppData)
 {
   char aLocal;
   GeckoProfilerInitRAII profilerGuard(&aLocal);
   PROFILER_LABEL("Startup", "XRE_Main");
 
   nsresult rv = NS_OK;
@@ -4314,33 +4335,32 @@ XRE_main(int argc, char* argv[], const n
 #if !defined(MOZ_METRO) || !defined(XP_WIN)
   XREMain main;
   int result = main.XRE_main(argc, argv, aAppData);
   mozilla::RecordShutdownEndTimeStamp();
   return result;
 #else
   if (aFlags == XRE_MAIN_FLAG_USE_METRO) {
     SetWindowsEnvironment(WindowsEnvironmentType_Metro);
-    SetLastWinRunType(AHE_IMMERSIVE);
-  } else {
-    SetLastWinRunType(AHE_DESKTOP);
   }
 
   // Desktop
   if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
     XREMain main;
     int result = main.XRE_main(argc, argv, aAppData);
     mozilla::RecordShutdownEndTimeStamp();
     return result;
   }
 
   // Metro
   NS_ASSERTION(XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro,
                "Unknown Windows environment");
 
+  SetLastWinRunType(AHE_IMMERSIVE);
+
   int result = XRE_mainMetro(argc, argv, aAppData);
   mozilla::RecordShutdownEndTimeStamp();
   return result;
 #endif // MOZ_METRO || !defined(XP_WIN)
 }
 
 nsresult
 XRE_InitCommandLine(int aArgc, char* aArgv[])