1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Pierre Phaneuf <pp@ludusdesign.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK *****
40 * This Original Code has been modified by IBM Corporation.
41 * Modifications made by IBM described herein are
42 * Copyright (c) International Business Machines
45 * Modifications to Mozilla code or documentation
46 * identified per MPL Section 3.3
48 * Date Modified by Description of modification
49 * 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
54 #include "nsIPrefBranch.h"
55 #include "nsIPrefBranchInternal.h"
56 #include "nsIFactory.h"
57 #include "nsIComponentManager.h"
58 #include "nsIObserver.h"
63 #ifndef MOZ_NO_XPCOM_OBSOLETE
64 #include "nsIFileSpec.h"
68 #include "nsILocalFile.h"
69 #include "nsIPrefBranch.h"
70 #include "nsIPrefLocalizedString.h"
71 #include "nsISecurityPref.h"
72 #include "nsIPrefService.h"
73 #include "nsISupportsPrimitives.h"
74 #include "nsWeakReference.h"
76 #include "nsIModule.h"
77 #include "nsIGenericFactory.h"
84 class nsPref
: public nsIPref
,
85 public nsIPrefService
,
87 public nsIPrefBranchInternal
,
88 public nsISecurityPref
,
89 public nsSupportsWeakReference
92 static nsPref
*GetInstance();
94 /* Use xpidl-generated macro to declare everything required by nsIPref */
97 NS_DECL_NSIPREFBRANCH2
98 NS_DECL_NSISECURITYPREF
100 NS_FORWARD_NSIPREFSERVICE(mPrefService
->)
102 NS_IMETHOD
CopyCharPref(const char *pref
, char ** return_buf
);
104 NS_IMETHODIMP
GetDefaultBoolPref(const char *pref
, PRBool
*_retval
)
105 { return mDefaultBranch
->GetBoolPref(pref
, _retval
); }
106 NS_IMETHODIMP
CopyDefaultCharPref(const char *pref
, char **_retval
)
107 { return mDefaultBranch
->GetCharPref(pref
, _retval
); }
108 NS_IMETHODIMP
GetDefaultIntPref(const char *pref
, PRInt32
*_retval
)
109 { return mDefaultBranch
->GetIntPref(pref
, _retval
); }
110 NS_IMETHODIMP
SetDefaultBoolPref(const char *pref
, PRBool value
)
111 { return mDefaultBranch
->SetBoolPref(pref
, value
); }
112 NS_IMETHODIMP
SetDefaultCharPref(const char *pref
, const char *value
)
113 { return mDefaultBranch
->SetCharPref(pref
, value
); }
114 NS_IMETHODIMP
SetDefaultIntPref(const char *pref
, PRInt32 value
)
115 { return mDefaultBranch
->SetIntPref(pref
, value
); }
117 NS_IMETHOD
CopyUnicharPref(const char *pref
, PRUnichar
**_retval
);
118 NS_IMETHOD
CopyDefaultUnicharPref(const char *pref
, PRUnichar
**_retval
);
119 NS_IMETHOD
SetUnicharPref(const char *pref
, const PRUnichar
*value
);
120 NS_IMETHOD
SetDefaultUnicharPref(const char *pref
, const PRUnichar
*value
);
121 NS_IMETHOD
GetLocalizedUnicharPref(const char *pref
, PRUnichar
**_retval
);
122 NS_IMETHOD
GetDefaultLocalizedUnicharPref(const char *pref
, PRUnichar
**_retval
);
124 NS_IMETHOD
GetFilePref(const char *pref
, nsIFileSpec
**_retval
);
125 NS_IMETHOD
SetFilePref(const char *pref
, nsIFileSpec
*value
, PRBool setDefault
);
126 NS_IMETHOD
GetFileXPref(const char *pref
, nsILocalFile
**_retval
);
127 NS_IMETHOD
SetFileXPref(const char *pref
, nsILocalFile
*value
);
129 NS_IMETHOD
RegisterCallback(const char *domain
, PrefChangedFunc callback
, void * closure
);
130 NS_IMETHOD
UnregisterCallback(const char *domain
, PrefChangedFunc callback
, void * closure
);
131 NS_IMETHOD
EnumerateChildren(const char *parent
, PrefEnumerationFunc callback
, void * data
);
137 static nsPref
*gInstance
;
140 nsCOMPtr
<nsIPrefService
> mPrefService
;
141 nsCOMPtr
<nsIPrefBranch
> mDefaultBranch
;
144 nsPref
* nsPref::gInstance
= NULL
;
145 static PRInt32 g_InstanceCount
= 0;
148 NS_IMPL_THREADSAFE_ISUPPORTS8(nsPref
,
154 nsIPrefBranchInternal
,
156 nsISupportsWeakReference
)
158 //----------------------------------------------------------------------------------------
160 //----------------------------------------------------------------------------------------
162 PR_AtomicIncrement(&g_InstanceCount
);
164 mPrefService
= do_GetService(NS_PREFSERVICE_CONTRACTID
);
165 NS_ASSERTION(mPrefService
, "Preference Service failed to start up!!");
168 mPrefService
->GetDefaultBranch("", getter_AddRefs(mDefaultBranch
));
171 //----------------------------------------------------------------------------------------
173 //----------------------------------------------------------------------------------------
175 PR_AtomicDecrement(&g_InstanceCount
);
180 * Implementations to pass branch calls through the PrefService.
183 NS_IMETHODIMP
nsPref::GetRoot(char * *aRoot
)
187 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
188 if (NS_SUCCEEDED(rv
))
189 rv
= prefBranch
->GetRoot(aRoot
);
193 NS_IMETHODIMP
nsPref::GetPrefType(const char *aPrefName
, PRInt32
*_retval
)
197 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
198 if (NS_SUCCEEDED(rv
))
199 rv
= prefBranch
->GetPrefType(aPrefName
, _retval
);
203 NS_IMETHODIMP
nsPref::CopyCharPref(const char *pref
, char ** return_buf
)
207 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
208 if (NS_SUCCEEDED(rv
))
209 rv
= prefBranch
->GetCharPref(pref
, return_buf
);
213 NS_IMETHODIMP
nsPref::GetBoolPref(const char *aPrefName
, PRBool
*_retval
)
217 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
218 if (NS_SUCCEEDED(rv
))
219 rv
= prefBranch
->GetBoolPref(aPrefName
, _retval
);
223 NS_IMETHODIMP
nsPref::SetBoolPref(const char *aPrefName
, PRInt32 aValue
)
227 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
228 if (NS_SUCCEEDED(rv
))
229 rv
= prefBranch
->SetBoolPref(aPrefName
, aValue
);
233 NS_IMETHODIMP
nsPref::GetCharPref(const char *aPrefName
, char **_retval
)
237 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
238 if (NS_SUCCEEDED(rv
))
239 rv
= prefBranch
->GetCharPref(aPrefName
, _retval
);
243 NS_IMETHODIMP
nsPref::SetCharPref(const char *aPrefName
, const char *aValue
)
247 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
248 if (NS_SUCCEEDED(rv
))
249 rv
= prefBranch
->SetCharPref(aPrefName
, aValue
);
253 NS_IMETHODIMP
nsPref::GetIntPref(const char *aPrefName
, PRInt32
*_retval
)
257 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
258 if (NS_SUCCEEDED(rv
))
259 rv
= prefBranch
->GetIntPref(aPrefName
, _retval
);
263 NS_IMETHODIMP
nsPref::SetIntPref(const char *aPrefName
, PRInt32 aValue
)
267 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
268 if (NS_SUCCEEDED(rv
))
269 rv
= prefBranch
->SetIntPref(aPrefName
, aValue
);
273 NS_IMETHODIMP
nsPref::GetComplexValue(const char *aPrefName
, const nsIID
& aType
, void * *aValue
)
277 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
278 if (NS_SUCCEEDED(rv
))
279 rv
= prefBranch
->GetComplexValue(aPrefName
, aType
, aValue
);
283 NS_IMETHODIMP
nsPref::SetComplexValue(const char *aPrefName
, const nsIID
& aType
, nsISupports
*aValue
)
287 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
288 if (NS_SUCCEEDED(rv
))
289 rv
= prefBranch
->SetComplexValue(aPrefName
, aType
, aValue
);
293 NS_IMETHODIMP
nsPref::ClearUserPref(const char *aPrefName
)
297 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
298 if (NS_SUCCEEDED(rv
))
299 rv
= prefBranch
->ClearUserPref(aPrefName
);
303 NS_IMETHODIMP
nsPref::LockPref(const char *aPrefName
)
307 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
308 if (NS_SUCCEEDED(rv
))
309 rv
= prefBranch
->LockPref(aPrefName
);
313 NS_IMETHODIMP
nsPref::PrefIsLocked(const char *aPrefName
, PRBool
*_retval
)
317 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
318 if (NS_SUCCEEDED(rv
))
319 rv
= prefBranch
->PrefIsLocked(aPrefName
, _retval
);
323 NS_IMETHODIMP
nsPref::PrefHasUserValue(const char *aPrefName
, PRBool
*_retval
)
327 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
328 if (NS_SUCCEEDED(rv
))
329 rv
= prefBranch
->PrefHasUserValue(aPrefName
, _retval
);
333 NS_IMETHODIMP
nsPref::UnlockPref(const char *aPrefName
)
337 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
338 if (NS_SUCCEEDED(rv
))
339 rv
= prefBranch
->UnlockPref(aPrefName
);
343 NS_IMETHODIMP
nsPref::ResetBranch(const char *aStartingAt
)
347 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
348 if (NS_SUCCEEDED(rv
))
349 rv
= prefBranch
->ResetBranch(aStartingAt
);
353 NS_IMETHODIMP
nsPref::DeleteBranch(const char *aStartingAt
)
357 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
358 if (NS_SUCCEEDED(rv
))
359 rv
= prefBranch
->DeleteBranch(aStartingAt
);
363 NS_IMETHODIMP
nsPref::GetChildList(const char *aStartingAt
, PRUint32
*aCount
, char ***aChildArray
)
367 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
368 if (NS_SUCCEEDED(rv
))
369 rv
= prefBranch
->GetChildList(aStartingAt
, aCount
, aChildArray
);
373 NS_IMETHODIMP
nsPref::AddObserver(const char *aDomain
, nsIObserver
*aObserver
, PRBool aHoldWeak
)
377 nsCOMPtr
<nsIPrefBranch2
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
378 if (NS_SUCCEEDED(rv
))
379 rv
= prefBranch
->AddObserver(aDomain
, aObserver
, aHoldWeak
);
383 NS_IMETHODIMP
nsPref::RemoveObserver(const char *aDomain
, nsIObserver
*aObserver
)
387 nsCOMPtr
<nsIPrefBranch2
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
388 if (NS_SUCCEEDED(rv
))
389 rv
= prefBranch
->RemoveObserver(aDomain
, aObserver
);
393 NS_IMETHODIMP
nsPref::Observe(nsISupports
*aSubject
, const char *aTopic
, const PRUnichar
*someData
)
397 nsCOMPtr
<nsIObserver
> observer
= do_QueryInterface(mPrefService
, &rv
);
398 if (NS_SUCCEEDED(rv
))
399 rv
= observer
->Observe(aSubject
, aTopic
, someData
);
405 * Some temporary support for deprecated functions.
409 * Items replaced by Get/SetComplexValue
412 NS_IMETHODIMP
nsPref::CopyUnicharPref(const char *pref
, PRUnichar
**_retval
)
416 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
417 if (NS_SUCCEEDED(rv
)) {
418 nsCOMPtr
<nsISupportsString
> theString
;
419 rv
= prefBranch
->GetComplexValue(pref
, NS_GET_IID(nsISupportsString
),
420 getter_AddRefs(theString
));
424 return theString
->ToString(_retval
);
429 NS_IMETHODIMP
nsPref::CopyDefaultUnicharPref(const char *pref
, PRUnichar
**_retval
)
432 nsCOMPtr
<nsISupportsString
> theString
;
434 rv
= mDefaultBranch
->GetComplexValue(pref
, NS_GET_IID(nsISupportsString
),
435 getter_AddRefs(theString
));
439 return theString
->ToString(_retval
);
442 NS_IMETHODIMP
nsPref::SetUnicharPref(const char *pref
, const PRUnichar
*value
)
446 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
447 if (NS_SUCCEEDED(rv
)) {
448 nsCOMPtr
<nsISupportsString
> theString
= do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID
, &rv
);
449 if (NS_SUCCEEDED(rv
)) {
450 theString
->SetData(nsDependentString(value
));
451 rv
= prefBranch
->SetComplexValue(pref
, NS_GET_IID(nsISupportsString
), theString
);
457 NS_IMETHODIMP
nsPref::SetDefaultUnicharPref(const char *pref
, const PRUnichar
*value
)
461 nsCOMPtr
<nsISupportsString
> theString
= do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID
, &rv
);
462 if (NS_SUCCEEDED(rv
)) {
463 theString
->SetData(nsDependentString(value
));
464 rv
= mDefaultBranch
->SetComplexValue(pref
, NS_GET_IID(nsISupportsString
), theString
);
469 NS_IMETHODIMP
nsPref::GetLocalizedUnicharPref(const char *pref
, PRUnichar
**_retval
)
473 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
474 if (NS_SUCCEEDED(rv
)) {
475 nsCOMPtr
<nsIPrefLocalizedString
> theString
;
476 rv
= prefBranch
->GetComplexValue(pref
, NS_GET_IID(nsIPrefLocalizedString
),
477 getter_AddRefs(theString
));
478 if (NS_SUCCEEDED(rv
)) {
479 rv
= theString
->ToString(_retval
);
485 NS_IMETHODIMP
nsPref::GetDefaultLocalizedUnicharPref(const char *pref
, PRUnichar
**_retval
)
488 nsCOMPtr
<nsIPrefLocalizedString
> theString
;
490 rv
= mDefaultBranch
->GetComplexValue(pref
, NS_GET_IID(nsIPrefLocalizedString
),
491 getter_AddRefs(theString
));
492 if (NS_SUCCEEDED(rv
)) {
493 rv
= theString
->ToString(_retval
);
499 NS_IMETHODIMP
nsPref::GetFilePref(const char *pref
, nsIFileSpec
**_retval
)
501 #ifdef MOZ_NO_XPCOM_OBSOLETE
502 return NS_ERROR_NOT_IMPLEMENTED
;
506 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
507 if (NS_SUCCEEDED(rv
))
508 rv
= prefBranch
->GetComplexValue(pref
, NS_GET_IID(nsIFileSpec
), (void **)_retval
);
513 NS_IMETHODIMP
nsPref::SetFilePref(const char *pref
, nsIFileSpec
*value
, PRBool setDefault
)
515 #ifdef MOZ_NO_XPCOM_OBSOLETE
516 return NS_ERROR_NOT_IMPLEMENTED
;
521 rv
= mDefaultBranch
->SetComplexValue(pref
, NS_GET_IID(nsIFileSpec
), value
);
523 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
524 if (NS_SUCCEEDED(rv
))
525 rv
= prefBranch
->SetComplexValue(pref
, NS_GET_IID(nsIFileSpec
), value
);
531 NS_IMETHODIMP
nsPref::GetFileXPref(const char *pref
, nsILocalFile
**_retval
)
535 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
536 if (NS_SUCCEEDED(rv
))
537 rv
= prefBranch
->GetComplexValue(pref
, NS_GET_IID(nsILocalFile
), (void **)_retval
);
541 NS_IMETHODIMP
nsPref::SetFileXPref(const char *pref
, nsILocalFile
*value
)
545 NS_ENSURE_ARG_POINTER(value
);
546 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
547 if (NS_SUCCEEDED(rv
))
548 rv
= prefBranch
->SetComplexValue(pref
, NS_GET_IID(nsILocalFile
), value
);
557 //----------------------------------------------------------------------------------------
558 NS_IMETHODIMP
nsPref::RegisterCallback( const char* domain
,
559 PrefChangedFunc callback
,
560 void* instance_data
)
561 //----------------------------------------------------------------------------------------
563 PREF_RegisterCallback(domain
, callback
, instance_data
);
567 //----------------------------------------------------------------------------------------
568 NS_IMETHODIMP
nsPref::UnregisterCallback( const char* domain
,
569 PrefChangedFunc callback
,
570 void* instance_data
)
571 //----------------------------------------------------------------------------------------
573 return PREF_UnregisterCallback(domain
, callback
, instance_data
);
577 * Preference enumeration
580 NS_IMETHODIMP
nsPref::EnumerateChildren(const char *parent
, PrefEnumerationFunc callback
, void *arg
)
588 rv
= GetChildList(parent
, &theCount
, &childArray
);
589 if (NS_SUCCEEDED(rv
)) {
590 // now that we've built up the list, run the callback on all the matching elements
591 for (i
= 0; i
< theCount
; i
++) {
592 prefName
= (char *)childArray
[i
];
593 (*callback
)((char*)prefName
, arg
);
596 // now release all the memory
597 NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(theCount
, childArray
);
604 * Pref access without security check - these are here
605 * to support nsScriptSecurityManager.
606 * These functions are part of nsISecurityPref, not nsIPref.
607 * **PLEASE** do not call these functions from elsewhere
609 NS_IMETHODIMP
nsPref::SecurityGetBoolPref(const char *pref
, PRBool
* return_val
)
613 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
617 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
618 if (NS_SUCCEEDED(rv
))
619 rv
= securityPref
->SecurityGetBoolPref(pref
, return_val
);
623 NS_IMETHODIMP
nsPref::SecuritySetBoolPref(const char *pref
, PRBool value
)
627 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
631 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
632 if (NS_SUCCEEDED(rv
))
633 rv
= securityPref
->SecuritySetBoolPref(pref
, value
);
637 NS_IMETHODIMP
nsPref::SecurityGetCharPref(const char *pref
, char ** return_buf
)
641 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
645 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
646 if (NS_SUCCEEDED(rv
))
647 rv
= securityPref
->SecurityGetCharPref(pref
, return_buf
);
651 NS_IMETHODIMP
nsPref::SecuritySetCharPref(const char *pref
, const char* value
)
655 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
659 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
660 if (NS_SUCCEEDED(rv
))
661 rv
= securityPref
->SecuritySetCharPref(pref
, value
);
665 NS_IMETHODIMP
nsPref::SecurityGetIntPref(const char *pref
, PRInt32
* return_val
)
669 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
673 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
674 if (NS_SUCCEEDED(rv
))
675 rv
= securityPref
->SecurityGetIntPref(pref
, return_val
);
679 NS_IMETHODIMP
nsPref::SecuritySetIntPref(const char *pref
, PRInt32 value
)
683 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
687 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
688 if (NS_SUCCEEDED(rv
))
689 rv
= securityPref
->SecuritySetIntPref(pref
, value
);
693 NS_IMETHODIMP
nsPref::SecurityClearUserPref(const char *pref_name
)
697 nsCOMPtr
<nsIPrefBranch
> prefBranch
= do_QueryInterface(mPrefService
, &rv
);
701 nsCOMPtr
<nsISecurityPref
> securityPref
= do_QueryInterface(prefBranch
, &rv
);
702 if (NS_SUCCEEDED(rv
))
703 rv
= securityPref
->SecurityClearUserPref(pref_name
);
708 //----------------------------------------------------------------------------------------
709 nsPref
* nsPref::GetInstance()
710 //----------------------------------------------------------------------------------------
714 NS_NEWXPCOM(gInstance
, nsPref
);
717 } // nsPref::GetInstance
720 //----------------------------------------------------------------------------------------
721 // Functions used to create new instances of a given object by the
725 ////////////////////////////////////////////////////////////////////////
726 // Hand implement the GenericFactory constructor macro so I can make it
727 // non static. This is simply to keep us from having to make an nsPref.h
728 // file because we are trying to remove this object, not add to it.
731 NS_IMETHODIMP
nsPrefConstructor(nsISupports
*aOuter
, REFNSIID aIID
, void **aResult
)
735 if (NULL
== aResult
) {
736 rv
= NS_ERROR_NULL_POINTER
;
740 if (NULL
!= aOuter
) {
741 rv
= NS_ERROR_NO_AGGREGATION
;
745 nsPref
*inst
= nsPref::GetInstance();
748 rv
= NS_ERROR_OUT_OF_MEMORY
;
752 rv
= inst
->QueryInterface(aIID
, aResult
);