LCOV - app.info - extensions/cookie/nsPopupWindowManager.cpp

LCOV - code coverage report
| Current view: | directory - extensions/cookie - nsPopupWindowManager.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 36 | 0 | 0.0 %
| Date: | 2012-06-02 | Functions: | 9 | 0 | 0.0 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is mozilla.org code.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Netscape Communications Corporation.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 2002
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : #include "nsPopupWindowManager.h"
          39                 :
          40                 : #include "nsCRT.h"
          41                 : #include "nsIServiceManager.h"
          42                 : #include "nsIPrefService.h"
          43                 : #include "nsIPrefBranch.h"
          44                 :
          45                 : /**
          46                 :  * The Popup Window Manager maintains popup window permissions by website.
          47                 :  */
          48                 :
          49                 : static const char kPopupDisablePref[] = "dom.disable_open_during_load";
          50                 :
          51                 : //*****************************************************************************
          52                 : //*** nsPopupWindowManager object management and nsISupports
          53                 : //*****************************************************************************
          54                 :
          55               0 : nsPopupWindowManager::nsPopupWindowManager() :
          56               0 :   mPolicy(ALLOW_POPUP)
          57                 : {
          58               0 : }
          59                 :
          60               0 : nsPopupWindowManager::~nsPopupWindowManager()
          61                 : {
          62               0 : }
          63                 :
          64               0 : NS_IMPL_ISUPPORTS3(nsPopupWindowManager,
          65                 :                    nsIPopupWindowManager,
          66                 :                    nsIObserver,
          67                 :                    nsSupportsWeakReference)
          68                 :
          69                 : nsresult
          70               0 : nsPopupWindowManager::Init()
          71                 : {
          72                 :   nsresult rv;
          73               0 :   mPermissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
          74                 :
          75                 :   nsCOMPtr<nsIPrefBranch> prefBranch =
          76               0 :     do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
          77               0 :   if (NS_SUCCEEDED(rv)) {
          78                 :     bool permission;
          79               0 :     rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
          80               0 :     if (NS_FAILED(rv)) {
          81               0 :       permission = true;
          82                 :     }
          83               0 :     mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP;
          84                 :
          85               0 :     prefBranch->AddObserver(kPopupDisablePref, this, true);
          86                 :   }
          87                 :
          88               0 :   return NS_OK;
          89                 : }
          90                 :
          91                 : //*****************************************************************************
          92                 : //*** nsPopupWindowManager::nsIPopupWindowManager
          93                 : //*****************************************************************************
          94                 :
          95                 : NS_IMETHODIMP
          96               0 : nsPopupWindowManager::TestPermission(nsIURI *aURI, PRUint32 *aPermission)
          97                 : {
          98               0 :   NS_ENSURE_ARG_POINTER(aURI);
          99               0 :   NS_ENSURE_ARG_POINTER(aPermission);
         100                 :
         101                 :   nsresult rv;
         102                 :   PRUint32 permit;
         103                 :
         104               0 :   *aPermission = mPolicy;
         105                 :
         106               0 :   if (mPermissionManager) {
         107               0 :     rv = mPermissionManager->TestPermission(aURI, "popup", &permit);
         108                 :
         109               0 :     if (NS_SUCCEEDED(rv)) {
         110                 :       // Share some constants between interfaces?
         111               0 :       if (permit == nsIPermissionManager::ALLOW_ACTION) {
         112               0 :         *aPermission = ALLOW_POPUP;
         113               0 :       } else if (permit == nsIPermissionManager::DENY_ACTION) {
         114               0 :         *aPermission = DENY_POPUP;
         115                 :       }
         116                 :     }
         117                 :   }
         118                 :
         119               0 :   return NS_OK;
         120                 : }
         121                 :
         122                 : //*****************************************************************************
         123                 : //*** nsPopupWindowManager::nsIObserver
         124                 : //*****************************************************************************
         125                 : NS_IMETHODIMP
         126               0 : nsPopupWindowManager::Observe(nsISupports *aSubject,
         127                 :                               const char *aTopic,
         128                 :                               const PRUnichar *aData)
         129                 : {
         130               0 :   nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject);
         131               0 :   NS_ASSERTION(!nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic),
         132                 :                "unexpected topic - we only deal with pref changes!");
         133                 :
         134               0 :   if (prefBranch) {
         135                 :     // refresh our local copy of the "disable popups" pref
         136               0 :     bool permission = true;
         137               0 :     prefBranch->GetBoolPref(kPopupDisablePref, &permission);
         138                 :
         139               0 :     mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP;
         140                 :   }
         141                 :
         142               0 :   return NS_OK;
         143                 : }

Generated by: LCOV version 1.7