NET_ReloadMethod aLoadMethod,
ImgCachePolicy aLoadMethod,
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<nsISupports> loadContext (do_QueryReferent(mLoadContext));     nsCOMPtr<nsILoadGroup> group (do_GetInterface(loadContext));    nsCOMPtr<nsIInterfaceRequestor> sink(do_QueryInterface(loadContext));    rv = NS_OpenURI(getter_AddRefs(channel), nsurl, nsnull, group, sink);    if (NS_FAILED(rv)) goto error;    nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);    if (httpChannel)    {        // Get the defloadchannel from the loadgroup-        nsCOMPtr<nsIChannel> defLoadChannel;        if (NS_SUCCEEDED(group->GetDefaultLoadChannel(                        getter_AddRefs(defLoadChannel))) && defLoadChannel)        {            // Get the referrer from the loadchannel-            nsCOMPtr<nsIURI> referrer;            if (NS_SUCCEEDED(defLoadChannel->GetURI(getter_AddRefs(referrer))))            {                // Set the referrer-                httpChannel->SetReferrer(referrer,                     nsIHTTPChannel::REFERRER_INLINES);            }        }    }    if (aURL->GetBackgroundLoad()) {      (void)channel->SetLoadAttributes(nsIChannel::LOAD_BACKGROUND);    }    nsLoadFlags flags;    rv = channel->GetLoadAttributes(&flags);    if (NS_FAILED(rv)) return rv;    switch(aLoadMethod){            case IMG_CACHE_ONLY:                 /* shouldn't get here, but don't fail if you do. Just fall to the next case. */            case IMG_NTWK_SERVER:                  (void)channel->SetLoadAttributes((nsIChannel::VALIDATE_NEVER) | flags);                    break;            case TV_IMG_NTWK_SERVER:            case TV_NTWK_SERVER_ONLY:                  (void)channel->SetLoadAttributes((nsIChannel::FORCE_VALIDATION) | flags);                  break;            case SERVER_ONLY:                  (void)channel->SetLoadAttributes((nsIChannel::FORCE_RELOAD) | flags);                  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(ic, nsnull);    if (NS_FAILED(rv)) goto error;  }  return mRequests->AppendElement((void *)ic) ? 0 : -1;error:  NS_RELEASE(ic);  return -1;}