LCOV - code coverage report
Current view: top level - caps - SystemPrincipal.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 25 43 58.1 %
Date: 2017-07-14 16:53:18 Functions: 10 17 58.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* The privileged system principal. */
       7             : 
       8             : #include "nscore.h"
       9             : #include "SystemPrincipal.h"
      10             : #include "nsIComponentManager.h"
      11             : #include "nsIServiceManager.h"
      12             : #include "nsIURL.h"
      13             : #include "nsCOMPtr.h"
      14             : #include "nsXPIDLString.h"
      15             : #include "nsReadableUtils.h"
      16             : #include "nsCRT.h"
      17             : #include "nsString.h"
      18             : #include "nsIClassInfoImpl.h"
      19             : #include "nsIScriptSecurityManager.h"
      20             : #include "pratom.h"
      21             : 
      22           3 : NS_IMPL_CLASSINFO(SystemPrincipal, nullptr,
      23             :                   nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
      24             :                   NS_SYSTEMPRINCIPAL_CID)
      25        4449 : NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal,
      26             :                            nsIPrincipal,
      27             :                            nsISerializable)
      28           2 : NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal,
      29             :                             nsIPrincipal,
      30             :                             nsISerializable)
      31             : 
      32             : #define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
      33             : 
      34             : already_AddRefed<SystemPrincipal>
      35           3 : SystemPrincipal::Create()
      36             : {
      37           6 :   RefPtr<SystemPrincipal> sp = new SystemPrincipal();
      38           9 :   sp->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC),
      39          12 :                  OriginAttributes());
      40           6 :   return sp.forget();
      41             : }
      42             : 
      43             : nsresult
      44           0 : SystemPrincipal::GetScriptLocation(nsACString &aStr)
      45             : {
      46           0 :     aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC);
      47           0 :     return NS_OK;
      48             : }
      49             : 
      50             : ///////////////////////////////////////
      51             : // Methods implementing nsIPrincipal //
      52             : ///////////////////////////////////////
      53             : 
      54             : NS_IMETHODIMP
      55           0 : SystemPrincipal::GetHashValue(uint32_t *result)
      56             : {
      57           0 :     *result = NS_PTR_TO_INT32(this);
      58           0 :     return NS_OK;
      59             : }
      60             : 
      61             : NS_IMETHODIMP
      62         184 : SystemPrincipal::GetURI(nsIURI** aURI)
      63             : {
      64         184 :     *aURI = nullptr;
      65         184 :     return NS_OK;
      66             : }
      67             : 
      68             : NS_IMETHODIMP
      69        1759 : SystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
      70             : {
      71        1759 :   *aCsp = nullptr;
      72        1759 :   return NS_OK;
      73             : }
      74             : 
      75             : NS_IMETHODIMP
      76           0 : SystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
      77             : {
      78             :   // Never destroy an existing CSP on the principal.
      79             :   // This method should only be called in rare cases.
      80             : 
      81           0 :   return NS_ERROR_FAILURE;
      82             : }
      83             : 
      84             : NS_IMETHODIMP
      85           1 : SystemPrincipal::EnsureCSP(nsIDOMDocument* aDocument,
      86             :                            nsIContentSecurityPolicy** aCSP)
      87             : {
      88             :   // CSP on a system principal makes no sense
      89           1 :   return NS_ERROR_FAILURE;
      90             : }
      91             : 
      92             : NS_IMETHODIMP
      93           0 : SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
      94             : {
      95           0 :   *aPreloadCSP = nullptr;
      96           0 :   return NS_OK;
      97             : }
      98             : 
      99             : NS_IMETHODIMP
     100           0 : SystemPrincipal::EnsurePreloadCSP(nsIDOMDocument* aDocument,
     101             :                                   nsIContentSecurityPolicy** aPreloadCSP)
     102             : {
     103             :   // CSP on a system principal makes no sense
     104           0 :   return NS_OK;
     105             : }
     106             : 
     107             : NS_IMETHODIMP
     108           0 : SystemPrincipal::GetDomain(nsIURI** aDomain)
     109             : {
     110           0 :     *aDomain = nullptr;
     111           0 :     return NS_OK;
     112             : }
     113             : 
     114             : NS_IMETHODIMP
     115           0 : SystemPrincipal::SetDomain(nsIURI* aDomain)
     116             : {
     117           0 :   return NS_OK;
     118             : }
     119             : 
     120             : NS_IMETHODIMP
     121         766 : SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
     122             : {
     123             :   // No base domain for chrome.
     124         766 :   return NS_OK;
     125             : }
     126             : 
     127             : NS_IMETHODIMP
     128           6 : SystemPrincipal::GetAddonId(nsAString& aAddonId)
     129             : {
     130           6 :   aAddonId.Truncate();
     131           6 :   return NS_OK;
     132             : };
     133             : 
     134             : //////////////////////////////////////////
     135             : // Methods implementing nsISerializable //
     136             : //////////////////////////////////////////
     137             : 
     138             : NS_IMETHODIMP
     139           7 : SystemPrincipal::Read(nsIObjectInputStream* aStream)
     140             : {
     141             :     // no-op: CID is sufficient to identify the mSystemPrincipal singleton
     142           7 :     return NS_OK;
     143             : }
     144             : 
     145             : NS_IMETHODIMP
     146           3 : SystemPrincipal::Write(nsIObjectOutputStream* aStream)
     147             : {
     148             :     // no-op: CID is sufficient to identify the mSystemPrincipal singleton
     149           3 :     return NS_OK;
     150             : }

Generated by: LCOV version 1.13