caps/src/nsJSPrincipals.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "xpcprivate.h"
michael@0 7 #include "nsString.h"
michael@0 8 #include "nsIObjectOutputStream.h"
michael@0 9 #include "nsIObjectInputStream.h"
michael@0 10 #include "nsJSPrincipals.h"
michael@0 11 #include "plstr.h"
michael@0 12 #include "nsXPIDLString.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsIJSRuntimeService.h"
michael@0 15 #include "nsIServiceManager.h"
michael@0 16 #include "nsMemory.h"
michael@0 17 #include "nsStringBuffer.h"
michael@0 18
michael@0 19 // for mozilla::dom::workers::kJSPrincipalsDebugToken
michael@0 20 #include "mozilla/dom/workers/Workers.h"
michael@0 21
michael@0 22 /* static */ bool
michael@0 23 nsJSPrincipals::Subsume(JSPrincipals *jsprin, JSPrincipals *other)
michael@0 24 {
michael@0 25 bool result;
michael@0 26 nsresult rv = nsJSPrincipals::get(jsprin)->Subsumes(nsJSPrincipals::get(other), &result);
michael@0 27 return NS_SUCCEEDED(rv) && result;
michael@0 28 }
michael@0 29
michael@0 30 /* static */ void
michael@0 31 nsJSPrincipals::Destroy(JSPrincipals *jsprin)
michael@0 32 {
michael@0 33 // The JS runtime can call this method during the last GC when
michael@0 34 // nsScriptSecurityManager is destroyed. So we must not assume here that
michael@0 35 // the security manager still exists.
michael@0 36
michael@0 37 nsJSPrincipals *nsjsprin = nsJSPrincipals::get(jsprin);
michael@0 38
michael@0 39 // We need to destroy the nsIPrincipal. We'll do this by adding
michael@0 40 // to the refcount and calling release
michael@0 41
michael@0 42 #ifdef NS_BUILD_REFCNT_LOGGING
michael@0 43 // The refcount logging considers AddRef-to-1 to indicate creation,
michael@0 44 // so trick it into thinking it's otherwise, but balance the
michael@0 45 // Release() we do below.
michael@0 46 nsjsprin->refcount++;
michael@0 47 nsjsprin->AddRef();
michael@0 48 nsjsprin->refcount--;
michael@0 49 #else
michael@0 50 nsjsprin->refcount++;
michael@0 51 #endif
michael@0 52 nsjsprin->Release();
michael@0 53 }
michael@0 54
michael@0 55 #ifdef DEBUG
michael@0 56
michael@0 57 // Defined here so one can do principals->dump() in the debugger
michael@0 58 JS_EXPORT_API(void)
michael@0 59 JSPrincipals::dump()
michael@0 60 {
michael@0 61 if (debugToken == nsJSPrincipals::DEBUG_TOKEN) {
michael@0 62 static_cast<nsJSPrincipals *>(this)->dumpImpl();
michael@0 63 } else if (debugToken == mozilla::dom::workers::kJSPrincipalsDebugToken) {
michael@0 64 fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
michael@0 65 } else {
michael@0 66 fprintf(stderr,
michael@0 67 "!!! JSPrincipals (%p) is not nsJSPrincipals instance - bad token: "
michael@0 68 "actual=0x%x expected=0x%x\n",
michael@0 69 this, unsigned(debugToken), unsigned(nsJSPrincipals::DEBUG_TOKEN));
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 #endif

mercurial