LCOV - code coverage report
Current view: top level - extensions/cookie - nsPopupWindowManager.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 1 36 2.8 %
Date: 2017-07-14 16:53:18 Functions: 2 11 18.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13