PRBool error = PR_FALSE;
PageGrabber::Grab(const nsAFlatCString& aURL){  nsresult rv;  // Create the Event Queue for this thread...  // Unix needs this  nsCOMPtr<nsIEventQueueService> eventQService =           do_GetService(kEventQueueServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);  nsCOMPtr<nsILocalFile> file = NextFile("html");  if (!file) {    return NS_ERROR_OUT_OF_MEMORY;  }  FILE* fp;  rv = file->OpenANSIFileDesc("wb", &fp);  if (NS_FAILED(rv)) {    return rv;  }  printf("Copying ");  fputs(aURL.get(), stdout);  nsAutoString path;  file->GetPath(path);  NS_ConvertUCS2toUTF8 cpath(path);  printf(" to %s\n", cpath.get());  // Create the URL object...  nsCOMPtr<nsIURI> url;  nsCOMPtr<nsIIOService> ioService(do_GetService(kIOServiceCID, &rv));  if (NS_FAILED(rv)) return rv;  rv = ioService->NewURI(aURL, nsnull, nsnull, getter_AddRefs(url));  nsIChannel *channel = nsnull;  rv = ioService->NewChannelFromURI(url, &channel);  if (NS_FAILED(rv)) return rv;  PRBool error = PR_FALSE;  // Start the URL load...  StreamToFile* copier = new StreamToFile(fp);  if(copier) {    NS_ADDREF(copier);    rv = channel->AsyncOpen(copier, nsnull);    if (NS_FAILED(rv)) {      NS_RELEASE(copier);      return rv;    }            // Enter the message pump to allow the URL load to proceed.  #ifdef XP_WIN    MSG msg;    while ( !copier->IsDone() ) {      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {        TranslateMessage(&msg);        DispatchMessage(&msg);      }    }  #endif  #ifdef XP_OS2    QMSG qmsg;    while ( !copier->IsDone() ) {      if (WinPeekMsg(0, &qmsg, NULL, 0, 0, PM_REMOVE)) {        WinDispatchMsg(0, &qmsg);      }    }  #endif  #ifdef XP_UNIX    while ( !copier->IsDone() ) {      PLEvent *gEvent;      gEventQ->WaitForEvent(&gEvent);      gEventQ->HandleEvent(gEvent);    }  #endif    error = copier->HaveError();    NS_RELEASE(copier);  }  return error ? NS_ERROR_OUT_OF_MEMORY : NS_OK;}