1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_mscom_ProcessRuntime_h
8 #define mozilla_mscom_ProcessRuntime_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/mscom/ApartmentRegion.h"
12 #include "nsWindowsHelpers.h"
13 #if defined(MOZILLA_INTERNAL_API)
14 # include "nsXULAppAPI.h"
15 #endif // defined(MOZILLA_INTERNAL_API)
20 class MOZ_NON_TEMPORARY_CLASS ProcessRuntime final
{
21 #if !defined(MOZILLA_INTERNAL_API)
23 #endif // defined(MOZILLA_INTERNAL_API)
24 enum class ProcessCategory
{
26 // We give Launcher its own process category, but internally to this class
27 // it should be treated identically to GeckoBrowserParent.
28 Launcher
= GeckoBrowserParent
,
33 // This constructor is only public when compiled outside of XUL
34 explicit ProcessRuntime(const ProcessCategory aProcessCategory
);
37 #if defined(MOZILLA_INTERNAL_API)
41 ~ProcessRuntime() = default;
42 #endif // defined(MOZILLA_INTERNAL_API)
44 explicit operator bool() const { return SUCCEEDED(mInitResult
); }
45 HRESULT
GetHResult() const { return mInitResult
; }
47 ProcessRuntime(const ProcessRuntime
&) = delete;
48 ProcessRuntime(ProcessRuntime
&&) = delete;
49 ProcessRuntime
& operator=(const ProcessRuntime
&) = delete;
50 ProcessRuntime
& operator=(ProcessRuntime
&&) = delete;
53 * @return 0 if call is in-process or resolving the calling thread failed,
54 * otherwise contains the thread id of the calling thread.
56 static DWORD
GetClientThreadId();
59 #if defined(MOZILLA_INTERNAL_API)
60 explicit ProcessRuntime(const GeckoProcessType aProcessType
);
61 # if defined(MOZ_SANDBOX)
62 void InitUsingPersistentMTAThread(const nsAutoHandle
& aCurThreadToken
);
63 # endif // defined(MOZ_SANDBOX)
64 #endif // defined(MOZILLA_INTERNAL_API)
65 void InitInsideApartment();
67 #if defined(MOZILLA_INTERNAL_API)
68 static void PostInit();
69 #endif // defined(MOZILLA_INTERNAL_API)
70 static HRESULT
InitializeSecurity(const ProcessCategory aProcessCategory
);
71 static COINIT
GetDesiredApartmentType(const ProcessCategory aProcessCategory
);
75 const ProcessCategory mProcessCategory
;
76 ApartmentRegion mAptRegion
;
79 #if defined(MOZILLA_INTERNAL_API)
80 static ProcessRuntime
* sInstance
;
81 #endif // defined(MOZILLA_INTERNAL_API)
85 } // namespace mozilla
87 #endif // mozilla_mscom_ProcessRuntime_h