зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
6882fa756b
Коммит
9e3345280e
|
@ -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
|
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче