2002-09-11 06:10:46 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2002-09-11 06:10:46 +04:00
|
|
|
|
|
|
|
#include "nsPopupWindowManager.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
2005-02-06 11:25:40 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPrefService.h"
|
2002-09-11 06:10:46 +04:00
|
|
|
#include "nsIPrefBranch.h"
|
2012-07-16 05:37:31 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIURI.h"
|
2014-04-29 21:27:26 +04:00
|
|
|
#include "mozilla/Services.h"
|
2002-09-11 06:10:46 +04:00
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
/**
|
|
|
|
* The Popup Window Manager maintains popup window permissions by website.
|
2002-09-11 06:10:46 +04:00
|
|
|
*/
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
static const char kPopupDisablePref[] = "dom.disable_open_during_load";
|
2003-01-21 10:38:02 +03:00
|
|
|
|
2002-09-11 06:10:46 +04:00
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPopupWindowManager object management and nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
nsPopupWindowManager::nsPopupWindowManager() :
|
2002-10-25 06:31:12 +04:00
|
|
|
mPolicy(ALLOW_POPUP)
|
2002-09-11 06:10:46 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-02-06 11:25:40 +03:00
|
|
|
nsPopupWindowManager::~nsPopupWindowManager()
|
2002-09-11 06:10:46 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsPopupWindowManager,
|
2014-04-27 11:06:00 +04:00
|
|
|
nsIPopupWindowManager,
|
|
|
|
nsIObserver,
|
|
|
|
nsISupportsWeakReference)
|
2002-09-11 06:10:46 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPopupWindowManager::Init()
|
|
|
|
{
|
2003-03-22 04:24:51 +03:00
|
|
|
nsresult rv;
|
2014-04-29 21:27:26 +04:00
|
|
|
mPermissionManager = mozilla::services::GetPermissionManager();
|
2002-09-11 06:10:46 +04:00
|
|
|
|
2012-01-18 14:23:28 +04:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
2005-02-06 11:25:40 +03:00
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
2003-03-22 04:24:51 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool permission;
|
2005-02-06 11:25:40 +03:00
|
|
|
rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
2003-03-22 04:24:51 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
permission = true;
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
mPolicy = permission ? (uint32_t) DENY_POPUP : (uint32_t) ALLOW_POPUP;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
prefBranch->AddObserver(kPopupDisablePref, this, true);
|
2017-07-06 15:00:35 +03:00
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-09-11 06:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPopupWindowManager::nsIPopupWindowManager
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-07-16 05:37:31 +04:00
|
|
|
nsPopupWindowManager::TestPermission(nsIPrincipal* aPrincipal,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *aPermission)
|
2002-09-11 06:10:46 +04:00
|
|
|
{
|
2012-07-16 05:37:31 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aPrincipal);
|
2003-03-22 04:24:51 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aPermission);
|
2002-09-11 06:10:46 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t permit;
|
2005-02-06 11:25:40 +03:00
|
|
|
*aPermission = mPolicy;
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
if (mPermissionManager) {
|
2012-07-16 05:37:31 +04:00
|
|
|
if (NS_SUCCEEDED(mPermissionManager->TestPermissionFromPrincipal(aPrincipal, "popup", &permit))) {
|
2005-02-06 11:25:40 +03:00
|
|
|
// Share some constants between interfaces?
|
|
|
|
if (permit == nsIPermissionManager::ALLOW_ACTION) {
|
|
|
|
*aPermission = ALLOW_POPUP;
|
|
|
|
} else if (permit == nsIPermissionManager::DENY_ACTION) {
|
|
|
|
*aPermission = DENY_POPUP;
|
|
|
|
}
|
2002-09-11 06:10:46 +04:00
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
2005-02-06 11:25:40 +03:00
|
|
|
|
2003-01-21 10:38:02 +03:00
|
|
|
return NS_OK;
|
2002-09-11 06:10:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPopupWindowManager::nsIObserver
|
|
|
|
//*****************************************************************************
|
|
|
|
NS_IMETHODIMP
|
2017-07-06 15:00:35 +03:00
|
|
|
nsPopupWindowManager::Observe(nsISupports *aSubject,
|
2003-03-22 04:24:51 +03:00
|
|
|
const char *aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aData)
|
2002-09-11 06:10:46 +04:00
|
|
|
{
|
2005-02-06 11:25:40 +03:00
|
|
|
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) {
|
2002-10-25 06:31:12 +04:00
|
|
|
// refresh our local copy of the "disable popups" pref
|
2011-09-29 10:19:26 +04:00
|
|
|
bool permission = true;
|
2005-02-06 11:25:40 +03:00
|
|
|
prefBranch->GetBoolPref(kPopupDisablePref, &permission);
|
2002-09-11 06:10:46 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
mPolicy = permission ? (uint32_t) DENY_POPUP : (uint32_t) ALLOW_POPUP;
|
2002-09-11 06:10:46 +04:00
|
|
|
}
|
2005-02-06 11:25:40 +03:00
|
|
|
|
2002-09-11 06:10:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|