caps/src/nsJSPrincipals.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/caps/src/nsJSPrincipals.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "xpcprivate.h"
    1.10 +#include "nsString.h"
    1.11 +#include "nsIObjectOutputStream.h"
    1.12 +#include "nsIObjectInputStream.h"
    1.13 +#include "nsJSPrincipals.h"
    1.14 +#include "plstr.h"
    1.15 +#include "nsXPIDLString.h"
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsIJSRuntimeService.h"
    1.18 +#include "nsIServiceManager.h"
    1.19 +#include "nsMemory.h"
    1.20 +#include "nsStringBuffer.h"
    1.21 +
    1.22 +// for mozilla::dom::workers::kJSPrincipalsDebugToken
    1.23 +#include "mozilla/dom/workers/Workers.h"
    1.24 +
    1.25 +/* static */ bool
    1.26 +nsJSPrincipals::Subsume(JSPrincipals *jsprin, JSPrincipals *other)
    1.27 +{
    1.28 +    bool result;
    1.29 +    nsresult rv = nsJSPrincipals::get(jsprin)->Subsumes(nsJSPrincipals::get(other), &result);
    1.30 +    return NS_SUCCEEDED(rv) && result;
    1.31 +}
    1.32 +
    1.33 +/* static */ void
    1.34 +nsJSPrincipals::Destroy(JSPrincipals *jsprin)
    1.35 +{
    1.36 +    // The JS runtime can call this method during the last GC when
    1.37 +    // nsScriptSecurityManager is destroyed. So we must not assume here that
    1.38 +    // the security manager still exists.
    1.39 +
    1.40 +    nsJSPrincipals *nsjsprin = nsJSPrincipals::get(jsprin);
    1.41 +
    1.42 +    // We need to destroy the nsIPrincipal. We'll do this by adding
    1.43 +    // to the refcount and calling release
    1.44 +
    1.45 +#ifdef NS_BUILD_REFCNT_LOGGING
    1.46 +    // The refcount logging considers AddRef-to-1 to indicate creation,
    1.47 +    // so trick it into thinking it's otherwise, but balance the
    1.48 +    // Release() we do below.
    1.49 +    nsjsprin->refcount++;
    1.50 +    nsjsprin->AddRef();
    1.51 +    nsjsprin->refcount--;
    1.52 +#else
    1.53 +    nsjsprin->refcount++;
    1.54 +#endif
    1.55 +    nsjsprin->Release();
    1.56 +}
    1.57 +
    1.58 +#ifdef DEBUG
    1.59 +
    1.60 +// Defined here so one can do principals->dump() in the debugger
    1.61 +JS_EXPORT_API(void)
    1.62 +JSPrincipals::dump()
    1.63 +{
    1.64 +    if (debugToken == nsJSPrincipals::DEBUG_TOKEN) {
    1.65 +        static_cast<nsJSPrincipals *>(this)->dumpImpl();
    1.66 +    } else if (debugToken == mozilla::dom::workers::kJSPrincipalsDebugToken) {
    1.67 +        fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
    1.68 +    } else {
    1.69 +        fprintf(stderr,
    1.70 +                "!!! JSPrincipals (%p) is not nsJSPrincipals instance - bad token: "
    1.71 +                "actual=0x%x expected=0x%x\n",
    1.72 +                this, unsigned(debugToken), unsigned(nsJSPrincipals::DEBUG_TOKEN));
    1.73 +    }
    1.74 +}
    1.75 +
    1.76 +#endif 

mercurial