1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef DOM_MEDIA_PRINCIPALHANDLE_H_
7 #define DOM_MEDIA_PRINCIPALHANDLE_H_
9 #include "nsIPrincipal.h"
10 #include "nsProxyRelease.h"
14 * We pass the principal through the MediaTrackGraph by wrapping it in a thread
15 * safe nsMainThreadPtrHandle, since it cannot be used directly off the main
16 * thread. We can compare two PrincipalHandles to each other on any thread, but
17 * they can only be created and converted back to nsIPrincipal* on main thread.
19 typedef nsMainThreadPtrHandle
<nsIPrincipal
> PrincipalHandle
;
21 inline PrincipalHandle
MakePrincipalHandle(nsIPrincipal
* aPrincipal
) {
22 RefPtr
<nsMainThreadPtrHolder
<nsIPrincipal
>> holder
=
23 new nsMainThreadPtrHolder
<nsIPrincipal
>(
24 "MakePrincipalHandle::nsIPrincipal", aPrincipal
);
25 return PrincipalHandle(holder
);
28 #define PRINCIPAL_HANDLE_NONE nullptr
30 inline nsIPrincipal
* GetPrincipalFromHandle(
31 const PrincipalHandle
& aPrincipalHandle
) {
32 MOZ_ASSERT(NS_IsMainThread());
33 return aPrincipalHandle
.get();
36 inline bool PrincipalHandleMatches(const PrincipalHandle
& aPrincipalHandle
,
37 nsIPrincipal
* aOther
) {
42 nsIPrincipal
* principal
= GetPrincipalFromHandle(aPrincipalHandle
);
48 if (NS_FAILED(principal
->Equals(aOther
, &result
))) {
49 NS_ERROR("Principal check failed");
55 } // namespace mozilla
57 #endif // DOM_MEDIA_PRINCIPALHANDLE_H_