2001-09-25 05:03:58 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-09-01 04:54:35 +04:00
|
|
|
|
|
|
|
/* The privileged system principal. */
|
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
#include "nsSystemPrincipal.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2003-10-22 02:11:49 +04:00
|
|
|
#include "nsString.h"
|
2006-03-15 07:59:42 +03:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2012-07-20 09:44:03 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2013-07-12 00:21:45 +04:00
|
|
|
#include "pratom.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2013-04-03 04:16:25 +04:00
|
|
|
NS_IMPL_CLASSINFO(nsSystemPrincipal, nullptr,
|
2010-06-22 20:59:57 +04:00
|
|
|
nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
|
|
|
|
NS_SYSTEMPRINCIPAL_CID)
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(nsSystemPrincipal,
|
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal,
|
2003-10-22 02:11:49 +04:00
|
|
|
nsIPrincipal,
|
|
|
|
nsISerializable)
|
1999-11-12 21:59:03 +03:00
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2003-10-22 02:11:49 +04:00
|
|
|
nsSystemPrincipal::AddRef()
|
2003-08-22 07:06:53 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
|
2013-11-27 19:37:10 +04:00
|
|
|
nsrefcnt count = ++refcount;
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
|
|
|
|
return count;
|
2003-08-22 07:06:53 +04:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType)
|
2003-10-22 02:11:49 +04:00
|
|
|
nsSystemPrincipal::Release()
|
2003-08-22 07:06:53 +04:00
|
|
|
{
|
2012-03-09 13:48:50 +04:00
|
|
|
NS_PRECONDITION(0 != refcount, "dup release");
|
2013-11-27 19:37:10 +04:00
|
|
|
nsrefcnt count = --refcount;
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
|
|
|
|
if (count == 0) {
|
2010-07-05 13:42:18 +04:00
|
|
|
delete this;
|
2003-10-22 02:11:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
2003-08-22 07:06:53 +04:00
|
|
|
}
|
|
|
|
|
2012-03-09 13:48:50 +04:00
|
|
|
static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]";
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSystemPrincipal::GetScriptLocation(nsACString &aStr)
|
|
|
|
{
|
|
|
|
aStr.Assign(SYSTEM_PRINCIPAL_SPEC);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void nsSystemPrincipal::dumpImpl()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "nsSystemPrincipal (%p)\n", this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
// Methods implementing nsIPrincipal //
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
1999-09-01 04:54:35 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSystemPrincipal::Equals(nsIPrincipal *other, bool *result)
|
1999-09-01 04:54:35 +04:00
|
|
|
{
|
|
|
|
*result = (other == this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-14 06:57:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::EqualsConsideringDomain(nsIPrincipal *other, bool *result)
|
|
|
|
{
|
|
|
|
return Equals(other, result);
|
|
|
|
}
|
|
|
|
|
2005-07-09 03:26:36 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsSystemPrincipal::Subsumes(nsIPrincipal *other, bool *result)
|
2012-02-23 21:41:25 +04:00
|
|
|
{
|
2012-02-23 21:47:02 +04:00
|
|
|
*result = true;
|
2012-02-23 21:41:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-14 06:57:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::SubsumesConsideringDomain(nsIPrincipal *other, bool *result)
|
|
|
|
{
|
|
|
|
*result = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-27 06:45:29 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-20 22:34:33 +04:00
|
|
|
nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
|
2008-02-27 06:45:29 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-01 04:54:35 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSystemPrincipal::GetHashValue(uint32_t *result)
|
1999-09-01 04:54:35 +04:00
|
|
|
{
|
2001-08-14 11:59:59 +04:00
|
|
|
*result = NS_PTR_TO_INT32(this);
|
1999-09-01 04:54:35 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2003-10-22 02:11:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetOrigin(char** aOrigin)
|
|
|
|
{
|
2011-07-20 03:59:16 +04:00
|
|
|
*aOrigin = ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC));
|
2003-10-22 02:11:49 +04:00
|
|
|
return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2010-01-23 00:38:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aCsp = nullptr;
|
2010-01-23 00:38:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
|
|
|
{
|
|
|
|
// CSP on a null principal makes no sense
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetDomain(nsIURI** aDomain)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDomain = nullptr;
|
2003-10-22 02:11:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::SetDomain(nsIURI* aDomain)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-20 09:44:03 +04:00
|
|
|
NS_IMETHODIMP
|
2013-09-11 08:18:36 +04:00
|
|
|
nsSystemPrincipal::GetJarPrefix(nsACString& aJarPrefix)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
2013-09-11 08:18:36 +04:00
|
|
|
aJarPrefix.Truncate();
|
|
|
|
return NS_OK;
|
2012-07-20 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
|
|
|
*aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSystemPrincipal::GetAppId(uint32_t* aAppId)
|
2012-07-20 09:44:03 +04:00
|
|
|
{
|
|
|
|
*aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-10-22 02:11:49 +04:00
|
|
|
|
2012-07-31 19:47:20 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
|
|
|
|
{
|
|
|
|
*aIsInBrowserElement = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-26 03:28:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|
|
|
{
|
|
|
|
*aUnknownAppId = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 20:31:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
|
|
|
|
{
|
|
|
|
*aIsNullPrincipal = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
|
|
|
|
{
|
|
|
|
// No base domain for chrome.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-13 23:15:09 +03:00
|
|
|
bool
|
|
|
|
nsSystemPrincipal::IsOnCSSUnprefixingWhitelist()
|
|
|
|
{
|
|
|
|
// chrome stylesheets should not be fed to the CSS Unprefixing Service.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
|
|
|
|
{
|
|
|
|
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
|
|
|
|
{
|
|
|
|
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-21 07:05:35 +03:00
|
|
|
/////////////////////////////////////////////
|
|
|
|
// Constructor, Destructor, initialization //
|
|
|
|
/////////////////////////////////////////////
|
1999-09-01 04:54:35 +04:00
|
|
|
|
|
|
|
nsSystemPrincipal::nsSystemPrincipal()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-09 13:48:50 +04:00
|
|
|
nsSystemPrincipal::~nsSystemPrincipal()
|
1999-09-01 04:54:35 +04:00
|
|
|
{
|
|
|
|
}
|