Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_cache_PrincipalVerifier_h
8 : #define mozilla_dom_cache_PrincipalVerifier_h
9 :
10 : #include "mozilla/ipc/PBackgroundSharedTypes.h"
11 : #include "nsThreadUtils.h"
12 : #include "nsTObserverArray.h"
13 :
14 : namespace mozilla {
15 :
16 : namespace ipc {
17 : class PBackgroundParent;
18 : } // namespace ipc
19 :
20 : namespace dom {
21 : namespace cache {
22 :
23 : class ManagerId;
24 :
25 : class PrincipalVerifier final : public Runnable
26 : {
27 : public:
28 : // An interface to be implemented by code wishing to use the
29 : // PrincipalVerifier. Note, the Listener implementation is responsible
30 : // for calling RemoveListener() on the PrincipalVerifier to clear the
31 : // weak reference.
32 0 : class Listener
33 : {
34 : public:
35 : virtual void OnPrincipalVerified(nsresult aRv, ManagerId* aManagerId) = 0;
36 : };
37 :
38 : static already_AddRefed<PrincipalVerifier>
39 : CreateAndDispatch(Listener* aListener, mozilla::ipc::PBackgroundParent* aActor,
40 : const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
41 :
42 : void AddListener(Listener* aListener);
43 :
44 : // The Listener must call RemoveListener() when OnPrincipalVerified() is
45 : // called or when the Listener is destroyed.
46 : void RemoveListener(Listener* aListener);
47 :
48 : private:
49 : PrincipalVerifier(Listener* aListener, mozilla::ipc::PBackgroundParent* aActor,
50 : const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
51 : virtual ~PrincipalVerifier();
52 :
53 : void VerifyOnMainThread();
54 : void CompleteOnInitiatingThread();
55 :
56 : void DispatchToInitiatingThread(nsresult aRv);
57 :
58 : // Weak reference cleared by RemoveListener()
59 : typedef nsTObserverArray<Listener*> ListenerList;
60 : ListenerList mListenerList;
61 :
62 : // set in originating thread at construction, but must be accessed and
63 : // released on main thread
64 : RefPtr<ContentParent> mActor;
65 :
66 : const mozilla::ipc::PrincipalInfo mPrincipalInfo;
67 : nsCOMPtr<nsIEventTarget> mInitiatingEventTarget;
68 : nsresult mResult;
69 : RefPtr<ManagerId> mManagerId;
70 :
71 : public:
72 : NS_DECL_NSIRUNNABLE
73 : };
74 :
75 : } // namespace cache
76 : } // namespace dom
77 : } // namespace mozilla
78 :
79 : #endif // mozilla_dom_cache_PrincipalVerifier_h
|