зеркало из https://github.com/mozilla/gecko-dev.git
r=pavlov, sr=vidur, a=blizzard. 84162. making nsImgManager a nsIContentPolicy which allows it to play in the image blocking arena again. this fixes image blocking.
This commit is contained in:
Родитель
d5a92356a7
Коммит
96b8bdb98e
|
@ -32,7 +32,6 @@
|
|||
interface nsIImgManager : nsISupports
|
||||
{
|
||||
void block(in string imageURL);
|
||||
boolean checkForPermission(in string hostname, in string firstHostname);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
|
||||
#include "nsImgManager.h"
|
||||
#include "nsImages.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -29,11 +34,13 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsImgManager Implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImgManager, nsIImgManager);
|
||||
NS_IMPL_ISUPPORTS2(nsImgManager,
|
||||
nsIImgManager,
|
||||
nsIContentPolicy);
|
||||
|
||||
nsImgManager::nsImgManager()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsImgManager::~nsImgManager(void)
|
||||
|
@ -42,17 +49,62 @@ nsImgManager::~nsImgManager(void)
|
|||
|
||||
nsresult nsImgManager::Init()
|
||||
{
|
||||
IMAGE_RegisterPrefCallbacks();
|
||||
return NS_OK;
|
||||
IMAGE_RegisterPrefCallbacks();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsImgManager::Block(const char * imageURL) {
|
||||
::IMAGE_Block(imageURL);
|
||||
return NS_OK;
|
||||
NS_IMETHODIMP nsImgManager::Block(const char * imageURL)
|
||||
{
|
||||
::IMAGE_Block(imageURL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImgManager::CheckForPermission
|
||||
(const char * hostname, const char * firstHostname, PRBool *permission) {
|
||||
return ::IMAGE_CheckForPermission(hostname, firstHostname, permission);
|
||||
// nsIContentPolicy Implementation
|
||||
NS_IMETHODIMP nsImgManager::ShouldLoad(PRInt32 aContentType,
|
||||
nsIURI *aContentLoc,
|
||||
nsISupports *aContext,
|
||||
nsIDOMWindow *aWindow,
|
||||
PRBool *_retval)
|
||||
{
|
||||
*_retval = PR_TRUE;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
switch (aContentType) {
|
||||
case nsIContentPolicy::IMAGE:
|
||||
{
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(aContext));
|
||||
NS_ASSERTION(content, "no content avail");
|
||||
if (content) {
|
||||
rv = content->GetDocument(*getter_AddRefs(doc));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = doc->GetBaseURL(*getter_AddRefs(baseURI));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString baseHost;
|
||||
rv = baseURI->GetHost(getter_Copies(baseHost));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString host;
|
||||
rv = aContentLoc->GetHost(getter_Copies(host));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return ::IMAGE_CheckForPermission(host, baseHost,
|
||||
_retval);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImgManager::ShouldProcess(PRInt32 aContentType,
|
||||
nsIURI *aDocumentLoc,
|
||||
nsISupports *aContext,
|
||||
nsIDOMWindow *aWindow,
|
||||
PRBool *_retval) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -24,15 +24,19 @@
|
|||
#define nsImgManager_h__
|
||||
|
||||
#include "nsIImgManager.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsImgManager : public nsIImgManager {
|
||||
class nsImgManager : public nsIImgManager,
|
||||
public nsIContentPolicy
|
||||
{
|
||||
public:
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIIMGMANAGER
|
||||
NS_DECL_NSICONTENTPOLICY
|
||||
|
||||
nsImgManager();
|
||||
virtual ~nsImgManager(void);
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "nsImgManager.h"
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsCookieHTTPNotify.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
// Define the constructor function for the objects
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCookie)
|
||||
|
@ -40,6 +42,38 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsImgManager, Init)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPermissionManager, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCookieHTTPNotify, Init)
|
||||
|
||||
static NS_METHOD
|
||||
RegisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
const char *registryLocation, const char *componentType,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsXPIDLCString previous;
|
||||
return catman->AddCategoryEntry("content-policy",
|
||||
NS_IMGMANAGER_CONTRACTID,
|
||||
NS_IMGMANAGER_CONTRACTID,
|
||||
PR_TRUE, PR_TRUE, getter_Copies(previous));
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
UnregisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catman =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return catman->DeleteCategoryEntry("content-policy",
|
||||
NS_IMGMANAGER_CONTRACTID,
|
||||
PR_TRUE);
|
||||
}
|
||||
|
||||
|
||||
// The list of components we register
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ "Cookie",
|
||||
|
@ -65,7 +99,8 @@ static nsModuleComponentInfo components[] = {
|
|||
{ "ImgManager",
|
||||
NS_IMGMANAGER_CID,
|
||||
NS_IMGMANAGER_CONTRACTID,
|
||||
nsImgManagerConstructor
|
||||
nsImgManagerConstructor,
|
||||
RegisterContentPolicy, UnregisterContentPolicy
|
||||
},
|
||||
{ "PermissionManager",
|
||||
NS_PERMISSIONMANAGER_CID,
|
||||
|
|
|
@ -1813,7 +1813,10 @@ PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver
|
|||
return PR_TRUE;
|
||||
}
|
||||
PRBool permission;
|
||||
rv = imgmanager->CheckForPermission(host, firstHost, &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)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче