Bug 1164292 - Rebrand nsBasePrincipal into mozilla::BasePrincipal and give it its own file. r=gabor

The goal here is to provide a common superclass for _all_ the principal
implementations, rather than just nsPrincipal and nsExpandedPrincipal.
This commit is contained in:
Bobby Holley 2015-05-11 14:25:59 -07:00
Родитель 6882fa756b
Коммит 9e3345280e
5 изменённых файлов: 75 добавлений и 43 удалений

30
caps/BasePrincipal.cpp Normal file
Просмотреть файл

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 sw=2 et 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/. */
#include "mozilla/BasePrincipal.h"
namespace mozilla {
NS_IMETHODIMP
BasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
{
NS_IF_ADDREF(*aCsp = mCSP);
return NS_OK;
}
NS_IMETHODIMP
BasePrincipal::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;
}
} // namespace mozilla

37
caps/BasePrincipal.h Normal file
Просмотреть файл

@ -0,0 +1,37 @@
/* -*- 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_BasePrincipal_h
#define mozilla_BasePrincipal_h
#include "nsIPrincipal.h"
#include "nsJSPrincipals.h"
namespace mozilla {
/*
* Base class from which all nsIPrincipal implementations inherit. Use this for
* default implementations and other commonalities between principal
* implementations.
*
* We should merge nsJSPrincipals into this class at some point.
*/
class BasePrincipal : public nsJSPrincipals
{
public:
BasePrincipal() {}
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
protected:
virtual ~BasePrincipal() {}
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
};
} // namespace mozilla
#endif /* mozilla_BasePrincipal_h */

Просмотреть файл

@ -20,7 +20,12 @@ EXPORTS += [
'nsNullPrincipalURI.h',
]
EXPORTS.mozilla = [
'BasePrincipal.h'
]
UNIFIED_SOURCES += [
'BasePrincipal.cpp',
'DomainPolicy.cpp',
'nsJSPrincipals.cpp',
'nsNullPrincipal.cpp',

Просмотреть файл

@ -46,28 +46,6 @@ static bool URIIsImmutable(nsIURI* aURI)
!isMutable;
}
// Static member variables
const char nsBasePrincipal::sInvalid[] = "Invalid";
NS_IMETHODIMP
nsBasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
{
NS_IF_ADDREF(*aCsp = mCSP);
return NS_OK;
}
NS_IMETHODIMP
nsBasePrincipal::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_IMPL_CLASSINFO(nsPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
NS_PRINCIPAL_CID)
NS_IMPL_QUERY_INTERFACE_CI(nsPrincipal,

Просмотреть файл

@ -15,27 +15,9 @@
#include "nsIProtocolHandler.h"
#include "nsNetUtil.h"
#include "nsScriptSecurityManager.h"
#include "mozilla/BasePrincipal.h"
class nsBasePrincipal : public nsJSPrincipals
{
public:
nsBasePrincipal() {}
protected:
virtual ~nsBasePrincipal() {}
public:
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
public:
static const char sInvalid[];
protected:
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
};
class nsPrincipal final : public nsBasePrincipal
class nsPrincipal final : public mozilla::BasePrincipal
{
public:
NS_DECL_NSISERIALIZABLE
@ -115,7 +97,7 @@ protected:
uint16_t GetAppStatus();
};
class nsExpandedPrincipal : public nsIExpandedPrincipal, public nsBasePrincipal
class nsExpandedPrincipal : public nsIExpandedPrincipal, public mozilla::BasePrincipal
{
public:
explicit nsExpandedPrincipal(nsTArray< nsCOMPtr<nsIPrincipal> > &aWhiteList);