Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / ipc / mscom / ActivationContext.h
blob3d0144528dc7b1cfe40f4ec6101962f3e898322e
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
10 #include <utility>
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)
20 #include <windows.h>
22 namespace mozilla {
23 namespace mscom {
25 class ActivationContext final {
26 public:
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);
43 ~ActivationContext();
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)
52 private:
53 void Init(ACTCTXW& aActCtx);
54 void AddRef();
55 void Release();
57 private:
58 HANDLE mActCtx;
60 friend class ActivationContextRegion;
63 class MOZ_NON_TEMPORARY_CLASS ActivationContextRegion final {
64 public:
65 template <typename... Args>
66 explicit ActivationContextRegion(Args&&... aArgs)
67 : mActCtx(std::forward<Args>(aArgs)...), mActCookie(0) {
68 Activate();
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;
89 bool Deactivate();
91 private:
92 void Activate();
94 ActivationContext mActCtx;
95 ULONG_PTR mActCookie;
98 } // namespace mscom
99 } // namespace mozilla
101 #endif // mozilla_mscom_ActivationContext_h