caps/src/nsJSPrincipals.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 #include "xpcprivate.h"
     7 #include "nsString.h"
     8 #include "nsIObjectOutputStream.h"
     9 #include "nsIObjectInputStream.h"
    10 #include "nsJSPrincipals.h"
    11 #include "plstr.h"
    12 #include "nsXPIDLString.h"
    13 #include "nsCOMPtr.h"
    14 #include "nsIJSRuntimeService.h"
    15 #include "nsIServiceManager.h"
    16 #include "nsMemory.h"
    17 #include "nsStringBuffer.h"
    19 // for mozilla::dom::workers::kJSPrincipalsDebugToken
    20 #include "mozilla/dom/workers/Workers.h"
    22 /* static */ bool
    23 nsJSPrincipals::Subsume(JSPrincipals *jsprin, JSPrincipals *other)
    24 {
    25     bool result;
    26     nsresult rv = nsJSPrincipals::get(jsprin)->Subsumes(nsJSPrincipals::get(other), &result);
    27     return NS_SUCCEEDED(rv) && result;
    28 }
    30 /* static */ void
    31 nsJSPrincipals::Destroy(JSPrincipals *jsprin)
    32 {
    33     // The JS runtime can call this method during the last GC when
    34     // nsScriptSecurityManager is destroyed. So we must not assume here that
    35     // the security manager still exists.
    37     nsJSPrincipals *nsjsprin = nsJSPrincipals::get(jsprin);
    39     // We need to destroy the nsIPrincipal. We'll do this by adding
    40     // to the refcount and calling release
    42 #ifdef NS_BUILD_REFCNT_LOGGING
    43     // The refcount logging considers AddRef-to-1 to indicate creation,
    44     // so trick it into thinking it's otherwise, but balance the
    45     // Release() we do below.
    46     nsjsprin->refcount++;
    47     nsjsprin->AddRef();
    48     nsjsprin->refcount--;
    49 #else
    50     nsjsprin->refcount++;
    51 #endif
    52     nsjsprin->Release();
    53 }
    55 #ifdef DEBUG
    57 // Defined here so one can do principals->dump() in the debugger
    58 JS_EXPORT_API(void)
    59 JSPrincipals::dump()
    60 {
    61     if (debugToken == nsJSPrincipals::DEBUG_TOKEN) {
    62         static_cast<nsJSPrincipals *>(this)->dumpImpl();
    63     } else if (debugToken == mozilla::dom::workers::kJSPrincipalsDebugToken) {
    64         fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
    65     } else {
    66         fprintf(stderr,
    67                 "!!! JSPrincipals (%p) is not nsJSPrincipals instance - bad token: "
    68                 "actual=0x%x expected=0x%x\n",
    69                 this, unsigned(debugToken), unsigned(nsJSPrincipals::DEBUG_TOKEN));
    70     }
    71 }
    73 #endif 

mercurial