diff --git a/mozilla/extensions/cookie/nsCookie.cpp b/mozilla/extensions/cookie/nsCookie.cpp index 23e96d44459..c538c013cfd 100644 --- a/mozilla/extensions/cookie/nsCookie.cpp +++ b/mozilla/extensions/cookie/nsCookie.cpp @@ -1067,7 +1067,7 @@ permission_Check } PUBLIC nsresult -Image_CheckForPermission(char * hostname, PRBool &permission) { +Image_CheckForPermission(char * hostname, char * firstHostname, PRBool &permission) { /* exit if imageblocker is not enabled */ nsresult rv; @@ -1082,7 +1082,8 @@ Image_CheckForPermission(char * hostname, PRBool &permission) { /* try to make a decision based on pref settings */ if ((image_GetBehaviorPref() == COOKIE_DontUse) || - (image_GetBehaviorPref() == COOKIE_DontAcceptForeign /* && foreign */)) { //??? + (image_GetBehaviorPref() == COOKIE_DontAcceptForeign && + PL_strcmp(hostname, firstHostname))) { permission = PR_FALSE; return NS_OK; } diff --git a/mozilla/extensions/cookie/nsCookie.h b/mozilla/extensions/cookie/nsCookie.h index 81860a8c1e2..7df433a7414 100644 --- a/mozilla/extensions/cookie/nsCookie.h +++ b/mozilla/extensions/cookie/nsCookie.h @@ -52,5 +52,6 @@ extern void COOKIE_GetPermissionListForViewer (nsString& aPermissionList, PRInt3 extern void COOKIE_CookieViewerReturn(nsAutoString results); extern COOKIE_BehaviorEnum COOKIE_GetBehaviorPref(); extern void Image_Block(nsString imageURL); -extern nsresult Image_CheckForPermission(char * hostname, PRBool &permission); +extern nsresult Image_CheckForPermission + (char * hostname, char * firstHostname, PRBool &permission); #endif /* COOKIES_H */ diff --git a/mozilla/extensions/cookie/nsCookieService.cpp b/mozilla/extensions/cookie/nsCookieService.cpp index 0414e4bc84a..bbd87df869d 100644 --- a/mozilla/extensions/cookie/nsCookieService.cpp +++ b/mozilla/extensions/cookie/nsCookieService.cpp @@ -162,8 +162,8 @@ NS_IMETHODIMP nsCookieService::Image_Block(nsAutoString imageURL) { } NS_IMETHODIMP nsCookieService::Image_CheckForPermission - (char * hostname, PRBool &permission) { - return ::Image_CheckForPermission(hostname, permission); + (char * hostname, char * firstHostname, PRBool &permission) { + return ::Image_CheckForPermission(hostname, firstHostname, permission); } diff --git a/mozilla/extensions/cookie/nsCookieService.h b/mozilla/extensions/cookie/nsCookieService.h index d506e44ef97..5bdd5b667c8 100644 --- a/mozilla/extensions/cookie/nsCookieService.h +++ b/mozilla/extensions/cookie/nsCookieService.h @@ -42,7 +42,8 @@ public: NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList); NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList, PRInt32 type); NS_IMETHOD Image_Block(nsAutoString imageURL); - NS_IMETHOD Image_CheckForPermission(char * hostname, PRBool &permission); + NS_IMETHOD Image_CheckForPermission + (char * hostname, char * firstHostname, PRBool &permission); NS_IMETHOD CookieEnabled(PRBool* aEnabled); nsCookieService(); diff --git a/mozilla/extensions/cookie/nsICookieService.h b/mozilla/extensions/cookie/nsICookieService.h index 1d737175778..200030f777b 100644 --- a/mozilla/extensions/cookie/nsICookieService.h +++ b/mozilla/extensions/cookie/nsICookieService.h @@ -95,7 +95,8 @@ public: NS_IMETHOD Cookie_GetCookieListForViewer(nsString& aCookieList)=0; NS_IMETHOD Cookie_GetPermissionListForViewer(nsString& aPermissionList, PRInt32 type)=0; NS_IMETHOD Image_Block(nsAutoString imageURL)=0; - NS_IMETHOD Image_CheckForPermission(char * hostname, PRBool &permission)=0; + NS_IMETHOD Image_CheckForPermission + (char * hostname, char * firstHostname, PRBool &permission)=0; /* * Specifies whether cookies will be accepted or not. diff --git a/mozilla/gfx/src/nsImageRequest.cpp b/mozilla/gfx/src/nsImageRequest.cpp index 6a1982ee80d..b16a5000ce3 100644 --- a/mozilla/gfx/src/nsImageRequest.cpp +++ b/mozilla/gfx/src/nsImageRequest.cpp @@ -254,11 +254,11 @@ ImageRequestImpl::Init(IL_GroupContext *aGroupContext, ((aFlags & IL_STICKY) ? nsImageLoadFlags_kSticky : 0) | ((aFlags & IL_BYPASS_CACHE) ? nsImageLoadFlags_kBypassCache : 0) | ((aFlags & IL_ONLY_FROM_CACHE) ? nsImageLoadFlags_kOnlyFromCache : 0); - + mImageReq = IL_GetImage(aUrl, aGroupContext, mXPObserver, nsnull == aBackgroundColor ? nsnull : &bgcolor, - aWidth, aHeight, flags, (void *)aNetContext); - + aWidth, aHeight, flags, (void *)aNetContext, aObserver); + if (mImageReq == nsnull) { XP_DisposeObserverList(mXPObserver); mXPObserver = nsnull; diff --git a/mozilla/modules/libimg/public/libimg.h b/mozilla/modules/libimg/public/libimg.h index 3ae64246dc3..f1048564bb9 100644 --- a/mozilla/modules/libimg/public/libimg.h +++ b/mozilla/modules/libimg/public/libimg.h @@ -22,7 +22,7 @@ /* -*- Mode: C; tab-width: 4 -*- * libimg.h --- API calls to the Image Library. - * $Id: libimg.h,v 3.6 1999-11-13 22:37:35 cls%seawood.org Exp $ + * $Id: libimg.h,v 3.7 2000-03-19 16:58:09 morse%netscape.com Exp $ */ @@ -36,6 +36,7 @@ #include "ilISystemServices.h" #include "ilIImageRenderer.h" +#include "nsIImageObserver.h" /*********************** Observers and Observables ***************************/ @@ -147,7 +148,8 @@ IL_GetImage(const char* url, IL_IRGB *background_color, PRUint32 width, PRUint32 height, PRUint32 flags, - void *net_context); + void *net_context, + nsIImageRequestObserver * aObserver); /* Release a reference to an image lib request. If there are no other clients of the request's associated pixmap, any related netlib diff --git a/mozilla/modules/libimg/src/if.cpp b/mozilla/modules/libimg/src/if.cpp index 1e049c8c92f..1f91c8c1186 100644 --- a/mozilla/modules/libimg/src/if.cpp +++ b/mozilla/modules/libimg/src/if.cpp @@ -37,6 +37,10 @@ #include "prprf.h" #include "nsCRT.h" +#include "nsIPresContext.h" +#include "nsICookieService.h" +#include "nsIServiceManager.h" + PR_BEGIN_EXTERN_C extern int XP_MSG_IMAGE_PIXELS; @@ -52,6 +56,8 @@ int il_debug=0; /* Global list of image group contexts. */ static IL_GroupContext *il_global_img_cx_list = NULL; +static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID); + /*-----------------------------------------*/ NS_IMETHODIMP ImgDCallbk::ImgDCBSetupColorspaceConverter() { @@ -1871,13 +1877,8 @@ il_internal_image(const char *image_url) return 0; } - -#include "nsICookieService.h" -#include "nsIServiceManager.h" -static NS_DEFINE_IID(kCookieServiceCID, NS_COOKIESERVICE_CID); - /* block certain hosts from loading images */ -PRBool il_PermitLoad(const char * image_url) { +PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver) { /* convert image_url to an nsIURL so we can extract host and scheme */ nsresult rv; @@ -1905,26 +1906,48 @@ PRBool il_PermitLoad(const char * image_url) { return PR_TRUE; } - /* check to see if we need to block image from loading */ - NS_WITH_SERVICE(nsICookieService, cookieservice, kCookieServiceCID, &rv); + /* obtain first url from aObserver */ + + if (!aObserver) { + Recycle(host); + return PR_TRUE; + } + + /* 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; } + + /* 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, permission); + rv = cookieservice->Image_CheckForPermission(host, firstHost, permission); Recycle(host); + Recycle(firstHost); if (NS_FAILED(rv)) { return PR_TRUE; } return permission; } -#include "nsWeakPtr.h" -#include "nsILoadGroup.h" -#include "ilIURL.h" -#include "nsIHTTPChannel.h" - IL_IMPLEMENT(IL_ImageReq *) IL_GetImage(const char* image_url, IL_GroupContext *img_cx, @@ -1932,10 +1955,11 @@ IL_GetImage(const char* image_url, NI_IRGB *background_color, PRUint32 req_width, PRUint32 req_height, PRUint32 flags, - void *opaque_cx) + void *opaque_cx, + nsIImageRequestObserver * aObserver) { /* block certain hosts from loading images */ - if (!il_PermitLoad(image_url)) { + if (!il_PermitLoad(image_url, aObserver)) { return NULL; }