summaryrefslogtreecommitdiffstats
path: root/extensions/cookie/nsPopupWindowManager.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /extensions/cookie/nsPopupWindowManager.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'extensions/cookie/nsPopupWindowManager.cpp')
-rw-r--r--extensions/cookie/nsPopupWindowManager.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/extensions/cookie/nsPopupWindowManager.cpp b/extensions/cookie/nsPopupWindowManager.cpp
new file mode 100644
index 000000000..d95fb7440
--- /dev/null
+++ b/extensions/cookie/nsPopupWindowManager.cpp
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "nsPopupWindowManager.h"
+
+#include "nsCRT.h"
+#include "nsIServiceManager.h"
+#include "nsIPrefService.h"
+#include "nsIPrefBranch.h"
+#include "nsIPrincipal.h"
+#include "nsIURI.h"
+#include "mozilla/Services.h"
+
+/**
+ * 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_ISUPPORTS(nsPopupWindowManager,
+ nsIPopupWindowManager,
+ nsIObserver,
+ nsISupportsWeakReference)
+
+nsresult
+nsPopupWindowManager::Init()
+{
+ nsresult rv;
+ mPermissionManager = mozilla::services::GetPermissionManager();
+
+ nsCOMPtr<nsIPrefBranch> prefBranch =
+ do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
+ if (NS_SUCCEEDED(rv)) {
+ bool permission;
+ rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
+ if (NS_FAILED(rv)) {
+ permission = true;
+ }
+ mPolicy = permission ? (uint32_t) DENY_POPUP : (uint32_t) ALLOW_POPUP;
+
+ prefBranch->AddObserver(kPopupDisablePref, this, true);
+ }
+
+ return NS_OK;
+}
+
+//*****************************************************************************
+//*** nsPopupWindowManager::nsIPopupWindowManager
+//*****************************************************************************
+
+NS_IMETHODIMP
+nsPopupWindowManager::TestPermission(nsIPrincipal* aPrincipal,
+ uint32_t *aPermission)
+{
+ NS_ENSURE_ARG_POINTER(aPrincipal);
+ NS_ENSURE_ARG_POINTER(aPermission);
+
+ uint32_t permit;
+ *aPermission = mPolicy;
+
+ if (mPermissionManager) {
+ if (NS_SUCCEEDED(mPermissionManager->TestPermissionFromPrincipal(aPrincipal, "popup", &permit))) {
+ // 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 char16_t *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
+ bool permission = true;
+ prefBranch->GetBoolPref(kPopupDisablePref, &permission);
+
+ mPolicy = permission ? (uint32_t) DENY_POPUP : (uint32_t) ALLOW_POPUP;
+ }
+
+ return NS_OK;
+}