content->GetAttrNameAt(index, nameSpaceID, *getter_AddRefs(atom), *getter_AddRefs(prefix));
content->GetAttrNameAt(index, &nameSpaceID, getter_AddRefs(atom), getter_AddRefs(prefix));
nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays(){  if (mCachedAttrParamValues)    return NS_OK;  NS_PRECONDITION(((mNumCachedAttrs + mNumCachedParams) == 0) &&                  !mCachedAttrParamNames,                  "re-cache of attrs/params not implemented! use the DOM "                  "node directy instead");  NS_ENSURE_TRUE(mOwner, NS_ERROR_NULL_POINTER);  // first, we need to find out how much we need to allocate for our  // arrays count up attributes  mNumCachedAttrs = 0;  nsCOMPtr<nsIContent> content;   nsresult rv = mOwner->GetContent(getter_AddRefs(content));  NS_ENSURE_TRUE(content, rv);  PRInt32 cattrs;  rv = content->GetAttrCount(cattrs);  NS_ENSURE_SUCCESS(rv, rv);  if (cattrs < 0x0000FFFF) {    // signed 32 bits to unsigned 16 bits conversion    mNumCachedAttrs = NS_STATIC_CAST(PRUint16, cattrs);  } else {     mNumCachedAttrs = 0xFFFE;  // minus one in case we add an extra "src" entry below  }  // now, we need to find all the PARAM tags that are children of us  // however, be carefull NOT to include any PARAMs that don't have us  // as a direct parent. For nested object (or applet) tags, be sure  // to only round up the param tags that coorespond with THIS  // instance. And also, weed out any bogus tags that may get in the  // way, see bug 39609. Then, with any param tag that meet our  // qualification, temporarly cache them in an nsISupportsArray until  // we can figure out what size to make our fixed char* array.  mNumCachedParams = 0;  nsCOMPtr<nsISupportsArray> ourParams;  rv = NS_NewISupportsArray(getter_AddRefs(ourParams));  NS_ENSURE_SUCCESS(rv, rv);   // use the DOM to get us ALL our dependant PARAM tags, even if not  // ours  nsCOMPtr<nsIDOMElement> mydomElement = do_QueryInterface(content);  NS_ENSURE_TRUE(mydomElement, NS_ERROR_NO_INTERFACE);  nsCOMPtr<nsIDOMNodeList> allParams;   nsCOMPtr<nsINodeInfo> ni;  content->GetNodeInfo(*getter_AddRefs(ni));  if (ni->NamespaceEquals(kNameSpaceID_XHTML)) {    // For XHTML elements we need to take the namespace URI into    // account when looking for param elements.    NS_NAMED_LITERAL_STRING(xhtml_ns, "http://www.w3.org/1999/xhtml");    mydomElement->GetElementsByTagNameNS(xhtml_ns, NS_LITERAL_STRING("param"),                                         getter_AddRefs(allParams));  } else {    // If content is not XHTML, it must be HTML, no need to worry    // about namespaces then...    mydomElement->GetElementsByTagName(NS_LITERAL_STRING("param"),                                       getter_AddRefs(allParams));  }      if (allParams) {    PRUint32 numAllParams;     allParams->GetLength(&numAllParams);    // loop through every so called dependant PARAM tag to check if it    // "belongs" to us    for (PRUint32 i = 0; i < numAllParams; i++) {      nsCOMPtr<nsIDOMNode> pnode;      allParams->Item(i, getter_AddRefs(pnode));      nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(pnode);      if (domelement) {        // let's NOT count up param tags that don't have a name attribute        nsAutoString name;        domelement->GetAttribute(NS_LITERAL_STRING("name"), name);        if (!name.IsEmpty()) {          nsCOMPtr<nsIDOMNode> parent;          nsCOMPtr<nsIDOMHTMLObjectElement> domobject;          nsCOMPtr<nsIDOMHTMLAppletElement> domapplet;          pnode->GetParentNode(getter_AddRefs(parent));          // walk up the parents of this PARAM until we find an object          // (or applet) tag          while (!(domobject || domapplet) && parent) {            domobject = do_QueryInterface(parent);            domapplet = do_QueryInterface(parent);            nsCOMPtr<nsIDOMNode> temp;            parent->GetParentNode(getter_AddRefs(temp));            parent = temp;          }          if (domapplet || domobject) {            if (domapplet)              parent = do_QueryInterface(domapplet);            else              parent = do_QueryInterface(domobject);            // now check to see if this PARAM's parent is us. if so,            // cache it for later            nsCOMPtr<nsIDOMNode> mydomNode = do_QueryInterface(mydomElement);            if (parent == mydomNode) {              ourParams->AppendElement(pnode);            }          }        }      }    }  }  PRUint32 cparams;  ourParams->Count(&cparams); // unsigned 32 bits to unsigned 16 bits conversion  if (cparams < 0x0000FFFF)    mNumCachedParams = NS_STATIC_CAST(PRUint16, cparams);  else     mNumCachedParams = 0xFFFF;  // Some plugins were never written to understand the "data" attribute of the OBJECT tag.  // Real and WMP will not play unless they find a "src" attribute, see bug 152334.  // Nav 4.x would simply replace the "data" with "src". Because some plugins correctly  // look for "data", lets instead copy the "data" attribute and add another entry  // to the bottom of the array if there isn't already a "src" specified.  PRInt16 numRealAttrs = mNumCachedAttrs;  nsAutoString data;  nsCOMPtr<nsIAtom> tag;  content->GetTag(*getter_AddRefs(tag));  if (nsHTMLAtoms::object == tag.get()     && !content->HasAttr(kNameSpaceID_None, nsHTMLAtoms::src)    && NS_CONTENT_ATTR_NOT_THERE != content->GetAttr(kNameSpaceID_None, nsHTMLAtoms::data, data)) {      mNumCachedAttrs++;  }  // now lets make the arrays  mCachedAttrParamNames  = (char **)PR_Calloc(sizeof(char *) * (mNumCachedAttrs + 1 + mNumCachedParams), 1);  NS_ENSURE_TRUE(mCachedAttrParamNames,  NS_ERROR_OUT_OF_MEMORY);  mCachedAttrParamValues = (char **)PR_Calloc(sizeof(char *) * (mNumCachedAttrs + 1 + mNumCachedParams), 1);  NS_ENSURE_TRUE(mCachedAttrParamValues, NS_ERROR_OUT_OF_MEMORY);  // let's fill in our attributes  PRInt16 c = 0;  for (PRInt16 index = 0; index < numRealAttrs; index++) {    PRInt32 nameSpaceID;    nsCOMPtr<nsIAtom> atom;    nsCOMPtr<nsIAtom> prefix;    content->GetAttrNameAt(index, nameSpaceID,                           *getter_AddRefs(atom),                           *getter_AddRefs(prefix));    nsAutoString value;    if (NS_CONTENT_ATTR_NOT_THERE != content->GetAttr(nameSpaceID, atom, value)) {      nsAutoString name;      atom->ToString(name);            mOwner->FixUpURLS(name, value);      mCachedAttrParamNames [c] = ToNewUTF8String(name);      mCachedAttrParamValues[c] = ToNewUTF8String(value);      c++;    }  }  // if the conditions above were met, copy the "data" attribute to a "src" array entry  if (data.Length()) {    mCachedAttrParamNames [mNumCachedAttrs-1] = ToNewUTF8String(NS_LITERAL_STRING("SRC"));    mCachedAttrParamValues[mNumCachedAttrs-1] = ToNewUTF8String(data);  }  // add our PARAM and null separator  mCachedAttrParamNames [mNumCachedAttrs] = ToNewUTF8String(NS_LITERAL_STRING("PARAM"));  mCachedAttrParamValues[mNumCachedAttrs] = nsnull;  // now fill in the PARAM name/value pairs from the cached DOM nodes  c = 0;  for (PRInt16 idx = 0; idx < mNumCachedParams; idx++) {    nsCOMPtr<nsIDOMElement> param = do_QueryElementAt(ourParams, idx);    if (param) {     nsAutoString name;     nsAutoString value;     param->GetAttribute(NS_LITERAL_STRING("name"), name); // check for empty done above     param->GetAttribute(NS_LITERAL_STRING("value"), value);     mOwner->FixUpURLS(name, value);     /*      * According to the HTML 4.01 spec, at      * http://www.w3.org/TR/html4/types.html#type-cdata      * ''User agents may ignore leading and trailing      * white space in CDATA attribute values (e.g., "      * myval " may be interpreted as "myval"). Authors      * should not declare attribute values with      * leading or trailing white space.''      * However, do not trim consecutive spaces as in bug 122119      */                 name.Trim(" \n\r\t\b", PR_TRUE, PR_TRUE, PR_FALSE);     value.Trim(" \n\r\t\b", PR_TRUE, PR_TRUE, PR_FALSE);     mCachedAttrParamNames [mNumCachedAttrs + 1 + c] = ToNewUTF8String(name);     mCachedAttrParamValues[mNumCachedAttrs + 1 + c] = ToNewUTF8String(value);     c++;                                                      // rules!    }  }  return NS_OK;}