nsCOMPtr<nsIDOMNode> clonedNode; domElement->CloneNode(PR_TRUE, getter_AddRefs(clonedNode));
if (childrenElement) { GetNestedChild(kChildrenAtom, clonedContent, getter_AddRefs(mChildrenElement)); } }
nsXBLBinding::GenerateAnonymousContent(){  // Fetch the content element for this binding.  nsCOMPtr<nsIContent> content;  GetImmediateChild(nsXBLAtoms::content, getter_AddRefs(content));  if (!content) {    // We have no anonymous content.    if (mNextBinding)      return mNextBinding->GenerateAnonymousContent();    else return NS_OK;  }       // Find out if we're really building kids or if we're just  // using the attribute-setting shorthand hack.  PRInt32 contentCount;  content->ChildCount(contentCount);  // Plan to build the content by default.  PRBool hasContent = (contentCount > 0);  PRBool hasInsertionPoints = mPrototypeBinding->HasInsertionPoints();#ifdef DEBUG  // See if there's an includes attribute.  nsAutoString includes;  content->GetAttr(kNameSpaceID_None, nsXBLAtoms::includes, includes);  if (!includes.IsEmpty()) {    nsCAutoString id;    mPrototypeBinding->GetID(id);    nsCAutoString message("An XBL Binding with an id of ");    message += id;    message += " and found in the file ";    nsCAutoString uri;    mPrototypeBinding->GetDocURI(uri);    message += uri;    message += " is still using the deprecated\n<content includes=\"\"> syntax! Use <children> instead!\n";     NS_WARNING(message.get());  }#endif  if (hasContent || hasInsertionPoints) {    nsIDocument* doc = mBoundElement->GetDocument();    // XXX doc will be null if we're in the midst of paint suppression.    if (! doc)      return NS_OK;        nsCOMPtr<nsIBindingManager> bindingManager;    doc->GetBindingManager(getter_AddRefs(bindingManager));    nsCOMPtr<nsIDOMNodeList> children;    bindingManager->GetContentListFor(mBoundElement, getter_AddRefs(children));     nsCOMPtr<nsIDOMNode> node;    nsCOMPtr<nsIContent> childContent;    PRUint32 length;    children->GetLength(&length);    if (length > 0 && !hasInsertionPoints) {      // There are children being placed underneath us, but we have no specified      // insertion points, and therefore no place to put the kids.  Don't generate      // anonymous content.      // Special case template and observes.      for (PRUint32 i = 0; i < length; i++) {        children->Item(i, getter_AddRefs(node));        childContent = do_QueryInterface(node);        nsCOMPtr<nsIAtom> tag;        childContent->GetTag(getter_AddRefs(tag));        if (tag != nsXULAtoms::observes && tag != nsXULAtoms::templateAtom) {          hasContent = PR_FALSE;          break;        }      }    }    if (hasContent || hasInsertionPoints) {      nsCOMPtr<nsIContent> clonedContent;      nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(content));      nsCOMPtr<nsIDOMNode> clonedNode;      domElement->CloneNode(PR_TRUE, getter_AddRefs(clonedNode));        clonedContent = do_QueryInterface(clonedNode);      SetAnonymousContent(clonedContent);      if (hasInsertionPoints) {        // Now check and see if we have a single insertion point         // or multiple insertion points.              // Enumerate the prototype binding's insertion table to build        // our table of instantiated insertion points.        mPrototypeBinding->InstantiateInsertionPoints(this);        // We now have our insertion point table constructed.  We        // enumerate this table.  For each array of insertion points        // bundled under the same content node, we generate a content        // list.  In the case of the bound element, we generate a new        // anonymous node list that will be used in place of the binding's        // cached anonymous node list.        ContentListData data(this, bindingManager);        mInsertionPointTable->Enumerate(BuildContentLists, &data);              // We need to place the children        // at their respective insertion points.        nsCOMPtr<nsIContent> singlePoint;        PRUint32 index = 0;        PRBool multiplePoints = PR_FALSE;        nsCOMPtr<nsIContent> singleDefaultContent;        GetSingleInsertionPoint(getter_AddRefs(singlePoint), &index,                                 &multiplePoints, getter_AddRefs(singleDefaultContent));              if (children) {          if (multiplePoints) {            // We must walk the entire content list in order to determine where            // each child belongs.            children->GetLength(&length);            for (PRUint32 i = 0; i < length; i++) {              children->Item(i, getter_AddRefs(node));              childContent = do_QueryInterface(node);              // Now determine the insertion point in the prototype table.              nsCOMPtr<nsIContent> point;              PRUint32 index;              nsCOMPtr<nsIContent> defContent;              GetInsertionPoint(childContent, getter_AddRefs(point), &index, getter_AddRefs(defContent));              bindingManager->SetInsertionParent(childContent, point);              // Find the correct nsIXBLInsertion point in our table.              nsVoidArray* arr;              GetInsertionPointsFor(point, &arr);              nsXBLInsertionPoint* insertionPoint = nsnull;              PRInt32 arrCount = arr->Count();              for (PRInt32 j = 0; j < arrCount; j++) {                insertionPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(j));                if (insertionPoint->Matches(point, index))                  break;                insertionPoint = nsnull;              }              if (insertionPoint)                 insertionPoint->AddChild(childContent);              else {                // We were unable to place this child.  All anonymous content                // should be thrown out.  Special-case template and observes.                nsCOMPtr<nsIAtom> tag;                childContent->GetTag(getter_AddRefs(tag));                if (tag != nsXULAtoms::observes && tag != nsXULAtoms::templateAtom) {                  // Kill all anonymous content.                  mContent = nsnull;                  bindingManager->SetContentListFor(mBoundElement, nsnull);                  bindingManager->SetAnonymousNodesFor(mBoundElement, nsnull);                  return NS_OK;                }              }            }          }          else {            // All of our children are shunted to this single insertion point.            nsVoidArray* arr;            GetInsertionPointsFor(singlePoint, &arr);            nsXBLInsertionPoint* insertionPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(0));                    nsCOMPtr<nsIDOMNode> node;            nsCOMPtr<nsIContent> content;            PRUint32 length;            children->GetLength(&length);                      for (PRUint32 i = 0; i < length; i++) {              children->Item(i, getter_AddRefs(node));              content = do_QueryInterface(node);              bindingManager->SetInsertionParent(content, singlePoint);              insertionPoint->AddChild(content);            }          }        }        // Now that all of our children have been added, we need to walk all of our        // nsIXBLInsertion points to see if any of them have default content that        // needs to be built.        mInsertionPointTable->Enumerate(RealizeDefaultContent, &data);      }    }    mPrototypeBinding->SetInitialAttributes(mBoundElement, mContent);  }  // Always check the content element for potential attributes.  // This shorthand hack always happens, even when we didn't  // build anonymous content.  PRInt32 length;  content->GetAttrCount(length);  PRInt32 namespaceID;  nsCOMPtr<nsIAtom> name;  nsCOMPtr<nsIAtom> prefix;  for (PRInt32 i = 0; i < length; ++i) {    content->GetAttrNameAt(i, &namespaceID, getter_AddRefs(name),                           getter_AddRefs(prefix));    if (name != nsXBLAtoms::includes) {      nsAutoString value;      mBoundElement->GetAttr(namespaceID, name, value);      if (value.IsEmpty()) {        nsAutoString value2;        content->GetAttr(namespaceID, name, value2);        mBoundElement->SetAttr(namespaceID, name, value2, PR_FALSE);      }    }    // Conserve space by wiping the attributes off the clone.    if (mContent)      mContent->UnsetAttr(namespaceID, name, PR_FALSE);  }    return NS_OK;}