Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes
nsDOMConstructor Class Reference
Inheritance diagram for nsDOMConstructor:
Inheritance graph
[legend]
Collaboration diagram for nsDOMConstructor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~nsDOMConstructor ()
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMCONSTRUCTOR
nsresult 
Construct (nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, PRUint32 argc, jsval *argv, jsval *vp, PRBool *_retval)
nsresult HasInstance (nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval val, PRBool *bp, PRBool *_retval)
nsresult Install (JSContext *cx, JSObject *target, jsval thisAsVal)
AString toString ()

Static Public Member Functions

static nsresult Create (const PRUnichar *aName, nsPIDOMWindow *aOwner, nsDOMConstructor **aResult)

Protected Member Functions

 nsDOMConstructor (const PRUnichar *aName, nsPIDOMWindow *aOwner)

Private Attributes

const PRUnicharmClassName
nsWeakPtr mWeakOwner

Detailed Description

Definition at line 4611 of file nsDOMClassInfo.cpp.


Constructor & Destructor Documentation

nsDOMConstructor::nsDOMConstructor ( const PRUnichar aName,
nsPIDOMWindow aOwner 
) [inline, protected]

Definition at line 4614 of file nsDOMClassInfo.cpp.

Here is the caller graph for this function:

Definition at line 4691 of file nsDOMClassInfo.cpp.

{
}

Member Function Documentation

nsresult nsDOMConstructor::Construct ( nsIXPConnectWrappedNative wrapper,
JSContext cx,
JSObject obj,
PRUint32  argc,
jsval argv,
jsval vp,
PRBool _retval 
)

Definition at line 4696 of file nsDOMClassInfo.cpp.

{
  JSObject* class_obj = JSVAL_TO_OBJECT(argv[-2]);
  if (!class_obj) {
    NS_ERROR("nsDOMConstructor::Construct couldn't get constructor object.");
    return NS_ERROR_UNEXPECTED;
  }

  extern nsScriptNameSpaceManager *gNameSpaceManager;
  if (!mClassName || !gNameSpaceManager) {
    NS_ERROR("nsDOMConstructor::Construct can't get name or namespace manager");
    return NS_ERROR_UNEXPECTED;
  }

  const nsGlobalNameStruct *name_struct = nsnull;
  gNameSpaceManager->LookupName(nsDependentString(mClassName), &name_struct);
  if (!name_struct) {
    NS_ERROR("Name isn't in hash.");
    return NS_ERROR_UNEXPECTED;
  }

  if ((name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor ||
       !FindConstructorContractID(name_struct->mDOMClassInfoID)) &&
      (name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo ||
       !name_struct->mData->mConstructorCID) &&
      name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructor &&
      name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructorAlias) {
    // ignore return value, we return JS_FALSE anyway
    NS_ERROR("object instantiated without constructor");
    return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
  }

  return BaseStubConstructor(mWeakOwner, name_struct, cx, obj, argc, argv, vp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDOMConstructor::Create ( const PRUnichar aName,
nsPIDOMWindow aOwner,
nsDOMConstructor **  aResult 
) [static]

Definition at line 4665 of file nsDOMClassInfo.cpp.

{
  *aResult = nsnull;
  if (!aOwner->IsOuterWindow()) {
    *aResult = new nsDOMConstructor(aName, aOwner);
  } else if (!nsContentUtils::CanCallerAccess(aOwner)) {
    return NS_ERROR_DOM_SECURITY_ERR;
  } else {
    *aResult =
      new nsDOMConstructor(aName, aOwner->GetCurrentInnerWindow());
  }
  NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsDOMConstructor::HasInstance ( nsIXPConnectWrappedNative wrapper,
JSContext cx,
JSObject obj,
jsval  val,
PRBool bp,
PRBool _retval 
)

Definition at line 4734 of file nsDOMClassInfo.cpp.

{
  // No need to look these up in the hash.
  if (JSVAL_IS_PRIMITIVE(v)) {
    return NS_OK;
  }

  JSObject *dom_obj = JSVAL_TO_OBJECT(v);
  NS_ASSERTION(dom_obj, "nsDOMConstructor::HasInstance couldn't get object");

  // This might not be the right object, if XPCNativeWrapping
  // happened.  Get the wrapped native for this object, then get its
  // JS object.
  nsCOMPtr<nsIXPConnectWrappedNative> wrapped_native;
  nsContentUtils::XPConnect()->
    GetWrappedNativeOfJSObject(cx, dom_obj, getter_AddRefs(wrapped_native));
  if (wrapped_native) {
    wrapped_native->GetJSObject(&dom_obj);
  }

  JSClass *dom_class = JS_GET_CLASS(cx, dom_obj);
  if (!dom_class) {
    NS_ERROR("nsDOMConstructor::HasInstance can't get class.");
    return NS_ERROR_UNEXPECTED;
  }

  const nsGlobalNameStruct *name_struct = nsnull;

  extern nsScriptNameSpaceManager *gNameSpaceManager;
  if (!gNameSpaceManager) {
    NS_ERROR("nsDOMConstructor::HasInstance can't get namespace manager.");
    return NS_ERROR_UNEXPECTED;
  }

  gNameSpaceManager->LookupName(NS_ConvertASCIItoUCS2(dom_class->name),
                                &name_struct);
  if (!name_struct) {
    // Name isn't in hash, not a DOM object.
    return NS_OK;
  }

  if (name_struct->mType != nsGlobalNameStruct::eTypeClassConstructor &&
      name_struct->mType != nsGlobalNameStruct::eTypeExternalClassInfo &&
      name_struct->mType != nsGlobalNameStruct::eTypeExternalConstructorAlias) {
    // Doesn't have DOM interfaces.
    return NS_OK;
  }

  if (!mClassName) {
    NS_ERROR("nsDOMConstructor::HasInstance can't get name.");
    return NS_ERROR_UNEXPECTED;
  }

  const nsGlobalNameStruct *class_name_struct = nsnull;
  gNameSpaceManager->LookupName(nsDependentString(mClassName),
                                &class_name_struct);
  if (!class_name_struct) {
    NS_ERROR("Name isn't in hash.");
    return NS_ERROR_UNEXPECTED;
  }

  if (name_struct == class_name_struct) {
    *bp = JS_TRUE;

    return NS_OK;
  }

  const nsIID *class_iid;
  if (class_name_struct->mType == nsGlobalNameStruct::eTypeInterface ||
      class_name_struct->mType == nsGlobalNameStruct::eTypeClassProto) {
    class_iid = &class_name_struct->mIID;
  } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
    class_iid =
      sClassInfoData[class_name_struct->mDOMClassInfoID].mProtoChainInterface;
  } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
    class_iid = class_name_struct->mData->mProtoChainInterface;
  } else if (class_name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
    const nsGlobalNameStruct* alias_struct =
      gNameSpaceManager->GetConstructorProto(class_name_struct);
    if (!alias_struct) {
      NS_ERROR("Couldn't get constructor prototype.");
      return NS_ERROR_UNEXPECTED;
    }

    if (alias_struct->mType == nsGlobalNameStruct::eTypeClassConstructor) {
      class_iid =
        sClassInfoData[alias_struct->mDOMClassInfoID].mProtoChainInterface;
    } else if (alias_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
      class_iid = alias_struct->mData->mProtoChainInterface;
    } else {
      NS_ERROR("Expected eTypeClassConstructor or eTypeExternalClassInfo.");
      return NS_ERROR_UNEXPECTED;
    }
  } else {
    *bp = JS_FALSE;

    return NS_OK;
  }

  if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias) {
    name_struct = gNameSpaceManager->GetConstructorProto(name_struct);
    if (!name_struct) {
      NS_ERROR("Couldn't get constructor prototype.");
      return NS_ERROR_UNEXPECTED;
    }
  }

  NS_ASSERTION(name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor ||
               name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo,
               "The constructor was set up with a struct of the wrong type.");

  const nsDOMClassInfoData *ci_data = nsnull;
  if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor &&
      name_struct->mDOMClassInfoID >= 0) {
    ci_data = &sClassInfoData[name_struct->mDOMClassInfoID];
  } else if (name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
    ci_data = name_struct->mData;
  }

  nsCOMPtr<nsIInterfaceInfoManager> iim =
    dont_AddRef(XPTI_GetInterfaceInfoManager());
  if (!iim) {
    NS_ERROR("nsDOMConstructor::HasInstance can't get interface info mgr.");
    return NS_ERROR_UNEXPECTED;
  }

  nsCOMPtr<nsIInterfaceInfo> if_info;
  PRUint32 count = 0;
  const nsIID* class_interface;
  while ((class_interface = ci_data->mInterfaces[count++])) {
    if (class_iid->Equals(*class_interface)) {
      *bp = JS_TRUE;

      return NS_OK;
    }

    iim->GetInfoForIID(class_interface, getter_AddRefs(if_info));
    if (!if_info) {
      NS_ERROR("nsDOMConstructor::HasInstance can't get interface info.");
      return NS_ERROR_UNEXPECTED;
    }

    if_info->HasAncestor(class_iid, bp);

    if (*bp) {
      return NS_OK;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDOMConstructor::Install ( JSContext cx,
JSObject target,
jsval  thisAsVal 
) [inline]

Definition at line 4641 of file nsDOMClassInfo.cpp.

Here is the call graph for this function:

AString nsIDOMConstructor::toString ( ) [inherited]

Member Data Documentation

Definition at line 4659 of file nsDOMClassInfo.cpp.

Definition at line 4660 of file nsDOMClassInfo.cpp.


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