nsIDOMXULDocument::GetIID(),
NS_GET_IID(nsIDOMXULDocument),
NS_IMETHODIMP nsXULKeyListenerImpl::LoadKeyBindingDocument(nsIURI* aURI, nsIDOMXULDocument** aResult){  *aResult = nsnull;  // Create the XUL document  nsCOMPtr<nsIDOMXULDocument> doc;  nsresult rv = nsComponentManager::CreateInstance(kXULDocumentCID, nsnull,                                                   nsIDOMXULDocument::GetIID(),                                                   getter_AddRefs(doc));  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(doc, &rv);  if (NS_FAILED(rv)) return rv;  xulDoc->SetIsKeybindingDocument(PR_TRUE);  // Now we have to synchronously load the key binding file.  // Create a XUL content sink, a parser, and kick off a load for  // the overlay.  nsCOMPtr<nsIChannel> channel;  rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull);  if (NS_FAILED(rv)) return rv;  // Create a new prototype document  nsCOMPtr<nsIXULPrototypeDocument> proto;  rv = NS_NewXULPrototypeDocument(nsnull, NS_GET_IID(nsIXULPrototypeDocument), getter_AddRefs(proto));  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsISupports> owner;  rv = channel->GetOwner(getter_AddRefs(owner));  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);  proto->SetDocumentPrincipal(principal);  // Set master and current prototype  xulDoc->SetMasterPrototype(proto);  xulDoc->SetCurrentPrototype(proto);  rv = proto->SetURI(aURI);  if (NS_FAILED(rv)) return rv;  xulDoc->SetDocumentURL(aURI);  xulDoc->PrepareStyleSheets(aURI);  nsCOMPtr<nsIXULContentSink> sink;  rv = nsComponentManager::CreateInstance(kXULContentSinkCID,                                          nsnull,                                          NS_GET_IID(nsIXULContentSink),                                          getter_AddRefs(sink));  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create XUL content sink");  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIDocument> document = do_QueryInterface(doc);  rv = sink->Init(document, proto);  NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to initialize content sink");  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIParser> parser;  rv = nsComponentManager::CreateInstance(kParserCID,                                          nsnull,                                          NS_GET_IID(nsIParser),                                          getter_AddRefs(parser));  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create parser");  if (NS_FAILED(rv)) return rv;  parser->SetCommand("view");  nsAutoString utf8("UTF-8");  parser->SetDocumentCharset(utf8, kCharsetFromDocTypeDefault);  parser->SetContentSink(sink); // grabs a reference to the parser  // Now do a blocking synchronous parse of the file.  nsCOMPtr<nsIStreamListener> listener = do_QueryInterface(parser, &rv);  if (NS_FAILED(rv)) return rv;  rv = parser->Parse(aURI);  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIInputStream> in;  PRUint32 sourceOffset = 0;  rv = channel->OpenInputStream(0, -1, getter_AddRefs(in));  // If we couldn't open the channel, then just return.  if (NS_FAILED(rv)) return NS_OK;  NS_ASSERTION(in != nsnull, "no input stream");  if (! in) return NS_ERROR_FAILURE;  rv = NS_ERROR_OUT_OF_MEMORY;  nsProxyStream* proxy = new nsProxyStream();  if (! proxy)    return NS_ERROR_FAILURE;  listener->OnStartRequest(channel, nsnull);  while (PR_TRUE) {    char buf[1024];    PRUint32 readCount;    if (NS_FAILED(rv = in->Read(buf, sizeof(buf), &readCount)))        break; // error    if (readCount == 0)        break; // eof    proxy->SetBuffer(buf, readCount);    rv = listener->OnDataAvailable(channel, nsnull, proxy, sourceOffset, readCount);    sourceOffset += readCount;    if (NS_FAILED(rv))        break;  }  listener->OnStopRequest(channel, nsnull, NS_OK, nsnull);  // don't leak proxy!  proxy->Close();  delete proxy;  // The document is parsed. We now have a prototype document.  // Everything worked, so we can just hand this back now.  *aResult = doc;  NS_IF_ADDREF(*aResult);  return NS_OK;}