зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1164292 - Hoist refcounting into nsJSPrincipals. r=gabor
This is a special-snowflake reference counting system that's tied to JSPrincipals, so it makes sense to consolidate this on nsJSPrincipals.
This commit is contained in:
Родитель
2689e0ffa6
Коммит
46b43e4f8b
|
@ -19,6 +19,30 @@
|
|||
// for mozilla::dom::workers::kJSPrincipalsDebugToken
|
||||
#include "mozilla/dom/workers/Workers.h"
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsJSPrincipals::AddRef()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
||||
nsrefcnt count = ++refcount;
|
||||
NS_LOG_ADDREF(this, count, "nsJSPrincipals", sizeof(*this));
|
||||
return count;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsJSPrincipals::Release()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
NS_PRECONDITION(0 != refcount, "dup release");
|
||||
nsrefcnt count = --refcount;
|
||||
NS_LOG_RELEASE(this, count, "nsJSPrincipals");
|
||||
if (count == 0) {
|
||||
delete this;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
nsJSPrincipals::Subsume(JSPrincipals *jsprin, JSPrincipals *other)
|
||||
{
|
||||
|
|
|
@ -9,36 +9,36 @@
|
|||
#include "jsapi.h"
|
||||
#include "nsIPrincipal.h"
|
||||
|
||||
struct nsJSPrincipals : nsIPrincipal, JSPrincipals
|
||||
class nsJSPrincipals : public nsIPrincipal, public JSPrincipals
|
||||
{
|
||||
public:
|
||||
/* SpiderMonkey security callbacks. */
|
||||
static bool Subsume(JSPrincipals *jsprin, JSPrincipals *other);
|
||||
static void Destroy(JSPrincipals *jsprin);
|
||||
|
||||
/*
|
||||
* Get a weak reference to nsIPrincipal associated with the given JS
|
||||
* principal.
|
||||
* principal, and vice-versa.
|
||||
*/
|
||||
static nsJSPrincipals* get(JSPrincipals *principals) {
|
||||
nsJSPrincipals *self = static_cast<nsJSPrincipals *>(principals);
|
||||
MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
|
||||
return self;
|
||||
}
|
||||
|
||||
static nsJSPrincipals* get(nsIPrincipal *principal) {
|
||||
nsJSPrincipals *self = static_cast<nsJSPrincipals *>(principal);
|
||||
MOZ_ASSERT_IF(self, self->debugToken == DEBUG_TOKEN);
|
||||
return self;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) override;
|
||||
NS_IMETHOD_(MozExternalRefCountType) Release(void) override;
|
||||
|
||||
nsJSPrincipals() {
|
||||
refcount = 0;
|
||||
setDebugToken(DEBUG_TOKEN);
|
||||
}
|
||||
|
||||
virtual ~nsJSPrincipals() {
|
||||
setDebugToken(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string that can be used as JS script filename in error reports.
|
||||
*/
|
||||
|
@ -49,6 +49,12 @@ struct nsJSPrincipals : nsIPrincipal, JSPrincipals
|
|||
#endif
|
||||
|
||||
static const uint32_t DEBUG_TOKEN = 0x0bf41760;
|
||||
|
||||
protected:
|
||||
virtual ~nsJSPrincipals() {
|
||||
setDebugToken(0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsJSPrincipals_h__ */
|
||||
|
|
|
@ -37,36 +37,6 @@ NS_IMPL_CI_INTERFACE_GETTER(nsNullPrincipal,
|
|||
nsIPrincipal,
|
||||
nsISerializable)
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsNullPrincipal::AddRef()
|
||||
{
|
||||
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
||||
nsrefcnt count = ++refcount;
|
||||
NS_LOG_ADDREF(this, count, "nsNullPrincipal", sizeof(*this));
|
||||
return count;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsNullPrincipal::Release()
|
||||
{
|
||||
NS_PRECONDITION(0 != refcount, "dup release");
|
||||
nsrefcnt count = --refcount;
|
||||
NS_LOG_RELEASE(this, count, "nsNullPrincipal");
|
||||
if (count == 0) {
|
||||
delete this;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
nsNullPrincipal::nsNullPrincipal()
|
||||
{
|
||||
}
|
||||
|
||||
nsNullPrincipal::~nsNullPrincipal()
|
||||
{
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsNullPrincipal>
|
||||
nsNullPrincipal::CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom)
|
||||
{
|
||||
|
|
|
@ -33,17 +33,11 @@ public:
|
|||
// This should only be used by deserialization, and the factory constructor.
|
||||
// Other consumers should use the Create and CreateWithInheritedAttributes
|
||||
// methods.
|
||||
nsNullPrincipal();
|
||||
nsNullPrincipal() {}
|
||||
|
||||
// Our refcount is managed by nsJSPrincipals. Use this macro to avoid an
|
||||
// extra refcount member.
|
||||
|
||||
// FIXME: bug 327245 -- I sorta wish there were a clean way to share the
|
||||
// nsJSPrincipals munging code between the various principal classes without
|
||||
// giving up the NS_DECL_NSIPRINCIPAL goodness.
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIPRINCIPAL
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
||||
|
||||
// Returns null on failure.
|
||||
static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIPrincipal *aInheritFrom);
|
||||
|
@ -63,7 +57,7 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
virtual ~nsNullPrincipal();
|
||||
virtual ~nsNullPrincipal() {}
|
||||
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
|
||||
|
|
|
@ -49,37 +49,6 @@ static bool URIIsImmutable(nsIURI* aURI)
|
|||
// Static member variables
|
||||
const char nsBasePrincipal::sInvalid[] = "Invalid";
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsBasePrincipal::AddRef()
|
||||
{
|
||||
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
||||
// XXXcaa does this need to be threadsafe? See bug 143559.
|
||||
nsrefcnt count = ++refcount;
|
||||
NS_LOG_ADDREF(this, count, "nsBasePrincipal", sizeof(*this));
|
||||
return count;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsBasePrincipal::Release()
|
||||
{
|
||||
NS_PRECONDITION(0 != refcount, "dup release");
|
||||
nsrefcnt count = --refcount;
|
||||
NS_LOG_RELEASE(this, count, "nsBasePrincipal");
|
||||
if (count == 0) {
|
||||
delete this;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
nsBasePrincipal::nsBasePrincipal()
|
||||
{
|
||||
}
|
||||
|
||||
nsBasePrincipal::~nsBasePrincipal(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
||||
{
|
||||
|
@ -116,8 +85,6 @@ NS_IMPL_QUERY_INTERFACE_CI(nsPrincipal,
|
|||
NS_IMPL_CI_INTERFACE_GETTER(nsPrincipal,
|
||||
nsIPrincipal,
|
||||
nsISerializable)
|
||||
NS_IMPL_ADDREF_INHERITED(nsPrincipal, nsBasePrincipal)
|
||||
NS_IMPL_RELEASE_INHERITED(nsPrincipal, nsBasePrincipal)
|
||||
|
||||
// Called at startup:
|
||||
/* static */ void
|
||||
|
@ -800,8 +767,6 @@ NS_IMPL_QUERY_INTERFACE_CI(nsExpandedPrincipal,
|
|||
NS_IMPL_CI_INTERFACE_GETTER(nsExpandedPrincipal,
|
||||
nsIPrincipal,
|
||||
nsIExpandedPrincipal)
|
||||
NS_IMPL_ADDREF_INHERITED(nsExpandedPrincipal, nsBasePrincipal)
|
||||
NS_IMPL_RELEASE_INHERITED(nsExpandedPrincipal, nsBasePrincipal)
|
||||
|
||||
nsExpandedPrincipal::nsExpandedPrincipal(nsTArray<nsCOMPtr <nsIPrincipal> > &aWhiteList)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsJSPrincipals.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsScriptSecurityManager.h"
|
||||
|
@ -18,14 +19,12 @@
|
|||
class nsBasePrincipal : public nsJSPrincipals
|
||||
{
|
||||
public:
|
||||
nsBasePrincipal();
|
||||
nsBasePrincipal() {}
|
||||
|
||||
protected:
|
||||
virtual ~nsBasePrincipal();
|
||||
virtual ~nsBasePrincipal() {}
|
||||
|
||||
public:
|
||||
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
|
||||
NS_IMETHOD_(MozExternalRefCountType) Release(void);
|
||||
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
|
||||
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
|
||||
public:
|
||||
|
@ -44,8 +43,8 @@ protected:
|
|||
class nsPrincipal final : public nsBasePrincipal
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
||||
NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
|
||||
|
@ -133,9 +132,11 @@ protected:
|
|||
virtual ~nsExpandedPrincipal();
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIEXPANDEDPRINCIPAL
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_IMETHODIMP_(MozExternalRefCountType) AddRef() override { return nsJSPrincipals::AddRef(); };
|
||||
NS_IMETHODIMP_(MozExternalRefCountType) Release() override { return nsJSPrincipals::Release(); };
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
||||
NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
|
||||
|
|
|
@ -29,28 +29,6 @@ NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal,
|
|||
nsIPrincipal,
|
||||
nsISerializable)
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsSystemPrincipal::AddRef()
|
||||
{
|
||||
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
||||
nsrefcnt count = ++refcount;
|
||||
NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
|
||||
return count;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(MozExternalRefCountType)
|
||||
nsSystemPrincipal::Release()
|
||||
{
|
||||
NS_PRECONDITION(0 != refcount, "dup release");
|
||||
nsrefcnt count = --refcount;
|
||||
NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
|
||||
if (count == 0) {
|
||||
delete this;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]";
|
||||
|
||||
void
|
||||
|
@ -225,15 +203,3 @@ nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
|
|||
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Constructor, Destructor, initialization //
|
||||
/////////////////////////////////////////////
|
||||
|
||||
nsSystemPrincipal::nsSystemPrincipal()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemPrincipal::~nsSystemPrincipal()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -20,13 +20,11 @@
|
|||
class nsSystemPrincipal final : public nsJSPrincipals
|
||||
{
|
||||
public:
|
||||
// Our refcount is managed by nsJSPrincipals. Use this macro to avoid
|
||||
// an extra refcount member.
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIPRINCIPAL
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
||||
|
||||
nsSystemPrincipal();
|
||||
nsSystemPrincipal() {}
|
||||
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
|
||||
|
@ -35,10 +33,7 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
virtual ~nsSystemPrincipal(void);
|
||||
|
||||
// XXX Probably unnecessary. See bug 143559.
|
||||
NS_DECL_OWNINGTHREAD
|
||||
virtual ~nsSystemPrincipal(void) {}
|
||||
};
|
||||
|
||||
#endif // nsSystemPrincipal_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче