Bug 1530809: Make LaunchElevated use mscom::ProcessRuntime instead of mscom::STARegion; r=mhowell
authorAaron Klotz <aklotz@mozilla.com>
Tue, 26 Feb 2019 21:40:59 +0000
changeset 519376 a20d059fc98bb69acfbe2c18b9a51ba8b920d072
parent 519375 5be3bd53aaade28dbe7c92f1c6174fd303fda3bf
child 519377 b09405c05c7b4e41cccb1fe225010a851c48744f
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1530809
milestone67.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 1530809: Make LaunchElevated use mscom::ProcessRuntime instead of mscom::STARegion; r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D21261
browser/app/winlauncher/LaunchUnelevated.cpp
ipc/mscom/ProcessRuntime.h
--- a/browser/app/winlauncher/LaunchUnelevated.cpp
+++ b/browser/app/winlauncher/LaunchUnelevated.cpp
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
 
 #include "LaunchUnelevated.h"
 
 #include "mozilla/Assertions.h"
 #include "mozilla/CmdLineAndEnvUtils.h"
 #include "mozilla/LauncherResult.h"
-#include "mozilla/mscom/ApartmentRegion.h"
+#include "mozilla/mscom/ProcessRuntime.h"
 #include "mozilla/RefPtr.h"
 #include "nsWindowsHelpers.h"
 
 // For _bstr_t and _variant_t
 #include <comdef.h>
 #include <comutil.h>
 
 #include <windows.h>
@@ -97,20 +97,21 @@ namespace mozilla {
 // user's normal integrity level. We do this by locating the active explorer
 // shell, and then asking it to do a ShellExecute on our behalf. We do it this
 // way to ensure that the child process runs as the original user in the active
 // session; an elevated process could be running with different credentials than
 // those of the session.
 // See https://blogs.msdn.microsoft.com/oldnewthing/20131118-00/?p=2643
 
 LauncherVoidResult LaunchUnelevated(int aArgc, wchar_t* aArgv[]) {
-  // We require a single-threaded apartment to talk to Explorer.
-  mscom::STARegion sta;
-  if (!sta.IsValid()) {
-    return LAUNCHER_ERROR_FROM_HRESULT(sta.GetHResult());
+  // We need COM to talk to Explorer. Using ProcessRuntime so that
+  // process-global COM configuration is done correctly
+  mozilla::mscom::ProcessRuntime mscom(GeckoProcessType_Default);
+  if (!mscom) {
+    return LAUNCHER_ERROR_FROM_HRESULT(mscom.GetHResult());
   }
 
   // NB: Explorer is a local server, not an inproc server
   RefPtr<IShellWindows> shellWindows;
   HRESULT hr =
       ::CoCreateInstance(CLSID_ShellWindows, nullptr, CLSCTX_LOCAL_SERVER,
                          IID_IShellWindows, getter_AddRefs(shellWindows));
   if (FAILED(hr)) {
--- a/ipc/mscom/ProcessRuntime.h
+++ b/ipc/mscom/ProcessRuntime.h
@@ -22,16 +22,17 @@ class MOZ_NON_TEMPORARY_CLASS ProcessRun
 #if defined(MOZILLA_INTERNAL_API)
   ProcessRuntime() : ProcessRuntime(XRE_GetProcessType()) {}
 #endif  // defined(MOZILLA_INTERNAL_API)
 
   explicit ProcessRuntime(GeckoProcessType aProcessType);
   ~ProcessRuntime() = default;
 
   explicit operator bool() const { return SUCCEEDED(mInitResult); }
+  HRESULT GetHResult() const { return mInitResult; }
 
   ProcessRuntime(ProcessRuntime&) = delete;
   ProcessRuntime(ProcessRuntime&&) = delete;
   ProcessRuntime& operator=(ProcessRuntime&) = delete;
   ProcessRuntime& operator=(ProcessRuntime&&) = delete;
 
   /**
    * @return 0 if call is in-process or resolving the calling thread failed,