make setting the default app on windows synchronous, so we can do instrumentation of it, r=sid0, bug 632639
authorDavid Bienvenu <bienvenu@nventure.com>
Fri, 11 Mar 2011 13:39:38 -0800
changeset 7328 fde57bc11aca6d31187328ae3019c00ff6aec21b
parent 7327 3b55dfd8506eb206c8145d81ef7d835f78418e2e
child 7329 1e34839acfdd4e83ab80d44693e555285668407b
push idunknown
push userunknown
push dateunknown
reviewerssid0, bug
bugs632639
make setting the default app on windows synchronous, so we can do instrumentation of it, r=sid0, bug 632639
mail/components/shell/nsMailWinIntegration.cpp
--- a/mail/components/shell/nsMailWinIntegration.cpp
+++ b/mail/components/shell/nsMailWinIntegration.cpp
@@ -216,42 +216,49 @@ nsWindowsShellService::SetDefaultClient(
 
   rv = appHelper->AppendNative(NS_LITERAL_CSTRING("helper.exe"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString appHelperPath;
   rv = appHelper->GetPath(appHelperPath);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  nsAutoString params;
   if (aForAllUsers)
   {
-    appHelperPath.AppendLiteral(" /SetAsDefaultAppGlobal");
+    params.AppendLiteral(" /SetAsDefaultAppGlobal");
   }
   else
   {
-    appHelperPath.AppendLiteral(" /SetAsDefaultAppUser");
+    params.AppendLiteral(" /SetAsDefaultAppUser");
     if (aApps & nsIShellService::MAIL)
-      appHelperPath.AppendLiteral(" Mail");
+      params.AppendLiteral(" Mail");
 
     if (aApps & nsIShellService::NEWS)
-      appHelperPath.AppendLiteral(" News");
+      params.AppendLiteral(" News");
   }
 
-  STARTUPINFOW si = {sizeof(si), 0};
-  PROCESS_INFORMATION pi = {0};
-
-  BOOL ok = CreateProcessW(NULL, (LPWSTR)appHelperPath.get(), NULL, NULL,
-                           FALSE, 0, NULL, NULL, &si, &pi);
+  SHELLEXECUTEINFOW executeInfo = {0};
 
-  if (!ok)
-    return NS_ERROR_FAILURE;
+  executeInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
+  executeInfo.hwnd = NULL;
+  executeInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
+  executeInfo.lpDirectory = NULL;
+  executeInfo.lpFile = appHelperPath.get();
+  executeInfo.lpParameters = params.get();
+  executeInfo.nShow = SW_SHOWNORMAL;
 
-  CloseHandle(pi.hProcess);
-  CloseHandle(pi.hThread);
+  if (ShellExecuteExW(&executeInfo))
+    // Block until the program exits
+    WaitForSingleObject(executeInfo.hProcess, INFINITE);
+  else
+    return NS_ERROR_ABORT;
 
+  // We're going to ignore errors here since there's nothing we can do about
+  // them, and helper.exe seems to return non-zero ret on success.
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowsShellService::GetShouldCheckDefaultClient(PRBool* aResult)
 {
   if (mCheckedThisSession)
   {