Bumping gaia.json for 4 gaia revision(s) a=gaia-bump
[gecko.git] / caps / nsJSPrincipals.cpp
blobb981d1d91d3be994ee648472fbf02d1bbd75a3e8
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)
25 bool result;
26 nsresult rv = nsJSPrincipals::get(jsprin)->Subsumes(nsJSPrincipals::get(other), &result);
27 return NS_SUCCEEDED(rv) && result;
30 /* static */ void
31 nsJSPrincipals::Destroy(JSPrincipals *jsprin)
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();
55 #ifdef DEBUG
57 // Defined here so one can do principals->dump() in the debugger
58 JS_EXPORT_API(void)
59 JSPrincipals::dump()
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));
73 #endif