2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 00:54:35 +00:00
|
|
|
|
|
|
|
/* The privileged system principal. */
|
|
|
|
|
2001-08-14 07:59:59 +00:00
|
|
|
#include "nscore.h"
|
2017-03-22 10:39:08 +00:00
|
|
|
#include "SystemPrincipal.h"
|
2022-12-02 00:53:51 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
1999-09-01 00:54:35 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsString.h"
|
2006-03-15 04:59:42 +00:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2013-07-11 20:21:45 +00:00
|
|
|
#include "pratom.h"
|
1999-09-01 00:54:35 +00:00
|
|
|
|
2018-07-17 19:38:19 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2023-02-01 21:45:44 +00:00
|
|
|
NS_IMPL_CLASSINFO(SystemPrincipal, nullptr, nsIClassInfo::SINGLETON,
|
2010-06-22 16:59:57 +00:00
|
|
|
NS_SYSTEMPRINCIPAL_CID)
|
2017-03-22 10:39:08 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal, nsIPrincipal, nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal, nsIPrincipal, nsISerializable)
|
1999-11-12 18:59:03 +00:00
|
|
|
|
2021-05-17 20:50:09 +00:00
|
|
|
static constexpr nsLiteralCString kSystemPrincipalSpec =
|
|
|
|
"[System Principal]"_ns;
|
|
|
|
|
|
|
|
SystemPrincipal::SystemPrincipal()
|
|
|
|
: BasePrincipal(eSystemPrincipal, kSystemPrincipalSpec,
|
|
|
|
OriginAttributes()) {}
|
2012-03-09 09:48:50 +00:00
|
|
|
|
2022-12-02 00:53:51 +00:00
|
|
|
static StaticMutex sSystemPrincipalMutex;
|
|
|
|
static StaticRefPtr<SystemPrincipal> sSystemPrincipal
|
|
|
|
MOZ_GUARDED_BY(sSystemPrincipalMutex);
|
|
|
|
|
|
|
|
already_AddRefed<SystemPrincipal> SystemPrincipal::Get() {
|
|
|
|
StaticMutexAutoLock lock(sSystemPrincipalMutex);
|
|
|
|
return do_AddRef(sSystemPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SystemPrincipal> SystemPrincipal::Init() {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
StaticMutexAutoLock lock(sSystemPrincipalMutex);
|
|
|
|
if (MOZ_UNLIKELY(sSystemPrincipal)) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("SystemPrincipal::Init() may only be called once");
|
|
|
|
} else {
|
|
|
|
sSystemPrincipal = new SystemPrincipal();
|
|
|
|
}
|
|
|
|
return do_AddRef(sSystemPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemPrincipal::Shutdown() {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
StaticMutexAutoLock lock(sSystemPrincipalMutex);
|
|
|
|
MOZ_ASSERT(sSystemPrincipal);
|
|
|
|
sSystemPrincipal = nullptr;
|
2017-02-24 22:02:24 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 10:39:08 +00:00
|
|
|
nsresult SystemPrincipal::GetScriptLocation(nsACString& aStr) {
|
2021-05-17 20:50:09 +00:00
|
|
|
aStr.Assign(kSystemPrincipalSpec);
|
2016-08-30 04:22:04 +00:00
|
|
|
return NS_OK;
|
2012-03-09 09:48:50 +00:00
|
|
|
}
|
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
///////////////////////////////////////
|
|
|
|
// Methods implementing nsIPrincipal //
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
2018-11-20 01:17:52 +00:00
|
|
|
uint32_t SystemPrincipal::GetHashValue() { return NS_PTR_TO_INT32(this); }
|
1999-09-01 00:54:35 +00:00
|
|
|
|
2017-01-30 13:09:37 +00:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::GetURI(nsIURI** aURI) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aURI = nullptr;
|
2003-10-21 22:11:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-05 16:04:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SystemPrincipal::GetIsOriginPotentiallyTrustworthy(bool* aResult) {
|
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::GetDomain(nsIURI** aDomain) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aDomain = nullptr;
|
2003-10-21 22:11:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::SetDomain(nsIURI* aDomain) { return NS_OK; }
|
2003-10-21 22:11:49 +00:00
|
|
|
|
2013-01-08 21:53:32 +00:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) {
|
2013-01-08 21:53:32 +00:00
|
|
|
// No base domain for chrome.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-06 05:38:17 +00:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::GetAddonId(nsAString& aAddonId) {
|
2016-11-06 05:38:17 +00:00
|
|
|
aAddonId.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
2001-07-31 19:05:34 +00:00
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::Read(nsIObjectInputStream* aStream) {
|
2001-07-31 19:05:34 +00:00
|
|
|
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 10:39:08 +00:00
|
|
|
SystemPrincipal::Write(nsIObjectOutputStream* aStream) {
|
2019-06-03 12:37:12 +00:00
|
|
|
// Read is used still for legacy principals
|
|
|
|
MOZ_RELEASE_ASSERT(false, "Old style serialization is removed");
|
2001-07-31 19:05:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|