2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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"
|
2017-03-22 13:39:08 +03:00
|
|
|
#include "SystemPrincipal.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
#include "nsCOMPtr.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"
|
2013-07-12 00:21:45 +04:00
|
|
|
#include "pratom.h"
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2018-07-17 22:38:19 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2017-03-22 13:39:08 +03:00
|
|
|
NS_IMPL_CLASSINFO(SystemPrincipal, nullptr,
|
2010-06-22 20:59:57 +04:00
|
|
|
nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
|
|
|
|
NS_SYSTEMPRINCIPAL_CID)
|
2017-03-22 13:39:08 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal, nsIPrincipal, nsISerializable)
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal, nsIPrincipal, nsISerializable)
|
1999-11-12 21:59:03 +03:00
|
|
|
|
2015-05-16 11:07:10 +03:00
|
|
|
#define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
|
2012-03-09 13:48:50 +04:00
|
|
|
|
2017-03-22 13:39:08 +03:00
|
|
|
already_AddRefed<SystemPrincipal> SystemPrincipal::Create() {
|
|
|
|
RefPtr<SystemPrincipal> sp = new SystemPrincipal();
|
2017-03-29 09:22:26 +03:00
|
|
|
sp->FinishInit(nsLiteralCString(SYSTEM_PRINCIPAL_SPEC), OriginAttributes());
|
2017-02-25 01:02:24 +03:00
|
|
|
return sp.forget();
|
|
|
|
}
|
|
|
|
|
2017-03-22 13:39:08 +03:00
|
|
|
nsresult SystemPrincipal::GetScriptLocation(nsACString& aStr) {
|
2015-05-16 11:07:10 +03:00
|
|
|
aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
|
2016-08-30 07:22:04 +03:00
|
|
|
return NS_OK;
|
2012-03-09 13:48:50 +04:00
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
///////////////////////////////////////
|
|
|
|
// Methods implementing nsIPrincipal //
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
2018-11-20 04:17:52 +03:00
|
|
|
uint32_t SystemPrincipal::GetHashValue() { return NS_PTR_TO_INT32(this); }
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2017-01-30 16:09:37 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetURI(nsIURI** aURI) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2003-10-22 02:11:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-05 19:04:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SystemPrincipal::GetIsOriginPotentiallyTrustworthy(bool* aResult) {
|
|
|
|
*aResult = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::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
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::SetDomain(nsIURI* aDomain) { return NS_OK; }
|
2003-10-22 02:11:49 +04:00
|
|
|
|
2013-01-09 01:53:32 +04:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) {
|
2013-01-09 01:53:32 +04:00
|
|
|
// No base domain for chrome.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-06 08:38:17 +03:00
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::GetAddonId(nsAString& aAddonId) {
|
2016-11-06 08:38:17 +03:00
|
|
|
aAddonId.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
};
|
|
|
|
|
2001-07-31 23:05:34 +04:00
|
|
|
//////////////////////////////////////////
|
|
|
|
// Methods implementing nsISerializable //
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::Read(nsIObjectInputStream* aStream) {
|
2001-07-31 23:05:34 +04:00
|
|
|
// no-op: CID is sufficient to identify the mSystemPrincipal singleton
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-22 13:39:08 +03:00
|
|
|
SystemPrincipal::Write(nsIObjectOutputStream* aStream) {
|
2019-06-03 15:37:12 +03:00
|
|
|
// Read is used still for legacy principals
|
|
|
|
MOZ_RELEASE_ASSERT(false, "Old style serialization is removed");
|
2001-07-31 23:05:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|