nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mLoadGroup);
nsCOMPtr<nsISupports> loadContext (do_QueryReferent(mLoadContext)); nsCOMPtr<nsILoadGroup> group (do_GetInterface(loadContext));
ImageNetContextImpl::GetURL (ilIURL * aURL,                              NET_ReloadMethod aLoadMethod,                             ilINetReader *aReader){  NS_PRECONDITION(nsnull != aURL, "null URL");  NS_PRECONDITION(nsnull != aReader, "null reader");  if (aURL == nsnull || aReader == nsnull) {    return -1;  }  if (mRequests == nsnull) {    mRequests = new nsVoidArray();    if (mRequests == nsnull) {      // XXX Should still call exit function      return -1;    }  }  nsresult rv;  nsCOMPtr<nsIURI> nsurl = do_QueryInterface(aURL, &rv);  if (NS_FAILED(rv)) return 0;  aURL->SetReader(aReader);  SetReloadPolicy(aLoadMethod);        // Find previously created ImageConsumer if possible  ImageConsumer *ic = new ImageConsumer(aURL, this);  if (ic == nsnull)    return -1;  NS_ADDREF(ic);          // See if a reconnect is being done...(XXX: hack!)  if (mReconnectCallback == nsnull      || !(*mReconnectCallback)(mReconnectArg, ic)) {    // first, create a channel for the protocol....    nsCOMPtr<nsIChannel> channel;    nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mLoadGroup);    rv = NS_OpenURI(getter_AddRefs(channel), nsurl, group);    if (NS_FAILED(rv)) goto error;    PRBool bIsBackground = aURL->GetBackgroundLoad();    if (bIsBackground) {      (void)channel->SetLoadAttributes(nsIChannel::LOAD_BACKGROUND);    }    switch(aLoadMethod){        case IMG_CACHE_ONLY:            /* should never get here, but don't fail if you do. */        case IMG_NTWK_SERVER:            (void)channel->SetLoadAttributes(nsIChannel::VALIDATE_NEVER);             break;        case TV_IMG_NTWK_SERVER:        case TV_NTWK_SERVER_ONLY:            (void)channel->SetLoadAttributes(nsIChannel::FORCE_VALIDATION);            break;        case SERVER_ONLY:           (void)channel->SetLoadAttributes(nsIChannel::FORCE_RELOAD);            break;                default:            break;    }       nsCOMPtr<nsISupports> window (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, ic)));    // let's try uri dispatching...    nsCOMPtr<nsIURILoader> pURILoader (do_GetService(NS_URI_LOADER_PROGID, &rv));    if (NS_SUCCEEDED(rv))     {      nsURILoadCommand loadCmd = nsIURILoader::viewNormal;      PRBool bIsBackground = aURL->GetBackgroundLoad();      if (bIsBackground) {        loadCmd = nsIURILoader::viewNormalBackground;      }      rv = pURILoader->OpenURI(channel, loadCmd, nsnull /* window target */,                                window);    }    // rv = channel->AsyncRead(0, -1, nsnull, ic);    if (NS_FAILED(rv)) goto error;  }  return mRequests->AppendElement((void *)ic) ? 0 : -1;error:  NS_RELEASE(ic);  return -1;}