mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 22:04:36 +00:00
tidy up popup blocker code.
b=279710, r+sr=dveditz.
This commit is contained in:
parent
9b22e34502
commit
33e373e757
@ -37,17 +37,11 @@
|
||||
|
||||
#include "nsPopupWindowManager.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsPermission.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
/**
|
||||
* The Popup Window Manager maintains popup window permissions by website.
|
||||
@ -64,7 +58,7 @@ nsPopupWindowManager::nsPopupWindowManager() :
|
||||
{
|
||||
}
|
||||
|
||||
nsPopupWindowManager::~nsPopupWindowManager(void)
|
||||
nsPopupWindowManager::~nsPopupWindowManager()
|
||||
{
|
||||
}
|
||||
|
||||
@ -79,16 +73,17 @@ nsPopupWindowManager::Init()
|
||||
nsresult rv;
|
||||
mPermissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
||||
|
||||
mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefBranch =
|
||||
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRBool permission;
|
||||
rv = mPrefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
||||
rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
||||
if (NS_FAILED(rv)) {
|
||||
permission = PR_FALSE;
|
||||
permission = PR_TRUE;
|
||||
}
|
||||
mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP;
|
||||
|
||||
mPrefBranch->AddObserver(kPopupDisablePref, this, PR_TRUE);
|
||||
prefBranch->AddObserver(kPopupDisablePref, this, PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -98,22 +93,6 @@ nsPopupWindowManager::Init()
|
||||
//*** nsPopupWindowManager::nsIPopupWindowManager
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPopupWindowManager::GetDefaultPermission(PRUint32 *aDefaultPermission)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDefaultPermission);
|
||||
*aDefaultPermission = mPolicy;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPopupWindowManager::SetDefaultPermission(PRUint32 aDefaultPermission)
|
||||
{
|
||||
mPolicy = aDefaultPermission;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPopupWindowManager::TestPermission(nsIURI *aURI, PRUint32 *aPermission)
|
||||
{
|
||||
@ -123,20 +102,21 @@ nsPopupWindowManager::TestPermission(nsIURI *aURI, PRUint32 *aPermission)
|
||||
nsresult rv;
|
||||
PRUint32 permit;
|
||||
|
||||
*aPermission = mPolicy;
|
||||
|
||||
if (mPermissionManager) {
|
||||
rv = mPermissionManager->TestPermission(aURI, "popup", &permit);
|
||||
|
||||
// Share some constants between interfaces?
|
||||
if (permit == nsIPermissionManager::ALLOW_ACTION) {
|
||||
*aPermission = ALLOW_POPUP;
|
||||
} else if (permit == nsIPermissionManager::DENY_ACTION) {
|
||||
*aPermission = DENY_POPUP;
|
||||
} else {
|
||||
*aPermission = mPolicy;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Share some constants between interfaces?
|
||||
if (permit == nsIPermissionManager::ALLOW_ACTION) {
|
||||
*aPermission = ALLOW_POPUP;
|
||||
} else if (permit == nsIPermissionManager::DENY_ACTION) {
|
||||
*aPermission = DENY_POPUP;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*aPermission = mPolicy;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -148,15 +128,17 @@ nsPopupWindowManager::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *aData)
|
||||
{
|
||||
NS_LossyConvertUCS2toASCII pref(aData);
|
||||
if (pref.Equals(kPopupDisablePref)) {
|
||||
// refresh our local copy of the "disable popups" pref
|
||||
PRBool permission = PR_FALSE;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
|
||||
NS_ASSERTION(!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic),
|
||||
"unexpected topic - we only deal with pref changes!");
|
||||
|
||||
if (prefBranch) {
|
||||
// refresh our local copy of the "disable popups" pref
|
||||
PRBool permission = PR_TRUE;
|
||||
prefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
||||
|
||||
if (mPrefBranch) {
|
||||
mPrefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
||||
}
|
||||
mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -41,10 +41,8 @@
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIPopupWindowManager.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class nsIURI;
|
||||
@ -65,11 +63,10 @@ public:
|
||||
private:
|
||||
PRUint32 mPolicy;
|
||||
nsCOMPtr<nsIPermissionManager> mPermissionManager;
|
||||
nsCOMPtr<nsIPrefBranchInternal> mPrefBranch;
|
||||
};
|
||||
|
||||
// {4275d3f4-752a-427a-b432-14d5dda1c20b}
|
||||
// {822bcd11-6432-48be-9e9d-36f7804b7747}
|
||||
#define NS_POPUPWINDOWMANAGER_CID \
|
||||
{0x4275d3f4, 0x752a, 0x427a, {0xb4, 0x32, 0x14, 0xd5, 0xdd, 0xa1, 0xc2, 0x0b}}
|
||||
{0x822bcd11, 0x6432, 0x48be, {0x9e, 0x9d, 0x36, 0xf7, 0x80, 0x4b, 0x77, 0x47}}
|
||||
|
||||
#endif /* nsPopupWindowManager_h__ */
|
||||
|
@ -42,11 +42,9 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIObserver;
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsIURI;
|
||||
|
||||
[scriptable, uuid(2e14fec9-e8e9-44cc-8c86-c8673c2383cc)]
|
||||
[scriptable, uuid(3210a6aa-b464-4f57-9335-b22815567cf1)]
|
||||
interface nsIPopupWindowManager : nsISupports {
|
||||
|
||||
/**
|
||||
@ -56,12 +54,6 @@ interface nsIPopupWindowManager : nsISupports {
|
||||
const PRUint32 DENY_POPUP = 2;
|
||||
const PRUint32 ALLOW_POPUP_WITH_PREJUDICE = 3;
|
||||
|
||||
/**
|
||||
* The manager's default permission can be ALLOW_POPUP (a blacklist)
|
||||
* or DENY_POPUP (a whitelist).
|
||||
*/
|
||||
attribute PRUint32 defaultPermission;
|
||||
|
||||
/**
|
||||
* Test whether a website has permission to show a popup window.
|
||||
* @param uri is the URI to be tested
|
||||
@ -71,10 +63,5 @@ interface nsIPopupWindowManager : nsISupports {
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// {2e14fec9-e8e9-44cc-8c86-c8673c2383cc}
|
||||
#define NS_POPUPWINDOWMANAGER_IID \
|
||||
{ 0x2e14fec9, 0xe8e9, 0x44cc, { 0x8c, 0x86, 0xc8, 0x67, 0x3c, 0x23, 0x83,0xcc }}
|
||||
#define NS_POPUPWINDOWMANAGER_CONTRACTID "@mozilla.org/PopupWindowManager;1"
|
||||
|
||||
#define PPM_CHANGE_NOTIFICATION "popup-perm-change"
|
||||
%}
|
||||
|
Loading…
x
Reference in New Issue
Block a user