Skip to content

Commit

Permalink
Bug 1343933 - Renaming Principal classes - part 2 - NullPrincipal, r=…
Browse files Browse the repository at this point in the history
…qdot
  • Loading branch information
bakulf committed Mar 22, 2017
1 parent 85a8ec6 commit 4fd2edf
Show file tree
Hide file tree
Showing 42 changed files with 205 additions and 203 deletions.
8 changes: 4 additions & 4 deletions caps/BasePrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "nsPrincipal.h"
#include "nsNetUtil.h"
#include "nsIURIWithPrincipal.h"
#include "nsNullPrincipal.h"
#include "NullPrincipal.h"
#include "nsScriptSecurityManager.h"
#include "nsServiceManagerUtils.h"

Expand Down Expand Up @@ -645,7 +645,7 @@ BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, const OriginAttributes& aAt
nsresult rv = NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
&inheritsPrincipal);
if (NS_FAILED(rv) || inheritsPrincipal) {
return nsNullPrincipal::Create(aAttrs);
return NullPrincipal::Create(aAttrs);
}

// Check whether the URI knows what its principal is supposed to be.
Expand All @@ -654,7 +654,7 @@ BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, const OriginAttributes& aAt
nsCOMPtr<nsIPrincipal> principal;
uriPrinc->GetPrincipal(getter_AddRefs(principal));
if (!principal) {
return nsNullPrincipal::Create(aAttrs);
return NullPrincipal::Create(aAttrs);
}
RefPtr<BasePrincipal> concrete = Cast(principal);
return concrete.forget();
Expand All @@ -674,7 +674,7 @@ BasePrincipal::CreateCodebasePrincipal(const nsACString& aOrigin)
"CreateCodebasePrincipal does not support System and Expanded principals");

MOZ_ASSERT(!StringBeginsWith(aOrigin, NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME ":")),
"CreateCodebasePrincipal does not support nsNullPrincipal");
"CreateCodebasePrincipal does not support NullPrincipal");

nsAutoCString originNoSuffix;
mozilla::OriginAttributes attrs;
Expand Down
59 changes: 30 additions & 29 deletions caps/nsNullPrincipal.cpp → caps/NullPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "mozilla/ArrayUtils.h"

#include "nsDocShell.h"
#include "nsNullPrincipal.h"
#include "nsNullPrincipalURI.h"
#include "NullPrincipal.h"
#include "NullPrincipalURI.h"
#include "nsMemory.h"
#include "nsIURIWithPrincipal.h"
#include "nsIClassInfoImpl.h"
Expand All @@ -27,48 +27,48 @@

using namespace mozilla;

NS_IMPL_CLASSINFO(nsNullPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
NS_IMPL_CLASSINFO(NullPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
NS_NULLPRINCIPAL_CID)
NS_IMPL_QUERY_INTERFACE_CI(nsNullPrincipal,
NS_IMPL_QUERY_INTERFACE_CI(NullPrincipal,
nsIPrincipal,
nsISerializable)
NS_IMPL_CI_INTERFACE_GETTER(nsNullPrincipal,
NS_IMPL_CI_INTERFACE_GETTER(NullPrincipal,
nsIPrincipal,
nsISerializable)

/* static */ already_AddRefed<nsNullPrincipal>
nsNullPrincipal::CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom)
/* static */ already_AddRefed<NullPrincipal>
NullPrincipal::CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom)
{
RefPtr<nsNullPrincipal> nullPrin = new nsNullPrincipal();
RefPtr<NullPrincipal> nullPrin = new NullPrincipal();
nsresult rv = nullPrin->Init(Cast(aInheritFrom)->OriginAttributesRef());
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
return nullPrin.forget();
}

/* static */ already_AddRefed<nsNullPrincipal>
nsNullPrincipal::CreateWithInheritedAttributes(nsIDocShell* aDocShell, bool aIsFirstParty)
/* static */ already_AddRefed<NullPrincipal>
NullPrincipal::CreateWithInheritedAttributes(nsIDocShell* aDocShell, bool aIsFirstParty)
{
OriginAttributes attrs = nsDocShell::Cast(aDocShell)->GetOriginAttributes();
attrs.SetFirstPartyDomain(aIsFirstParty, NS_LITERAL_CSTRING(NULL_PRINCIPAL_FIRST_PARTY_DOMAIN));

RefPtr<nsNullPrincipal> nullPrin = new nsNullPrincipal();
RefPtr<NullPrincipal> nullPrin = new NullPrincipal();
nsresult rv = nullPrin->Init(attrs);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
return nullPrin.forget();
}

/* static */ already_AddRefed<nsNullPrincipal>
nsNullPrincipal::Create(const OriginAttributes& aOriginAttributes, nsIURI* aURI)
/* static */ already_AddRefed<NullPrincipal>
NullPrincipal::Create(const OriginAttributes& aOriginAttributes, nsIURI* aURI)
{
RefPtr<nsNullPrincipal> nullPrin = new nsNullPrincipal();
RefPtr<NullPrincipal> nullPrin = new NullPrincipal();
nsresult rv = nullPrin->Init(aOriginAttributes, aURI);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));

return nullPrin.forget();
}

nsresult
nsNullPrincipal::Init(const OriginAttributes& aOriginAttributes, nsIURI* aURI)
NullPrincipal::Init(const OriginAttributes& aOriginAttributes, nsIURI* aURI)
{
mOriginAttributes = aOriginAttributes;

Expand All @@ -82,7 +82,7 @@ nsNullPrincipal::Init(const OriginAttributes& aOriginAttributes, nsIURI* aURI)

mURI = aURI;
} else {
mURI = nsNullPrincipalURI::Create();
mURI = NullPrincipalURI::Create();
NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_AVAILABLE);
}

Expand All @@ -92,7 +92,7 @@ nsNullPrincipal::Init(const OriginAttributes& aOriginAttributes, nsIURI* aURI)
}

nsresult
nsNullPrincipal::GetScriptLocation(nsACString &aStr)
NullPrincipal::GetScriptLocation(nsACString &aStr)
{
return mURI->GetSpec(aStr);
}
Expand All @@ -102,14 +102,15 @@ nsNullPrincipal::GetScriptLocation(nsACString &aStr)
*/

NS_IMETHODIMP
nsNullPrincipal::GetHashValue(uint32_t *aResult)
NullPrincipal::GetHashValue(uint32_t *aResult)
{
*aResult = (NS_PTR_TO_INT32(this) >> 2);
return NS_OK;
}

NS_IMETHODIMP
nsNullPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp) {
NullPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
{
// Never destroy an existing CSP on the principal.
// This method should only be called in rare cases.

Expand All @@ -123,33 +124,33 @@ nsNullPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp) {
}

NS_IMETHODIMP
nsNullPrincipal::GetURI(nsIURI** aURI)
NullPrincipal::GetURI(nsIURI** aURI)
{
return NS_EnsureSafeToReturn(mURI, aURI);
}

NS_IMETHODIMP
nsNullPrincipal::GetDomain(nsIURI** aDomain)
NullPrincipal::GetDomain(nsIURI** aDomain)
{
return NS_EnsureSafeToReturn(mURI, aDomain);
}

NS_IMETHODIMP
nsNullPrincipal::SetDomain(nsIURI* aDomain)
NullPrincipal::SetDomain(nsIURI* aDomain)
{
// I think the right thing to do here is to just throw... Silently failing
// seems counterproductive.
return NS_ERROR_NOT_AVAILABLE;
}

nsresult
nsNullPrincipal::GetOriginInternal(nsACString& aOrigin)
NullPrincipal::GetOriginInternal(nsACString& aOrigin)
{
return mURI->GetSpec(aOrigin);
}

bool
nsNullPrincipal::MayLoadInternal(nsIURI* aURI)
NullPrincipal::MayLoadInternal(nsIURI* aURI)
{
// Also allow the load if we are the principal of the URI being checked.
nsCOMPtr<nsIURIWithPrincipal> uriPrinc = do_QueryInterface(aURI);
Expand All @@ -166,14 +167,14 @@ nsNullPrincipal::MayLoadInternal(nsIURI* aURI)
}

NS_IMETHODIMP
nsNullPrincipal::GetBaseDomain(nsACString& aBaseDomain)
NullPrincipal::GetBaseDomain(nsACString& aBaseDomain)
{
// For a null principal, we use our unique uuid as the base domain.
return mURI->GetPath(aBaseDomain);
}

NS_IMETHODIMP
nsNullPrincipal::GetAddonId(nsAString& aAddonId)
NullPrincipal::GetAddonId(nsAString& aAddonId)
{
aAddonId.Truncate();
return NS_OK;
Expand All @@ -183,9 +184,9 @@ nsNullPrincipal::GetAddonId(nsAString& aAddonId)
* nsISerializable implementation
*/
NS_IMETHODIMP
nsNullPrincipal::Read(nsIObjectInputStream* aStream)
NullPrincipal::Read(nsIObjectInputStream* aStream)
{
// Note - nsNullPrincipal use NS_GENERIC_FACTORY_CONSTRUCTOR_INIT, which means
// Note - NullPrincipal use NS_GENERIC_FACTORY_CONSTRUCTOR_INIT, which means
// that the Init() method has already been invoked by the time we deserialize.
// This is in contrast to nsPrincipal, which uses NS_GENERIC_FACTORY_CONSTRUCTOR,
// in which case ::Read needs to invoke Init().
Expand All @@ -210,7 +211,7 @@ nsNullPrincipal::Read(nsIObjectInputStream* aStream)
}

NS_IMETHODIMP
nsNullPrincipal::Write(nsIObjectOutputStream* aStream)
NullPrincipal::Write(nsIObjectOutputStream* aStream)
{
NS_ENSURE_STATE(mURI);

Expand Down
19 changes: 10 additions & 9 deletions caps/nsNullPrincipal.h → caps/NullPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* same-origin with anything but themselves.
*/

#ifndef nsNullPrincipal_h__
#define nsNullPrincipal_h__
#ifndef NullPrincipal_h
#define NullPrincipal_h

#include "nsIPrincipal.h"
#include "nsJSPrincipals.h"
Expand All @@ -30,13 +30,13 @@ class nsIURI;

#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"

class nsNullPrincipal final : public mozilla::BasePrincipal
class NullPrincipal final : public mozilla::BasePrincipal
{
public:
// This should only be used by deserialization, and the factory constructor.
// Other consumers should use the Create and CreateWithInheritedAttributes
// methods.
nsNullPrincipal()
NullPrincipal()
: BasePrincipal(eNullPrincipal)
{
}
Expand All @@ -53,15 +53,16 @@ class nsNullPrincipal final : public mozilla::BasePrincipal
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
nsresult GetOriginInternal(nsACString& aOrigin) override;

static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom);
static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom);

// Create NullPrincipal with origin attributes from docshell.
// If aIsFirstParty is true, and the pref 'privacy.firstparty.isolate' is also
// enabled, the mFirstPartyDomain value of the origin attributes will be set
// to NULL_PRINCIPAL_FIRST_PARTY_DOMAIN.
static already_AddRefed<nsNullPrincipal> CreateWithInheritedAttributes(nsIDocShell* aDocShell, bool aIsFirstParty = false);
static already_AddRefed<NullPrincipal>
CreateWithInheritedAttributes(nsIDocShell* aDocShell, bool aIsFirstParty = false);

static already_AddRefed<nsNullPrincipal>
static already_AddRefed<NullPrincipal>
Create(const mozilla::OriginAttributes& aOriginAttributes = mozilla::OriginAttributes(),
nsIURI* aURI = nullptr);

Expand All @@ -71,7 +72,7 @@ class nsNullPrincipal final : public mozilla::BasePrincipal
virtual nsresult GetScriptLocation(nsACString &aStr) override;

protected:
virtual ~nsNullPrincipal() {}
virtual ~NullPrincipal() = default;

bool SubsumesInternal(nsIPrincipal* aOther, DocumentDomainConsideration aConsideration) override
{
Expand All @@ -83,4 +84,4 @@ class nsNullPrincipal final : public mozilla::BasePrincipal
nsCOMPtr<nsIURI> mURI;
};

#endif // nsNullPrincipal_h__
#endif // NullPrincipal_h__
Loading

0 comments on commit 4fd2edf

Please sign in to comment.