forked from mirrors/gecko-dev
Bug 1452666. Implement nsISerializable on expanded principals. r=kmag
This commit is contained in:
parent
95fd40defd
commit
b134958200
3 changed files with 77 additions and 4 deletions
|
|
@ -13,10 +13,12 @@ NS_IMPL_CLASSINFO(ExpandedPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
|
||||||
NS_EXPANDEDPRINCIPAL_CID)
|
NS_EXPANDEDPRINCIPAL_CID)
|
||||||
NS_IMPL_QUERY_INTERFACE_CI(ExpandedPrincipal,
|
NS_IMPL_QUERY_INTERFACE_CI(ExpandedPrincipal,
|
||||||
nsIPrincipal,
|
nsIPrincipal,
|
||||||
nsIExpandedPrincipal)
|
nsIExpandedPrincipal,
|
||||||
|
nsISerializable)
|
||||||
NS_IMPL_CI_INTERFACE_GETTER(ExpandedPrincipal,
|
NS_IMPL_CI_INTERFACE_GETTER(ExpandedPrincipal,
|
||||||
nsIPrincipal,
|
nsIPrincipal,
|
||||||
nsIExpandedPrincipal)
|
nsIExpandedPrincipal,
|
||||||
|
nsISerializable)
|
||||||
|
|
||||||
struct OriginComparator
|
struct OriginComparator
|
||||||
{
|
{
|
||||||
|
|
@ -54,6 +56,11 @@ ExpandedPrincipal::ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>> &aWhiteLis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExpandedPrincipal::ExpandedPrincipal()
|
||||||
|
: BasePrincipal(eExpandedPrincipal)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ExpandedPrincipal::~ExpandedPrincipal()
|
ExpandedPrincipal::~ExpandedPrincipal()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
@ -234,14 +241,71 @@ ExpandedPrincipal::GetScriptLocation(nsACString& aStr)
|
||||||
// Methods implementing nsISerializable //
|
// Methods implementing nsISerializable //
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
|
// We've had way too many issues with unversioned serializations, so
|
||||||
|
// explicitly version this one.
|
||||||
|
static const uint32_t kSerializationVersion = 1;
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
ExpandedPrincipal::Read(nsIObjectInputStream* aStream)
|
ExpandedPrincipal::Read(nsIObjectInputStream* aStream)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
uint32_t version;
|
||||||
|
nsresult rv = aStream->Read32(&version);
|
||||||
|
if (version != kSerializationVersion) {
|
||||||
|
MOZ_ASSERT(false,
|
||||||
|
"We really need to add handling of the old(?) version here");
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t count;
|
||||||
|
rv = aStream->Read32(&count);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mPrincipals.SetCapacity(count, fallible)) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
OriginComparator c;
|
||||||
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
|
nsCOMPtr<nsISupports> read;
|
||||||
|
rv = aStream->ReadObject(true, getter_AddRefs(read));
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(read);
|
||||||
|
if (!principal) {
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Play it safe and InsertElementSorted, in case the sort order
|
||||||
|
// changed for some bizarre reason.
|
||||||
|
mPrincipals.InsertElementSorted(Move(principal), c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
ExpandedPrincipal::Write(nsIObjectOutputStream* aStream)
|
ExpandedPrincipal::Write(nsIObjectOutputStream* aStream)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
nsresult rv = aStream->Write32(kSerializationVersion);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = aStream->Write32(mPrincipals.Length());
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& principal : mPrincipals) {
|
||||||
|
rv = aStream->WriteObject(principal, true);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ public:
|
||||||
|
|
||||||
static PrincipalKind Kind() { return eExpandedPrincipal; }
|
static PrincipalKind Kind() { return eExpandedPrincipal; }
|
||||||
|
|
||||||
|
// For use from the XPCOM factory constructor only. Do not ever use this
|
||||||
|
// constructor by hand!
|
||||||
|
ExpandedPrincipal();
|
||||||
|
|
||||||
NS_DECL_NSIEXPANDEDPRINCIPAL
|
NS_DECL_NSIEXPANDEDPRINCIPAL
|
||||||
NS_DECL_NSISERIALIZABLE
|
NS_DECL_NSISERIALIZABLE
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@ using mozilla::dom::AudioChannelAgent;
|
||||||
|
|
||||||
#include "nsScriptSecurityManager.h"
|
#include "nsScriptSecurityManager.h"
|
||||||
#include "ContentPrincipal.h"
|
#include "ContentPrincipal.h"
|
||||||
|
#include "ExpandedPrincipal.h"
|
||||||
#include "SystemPrincipal.h"
|
#include "SystemPrincipal.h"
|
||||||
#include "NullPrincipal.h"
|
#include "NullPrincipal.h"
|
||||||
#include "nsNetCID.h"
|
#include "nsNetCID.h"
|
||||||
|
|
@ -462,6 +463,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(CSPService)
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMixedContentBlocker)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMixedContentBlocker)
|
||||||
|
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR(ContentPrincipal)
|
NS_GENERIC_FACTORY_CONSTRUCTOR(ContentPrincipal)
|
||||||
|
NS_GENERIC_FACTORY_CONSTRUCTOR(ExpandedPrincipal)
|
||||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(SystemPrincipal,
|
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(SystemPrincipal,
|
||||||
nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
|
nsScriptSecurityManager::SystemPrincipalSingletonConstructor)
|
||||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NullPrincipal, Init)
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NullPrincipal, Init)
|
||||||
|
|
@ -578,6 +580,7 @@ NS_DEFINE_NAMED_CID(NS_PARENTPROCESSMESSAGEMANAGER_CID);
|
||||||
NS_DEFINE_NAMED_CID(NS_CHILDPROCESSMESSAGEMANAGER_CID);
|
NS_DEFINE_NAMED_CID(NS_CHILDPROCESSMESSAGEMANAGER_CID);
|
||||||
NS_DEFINE_NAMED_CID(NS_SCRIPTSECURITYMANAGER_CID);
|
NS_DEFINE_NAMED_CID(NS_SCRIPTSECURITYMANAGER_CID);
|
||||||
NS_DEFINE_NAMED_CID(NS_PRINCIPAL_CID);
|
NS_DEFINE_NAMED_CID(NS_PRINCIPAL_CID);
|
||||||
|
NS_DEFINE_NAMED_CID(NS_EXPANDEDPRINCIPAL_CID);
|
||||||
NS_DEFINE_NAMED_CID(NS_SYSTEMPRINCIPAL_CID);
|
NS_DEFINE_NAMED_CID(NS_SYSTEMPRINCIPAL_CID);
|
||||||
NS_DEFINE_NAMED_CID(NS_NULLPRINCIPAL_CID);
|
NS_DEFINE_NAMED_CID(NS_NULLPRINCIPAL_CID);
|
||||||
NS_DEFINE_NAMED_CID(THIRDPARTYUTIL_CID);
|
NS_DEFINE_NAMED_CID(THIRDPARTYUTIL_CID);
|
||||||
|
|
@ -825,6 +828,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
|
||||||
{ &kNS_CHILDPROCESSMESSAGEMANAGER_CID, false, nullptr, CreateChildMessageManager },
|
{ &kNS_CHILDPROCESSMESSAGEMANAGER_CID, false, nullptr, CreateChildMessageManager },
|
||||||
{ &kNS_SCRIPTSECURITYMANAGER_CID, false, nullptr, Construct_nsIScriptSecurityManager },
|
{ &kNS_SCRIPTSECURITYMANAGER_CID, false, nullptr, Construct_nsIScriptSecurityManager },
|
||||||
{ &kNS_PRINCIPAL_CID, false, nullptr, ContentPrincipalConstructor },
|
{ &kNS_PRINCIPAL_CID, false, nullptr, ContentPrincipalConstructor },
|
||||||
|
{ &kNS_EXPANDEDPRINCIPAL_CID, false, nullptr, ExpandedPrincipalConstructor },
|
||||||
{ &kNS_SYSTEMPRINCIPAL_CID, false, nullptr, SystemPrincipalConstructor },
|
{ &kNS_SYSTEMPRINCIPAL_CID, false, nullptr, SystemPrincipalConstructor },
|
||||||
{ &kNS_NULLPRINCIPAL_CID, false, nullptr, NullPrincipalConstructor },
|
{ &kNS_NULLPRINCIPAL_CID, false, nullptr, NullPrincipalConstructor },
|
||||||
{ &kNS_DEVICE_SENSORS_CID, false, nullptr, nsDeviceSensorsConstructor },
|
{ &kNS_DEVICE_SENSORS_CID, false, nullptr, nsDeviceSensorsConstructor },
|
||||||
|
|
@ -929,6 +933,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
|
||||||
{ NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID, &kNS_CHILDPROCESSMESSAGEMANAGER_CID },
|
{ NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID, &kNS_CHILDPROCESSMESSAGEMANAGER_CID },
|
||||||
{ NS_SCRIPTSECURITYMANAGER_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
|
{ NS_SCRIPTSECURITYMANAGER_CONTRACTID, &kNS_SCRIPTSECURITYMANAGER_CID },
|
||||||
{ NS_PRINCIPAL_CONTRACTID, &kNS_PRINCIPAL_CID },
|
{ NS_PRINCIPAL_CONTRACTID, &kNS_PRINCIPAL_CID },
|
||||||
|
{ NS_EXPANDEDPRINCIPAL_CONTRACTID, &kNS_EXPANDEDPRINCIPAL_CID },
|
||||||
{ NS_SYSTEMPRINCIPAL_CONTRACTID, &kNS_SYSTEMPRINCIPAL_CID },
|
{ NS_SYSTEMPRINCIPAL_CONTRACTID, &kNS_SYSTEMPRINCIPAL_CID },
|
||||||
{ NS_NULLPRINCIPAL_CONTRACTID, &kNS_NULLPRINCIPAL_CID },
|
{ NS_NULLPRINCIPAL_CONTRACTID, &kNS_NULLPRINCIPAL_CID },
|
||||||
{ NS_DEVICE_SENSORS_CONTRACTID, &kNS_DEVICE_SENSORS_CID },
|
{ NS_DEVICE_SENSORS_CONTRACTID, &kNS_DEVICE_SENSORS_CID },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue