2016-10-26 00:04:47 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_mscom_ActivationContext_h
|
|
|
|
#define mozilla_mscom_ActivationContext_h
|
|
|
|
|
2017-01-17 23:19:40 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-06-13 23:50:05 +03:00
|
|
|
#include "mozilla/Move.h"
|
2017-08-29 00:16:20 +03:00
|
|
|
#include "mozilla/Result.h"
|
2017-01-17 23:19:40 +03:00
|
|
|
|
2017-09-19 23:35:27 +03:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
|
|
|
# include "nsString.h"
|
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
2016-10-26 00:04:47 +03:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace mscom {
|
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
class ActivationContext final {
|
2016-10-26 00:04:47 +03:00
|
|
|
public:
|
2017-09-30 00:41:28 +03:00
|
|
|
ActivationContext() : mActCtx(INVALID_HANDLE_VALUE) {}
|
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
explicit ActivationContext(WORD aResourceId);
|
|
|
|
explicit ActivationContext(HMODULE aLoadFromModule, WORD aResourceId = 2);
|
|
|
|
|
|
|
|
ActivationContext(ActivationContext&& aOther);
|
|
|
|
ActivationContext& operator=(ActivationContext&& aOther);
|
|
|
|
|
|
|
|
ActivationContext(const ActivationContext& aOther);
|
|
|
|
ActivationContext& operator=(const ActivationContext& aOther);
|
|
|
|
|
2016-10-26 00:04:47 +03:00
|
|
|
~ActivationContext();
|
|
|
|
|
|
|
|
explicit operator bool() const { return mActCtx != INVALID_HANDLE_VALUE; }
|
|
|
|
|
2017-09-19 23:35:27 +03:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
2017-08-29 00:16:20 +03:00
|
|
|
static Result<uintptr_t, HRESULT> GetCurrent();
|
2017-09-19 23:35:27 +03:00
|
|
|
static HRESULT GetCurrentManifestPath(nsAString& aOutManifestPath);
|
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
2017-08-29 00:16:20 +03:00
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
private:
|
|
|
|
void Init(ACTCTX& aActCtx);
|
|
|
|
void AddRef();
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
private:
|
|
|
|
HANDLE mActCtx;
|
|
|
|
|
|
|
|
friend class ActivationContextRegion;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MOZ_NON_TEMPORARY_CLASS ActivationContextRegion final {
|
|
|
|
public:
|
|
|
|
template <typename... Args>
|
|
|
|
explicit ActivationContextRegion(Args... aArgs)
|
2018-06-01 19:30:30 +03:00
|
|
|
: mActCtx(std::forward<Args>(aArgs)...), mActCookie(0) {
|
2017-06-13 23:50:05 +03:00
|
|
|
Activate();
|
|
|
|
}
|
|
|
|
|
2017-09-30 00:41:28 +03:00
|
|
|
ActivationContextRegion();
|
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
explicit ActivationContextRegion(const ActivationContext& aActCtx);
|
2017-09-30 00:41:28 +03:00
|
|
|
ActivationContextRegion& operator=(const ActivationContext& aActCtx);
|
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
explicit ActivationContextRegion(ActivationContext&& aActCtx);
|
2017-09-30 00:41:28 +03:00
|
|
|
ActivationContextRegion& operator=(ActivationContext&& aActCtx);
|
|
|
|
|
|
|
|
ActivationContextRegion(ActivationContextRegion&& aRgn);
|
|
|
|
ActivationContextRegion& operator=(ActivationContextRegion&& aRgn);
|
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
~ActivationContextRegion();
|
|
|
|
|
2017-09-30 00:41:28 +03:00
|
|
|
explicit operator bool() const { return !!mActCookie; }
|
|
|
|
|
2017-06-13 23:50:05 +03:00
|
|
|
ActivationContextRegion(const ActivationContextRegion&) = delete;
|
|
|
|
ActivationContextRegion& operator=(const ActivationContextRegion&) = delete;
|
2017-09-30 00:41:28 +03:00
|
|
|
|
|
|
|
bool Deactivate();
|
2017-01-17 23:19:40 +03:00
|
|
|
|
2016-10-26 00:04:47 +03:00
|
|
|
private:
|
2017-06-13 23:50:05 +03:00
|
|
|
void Activate();
|
|
|
|
|
|
|
|
ActivationContext mActCtx;
|
|
|
|
ULONG_PTR mActCookie;
|
2016-10-26 00:04:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mscom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_mscom_ActivationContext_h
|