switching to the new, final(!?) popup window management preferences organisation. bug 166442 r=jag,jst

This commit is contained in:
danm%netscape.com 2002-09-18 14:45:31 +00:00
Родитель 600a663b4a
Коммит 52f1d992ef
5 изменённых файлов: 35 добавлений и 22 удалений

Просмотреть файл

@ -54,9 +54,11 @@
*/ */
#define POLICYSTRING "policy" #define POLICYSTRING "policy"
#define CUSTOMSTRING "usecustom"
static const char *sPopupPrefRoot = "privacy.popups."; static const char *sPopupPrefRoot = "privacy.popups.";
static const char *sPopupPrefLeaf = POLICYSTRING; static const char *sPopupPrefPolicyLeaf = POLICYSTRING;
static const char *sPopupPrefCustomLeaf = CUSTOMSTRING;
static const char *sPermissionChangeNotification = PPM_CHANGE_NOTIFICATION; static const char *sPermissionChangeNotification = PPM_CHANGE_NOTIFICATION;
static const char *sXPCOMShutdownTopic = NS_XPCOM_SHUTDOWN_OBSERVER_ID; static const char *sXPCOMShutdownTopic = NS_XPCOM_SHUTDOWN_OBSERVER_ID;
static const char *sPrefChangedTopic = NS_PREFBRANCH_PREFCHANGE_TOPIC_ID; static const char *sPrefChangedTopic = NS_PREFBRANCH_PREFCHANGE_TOPIC_ID;
@ -66,7 +68,8 @@ static const char *sPrefChangedTopic = NS_PREFBRANCH_PREFCHANGE_TOPIC_ID;
//***************************************************************************** //*****************************************************************************
nsPopupWindowManager::nsPopupWindowManager() : nsPopupWindowManager::nsPopupWindowManager() :
mPopupPerm(eAllow) mPolicy(eAllow),
mCustomPermissions(PR_FALSE)
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
} }
@ -93,6 +96,8 @@ nsPopupWindowManager::Init()
// initialize our local copy of the pref // initialize our local copy of the pref
Observe(NS_STATIC_CAST(nsIPopupWindowManager *, this), Observe(NS_STATIC_CAST(nsIPopupWindowManager *, this),
sPrefChangedTopic, NS_LITERAL_STRING(POLICYSTRING).get()); sPrefChangedTopic, NS_LITERAL_STRING(POLICYSTRING).get());
Observe(NS_STATIC_CAST(nsIPopupWindowManager *, this),
sPrefChangedTopic, NS_LITERAL_STRING(CUSTOMSTRING).get());
return ObserveThings(); return ObserveThings();
} }
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -105,14 +110,14 @@ nsPopupWindowManager::Init()
NS_IMETHODIMP NS_IMETHODIMP
nsPopupWindowManager::GetDefaultPermission(PRUint32 *aDefaultPermission) nsPopupWindowManager::GetDefaultPermission(PRUint32 *aDefaultPermission)
{ {
return eDisallow; return eAllow;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPopupWindowManager::SetDefaultPermission(PRUint32 aDefaultPermission) nsPopupWindowManager::SetDefaultPermission(PRUint32 aDefaultPermission)
{ {
NS_ASSERTION(aDefaultPermission == eDisallow, "whitelist not supported"); NS_ASSERTION(aDefaultPermission == eAllow, "whitelist not supported");
return aDefaultPermission == eDisallow ? NS_OK : NS_ERROR_FAILURE; return aDefaultPermission == eAllow ? NS_OK : NS_ERROR_FAILURE;
} }
/* Note: since we don't support whitelists, Add(uri, true) is the same thing /* Note: since we don't support whitelists, Add(uri, true) is the same thing
@ -173,9 +178,9 @@ nsPopupWindowManager::TestPermission(nsIURI *aURI, PRUint32 *_retval)
NS_ENSURE_ARG_POINTER(aURI); NS_ENSURE_ARG_POINTER(aURI);
NS_ENSURE_ARG_POINTER(_retval); NS_ENSURE_ARG_POINTER(_retval);
*_retval = mPopupPerm; *_retval = mPolicy;
if (mPopupPerm == eAllowConditionally) { if (mPolicy == eAllow && mCustomPermissions) {
if (mPermManager) { if (mPermManager) {
/* Because of a bug/quirk/something in the PermissionManager /* Because of a bug/quirk/something in the PermissionManager
the value of blockDomain will be left unchanged if the URI the value of blockDomain will be left unchanged if the URI
@ -188,8 +193,7 @@ nsPopupWindowManager::TestPermission(nsIURI *aURI, PRUint32 *_retval)
nsCAutoString uri; nsCAutoString uri;
aURI->GetPrePath(uri); aURI->GetPrePath(uri);
mPermManager->TestForBlocking(uri, WINDOWPERMISSION, &blockDomain); mPermManager->TestForBlocking(uri, WINDOWPERMISSION, &blockDomain);
if (blockDomain) *_retval = blockDomain ? eDisallow : eAllowConditionally;
*_retval = eDisallow;
} }
} }
return NS_OK; return NS_OK;
@ -228,16 +232,19 @@ nsPopupWindowManager::Observe(nsISupports *aSubject, const char *aTopic,
const PRUnichar *aData) const PRUnichar *aData)
{ {
if (nsCRT::strcmp(aTopic, sPrefChangedTopic) == 0 && if (nsCRT::strcmp(aTopic, sPrefChangedTopic) == 0 &&
NS_LITERAL_STRING(POLICYSTRING).Equals(aData)) { (NS_LITERAL_STRING(POLICYSTRING).Equals(aData) ||
NS_LITERAL_STRING(CUSTOMSTRING).Equals(aData))) {
// refresh our local copy of the "allow popups" pref // refresh our local copy of the "allow popups" pref
mPopupPerm = eAllow; PRInt32 perm = eAllow;
PRBool custom = PR_FALSE;
if (mPopupPrefBranch) { if (mPopupPrefBranch) {
PRInt32 perm = eAllow; mPopupPrefBranch->GetIntPref(sPopupPrefPolicyLeaf, &perm);
mPopupPrefBranch->GetIntPref(sPopupPrefLeaf, &perm); mPopupPrefBranch->GetBoolPref(sPopupPrefCustomLeaf, &custom);
NS_ASSERTION(perm >= 0, "popup pref value out of range"); NS_ASSERTION(perm >= 0, "popup pref value out of range");
mPopupPerm = NS_STATIC_CAST(PRUint32, perm);
} }
mPolicy = NS_STATIC_CAST(PRUint32, perm);
mCustomPermissions = custom;
} else if (nsCRT::strcmp(aTopic, sXPCOMShutdownTopic) == 0) { } else if (nsCRT::strcmp(aTopic, sXPCOMShutdownTopic) == 0) {
// unhook cyclical references // unhook cyclical references
StopObservingThings(); StopObservingThings();
@ -262,8 +269,10 @@ nsPopupWindowManager::ObserveThings()
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIPrefBranchInternal> ibranch(do_QueryInterface(mPopupPrefBranch)); nsCOMPtr<nsIPrefBranchInternal> ibranch(do_QueryInterface(mPopupPrefBranch));
if (ibranch) if (ibranch) {
rv = ibranch->AddObserver(sPopupPrefLeaf, this, PR_FALSE); ibranch->AddObserver(sPopupPrefPolicyLeaf, this, PR_FALSE);
rv = ibranch->AddObserver(sPopupPrefCustomLeaf, this, PR_FALSE);
}
} }
return rv; return rv;
@ -274,8 +283,10 @@ nsresult
nsPopupWindowManager::StopObservingThings() nsPopupWindowManager::StopObservingThings()
{ {
nsCOMPtr<nsIPrefBranchInternal> ibranch(do_QueryInterface(mPopupPrefBranch)); nsCOMPtr<nsIPrefBranchInternal> ibranch(do_QueryInterface(mPopupPrefBranch));
if (ibranch) if (ibranch) {
ibranch->RemoveObserver(sPopupPrefLeaf, this); ibranch->RemoveObserver(sPopupPrefPolicyLeaf, this);
ibranch->RemoveObserver(sPopupPrefCustomLeaf, this);
}
if (mOS) if (mOS)
mOS->RemoveObserver(this, sXPCOMShutdownTopic); mOS->RemoveObserver(this, sXPCOMShutdownTopic);

Просмотреть файл

@ -64,7 +64,8 @@ private:
nsresult NotifyObservers(); nsresult NotifyObservers();
void DeInitialize(); void DeInitialize();
PRUint32 mPopupPerm; PRUint32 mPolicy;
PRBool mCustomPermissions;
nsCOMPtr<nsIObserverService> mOS; nsCOMPtr<nsIObserverService> mOS;
nsCOMPtr<nsIPermissionManager> mPermManager; nsCOMPtr<nsIPermissionManager> mPermManager;
nsCOMPtr<nsIPrefBranch> mPopupPrefBranch; nsCOMPtr<nsIPrefBranch> mPopupPrefBranch;

Просмотреть файл

@ -131,7 +131,7 @@
try { try {
var hide = pref.getBoolPref("dom.disable_open_during_load"); var hide = pref.getBoolPref("dom.disable_open_during_load");
if (!hide) if (!hide)
hide = pref.getIntPref("privacy.popups.policy") != Components.interfaces.nsIPopupWindowManager.eAllowConditionally; hide = pref.getIntPref("privacy.popups.policy") != Components.interfaces.nsIPopupWindowManager.eAllow || !pref.getBoolPref("privacy.popups.usecustom");
HidePopups(hide); HidePopups(hide);
} catch(e) { } catch(e) {
HidePopups(true); HidePopups(true);

Просмотреть файл

@ -378,8 +378,9 @@ pref("javascript.allow.mailnews", false);
pref("javascript.options.strict", false); pref("javascript.options.strict", false);
pref("javascript.options.showInConsole", true); pref("javascript.options.showInConsole", true);
// popups.policy values are in nsIPopupWindowManager.idl // popups.policy 1=allow,2=reject
pref("privacy.popups.policy", 1); pref("privacy.popups.policy", 1);
pref("privacy.popups.usecustom", false);
// advanced prefs // advanced prefs
pref("advanced.always_load_images", true); pref("advanced.always_load_images", true);

Просмотреть файл

@ -131,7 +131,7 @@
try { try {
var hide = pref.getBoolPref("dom.disable_open_during_load"); var hide = pref.getBoolPref("dom.disable_open_during_load");
if (!hide) if (!hide)
hide = pref.getIntPref("privacy.popups.policy") != Components.interfaces.nsIPopupWindowManager.eAllowConditionally; hide = pref.getIntPref("privacy.popups.policy") != Components.interfaces.nsIPopupWindowManager.eAllow || !pref.getBoolPref("privacy.popups.usecustom");
HidePopups(hide); HidePopups(hide);
} catch(e) { } catch(e) {
HidePopups(true); HidePopups(true);