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_dom_cache_PrincipalVerifier_h
8 #define mozilla_dom_cache_PrincipalVerifier_h
10 #include "mozilla/dom/SafeRefPtr.h"
11 #include "mozilla/ipc/PBackgroundSharedTypes.h"
12 #include "nsThreadUtils.h"
13 #include "nsTObserverArray.h"
18 class PBackgroundParent
;
23 class ThreadsafeContentParentHandle
;
29 class PrincipalVerifier final
: public Runnable
{
31 // An interface to be implemented by code wishing to use the
32 // PrincipalVerifier. Note, the Listener implementation is responsible
33 // for calling RemoveListener() on the PrincipalVerifier to clear the
37 virtual void OnPrincipalVerified(
38 nsresult aRv
, const SafeRefPtr
<ManagerId
>& aManagerId
) = 0;
41 static already_AddRefed
<PrincipalVerifier
> CreateAndDispatch(
42 Listener
& aListener
, mozilla::ipc::PBackgroundParent
* aActor
,
43 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
);
45 void AddListener(Listener
& aListener
);
47 // The Listener must call RemoveListener() when OnPrincipalVerified() is
48 // called or when the Listener is destroyed.
49 void RemoveListener(Listener
& aListener
);
52 PrincipalVerifier(Listener
& aListener
,
53 mozilla::ipc::PBackgroundParent
* aActor
,
54 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
);
55 virtual ~PrincipalVerifier();
57 void VerifyOnMainThread();
58 void CompleteOnInitiatingThread();
60 void DispatchToInitiatingThread(nsresult aRv
);
62 // Weak reference cleared by RemoveListener()
63 nsTObserverArray
<NotNull
<Listener
*>> mListenerList
;
65 RefPtr
<ThreadsafeContentParentHandle
> mHandle
;
67 const mozilla::ipc::PrincipalInfo mPrincipalInfo
;
68 nsCOMPtr
<nsIEventTarget
> mInitiatingEventTarget
;
70 SafeRefPtr
<ManagerId
> mManagerId
;
78 } // namespace mozilla
80 #endif // mozilla_dom_cache_PrincipalVerifier_h