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_ActivationContext_h
8 #define mozilla_mscom_ActivationContext_h
12 #include "mozilla/Attributes.h"
13 #include "mozilla/mscom/ActCtxResource.h"
15 #if defined(MOZILLA_INTERNAL_API)
16 # include "mozilla/ResultVariant.h"
17 # include "nsString.h"
18 #endif // defined(MOZILLA_INTERNAL_API)
25 class ActivationContext final
{
27 // This is the default resource ID that the Windows dynamic linker searches
28 // for when seeking a manifest while loading a DLL.
29 static constexpr WORD kDllManifestDefaultResourceId
= 2;
31 ActivationContext() : mActCtx(INVALID_HANDLE_VALUE
) {}
33 explicit ActivationContext(ActCtxResource aResource
);
34 explicit ActivationContext(HMODULE aLoadFromModule
,
35 WORD aResourceId
= kDllManifestDefaultResourceId
);
37 ActivationContext(ActivationContext
&& aOther
);
38 ActivationContext
& operator=(ActivationContext
&& aOther
);
40 ActivationContext(const ActivationContext
& aOther
);
41 ActivationContext
& operator=(const ActivationContext
& aOther
);
45 explicit operator bool() const { return mActCtx
!= INVALID_HANDLE_VALUE
; }
47 #if defined(MOZILLA_INTERNAL_API)
48 static Result
<uintptr_t, HRESULT
> GetCurrent();
49 static HRESULT
GetCurrentManifestPath(nsAString
& aOutManifestPath
);
50 #endif // defined(MOZILLA_INTERNAL_API)
53 void Init(ACTCTXW
& aActCtx
);
60 friend class ActivationContextRegion
;
63 class MOZ_NON_TEMPORARY_CLASS ActivationContextRegion final
{
65 template <typename
... Args
>
66 explicit ActivationContextRegion(Args
&&... aArgs
)
67 : mActCtx(std::forward
<Args
>(aArgs
)...), mActCookie(0) {
71 ActivationContextRegion();
73 explicit ActivationContextRegion(const ActivationContext
& aActCtx
);
74 ActivationContextRegion
& operator=(const ActivationContext
& aActCtx
);
76 explicit ActivationContextRegion(ActivationContext
&& aActCtx
);
77 ActivationContextRegion
& operator=(ActivationContext
&& aActCtx
);
79 ActivationContextRegion(ActivationContextRegion
&& aRgn
);
80 ActivationContextRegion
& operator=(ActivationContextRegion
&& aRgn
);
82 ~ActivationContextRegion();
84 explicit operator bool() const { return !!mActCookie
; }
86 ActivationContextRegion(const ActivationContextRegion
&) = delete;
87 ActivationContextRegion
& operator=(const ActivationContextRegion
&) = delete;
94 ActivationContext mActCtx
;
99 } // namespace mozilla
101 #endif // mozilla_mscom_ActivationContext_h