nsPrivateBrowsingServiceWrapper.cpp
Go to the documentation of this file.
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 
38 #include "nsServiceManagerUtils.h"
39 #include "jsapi.h"
40 #include "nsIJSContextStack.h"
41 
43 {
44 public:
45  JSStackGuard();
46  ~JSStackGuard();
47 
48 private:
49  nsCOMPtr<nsIJSContextStack> mJSStack;
50 };
51 
53 
54 nsresult
56 {
57  nsresult rv;
58  mPBService = do_GetService("@mozilla.org/privatebrowsing;1", &rv);
59  return rv;
60 }
61 
63  : mJSStack(nsnull)
64 {
65  nsresult rv;
66  mJSStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
67 
68  if (NS_SUCCEEDED(rv) && mJSStack) {
69  rv = mJSStack->Push(nsnull);
70  if (NS_FAILED(rv))
71  mJSStack = nsnull;
72  }
73 }
74 
76 {
77  if (mJSStack) {
78  JSContext *cx;
79  mJSStack->Pop(&cx);
80  NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
81  }
82 }
83 
84 NS_IMETHODIMP
85 nsPrivateBrowsingServiceWrapper::GetPrivateBrowsingEnabled(PRBool *aPrivateBrowsingEnabled)
86 {
87  if (!aPrivateBrowsingEnabled)
88  return NS_ERROR_NULL_POINTER;
89  JSStackGuard guard;
90  return mPBService->GetPrivateBrowsingEnabled(aPrivateBrowsingEnabled);
91 }
92 
93 NS_IMETHODIMP
94 nsPrivateBrowsingServiceWrapper::SetPrivateBrowsingEnabled(PRBool aPrivateBrowsingEnabled)
95 {
96  JSStackGuard guard;
97  return mPBService->SetPrivateBrowsingEnabled(aPrivateBrowsingEnabled);
98 }
99 
100 NS_IMETHODIMP
101 nsPrivateBrowsingServiceWrapper::GetAutoStarted(PRBool *aAutoStarted)
102 {
103  if (!aAutoStarted)
104  return NS_ERROR_NULL_POINTER;
105  JSStackGuard guard;
106  return mPBService->GetAutoStarted(aAutoStarted);
107 }
108 
109 NS_IMETHODIMP
110 nsPrivateBrowsingServiceWrapper::RemoveDataFromDomain(const nsACString & aDomain)
111 {
112  JSStackGuard guard;
113  return mPBService->RemoveDataFromDomain(aDomain);
114 }
115 
116 NS_IMETHODIMP
117 nsPrivateBrowsingServiceWrapper::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
118 {
119  JSStackGuard guard;
120  nsCOMPtr<nsIObserver> observer(do_QueryInterface(mPBService));
121  NS_ENSURE_TRUE(observer, NS_ERROR_FAILURE);
122  return observer->Observe(aSubject, aTopic, aData);
123 }
NS_IMPL_ISUPPORTS2(sbAlbumArtService, sbIAlbumArtService, nsIObserver) NS_IMETHODIMP sbAlbumArtService
function Init()
let observer
_updateTextAndScrollDataForFrame aData