NS_WITH_SERVICE(nsIURL, uri, "@mozilla.org/network/standard-url;1", &rv); if (NS_FAILED(rv) || NS_FAILED(uri->SetSpec(image_url))) {
nsCOMPtr<nsIURI> uri; rv = NS_NewURI(getter_AddRefs(uri), image_url); if (NS_FAILED(rv)) {
PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver) {    /* convert image_url to an nsIURL so we can extract host and scheme */    nsresult rv;    NS_WITH_SERVICE(nsIURL, uri, "@mozilla.org/network/standard-url;1", &rv);    if (NS_FAILED(rv) || NS_FAILED(uri->SetSpec(image_url))) {        return PR_TRUE;    }    // remove this code once #73845 is fixed.    nsXPIDLCString scheme;    rv = uri->GetScheme(getter_Copies(scheme));    if (NS_FAILED(rv) || (!scheme.get())) {        return PR_TRUE;    }    /* extract scheme -- we block loading of only http and https images */    PRBool isHTTP = PR_FALSE;    PRBool isHTTPS = PR_FALSE;    if (NS_FAILED(uri->SchemeIs("http", &isHTTP)) ||         NS_FAILED(uri->SchemeIs("https", &isHTTPS)) ||         (!isHTTP && !isHTTPS))        return PR_TRUE;    /* extract host */    char * host;    rv = uri->GetHost(&host);    if (NS_FAILED(rv) || !host) {        return PR_TRUE;    }    /* obtain first url from aObserver */    if (!aObserver) {        Recycle(host);        return PR_TRUE;    }    char* firstHost = 0;    nsCOMPtr<nsIFrameImageLoader> frameImageLoader = do_QueryInterface(aObserver);    if (frameImageLoader) {        nsCOMPtr<nsIPresContext> presContext;        rv = frameImageLoader->GetPresContext(getter_AddRefs(presContext));        if (presContext) {            nsCOMPtr<nsIURI> firstURI;            presContext->GetBaseURL(getter_AddRefs(firstURI));            /* Check to see if the image is the whole page, in which case accept it */            PRBool eq;                       if(firstURI){                firstURI->Equals(uri, &eq);                     if (eq) {                    Recycle(host);                    return PR_TRUE;                }                rv = firstURI->GetHost(&firstHost);            }        }    }    if (!firstHost) {        firstHost = PL_strdup(host);    }    /* check to see if we need to block image from loading */    NS_WITH_SERVICE(nsIImgManager, imgmanager, kImgManagerCID, &rv);    if (NS_FAILED(rv)) {        Recycle(host);        Recycle(firstHost);        return PR_TRUE;    }    PRBool permission;    // commenting this out per pavlov's suggestion. he says this file is    // going away soon. CheckForPermission() no longer exists.    // nsIContentPolicy is used to block images now.    //rv = imgmanager->CheckForPermission(host, firstHost, &permission);    Recycle(host);    Recycle(firstHost);    if (NS_FAILED(rv)) {      return PR_TRUE;    }    return permission;}