NET_ReloadMethod aLoadMethod,
ImgCachePolicy aLoadMethod,
ImageNetContextSyncImpl::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;  }    aURL->SetReader(aReader);  PRInt32 status = 0;  // Get a nsIURI interface  nsIURI* url = nsnull;  aURL->QueryInterface(kIURLIID, (void **)&url);  nsresult res;  // Get a network service interface which we'll use to create a stream  NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);  if (NS_SUCCEEDED(res)) {    nsIInputStream* stream = nsnull;    nsIURI *uri = nsnull;    nsresult rv;    rv = url->QueryInterface(NS_GET_IID(nsIURI), (void**)&uri);    if (NS_FAILED(rv)) return -1;    nsIChannel *channel = nsnull;    rv = service->NewChannelFromURI(uri, &channel);    NS_RELEASE(uri);    if (NS_FAILED(rv))         return -1;    char* aContentType = NULL;    rv = channel->GetContentType(&aContentType); //nsCRT alloc's str    if (NS_FAILED(rv)) {        if(aContentType){            nsCRT::free(aContentType);        }        aContentType = nsCRT::strdup("unknown");            }    if(nsCRT::strlen(aContentType) > 50){        //somethings wrong. mimetype string shouldn't be this big.        //protect us from the user.        nsCRT::free(aContentType);        aContentType = nsCRT::strdup("unknown");     }     rv = channel->OpenInputStream(&stream);    NS_RELEASE(channel);    if (NS_SUCCEEDED(rv)) {      if (aReader->StreamCreated(aURL, aContentType) == PR_TRUE) {        // Read the URL data        char      buf[2048];        PRUint32  count;        nsresult  result;        PRBool    first = PR_TRUE;		char* uriStr = NULL;	    uriStr = aURL->GetAddress();        result = stream->Read(buf, sizeof(buf), &count);        while (NS_SUCCEEDED(result) && (count > 0)) {          if (first == PR_TRUE) {            PRInt32 ilErr;              ilErr = aReader->FirstWrite((const unsigned char *)buf, (int32)count, uriStr);            first = PR_FALSE;            // If FirstWrite fails then the image type cannot be determined            if (ilErr != 0) {              result = NS_ERROR_ABORT;              break;            }          }                           aReader->Write((const unsigned char *)buf, (int32)count);            // Get the next block          result = stream->Read(buf, sizeof(buf), &count);        }		nsCRT::free(uriStr);          if (NS_FAILED(result)) {          aReader->StreamAbort(-1);          status = -1;          } else {          NS_ASSERTION(0 == count, "expected EOF");          aReader->StreamComplete(PR_FALSE);        }      } else {        aReader->StreamAbort(-1);        status = -1;      }      NS_IF_RELEASE(stream);    } else {      aReader->StreamAbort(-1);      status = -1;    }    nsCRT::free(aContentType);  } else {    aReader->StreamAbort(-1);    status = -1;  }    aReader->NetRequestDone(aURL, status);  NS_IF_RELEASE(url);  return 0;}