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"
8 #include "nsIObjectOutputStream.h"
9 #include "nsIObjectInputStream.h"
10 #include "nsJSPrincipals.h"
12 #include "nsXPIDLString.h"
14 #include "nsIJSRuntimeService.h"
15 #include "nsIServiceManager.h"
17 #include "nsStringBuffer.h"
19 // for mozilla::dom::workers::kJSPrincipalsDebugToken
20 #include "mozilla/dom/workers/Workers.h"
23 nsJSPrincipals::Subsume(JSPrincipals
*jsprin
, JSPrincipals
*other
)
26 nsresult rv
= nsJSPrincipals::get(jsprin
)->Subsumes(nsJSPrincipals::get(other
), &result
);
27 return NS_SUCCEEDED(rv
) && result
;
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.
57 // Defined here so one can do principals->dump() in the debugger
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);
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
));