return mRequests->AppendElement((void *)ic) ? 0 : -1;
{ int ret = mRequests->AppendElement((void *)ic) ? 0 : -1; NS_RELEASE(ic);  return ret; }
ImageNetContextImpl::GetURL (ilIURL * aURL,                              ImgCachePolicy aLoadMethod,                             ilINetReader *aReader,                             PRBool IsAnimationLoop){  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));   nsLoadFlags flags=0;      if(IsAnimationLoop)       flags |= nsIChannel::VALIDATE_NEVER;    rv = NS_OpenURI(getter_AddRefs(channel), nsurl, nsnull, group, sink, flags);    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);            }        }    }    rv = channel->GetLoadAttributes(&flags);    if (NS_FAILED(rv)) goto error;   if (aURL->GetBackgroundLoad())       flags |= nsIChannel::LOAD_BACKGROUND;          (void)channel->SetLoadAttributes(flags);   nsCOMPtr<nsISupports> window (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, ic)));    // let's try uri dispatching...    nsCOMPtr<nsIURILoader> pURILoader (do_GetService(NS_URI_LOADER_CONTRACTID, &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;}