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/. */ 6 7 #ifndef mozilla_mscom_MainThreadRuntime_h 8 #define mozilla_mscom_MainThreadRuntime_h 9 10 #include "mozilla/Attributes.h" 11 #if defined(ACCESSIBILITY) 12 #include "mozilla/mscom/ActivationContext.h" 13 #endif // defined(ACCESSIBILITY) 14 #include "mozilla/mscom/COMApartmentRegion.h" 15 #include "mozilla/mscom/MainThreadClientInfo.h" 16 #include "mozilla/RefPtr.h" 17 18 namespace mozilla { 19 namespace mscom { 20 21 class MOZ_NON_TEMPORARY_CLASS MainThreadRuntime { 22 public: 23 MainThreadRuntime(); 24 ~MainThreadRuntime(); 25 26 explicit operator bool() const { 27 return mStaRegion.IsValidOutermost() && SUCCEEDED(mInitResult); 28 } 29 30 MainThreadRuntime(MainThreadRuntime&) = delete; 31 MainThreadRuntime(MainThreadRuntime&&) = delete; 32 MainThreadRuntime& operator=(MainThreadRuntime&) = delete; 33 MainThreadRuntime& operator=(MainThreadRuntime&&) = delete; 34 35 /** 36 * @return 0 if call is in-process or resolving the calling thread failed, 37 * otherwise contains the thread id of the calling thread. 38 */ 39 static DWORD GetClientThreadId(); 40 41 private: 42 HRESULT InitializeSecurity(); 43 44 HRESULT mInitResult; 45 #if defined(ACCESSIBILITY) 46 ActivationContextRegion mActCtxRgn; 47 #endif // defined(ACCESSIBILITY) 48 STARegion mStaRegion; 49 50 RefPtr<MainThreadClientInfo> mClientInfo; 51 52 static MainThreadRuntime* sInstance; 53 }; 54 55 } // namespace mscom 56 } // namespace mozilla 57 58 #endif // mozilla_mscom_MainThreadRuntime_h 59