nsCOMPtr<nsIBindingManager> xblDocBindingManager; mBindingDocument->GetBindingManager(getter_AddRefs(xblDocBindingManager));
nsIBindingManager *xblDocBindingManager = mBindingDocument->GetBindingManager();
nsXBLStreamListener::Load(nsIDOMEvent* aEvent){  nsresult rv = NS_OK;  PRUint32 i;  PRUint32 count = mBindingRequests.Count();    // See if we're still alive.  nsCOMPtr<nsIDocument> doc(do_QueryReferent(mDocument));  if (!doc) {    NS_WARNING("XBL load did not complete until after document went away! Modal dialog bug?\n");  }  else {    // We have to do a flush prior to notification of the document load.    // This has to happen since the HTML content sink can be holding on    // to notifications related to our children (e.g., if you bind to the    // <body> tag) that result in duplication of content.      // We need to get the sink's notifications flushed and then make the binding    // ready.    if (count > 0) {      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(0);      nsIDocument* document = req->mBoundElement->GetDocument();      if (document)        document->FlushPendingNotifications();    }    // Remove ourselves from the set of pending docs.    nsCOMPtr<nsIBindingManager> bindingManager;    doc->GetBindingManager(getter_AddRefs(bindingManager));    nsCOMPtr<nsIURI> uri;    mBindingDocument->GetDocumentURL(getter_AddRefs(uri));    nsCAutoString str;    uri->GetSpec(str);    bindingManager->RemoveLoadingDocListener(str);    nsCOMPtr<nsIContent> root;    mBindingDocument->GetRootContent(getter_AddRefs(root));    if (!root) {      NS_ERROR("*** XBL doc with no root element! Something went horribly wrong! ***");      return NS_ERROR_FAILURE;    }    // Put our doc info in the doc table.    nsCOMPtr<nsIXBLDocumentInfo> info;    nsCOMPtr<nsIBindingManager> xblDocBindingManager;    mBindingDocument->GetBindingManager(getter_AddRefs(xblDocBindingManager));    xblDocBindingManager->GetXBLDocumentInfo(str, getter_AddRefs(info));    xblDocBindingManager->RemoveXBLDocumentInfo(info); // Break the self-imposed cycle.    if (!info) {      NS_ERROR("An XBL file is malformed.  Did you forget the XBL namespace on the bindings tag?");      return NS_ERROR_FAILURE;    }    // If the doc is a chrome URI, then we put it into the XUL cache.#ifdef MOZ_XUL    if (IsChromeOrResourceURI(uri)) {      PRBool useXULCache;      gXULCache->GetEnabled(&useXULCache);      if (useXULCache)        gXULCache->PutXBLDocumentInfo(info);    }#endif      bindingManager->PutXBLDocumentInfo(info);    // Notify all pending requests that their bindings are    // ready and can be installed.    for (i = 0; i < count; i++) {      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);      req->DocumentLoaded(mBindingDocument);    }    // All reqs normally have the same binding doc.  Force a synchronous    // reflow on this binding doc to deal with the fact that iframes    // don't construct or load their subdocs until they get a reflow.    if (count > 0) {      nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(0);      nsIDocument* document = req->mBoundElement->GetDocument();      if (document)        document->FlushPendingNotifications();    }  }    for (i = 0; i < count; i++) {    nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);    nsXBLBindingRequest::Destroy(mXBLService->mPool, req);  }  nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(mBindingDocument));  rec->RemoveEventListener(NS_LITERAL_STRING("load"), (nsIDOMLoadListener*)this, PR_FALSE);  mBindingRequests.Clear();  mDocument = nsnull;  mBindingDocument = nsnull;  return rv;}