Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Protected Attributes
XPCNativeWrapper Class Reference

#include <XPCNativeWrapper.h>

Collaboration diagram for XPCNativeWrapper:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static PRBool AttachNewConstructorObject (XPCCallContext &ccx, JSObject *aGlobalObject)
static JSObjectGetNewOrUsed (JSContext *cx, XPCWrappedNative *wrapper, JSObject *callee)
static PRBool IsNativeWrapperClass (JSClass *clazz)
static PRBool IsNativeWrapper (JSContext *cx, JSObject *obj)
static XPCWrappedNativeGetWrappedNative (JSContext *cx, JSObject *obj)
static JSClassGetJSClass ()
static void ClearWrappedNativeScopes (JSContext *cx, XPCWrappedNative *wrapper)

Static Protected Attributes

static JSExtendedClass sXPC_NW_JSClass

Detailed Description

Definition at line 43 of file XPCNativeWrapper.h.


Member Function Documentation

Definition at line 1470 of file XPCNativeWrapper.cpp.

{
  JSObject *class_obj =
    ::JS_InitClass(ccx, aGlobalObject, nsnull, &sXPC_NW_JSClass.base,
                   XPCNativeWrapperCtor, 0, nsnull, nsnull,
                   nsnull, nsnull);
  if (!class_obj) {
    NS_WARNING("can't initialize the XPCNativeWrapper class");
    return PR_FALSE;
  }
  
  // Make sure our prototype chain is empty and that people can't mess
  // with XPCNativeWrapper.prototype.
  ::JS_SetPrototype(ccx, class_obj, nsnull);
  if (!::JS_SealObject(ccx, class_obj, JS_FALSE)) {
    NS_WARNING("Failed to seal XPCNativeWrapper.prototype");
    return PR_FALSE;
  }

  JSBool found;
  return ::JS_SetPropertyAttributes(ccx, aGlobalObject,
                                    sXPC_NW_JSClass.base.name,
                                    JSPROP_READONLY | JSPROP_PERMANENT,
                                    &found);
}

Here is the call graph for this function:

Definition at line 1614 of file XPCNativeWrapper.cpp.

{
  JSObject *nativeWrapper = wrapper->GetNativeWrapper();

  if (nativeWrapper) {
    ::JS_ClearScope(cx, nativeWrapper);
  }

  WrapperAndCxHolder d =
    {
      wrapper,
      cx
    };

  wrapper->GetRuntime()->GetExplicitNativeWrapperMap()->
    Enumerate(ClearNativeWrapperScope, &d);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSClass* XPCNativeWrapper::GetJSClass ( ) [inline, static]

Definition at line 67 of file XPCNativeWrapper.h.

  {
    return &sXPC_NW_JSClass.base;
  }

Here is the caller graph for this function:

JSObject * XPCNativeWrapper::GetNewOrUsed ( JSContext cx,
XPCWrappedNative wrapper,
JSObject callee 
) [static]

Definition at line 1499 of file XPCNativeWrapper.cpp.

{
  if (callee) {
    nsCOMPtr<nsIPrincipal> prin;

    nsCOMPtr<nsIScriptSecurityManager> ssm = GetSecurityManager(cx);
    nsresult rv = ssm
                  ? ssm->GetObjectPrincipal(cx, callee, getter_AddRefs(prin))
                  : NS_ERROR_FAILURE;
    if (NS_SUCCEEDED(rv) && prin) {
      nsCOMPtr<nsIPrincipal> sysprin;
      rv = ssm->GetSystemPrincipal(getter_AddRefs(sysprin));
      if (NS_SUCCEEDED(rv) && sysprin != prin) {
        jsval v = OBJECT_TO_JSVAL(wrapper->GetFlatJSObject());
        if (!XPCNativeWrapperCtor(cx, JSVAL_TO_OBJECT(v), 1, &v, &v))
          return nsnull;
        return JSVAL_TO_OBJECT(v);
      }
    }
  }

  // Prevent wrapping a double-wrapped JS object in an
  // XPCNativeWrapper!
  nsCOMPtr<nsIXPConnectWrappedJS> xpcwrappedjs(do_QueryWrappedNative(wrapper));

  if (xpcwrappedjs) {
    XPCThrower::Throw(NS_ERROR_INVALID_ARG, cx);

    return nsnull;
  }

  JSObject *obj = wrapper->GetNativeWrapper();
  if (obj) {
    return obj;
  }

  JSObject *nw_parent;
  if (!MirrorWrappedNativeParent(cx, wrapper, &nw_parent)) {
    return nsnull;
  }

  PRBool lock;

  if (!nw_parent) {
    nw_parent = wrapper->GetScope()->GetGlobalJSObject();

    lock = PR_FALSE;
  } else {
    lock = PR_TRUE;
  }

  if (lock) {
    // Make sure nw_parent doesn't get collected while we're creating
    // the new wrapper.
    ::JS_LockGCThing(cx, nw_parent);
  }

  obj = ::JS_NewObject(cx, GetJSClass(), nsnull, nsnull);

  if (lock) {
    ::JS_UnlockGCThing(cx, nw_parent);
  }

  if (!obj ||
      !::JS_SetParent(cx, obj, nw_parent) ||
      !::JS_SetPrivate(cx, obj, wrapper) ||
      !::JS_SetPrototype(cx, obj, nsnull) ||
      !::JS_SetReservedSlot(cx, obj, 0, INT_TO_JSVAL(FLAG_DEEP))) {
    return nsnull;
  }

  wrapper->SetNativeWrapper(obj);

#ifdef DEBUG_XPCNativeWrapper
  {
    XPCCallContext ccx(NATIVE_CALLER, cx);

    // Keep obj alive while we mess with strings
    AUTO_MARK_JSVAL(ccx, OBJECT_TO_JSVAL(obj));

    char *s = wrapper->ToString(ccx);
    printf("Created new XPCNativeWrapper %p for wrapped native %s\n",
           (void*)obj, s);
    if (s)
      JS_smprintf_free(s);
  }
#endif
  
  return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static XPCWrappedNative* XPCNativeWrapper::GetWrappedNative ( JSContext cx,
JSObject obj 
) [inline, static]

Definition at line 62 of file XPCNativeWrapper.h.

  {
    return (XPCWrappedNative *)::JS_GetPrivate(cx, obj);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool XPCNativeWrapper::IsNativeWrapper ( JSContext cx,
JSObject obj 
) [inline, static]

Definition at line 57 of file XPCNativeWrapper.h.

  {
    return JS_GET_CLASS(cx, obj) == &sXPC_NW_JSClass.base;
  }

Here is the caller graph for this function:

static PRBool XPCNativeWrapper::IsNativeWrapperClass ( JSClass clazz) [inline, static]

Definition at line 52 of file XPCNativeWrapper.h.

  {
    return clazz == &sXPC_NW_JSClass.base;
  }

Here is the caller graph for this function:


Member Data Documentation


The documentation for this class was generated from the following files: