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)); rv = firstURI->GetHost(&firstHost); }
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, "component://netscape/network/standard-url", &rv);    if (NS_FAILED(rv) || NS_FAILED(uri->SetSpec(image_url))) {        return PR_TRUE;    }    /* extract scheme -- we block loading of only http and https images */    char * scheme;    rv = uri->GetScheme(&scheme);    if (NS_FAILED(rv)) {        return PR_TRUE;    }    if (PL_strcasecmp(scheme, "http") && PL_strcasecmp(scheme, "https")) {        Recycle(scheme);        return PR_TRUE;    }    Recycle(scheme);    /* extract host */    char * host;    rv = uri->GetHost(&host);    if (NS_FAILED(rv)) {        return PR_TRUE;    }    /* obtain first url from aObserver */    if (!aObserver) {        Recycle(host);        return PR_TRUE;    }#ifdef xxx    /* real ugly hack until I figure out the right way to get the presContext from aObserver */    nsIPresContext* presContext = (nsIPresContext*)(((PRInt32 *)aObserver)[3]);    nsIURI * firstUri;    rv = presContext->GetBaseURL(&firstUri);    if (NS_FAILED(rv) || !firstUri) {        Recycle(host);        return PR_TRUE;    }    char* firstHost = nsnull;    rv = firstUri->GetHost(&firstHost);    NS_RELEASE(firstUri);    if (NS_FAILED(rv)) {        Recycle(host);        return PR_TRUE;    }#else    char* firstHost = PL_strdup(host);#endif    /* check to see if we need to block image from loading */    NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv);    if (NS_FAILED(rv)) {        Recycle(host);        Recycle(firstHost);        return PR_TRUE;    }    PRBool permission;    rv = cookieservice->Image_CheckForPermission(host, firstHost, permission);    Recycle(host);    Recycle(firstHost);    if (NS_FAILED(rv)) {      return PR_TRUE;    }    return permission;}