caps/SystemPrincipal.cpp
author Brindusan Cristian <cbrindusan@mozilla.com>
Fri, 13 Jul 2018 22:11:24 +0300
changeset 426575 bd747e24063da7d803dc5fd20b5a8af0d036f4d5
parent 418170 3fdd267726d3db4fb48f1fbadf2ef06c99aa248b
child 427020 08d2f7d9a956c8dcccc9336bc3b0e32263987b4c
permissions -rw-r--r--
Backed out 12 changesets (bug 1471025) for build bustages on dom/ipc/ContentProcess.cpp. CLOSED TREE Backed out changeset 398ccedc20dc (bug 1471025) Backed out changeset 599895de063e (bug 1471025) Backed out changeset dc7ec17179d1 (bug 1471025) Backed out changeset 5051f15fc200 (bug 1471025) Backed out changeset faef4df47b20 (bug 1471025) Backed out changeset d344247b8706 (bug 1471025) Backed out changeset 83d98ea5ebac (bug 1471025) Backed out changeset 38f690f30e78 (bug 1471025) Backed out changeset 4b7a8a35ed95 (bug 1471025) Backed out changeset e3bbc87b71af (bug 1471025) Backed out changeset 68bb03c63b3c (bug 1471025) Backed out changeset 4a8fbb472c91 (bug 1471025)

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */

/* The privileged system principal. */

#include "nscore.h"
#include "SystemPrincipal.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsCOMPtr.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIClassInfoImpl.h"
#include "nsIScriptSecurityManager.h"
#include "pratom.h"

NS_IMPL_CLASSINFO(SystemPrincipal, nullptr,
                  nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
                  NS_SYSTEMPRINCIPAL_CID)
NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal,
                           nsIPrincipal,
                           nsISerializable)
NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal,
                            nsIPrincipal,
                            nsISerializable)

#define SYSTEM_PRINCIPAL_SPEC "[System Principal]"

already_AddRefed<SystemPrincipal>
SystemPrincipal::Create()
{
  RefPtr<SystemPrincipal> sp = new SystemPrincipal();
  sp->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC),
                 OriginAttributes());
  return sp.forget();
}

nsresult
SystemPrincipal::GetScriptLocation(nsACString &aStr)
{
    aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
    return NS_OK;
}

///////////////////////////////////////
// Methods implementing nsIPrincipal //
///////////////////////////////////////

NS_IMETHODIMP
SystemPrincipal::GetHashValue(uint32_t *result)
{
    *result = NS_PTR_TO_INT32(this);
    return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::GetURI(nsIURI** aURI)
{
    *aURI = nullptr;
    return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
{
  *aCsp = nullptr;
  return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
{
  // Never destroy an existing CSP on the principal.
  // This method should only be called in rare cases.

  return NS_ERROR_FAILURE;
}

NS_IMETHODIMP
SystemPrincipal::EnsureCSP(nsIDocument* aDocument,
                           nsIContentSecurityPolicy** aCSP)
{
  // CSP on a system principal makes no sense
  return NS_ERROR_FAILURE;
}

NS_IMETHODIMP
SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
{
  *aPreloadCSP = nullptr;
  return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::EnsurePreloadCSP(nsIDocument* aDocument,
                                  nsIContentSecurityPolicy** aPreloadCSP)
{
  // CSP on a system principal makes no sense
  return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::GetDomain(nsIURI** aDomain)
{
    *aDomain = nullptr;
    return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::SetDomain(nsIURI* aDomain)
{
  return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
{
  // No base domain for chrome.
  return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::GetAddonId(nsAString& aAddonId)
{
  aAddonId.Truncate();
  return NS_OK;
};

//////////////////////////////////////////
// Methods implementing nsISerializable //
//////////////////////////////////////////

NS_IMETHODIMP
SystemPrincipal::Read(nsIObjectInputStream* aStream)
{
    // no-op: CID is sufficient to identify the mSystemPrincipal singleton
    return NS_OK;
}

NS_IMETHODIMP
SystemPrincipal::Write(nsIObjectOutputStream* aStream)
{
    // no-op: CID is sufficient to identify the mSystemPrincipal singleton
    return NS_OK;
}