зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1164292 - Make all nsIPrincipal implementations inherit BasePrincipal and hoist some repeated code. r=gabor
Losing the NS_DECL_NSIPRINCIPAL isn't great, but I think it's worth it to share more code.
This commit is contained in:
Родитель
9e3345280e
Коммит
93d7d50247
|
@ -27,4 +27,12 @@ BasePrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BasePrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
||||
{
|
||||
*aIsNullPrincipal = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -25,6 +25,9 @@ public:
|
|||
BasePrincipal() {}
|
||||
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
|
||||
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
|
||||
NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
|
||||
|
||||
virtual bool IsOnCSSUnprefixingWhitelist() override { return false; }
|
||||
|
||||
protected:
|
||||
virtual ~BasePrincipal() {}
|
||||
|
|
|
@ -107,25 +107,6 @@ nsNullPrincipal::GetURI(nsIURI** aURI)
|
|||
return NS_EnsureSafeToReturn(mURI, aURI);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNullPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
||||
{
|
||||
NS_IF_ADDREF(*aCsp = mCSP);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNullPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
||||
{
|
||||
// If CSP was already set, it should not be destroyed! Instead, it should
|
||||
// get set anew when a new principal is created.
|
||||
if (mCSP)
|
||||
return NS_ERROR_ALREADY_INITIALIZED;
|
||||
|
||||
mCSP = aCsp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsNullPrincipal::GetDomain(nsIURI** aDomain)
|
||||
{
|
||||
|
@ -248,12 +229,6 @@ nsNullPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|||
return mURI->GetPath(aBaseDomain);
|
||||
}
|
||||
|
||||
bool
|
||||
nsNullPrincipal::IsOnCSSUnprefixingWhitelist()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* nsISerializable implementation
|
||||
*/
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
|
||||
class nsIURI;
|
||||
|
||||
#define NS_NULLPRINCIPAL_CID \
|
||||
|
@ -27,7 +29,7 @@ class nsIURI;
|
|||
|
||||
#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
|
||||
|
||||
class nsNullPrincipal final : public nsJSPrincipals
|
||||
class nsNullPrincipal final : public mozilla::BasePrincipal
|
||||
{
|
||||
public:
|
||||
// This should only be used by deserialization, and the factory constructor.
|
||||
|
@ -35,9 +37,26 @@ public:
|
|||
// methods.
|
||||
nsNullPrincipal() {}
|
||||
|
||||
NS_DECL_NSIPRINCIPAL
|
||||
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;
|
||||
NS_IMETHOD GetURI(nsIURI** aURI) override;
|
||||
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
|
||||
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
|
||||
NS_IMETHOD GetOrigin(char** aOrigin) override;
|
||||
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal) override;
|
||||
NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix) override;
|
||||
NS_IMETHOD GetAppStatus(uint16_t* aAppStatus) override;
|
||||
NS_IMETHOD GetAppId(uint32_t* aAppStatus) override;
|
||||
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) override;
|
||||
NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) override;
|
||||
NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
|
||||
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
||||
|
||||
// Returns null on failure.
|
||||
static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIPrincipal *aInheritFrom);
|
||||
|
|
|
@ -414,13 +414,6 @@ nsPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
||||
{
|
||||
*aIsNullPrincipal = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
||||
{
|
||||
|
@ -924,13 +917,6 @@ nsExpandedPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpandedPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
||||
{
|
||||
*aIsNullPrincipal = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsExpandedPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,6 @@ public:
|
|||
NS_IMETHOD GetAppId(uint32_t* aAppStatus) override;
|
||||
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) override;
|
||||
NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) override;
|
||||
NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
|
||||
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
||||
virtual bool IsOnCSSUnprefixingWhitelist() override;
|
||||
|
||||
|
@ -126,7 +125,6 @@ public:
|
|||
NS_IMETHOD GetAppId(uint32_t* aAppStatus) override;
|
||||
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) override;
|
||||
NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) override;
|
||||
NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
|
||||
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
||||
virtual bool IsOnCSSUnprefixingWhitelist() override;
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
|
|
|
@ -157,13 +157,6 @@ nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
||||
{
|
||||
*aIsNullPrincipal = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
||||
{
|
||||
|
@ -171,13 +164,6 @@ nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
nsSystemPrincipal::IsOnCSSUnprefixingWhitelist()
|
||||
{
|
||||
// chrome stylesheets should not be fed to the CSS Unprefixing Service.
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// Methods implementing nsISerializable //
|
||||
//////////////////////////////////////////
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- 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/. */
|
||||
|
@ -11,25 +12,44 @@
|
|||
#include "nsIPrincipal.h"
|
||||
#include "nsJSPrincipals.h"
|
||||
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
|
||||
#define NS_SYSTEMPRINCIPAL_CID \
|
||||
{ 0x4a6212db, 0xaccb, 0x11d3, \
|
||||
{ 0xb7, 0x65, 0x0, 0x60, 0xb0, 0xb6, 0xce, 0xcb }}
|
||||
#define NS_SYSTEMPRINCIPAL_CONTRACTID "@mozilla.org/systemprincipal;1"
|
||||
|
||||
|
||||
class nsSystemPrincipal final : public nsJSPrincipals
|
||||
class nsSystemPrincipal final : public mozilla::BasePrincipal
|
||||
{
|
||||
public:
|
||||
NS_DECL_NSIPRINCIPAL
|
||||
NS_DECL_NSISERIALIZABLE
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
||||
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;
|
||||
NS_IMETHOD GetURI(nsIURI** aURI) override;
|
||||
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
|
||||
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
|
||||
NS_IMETHOD GetOrigin(char** aOrigin) override;
|
||||
NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval) override;
|
||||
NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal) override;
|
||||
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
|
||||
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
|
||||
NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix) override;
|
||||
NS_IMETHOD GetAppStatus(uint16_t* aAppStatus) override;
|
||||
NS_IMETHOD GetAppId(uint32_t* aAppStatus) override;
|
||||
NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) override;
|
||||
NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) override;
|
||||
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
||||
|
||||
nsSystemPrincipal() {}
|
||||
nsSystemPrincipal() {}
|
||||
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
virtual void GetScriptLocation(nsACString &aStr) override;
|
||||
|
||||
protected:
|
||||
virtual ~nsSystemPrincipal(void) {}
|
||||
virtual ~nsSystemPrincipal(void) {}
|
||||
};
|
||||
|
||||
#endif // nsSystemPrincipal_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче