2015-03-02 16:20:00 +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_dom_cache_PrincipalVerifier_h
|
|
|
|
#define mozilla_dom_cache_PrincipalVerifier_h
|
|
|
|
|
|
|
|
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2015-04-16 22:00:15 +03:00
|
|
|
#include "nsTObserverArray.h"
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PBackgroundParent;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace ipc
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class ManagerId;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class PrincipalVerifier final : public Runnable
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// An interface to be implemented by code wishing to use the
|
|
|
|
// PrincipalVerifier. Note, the Listener implementation is responsible
|
2015-04-16 22:00:15 +03:00
|
|
|
// for calling RemoveListener() on the PrincipalVerifier to clear the
|
2015-03-02 16:20:00 +03:00
|
|
|
// weak reference.
|
|
|
|
class Listener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void OnPrincipalVerified(nsresult aRv, ManagerId* aManagerId) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static already_AddRefed<PrincipalVerifier>
|
|
|
|
CreateAndDispatch(Listener* aListener, mozilla::ipc::PBackgroundParent* aActor,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
void AddListener(Listener* aListener);
|
|
|
|
|
|
|
|
// The Listener must call RemoveListener() when OnPrincipalVerified() is
|
2015-03-02 16:20:00 +03:00
|
|
|
// called or when the Listener is destroyed.
|
2015-04-16 22:00:15 +03:00
|
|
|
void RemoveListener(Listener* aListener);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
PrincipalVerifier(Listener* aListener, mozilla::ipc::PBackgroundParent* aActor,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
|
|
|
virtual ~PrincipalVerifier();
|
|
|
|
|
|
|
|
void VerifyOnMainThread();
|
|
|
|
void CompleteOnInitiatingThread();
|
|
|
|
|
|
|
|
void DispatchToInitiatingThread(nsresult aRv);
|
|
|
|
|
2015-04-16 22:00:15 +03:00
|
|
|
// Weak reference cleared by RemoveListener()
|
|
|
|
typedef nsTObserverArray<Listener*> ListenerList;
|
|
|
|
ListenerList mListenerList;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
// set in originating thread at construction, but must be accessed and
|
|
|
|
// released on main thread
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ContentParent> mActor;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
const mozilla::ipc::PrincipalInfo mPrincipalInfo;
|
|
|
|
nsCOMPtr<nsIThread> mInitiatingThread;
|
|
|
|
nsresult mResult;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ManagerId> mManagerId;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace cache
|
2015-03-02 16:20:00 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_cache_PrincipalVerifier_h
|