2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsPopupWindowManager.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
2012-07-15 18:37:31 -07:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIURI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Popup Window Manager maintains popup window permissions by website.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char kPopupDisablePref[] = "dom.disable_open_during_load";
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPopupWindowManager object management and nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
nsPopupWindowManager::nsPopupWindowManager() :
|
|
|
|
mPolicy(ALLOW_POPUP)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPopupWindowManager::~nsPopupWindowManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS3(nsPopupWindowManager,
|
|
|
|
nsIPopupWindowManager,
|
|
|
|
nsIObserver,
|
|
|
|
nsSupportsWeakReference)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPopupWindowManager::Init()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
mPermissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
|
2012-01-18 02:23:28 -08:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
2007-03-22 10:30:00 -07:00
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool permission;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
permission = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
prefBranch->AddObserver(kPopupDisablePref, this, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPopupWindowManager::nsIPopupWindowManager
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-15 18:37:31 -07:00
|
|
|
nsPopupWindowManager::TestPermission(nsIPrincipal* aPrincipal,
|
|
|
|
PRUint32 *aPermission)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-15 18:37:31 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrincipal);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aPermission);
|
|
|
|
|
|
|
|
PRUint32 permit;
|
|
|
|
*aPermission = mPolicy;
|
|
|
|
|
|
|
|
if (mPermissionManager) {
|
2012-07-15 18:37:31 -07:00
|
|
|
if (NS_SUCCEEDED(mPermissionManager->TestPermissionFromPrincipal(aPrincipal, "popup", &permit))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Share some constants between interfaces?
|
|
|
|
if (permit == nsIPermissionManager::ALLOW_ACTION) {
|
|
|
|
*aPermission = ALLOW_POPUP;
|
|
|
|
} else if (permit == nsIPermissionManager::DENY_ACTION) {
|
|
|
|
*aPermission = DENY_POPUP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPopupWindowManager::nsIObserver
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPopupWindowManager::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
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
|
2011-09-28 23:19:26 -07:00
|
|
|
bool permission = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
prefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
|
|
|
|
|
|
|
mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|