LCOV - code coverage report
Current view: directory - browser/components/privatebrowsing/src - nsPrivateBrowsingServiceWrapper.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 43 39 90.7 %
Date: 2012-06-02 Functions: 12 12 100.0 %

       1                 : /* ***** BEGIN LICENSE BLOCK *****
       2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       3                 :  *
       4                 :  * The contents of this file are subject to the Mozilla Public License Version
       5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       6                 :  * the License. You may obtain a copy of the License at
       7                 :  * http://www.mozilla.org/MPL/
       8                 :  *
       9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11                 :  * for the specific language governing rights and limitations under the
      12                 :  * License.
      13                 :  *
      14                 :  * The Original Code is Private Browsing.
      15                 :  *
      16                 :  * The Initial Developer of the Original Code is
      17                 :  * Ehsan Akhgari <ehsan.akhgari@gmail.com>
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      25                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #include "nsPrivateBrowsingServiceWrapper.h"
      38                 : #include "nsServiceManagerUtils.h"
      39                 : #include "jsapi.h"
      40                 : #include "nsIJSContextStack.h"
      41                 : 
      42                 : class JSStackGuard
      43                 : {
      44                 : public:
      45                 :   JSStackGuard();
      46                 :   ~JSStackGuard();
      47                 : 
      48                 : private:
      49                 :   nsCOMPtr<nsIJSContextStack> mJSStack;
      50                 : };
      51                 : 
      52            8927 : NS_IMPL_ISUPPORTS2(nsPrivateBrowsingServiceWrapper, nsIPrivateBrowsingService, nsIObserver)
      53                 : 
      54                 : nsresult
      55             470 : nsPrivateBrowsingServiceWrapper::Init()
      56                 : {
      57                 :   nsresult rv;
      58             470 :   mPBService = do_GetService("@mozilla.org/privatebrowsing;1", &rv);
      59             470 :   return rv;
      60                 : }
      61                 : 
      62            1368 : JSStackGuard::JSStackGuard()
      63            1368 :   : mJSStack(nsnull)
      64                 : {
      65                 :   nsresult rv;
      66            1368 :   mJSStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
      67                 : 
      68            1368 :   if (NS_SUCCEEDED(rv) && mJSStack) {
      69            1368 :     rv = mJSStack->Push(nsnull);
      70            1368 :     if (NS_FAILED(rv))
      71               0 :       mJSStack = nsnull;
      72                 :   }
      73            1368 : }
      74                 : 
      75            2736 : JSStackGuard::~JSStackGuard()
      76                 : {
      77            1368 :   if (mJSStack) {
      78                 :     JSContext *cx;
      79            1368 :     mJSStack->Pop(&cx);
      80            1368 :     NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
      81                 :   }
      82            1368 : }
      83                 : 
      84                 : NS_IMETHODIMP
      85            1290 : nsPrivateBrowsingServiceWrapper::GetPrivateBrowsingEnabled(bool *aPrivateBrowsingEnabled)
      86                 : {
      87            1290 :   if (!aPrivateBrowsingEnabled)
      88               0 :     return NS_ERROR_NULL_POINTER;
      89            2580 :   JSStackGuard guard;
      90            1290 :   return mPBService->GetPrivateBrowsingEnabled(aPrivateBrowsingEnabled);
      91                 : }
      92                 : 
      93                 : NS_IMETHODIMP
      94              41 : nsPrivateBrowsingServiceWrapper::SetPrivateBrowsingEnabled(bool aPrivateBrowsingEnabled)
      95                 : {
      96              82 :   JSStackGuard guard;
      97              41 :   return mPBService->SetPrivateBrowsingEnabled(aPrivateBrowsingEnabled);
      98                 : }
      99                 : 
     100                 : NS_IMETHODIMP
     101               8 : nsPrivateBrowsingServiceWrapper::GetAutoStarted(bool *aAutoStarted)
     102                 : {
     103               8 :   if (!aAutoStarted)
     104               0 :     return NS_ERROR_NULL_POINTER;
     105              16 :   JSStackGuard guard;
     106               8 :   return mPBService->GetAutoStarted(aAutoStarted);
     107                 : }
     108                 : 
     109                 : NS_IMETHODIMP
     110               4 : nsPrivateBrowsingServiceWrapper::GetLastChangedByCommandLine(bool *aReason)
     111                 : {
     112               4 :   if (!aReason)
     113               0 :     return NS_ERROR_NULL_POINTER;
     114               8 :   JSStackGuard guard;
     115               4 :   return mPBService->GetLastChangedByCommandLine(aReason);
     116                 : }
     117                 : 
     118                 : NS_IMETHODIMP
     119              23 : nsPrivateBrowsingServiceWrapper::RemoveDataFromDomain(const nsACString & aDomain)
     120                 : {
     121              46 :   JSStackGuard guard;
     122              23 :   return mPBService->RemoveDataFromDomain(aDomain);
     123                 : }
     124                 : 
     125                 : NS_IMETHODIMP
     126               2 : nsPrivateBrowsingServiceWrapper::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
     127                 : {
     128               4 :   JSStackGuard guard;
     129               4 :   nsCOMPtr<nsIObserver> observer(do_QueryInterface(mPBService));
     130               2 :   NS_ENSURE_TRUE(observer, NS_ERROR_FAILURE);
     131               2 :   return observer->Observe(aSubject, aTopic, aData);
     132                 : }

Generated by: LCOV version 1.7