extensions/cookie/nsPopupWindowManager.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsPopupWindowManager.h"
michael@0 7
michael@0 8 #include "nsCRT.h"
michael@0 9 #include "nsIServiceManager.h"
michael@0 10 #include "nsIPrefService.h"
michael@0 11 #include "nsIPrefBranch.h"
michael@0 12 #include "nsIPrincipal.h"
michael@0 13 #include "nsIURI.h"
michael@0 14
michael@0 15 /**
michael@0 16 * The Popup Window Manager maintains popup window permissions by website.
michael@0 17 */
michael@0 18
michael@0 19 static const char kPopupDisablePref[] = "dom.disable_open_during_load";
michael@0 20
michael@0 21 //*****************************************************************************
michael@0 22 //*** nsPopupWindowManager object management and nsISupports
michael@0 23 //*****************************************************************************
michael@0 24
michael@0 25 nsPopupWindowManager::nsPopupWindowManager() :
michael@0 26 mPolicy(ALLOW_POPUP)
michael@0 27 {
michael@0 28 }
michael@0 29
michael@0 30 nsPopupWindowManager::~nsPopupWindowManager()
michael@0 31 {
michael@0 32 }
michael@0 33
michael@0 34 NS_IMPL_ISUPPORTS(nsPopupWindowManager,
michael@0 35 nsIPopupWindowManager,
michael@0 36 nsIObserver,
michael@0 37 nsISupportsWeakReference)
michael@0 38
michael@0 39 nsresult
michael@0 40 nsPopupWindowManager::Init()
michael@0 41 {
michael@0 42 nsresult rv;
michael@0 43 mPermissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
michael@0 44
michael@0 45 nsCOMPtr<nsIPrefBranch> prefBranch =
michael@0 46 do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
michael@0 47 if (NS_SUCCEEDED(rv)) {
michael@0 48 bool permission;
michael@0 49 rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
michael@0 50 if (NS_FAILED(rv)) {
michael@0 51 permission = true;
michael@0 52 }
michael@0 53 mPolicy = permission ? (uint32_t) DENY_POPUP : (uint32_t) ALLOW_POPUP;
michael@0 54
michael@0 55 prefBranch->AddObserver(kPopupDisablePref, this, true);
michael@0 56 }
michael@0 57
michael@0 58 return NS_OK;
michael@0 59 }
michael@0 60
michael@0 61 //*****************************************************************************
michael@0 62 //*** nsPopupWindowManager::nsIPopupWindowManager
michael@0 63 //*****************************************************************************
michael@0 64
michael@0 65 NS_IMETHODIMP
michael@0 66 nsPopupWindowManager::TestPermission(nsIPrincipal* aPrincipal,
michael@0 67 uint32_t *aPermission)
michael@0 68 {
michael@0 69 NS_ENSURE_ARG_POINTER(aPrincipal);
michael@0 70 NS_ENSURE_ARG_POINTER(aPermission);
michael@0 71
michael@0 72 uint32_t permit;
michael@0 73 *aPermission = mPolicy;
michael@0 74
michael@0 75 if (mPermissionManager) {
michael@0 76 if (NS_SUCCEEDED(mPermissionManager->TestPermissionFromPrincipal(aPrincipal, "popup", &permit))) {
michael@0 77 // Share some constants between interfaces?
michael@0 78 if (permit == nsIPermissionManager::ALLOW_ACTION) {
michael@0 79 *aPermission = ALLOW_POPUP;
michael@0 80 } else if (permit == nsIPermissionManager::DENY_ACTION) {
michael@0 81 *aPermission = DENY_POPUP;
michael@0 82 }
michael@0 83 }
michael@0 84 }
michael@0 85
michael@0 86 return NS_OK;
michael@0 87 }
michael@0 88
michael@0 89 //*****************************************************************************
michael@0 90 //*** nsPopupWindowManager::nsIObserver
michael@0 91 //*****************************************************************************
michael@0 92 NS_IMETHODIMP
michael@0 93 nsPopupWindowManager::Observe(nsISupports *aSubject,
michael@0 94 const char *aTopic,
michael@0 95 const char16_t *aData)
michael@0 96 {
michael@0 97 nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
michael@0 98 NS_ASSERTION(!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic),
michael@0 99 "unexpected topic - we only deal with pref changes!");
michael@0 100
michael@0 101 if (prefBranch) {
michael@0 102 // refresh our local copy of the "disable popups" pref
michael@0 103 bool permission = true;
michael@0 104 prefBranch->GetBoolPref(kPopupDisablePref, &permission);
michael@0 105
michael@0 106 mPolicy = permission ? (uint32_t) DENY_POPUP : (uint32_t) ALLOW_POPUP;
michael@0 107 }
michael@0 108
michael@0 109 return NS_OK;
michael@0 110 }

mercurial