caps/src/nsSystemPrincipal.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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/. */
     6 /* The privileged system principal. */
     8 #include "nscore.h"
     9 #include "nsSystemPrincipal.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"
    22 NS_IMPL_CLASSINFO(nsSystemPrincipal, nullptr,
    23                   nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
    24                   NS_SYSTEMPRINCIPAL_CID)
    25 NS_IMPL_QUERY_INTERFACE_CI(nsSystemPrincipal,
    26                            nsIPrincipal,
    27                            nsISerializable)
    28 NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal,
    29                             nsIPrincipal,
    30                             nsISerializable)
    32 NS_IMETHODIMP_(MozExternalRefCountType)
    33 nsSystemPrincipal::AddRef()
    34 {
    35   NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt");
    36   nsrefcnt count = ++refcount;
    37   NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
    38   return count;
    39 }
    41 NS_IMETHODIMP_(MozExternalRefCountType)
    42 nsSystemPrincipal::Release()
    43 {
    44   NS_PRECONDITION(0 != refcount, "dup release");
    45   nsrefcnt count = --refcount;
    46   NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
    47   if (count == 0) {
    48     delete this;
    49   }
    51   return count;
    52 }
    54 static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]";
    56 void
    57 nsSystemPrincipal::GetScriptLocation(nsACString &aStr)
    58 {
    59     aStr.Assign(SYSTEM_PRINCIPAL_SPEC);
    60 }
    62 #ifdef DEBUG
    63 void nsSystemPrincipal::dumpImpl()
    64 {
    65   fprintf(stderr, "nsSystemPrincipal (%p)\n", this);
    66 }
    67 #endif 
    70 ///////////////////////////////////////
    71 // Methods implementing nsIPrincipal //
    72 ///////////////////////////////////////
    74 NS_IMETHODIMP
    75 nsSystemPrincipal::Equals(nsIPrincipal *other, bool *result)
    76 {
    77     *result = (other == this);
    78     return NS_OK;
    79 }
    81 NS_IMETHODIMP
    82 nsSystemPrincipal::EqualsConsideringDomain(nsIPrincipal *other, bool *result)
    83 {
    84     return Equals(other, result);
    85 }
    87 NS_IMETHODIMP
    88 nsSystemPrincipal::Subsumes(nsIPrincipal *other, bool *result)
    89 {
    90     *result = true;
    91     return NS_OK;
    92 }
    94 NS_IMETHODIMP
    95 nsSystemPrincipal::SubsumesConsideringDomain(nsIPrincipal *other, bool *result)
    96 {
    97     *result = true;
    98     return NS_OK;
    99 }
   101 NS_IMETHODIMP
   102 nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
   103 {
   104     return NS_OK;
   105 }
   107 NS_IMETHODIMP
   108 nsSystemPrincipal::GetHashValue(uint32_t *result)
   109 {
   110     *result = NS_PTR_TO_INT32(this);
   111     return NS_OK;
   112 }
   114 NS_IMETHODIMP 
   115 nsSystemPrincipal::GetURI(nsIURI** aURI)
   116 {
   117     *aURI = nullptr;
   118     return NS_OK;
   119 }
   121 NS_IMETHODIMP 
   122 nsSystemPrincipal::GetOrigin(char** aOrigin)
   123 {
   124     *aOrigin = ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC));
   125     return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
   126 }
   128 NS_IMETHODIMP
   129 nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
   130 {
   131   *aCsp = nullptr;
   132   return NS_OK;
   133 }
   135 NS_IMETHODIMP
   136 nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
   137 {
   138   // CSP on a null principal makes no sense
   139   return NS_OK;
   140 }
   142 NS_IMETHODIMP
   143 nsSystemPrincipal::GetDomain(nsIURI** aDomain)
   144 {
   145     *aDomain = nullptr;
   146     return NS_OK;
   147 }
   149 NS_IMETHODIMP
   150 nsSystemPrincipal::SetDomain(nsIURI* aDomain)
   151 {
   152   return NS_OK;
   153 }
   155 NS_IMETHODIMP
   156 nsSystemPrincipal::GetJarPrefix(nsACString& aJarPrefix)
   157 {
   158   aJarPrefix.Truncate();
   159   return NS_OK;
   160 }
   162 NS_IMETHODIMP
   163 nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus)
   164 {
   165   *aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
   166   return NS_OK;
   167 }
   169 NS_IMETHODIMP
   170 nsSystemPrincipal::GetAppId(uint32_t* aAppId)
   171 {
   172   *aAppId = nsIScriptSecurityManager::NO_APP_ID;
   173   return NS_OK;
   174 }
   176 NS_IMETHODIMP
   177 nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
   178 {
   179   *aIsInBrowserElement = false;
   180   return NS_OK;
   181 }
   183 NS_IMETHODIMP
   184 nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId)
   185 {
   186   *aUnknownAppId = false;
   187   return NS_OK;
   188 }
   190 NS_IMETHODIMP
   191 nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
   192 {
   193   *aIsNullPrincipal = false;
   194   return NS_OK;
   195 }
   197 NS_IMETHODIMP
   198 nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
   199 {
   200   // No base domain for chrome.
   201   return NS_OK;
   202 }
   204 //////////////////////////////////////////
   205 // Methods implementing nsISerializable //
   206 //////////////////////////////////////////
   208 NS_IMETHODIMP
   209 nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
   210 {
   211     // no-op: CID is sufficient to identify the mSystemPrincipal singleton
   212     return NS_OK;
   213 }
   215 NS_IMETHODIMP
   216 nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
   217 {
   218     // no-op: CID is sufficient to identify the mSystemPrincipal singleton
   219     return NS_OK;
   220 }
   222 /////////////////////////////////////////////
   223 // Constructor, Destructor, initialization //
   224 /////////////////////////////////////////////
   226 nsSystemPrincipal::nsSystemPrincipal()
   227 {
   228 }
   230 nsSystemPrincipal::~nsSystemPrincipal()
   231 {
   232 }

mercurial