Bug 950288 - Update the last run id when the browser launches so it's always up to date. r=bbondy a=lsblakk
authorJim Mathies <jmathies@mozilla.com>
Mon, 16 Dec 2013 11:06:08 -0600
changeset 175393 14d5fa456121d254dbacb0980f92c9c5f68c7a45
parent 175392 324520eef2398fb6e0a13fff2bbb65098babc366
child 175394 a380a4c5d8cc6b9892397173450619d7e21e3d99
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
bugs950288
milestone28.0a2
Bug 950288 - Update the last run id when the browser launches so it's always up to date. r=bbondy a=lsblakk
browser/metro/shell/commandexecutehandler/CEHHelper.cpp
browser/metro/shell/commandexecutehandler/CommandExecuteHandler.cpp
toolkit/xre/nsAppRunner.cpp
--- a/browser/metro/shell/commandexecutehandler/CEHHelper.cpp
+++ b/browser/metro/shell/commandexecutehandler/CEHHelper.cpp
@@ -103,34 +103,32 @@ IsProcessRunning(const wchar_t *processN
       }
     }
   }
 
   CloseHandle(snapshot);
   return exists;
 }
 
-
+/*
+ * Retrieve the last front end ui we launched so we can target it
+ * again. This value is updated down in nsAppRunner when the browser
+ * starts up.
+ */
 AHE_TYPE
 GetLastAHE()
 {
   DWORD ahe;
   if (GetDWORDRegKey(metroLastAHE, ahe)) {
     return (AHE_TYPE) ahe;
   }
   return AHE_DESKTOP;
 }
 
 bool
-SetLastAHE(AHE_TYPE ahe)
-{
-  return SetDWORDRegKey(metroLastAHE, (DWORD) ahe);
-}
-
-bool
 IsDX10Available()
 {
   DWORD isDX10Available;
   if (GetDWORDRegKey(metroDX10Available, isDX10Available)) {
     return isDX10Available;
   }
 
   HMODULE dxgiModule = LoadLibraryA("dxgi.dll");
--- a/browser/metro/shell/commandexecutehandler/CommandExecuteHandler.cpp
+++ b/browser/metro/shell/commandexecutehandler/CommandExecuteHandler.cpp
@@ -15,17 +15,16 @@
 #include <shlwapi.h>
 #include <propkey.h>
 #include <propvarutil.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <strsafe.h>
 #include <io.h>
 #include <shellapi.h>
-#include <wininet.h>
 
 #ifdef SHOW_CONSOLE
 #define DEBUG_DELAY_SHUTDOWN 1
 #endif
 
 // Heartbeat timer duration used while waiting for an incoming request.
 #define HEARTBEAT_MSEC 1000
 // Total number of heartbeats we wait before giving up and shutting down.
@@ -259,23 +258,24 @@ public:
   }
 
   // IExecuteCommandApplicationHostEnvironment
   IFACEMETHODIMP GetValue(AHE_TYPE *aLaunchType)
   {
     Log(L"IExecuteCommandApplicationHostEnvironment::GetValue()");
     *aLaunchType = GetLaunchType();
     mIsDesktopRequest = (*aLaunchType == AHE_DESKTOP);
-    SetLastAHE(*aLaunchType);
     return S_OK;
   }
 
   /**
    * Choose the appropriate launch type based on the user's previously chosen
    * host environment, along with system constraints.
+   * AHE_DESKTOP	= 0
+   * AHE_IMMERSIVE	= 1
    */
   AHE_TYPE GetLaunchType() {
     AHE_TYPE ahe = GetLastAHE();
     Log(L"Previous AHE: %d", ahe);
 
     if (!mIsRestartMetroRequest && IsProcessRunning(kFirefoxExe, false)) {
       Log(L"Returning AHE_DESKTOP because desktop is already running");
       return AHE_DESKTOP;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4217,16 +4217,46 @@ 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;
@@ -4284,16 +4314,19 @@ 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;