if (gXULUtils && gXULUtils->UseXULCache()) {
PRBool useXULCache; gXULCache->GetEnabled(&useXULCache); if (useXULCache) {
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 {    // Remove ourselves from the set of pending docs.    nsCOMPtr<nsIBindingManager> bindingManager;    doc->GetBindingManager(getter_AddRefs(bindingManager));    nsCOMPtr<nsIURI> uri(getter_AddRefs(mBindingDocument->GetDocumentURL()));    nsXPIDLCString str;    uri->GetSpec(getter_Copies(str));    bindingManager->RemoveLoadingDocListener(nsCAutoString(NS_STATIC_CAST(const char*, str)));    nsCOMPtr<nsIContent> root = getter_AddRefs(mBindingDocument->GetRootContent());    if (root)      nsXBLService::StripWhitespaceNodes(root);    else {      NS_ERROR("*** XBL doc with no root element! Something went horribly wrong! ***");      return NS_ERROR_FAILURE;    }    // Put our doc in the doc table.    nsCOMPtr<nsIXBLDocumentInfo> info;    NS_NewXBLDocumentInfo(mBindingDocument, getter_AddRefs(info));     // If the doc is a chrome URI, then we put it into the XUL cache.    PRBool cached = PR_FALSE;    if (IsChromeOrResourceURI(uri)) {      if (gXULUtils && gXULUtils->UseXULCache()) {        cached = PR_TRUE;        gXULCache->PutXBLDocumentInfo(info);      }      // Cache whether or not this chrome XBL can execute scripts.      nsCOMPtr<nsIChromeRegistry> reg(do_GetService(kChromeRegistryCID, &rv));      if (NS_SUCCEEDED(rv) && reg) {        PRBool allow = PR_TRUE;        reg->AllowScriptsForSkin(uri, &allow);        info->SetScriptAccess(allow);      }    }      if (!cached)      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);      nsCOMPtr<nsIDocument> document;      req->mBoundElement->GetDocument(*getter_AddRefs(document));      if (document)        document->FlushPendingNotifications();    }  }    for (i = 0; i < count; i++) {    nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);    delete req;  }  nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(mBindingDocument));  rec->RemoveEventListener(NS_ConvertASCIItoUCS2("load"), (nsIDOMLoadListener*)this, PR_FALSE);  mBindingRequests.Clear();  mDocument = nsnull;  mBindingDocument = nsnull;  return rv;}