2001-09-29 00:14:13 +04:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/. */
2001-03-23 02:34:41 +03:00
2010-07-19 22:33:33 +04:00
# include "mozilla/dom/ContentChild.h"
2010-05-26 04:13:47 +04:00
# include "nsXULAppAPI.h"
2001-03-23 02:34:41 +03:00
# include "nsPrefBranch.h"
2012-06-06 06:08:30 +04:00
# include "nsILocalFile.h" // nsILocalFile used for backwards compatibility
2001-03-23 02:34:41 +03:00
# include "nsIObserverService.h"
2002-09-04 03:36:13 +04:00
# include "nsXPCOM.h"
2001-03-23 02:34:41 +03:00
# include "nsISupportsPrimitives.h"
2002-04-09 18:18:39 +04:00
# include "nsIDirectoryService.h"
2001-03-23 02:34:41 +03:00
# include "nsString.h"
2001-09-29 12:28:41 +04:00
# include "nsReadableUtils.h"
2001-03-23 02:34:41 +03:00
# include "nsXPIDLString.h"
2013-03-08 21:27:58 +04:00
# include "nsPrintfCString.h"
2001-04-20 10:45:56 +04:00
# include "nsIStringBundle.h"
2001-09-06 23:30:47 +04:00
# include "prefapi.h"
2001-12-04 04:52:44 +03:00
# include "pldhash.h"
2001-03-23 02:34:41 +03:00
2005-08-05 21:09:41 +04:00
# include "nsCRT.h"
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
# include "mozilla/Services.h"
2005-08-05 21:09:41 +04:00
2001-03-23 02:34:41 +03:00
# include "prefapi_private_data.h"
2013-03-08 21:27:58 +04:00
# ifdef MOZ_CRASHREPORTER
# include "nsICrashReporter.h"
# endif
2013-06-04 16:21:06 +04:00
# include "nsIConsoleService.h"
2013-12-04 03:18:09 +04:00
# ifdef DEBUG
# define ENSURE_MAIN_PROCESS(message, pref) do { \
if ( GetContentChild ( ) ) { \
nsPrintfCString msg ( " ENSURE_MAIN_PROCESS failed. %s %s " , message , pref ) ; \
NS_ERROR ( msg . get ( ) ) ; \
return NS_ERROR_NOT_AVAILABLE ; \
} \
} while ( 0 ) ;
# else
# define ENSURE_MAIN_PROCESS(message, pref) \
if ( GetContentChild ( ) ) { \
return NS_ERROR_NOT_AVAILABLE ; \
}
# endif
2001-03-23 02:34:41 +03:00
// Definitions
struct EnumerateData {
2001-04-12 03:07:03 +04:00
const char * parent ;
2010-05-28 22:09:15 +04:00
nsTArray < nsCString > * pref_list ;
2001-04-12 03:07:03 +04:00
} ;
2001-03-23 02:34:41 +03:00
// Prototypes
2008-10-10 19:04:34 +04:00
static PLDHashOperator
2001-12-04 04:52:44 +03:00
pref_enumChild ( PLDHashTable * table , PLDHashEntryHdr * heh ,
2012-08-22 19:56:38 +04:00
uint32_t i , void * arg ) ;
2001-03-23 02:34:41 +03:00
2010-07-19 22:33:33 +04:00
using mozilla : : dom : : ContentChild ;
2010-07-03 07:03:18 +04:00
2010-07-19 22:33:33 +04:00
static ContentChild *
GetContentChild ( )
2010-07-03 07:03:18 +04:00
{
if ( XRE_GetProcessType ( ) = = GeckoProcessType_Content ) {
2010-07-19 22:33:33 +04:00
ContentChild * cpc = ContentChild : : GetSingleton ( ) ;
2010-07-03 07:03:18 +04:00
if ( ! cpc ) {
NS_RUNTIMEABORT ( " Content Protocol is NULL! We're going to crash! " ) ;
}
return cpc ;
}
2012-07-30 18:20:58 +04:00
return nullptr ;
2010-07-03 07:03:18 +04:00
}
2001-03-29 04:48:30 +04:00
/*
* Constructor / Destructor
*/
2001-03-23 02:34:41 +03:00
2011-09-29 10:19:26 +04:00
nsPrefBranch : : nsPrefBranch ( const char * aPrefRoot , bool aDefaultBranch )
2001-03-23 02:34:41 +03:00
{
mPrefRoot = aPrefRoot ;
mPrefRootLength = mPrefRoot . Length ( ) ;
mIsDefault = aDefaultBranch ;
2011-10-17 18:59:28 +04:00
mFreeingObserverList = false ;
2001-10-23 00:54:48 +04:00
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
nsCOMPtr < nsIObserverService > observerService =
mozilla : : services : : GetObserverService ( ) ;
2001-10-23 00:54:48 +04:00
if ( observerService ) {
+ + mRefCnt ; // Our refcnt must be > 0 when we call this, or we'll get deleted!
2001-10-31 01:57:44 +03:00
// add weak so we don't have to clean up at shutdown
2011-10-17 18:59:28 +04:00
observerService - > AddObserver ( this , NS_XPCOM_SHUTDOWN_OBSERVER_ID , true ) ;
2001-10-23 00:54:48 +04:00
- - mRefCnt ;
}
2001-03-23 02:34:41 +03:00
}
nsPrefBranch : : ~ nsPrefBranch ( )
{
2001-10-23 00:54:48 +04:00
freeObserverList ( ) ;
2010-11-04 23:06:05 +03:00
nsCOMPtr < nsIObserverService > observerService =
mozilla : : services : : GetObserverService ( ) ;
if ( observerService )
observerService - > RemoveObserver ( this , NS_XPCOM_SHUTDOWN_OBSERVER_ID ) ;
2001-03-23 02:34:41 +03:00
}
2001-03-29 04:48:30 +04:00
/*
* nsISupports Implementation
*/
2013-07-19 06:23:44 +04:00
NS_IMPL_ADDREF ( nsPrefBranch )
NS_IMPL_RELEASE ( nsPrefBranch )
2001-03-29 04:48:30 +04:00
NS_INTERFACE_MAP_BEGIN ( nsPrefBranch )
2001-04-12 03:07:03 +04:00
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS ( nsISupports , nsIPrefBranch )
NS_INTERFACE_MAP_ENTRY ( nsIPrefBranch )
2005-05-12 17:23:30 +04:00
NS_INTERFACE_MAP_ENTRY_CONDITIONAL ( nsIPrefBranch2 , ! mIsDefault )
NS_INTERFACE_MAP_ENTRY_CONDITIONAL ( nsIPrefBranchInternal , ! mIsDefault )
2001-10-23 00:54:48 +04:00
NS_INTERFACE_MAP_ENTRY ( nsIObserver )
2001-06-19 05:40:19 +04:00
NS_INTERFACE_MAP_ENTRY ( nsISupportsWeakReference )
2001-03-29 04:48:30 +04:00
NS_INTERFACE_MAP_END
/*
* nsIPrefBranch Implementation
*/
2010-05-26 04:13:47 +04:00
NS_IMETHODIMP nsPrefBranch : : GetRoot ( char * * aRoot )
2001-03-23 02:34:41 +03:00
{
NS_ENSURE_ARG_POINTER ( aRoot ) ;
mPrefRoot . Truncate ( mPrefRootLength ) ;
2001-09-29 12:28:41 +04:00
* aRoot = ToNewCString ( mPrefRoot ) ;
2001-03-23 02:34:41 +03:00
return NS_OK ;
}
2012-08-22 19:56:38 +04:00
NS_IMETHODIMP nsPrefBranch : : GetPrefType ( const char * aPrefName , int32_t * _retval )
2001-03-23 02:34:41 +03:00
{
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
2001-09-06 23:30:47 +04:00
* _retval = PREF_GetPrefType ( pref ) ;
2001-03-23 02:34:41 +03:00
return NS_OK ;
}
2011-09-29 10:19:26 +04:00
NS_IMETHODIMP nsPrefBranch : : GetBoolPref ( const char * aPrefName , bool * _retval )
2001-03-23 02:34:41 +03:00
{
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_GetBoolPref ( pref , _retval , mIsDefault ) ;
2001-03-23 02:34:41 +03:00
}
2011-09-29 10:19:26 +04:00
NS_IMETHODIMP nsPrefBranch : : SetBoolPref ( const char * aPrefName , bool aValue )
2001-03-23 02:34:41 +03:00
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot SetBoolPref from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_SetBoolPref ( pref , aValue , mIsDefault ) ;
2001-03-23 02:34:41 +03:00
}
2012-09-27 00:53:37 +04:00
NS_IMETHODIMP nsPrefBranch : : GetFloatPref ( const char * aPrefName , float * _retval )
{
NS_ENSURE_ARG ( aPrefName ) ;
const char * pref = getPrefName ( aPrefName ) ;
nsAutoCString stringVal ;
nsresult rv = GetCharPref ( pref , getter_Copies ( stringVal ) ) ;
if ( NS_SUCCEEDED ( rv ) ) {
* _retval = stringVal . ToFloat ( & rv ) ;
}
return rv ;
}
2001-03-23 02:34:41 +03:00
NS_IMETHODIMP nsPrefBranch : : GetCharPref ( const char * aPrefName , char * * _retval )
{
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_CopyCharPref ( pref , _retval , mIsDefault ) ;
2001-03-23 02:34:41 +03:00
}
NS_IMETHODIMP nsPrefBranch : : SetCharPref ( const char * aPrefName , const char * aValue )
2013-06-04 16:21:06 +04:00
{
nsresult rv = CheckSanityOfStringLength ( aPrefName , aValue ) ;
if ( NS_FAILED ( rv ) ) {
return rv ;
}
return SetCharPrefInternal ( aPrefName , aValue ) ;
}
nsresult nsPrefBranch : : SetCharPrefInternal ( const char * aPrefName , const char * aValue )
2001-03-23 02:34:41 +03:00
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot SetCharPref from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
NS_ENSURE_ARG ( aValue ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_SetCharPref ( pref , aValue , mIsDefault ) ;
2001-03-23 02:34:41 +03:00
}
2012-08-22 19:56:38 +04:00
NS_IMETHODIMP nsPrefBranch : : GetIntPref ( const char * aPrefName , int32_t * _retval )
2001-03-23 02:34:41 +03:00
{
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_GetIntPref ( pref , _retval , mIsDefault ) ;
2001-03-23 02:34:41 +03:00
}
2012-08-22 19:56:38 +04:00
NS_IMETHODIMP nsPrefBranch : : SetIntPref ( const char * aPrefName , int32_t aValue )
2001-03-23 02:34:41 +03:00
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot SetIntPref from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_SetIntPref ( pref , aValue , mIsDefault ) ;
2001-03-23 02:34:41 +03:00
}
2010-05-26 04:13:47 +04:00
NS_IMETHODIMP nsPrefBranch : : GetComplexValue ( const char * aPrefName , const nsIID & aType , void * * _retval )
2001-03-23 02:34:41 +03:00
{
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2001-03-23 02:34:41 +03:00
nsresult rv ;
nsXPIDLCString utf8String ;
2001-04-25 00:32:16 +04:00
// we have to do this one first because it's different than all the rest
if ( aType . Equals ( NS_GET_IID ( nsIPrefLocalizedString ) ) ) {
nsCOMPtr < nsIPrefLocalizedString > theString ( do_CreateInstance ( NS_PREFLOCALIZEDSTRING_CONTRACTID , & rv ) ) ;
2010-05-26 23:29:15 +04:00
if ( NS_FAILED ( rv ) ) return rv ;
2001-04-25 00:32:16 +04:00
2010-06-23 04:33:57 +04:00
const char * pref = getPrefName ( aPrefName ) ;
2011-09-29 10:19:26 +04:00
bool bNeedDefault = false ;
2001-04-25 00:32:16 +04:00
2010-05-26 23:29:15 +04:00
if ( mIsDefault ) {
2011-10-17 18:59:28 +04:00
bNeedDefault = true ;
2010-05-26 23:29:15 +04:00
} else {
// if there is no user (or locked) value
if ( ! PREF_HasUserPref ( pref ) & & ! PREF_PrefIsLocked ( pref ) ) {
2011-10-17 18:59:28 +04:00
bNeedDefault = true ;
2001-04-25 00:32:16 +04:00
}
2010-05-26 23:29:15 +04:00
}
2001-04-25 00:32:16 +04:00
2010-05-26 23:29:15 +04:00
// if we need to fetch the default value, do that instead, otherwise use the
// value we pulled in at the top of this function
if ( bNeedDefault ) {
nsXPIDLString utf16String ;
rv = GetDefaultFromPropertiesFile ( pref , getter_Copies ( utf16String ) ) ;
if ( NS_SUCCEEDED ( rv ) ) {
theString - > SetData ( utf16String . get ( ) ) ;
2001-04-25 00:32:16 +04:00
}
2010-05-26 23:29:15 +04:00
} else {
rv = GetCharPref ( aPrefName , getter_Copies ( utf8String ) ) ;
2001-04-25 00:32:16 +04:00
if ( NS_SUCCEEDED ( rv ) ) {
2010-05-26 23:29:15 +04:00
theString - > SetData ( NS_ConvertUTF8toUTF16 ( utf8String ) . get ( ) ) ;
2001-04-25 00:32:16 +04:00
}
}
2010-05-26 23:29:15 +04:00
if ( NS_SUCCEEDED ( rv ) ) {
2011-02-23 20:16:50 +03:00
theString . forget ( reinterpret_cast < nsIPrefLocalizedString * * > ( _retval ) ) ;
2010-05-26 23:29:15 +04:00
}
2001-04-25 00:32:16 +04:00
return rv ;
2001-03-29 04:48:30 +04:00
}
2001-04-25 00:32:16 +04:00
// if we can't get the pref, there's no point in being here
rv = GetCharPref ( aPrefName , getter_Copies ( utf8String ) ) ;
2001-03-23 02:34:41 +03:00
if ( NS_FAILED ( rv ) ) {
return rv ;
}
2012-06-06 06:08:30 +04:00
// also check nsILocalFile, for backwards compatibility
if ( aType . Equals ( NS_GET_IID ( nsIFile ) ) | | aType . Equals ( NS_GET_IID ( nsILocalFile ) ) ) {
2010-07-19 22:33:33 +04:00
if ( GetContentChild ( ) ) {
2012-06-06 06:08:30 +04:00
NS_ERROR ( " cannot get nsIFile pref from content process " ) ;
2010-05-26 23:29:15 +04:00
return NS_ERROR_NOT_AVAILABLE ;
}
2012-06-06 06:08:30 +04:00
nsCOMPtr < nsIFile > file ( do_CreateInstance ( NS_LOCAL_FILE_CONTRACTID , & rv ) ) ;
2001-03-23 02:34:41 +03:00
if ( NS_SUCCEEDED ( rv ) ) {
rv = file - > SetPersistentDescriptor ( utf8String ) ;
if ( NS_SUCCEEDED ( rv ) ) {
2012-06-06 06:08:30 +04:00
file . forget ( reinterpret_cast < nsIFile * * > ( _retval ) ) ;
2001-03-23 02:34:41 +03:00
return NS_OK ;
}
}
return rv ;
}
2002-04-09 18:18:39 +04:00
if ( aType . Equals ( NS_GET_IID ( nsIRelativeFilePref ) ) ) {
2010-07-19 22:33:33 +04:00
if ( GetContentChild ( ) ) {
2010-05-26 23:29:15 +04:00
NS_ERROR ( " cannot get nsIRelativeFilePref from content process " ) ;
return NS_ERROR_NOT_AVAILABLE ;
}
2002-04-09 18:18:39 +04:00
nsACString : : const_iterator keyBegin , strEnd ;
utf8String . BeginReading ( keyBegin ) ;
utf8String . EndReading ( strEnd ) ;
// The pref has the format: [fromKey]a/b/c
if ( * keyBegin + + ! = ' [ ' )
2010-05-26 04:13:47 +04:00
return NS_ERROR_FAILURE ;
2002-04-09 18:18:39 +04:00
nsACString : : const_iterator keyEnd ( keyBegin ) ;
if ( ! FindCharInReadable ( ' ] ' , keyEnd , strEnd ) )
2010-05-26 04:13:47 +04:00
return NS_ERROR_FAILURE ;
2012-09-02 06:35:17 +04:00
nsAutoCString key ( Substring ( keyBegin , keyEnd ) ) ;
2002-04-09 18:18:39 +04:00
2012-06-06 06:08:30 +04:00
nsCOMPtr < nsIFile > fromFile ;
2002-04-09 18:18:39 +04:00
nsCOMPtr < nsIProperties > directoryService ( do_GetService ( NS_DIRECTORY_SERVICE_CONTRACTID , & rv ) ) ;
if ( NS_FAILED ( rv ) )
return rv ;
2012-06-06 06:08:30 +04:00
rv = directoryService - > Get ( key . get ( ) , NS_GET_IID ( nsIFile ) , getter_AddRefs ( fromFile ) ) ;
2002-04-09 18:18:39 +04:00
if ( NS_FAILED ( rv ) )
return rv ;
2012-06-06 06:08:30 +04:00
nsCOMPtr < nsIFile > theFile ;
2011-10-17 18:59:28 +04:00
rv = NS_NewNativeLocalFile ( EmptyCString ( ) , true , getter_AddRefs ( theFile ) ) ;
2002-04-09 18:18:39 +04:00
if ( NS_FAILED ( rv ) )
return rv ;
rv = theFile - > SetRelativeDescriptor ( fromFile , Substring ( + + keyEnd , strEnd ) ) ;
if ( NS_FAILED ( rv ) )
return rv ;
nsCOMPtr < nsIRelativeFilePref > relativePref ;
rv = NS_NewRelativeFilePref ( theFile , key , getter_AddRefs ( relativePref ) ) ;
if ( NS_FAILED ( rv ) )
return rv ;
2010-05-26 23:29:15 +04:00
relativePref . forget ( reinterpret_cast < nsIRelativeFilePref * * > ( _retval ) ) ;
2002-04-09 18:18:39 +04:00
return NS_OK ;
}
2002-08-06 04:53:19 +04:00
if ( aType . Equals ( NS_GET_IID ( nsISupportsString ) ) ) {
nsCOMPtr < nsISupportsString > theString ( do_CreateInstance ( NS_SUPPORTS_STRING_CONTRACTID , & rv ) ) ;
2001-03-23 02:34:41 +03:00
if ( NS_SUCCEEDED ( rv ) ) {
2013-03-08 21:27:58 +04:00
// Debugging to see why we end up with very long strings here with
// some addons, see bug 836263.
nsAutoString wdata ;
if ( ! AppendUTF8toUTF16 ( utf8String , wdata , mozilla : : fallible_t ( ) ) ) {
# ifdef MOZ_CRASHREPORTER
nsCOMPtr < nsICrashReporter > cr =
do_GetService ( " @mozilla.org/toolkit/crash-reporter;1 " ) ;
if ( cr ) {
cr - > AnnotateCrashReport ( NS_LITERAL_CSTRING ( " bug836263-size " ) ,
nsPrintfCString ( " %x " , utf8String . Length ( ) ) ) ;
cr - > RegisterAppMemory ( uint64_t ( utf8String . BeginReading ( ) ) ,
std : : min ( 0x1000U , utf8String . Length ( ) ) ) ;
}
# endif
NS_RUNTIMEABORT ( " bug836263 " ) ;
}
theString - > SetData ( wdata ) ;
2010-05-26 23:29:15 +04:00
theString . forget ( reinterpret_cast < nsISupportsString * * > ( _retval ) ) ;
2001-03-23 02:34:41 +03:00
}
return rv ;
}
NS_WARNING ( " nsPrefBranch::GetComplexValue - Unsupported interface type " ) ;
return NS_NOINTERFACE ;
}
2013-06-04 16:21:06 +04:00
nsresult nsPrefBranch : : CheckSanityOfStringLength ( const char * aPrefName , const char * aValue ) {
if ( ! aValue ) {
return NS_OK ;
}
return CheckSanityOfStringLength ( aPrefName , strlen ( aValue ) ) ;
}
nsresult nsPrefBranch : : CheckSanityOfStringLength ( const char * aPrefName , const nsAString & aValue ) {
return CheckSanityOfStringLength ( aPrefName , aValue . Length ( ) ) ;
}
nsresult nsPrefBranch : : CheckSanityOfStringLength ( const char * aPrefName , const uint32_t aLength ) {
if ( aLength > MAX_PREF_LENGTH ) {
2014-01-22 00:51:05 +04:00
return NS_ERROR_ILLEGAL_VALUE ;
2013-06-04 16:21:06 +04:00
}
if ( aLength < = MAX_ADVISABLE_PREF_LENGTH ) {
return NS_OK ;
}
nsresult rv ;
nsCOMPtr < nsIConsoleService > console = do_GetService ( " @mozilla.org/consoleservice;1 " , & rv ) ;
if ( NS_FAILED ( rv ) ) {
return rv ;
}
nsAutoCString message ( nsPrintfCString ( " Warning: attempting to write %d bytes to preference %s. This is bad for general performance and memory usage. Such an amount of data should rather be written to an external file. " ,
aLength ,
aPrefName ) ) ;
rv = console - > LogStringMessage ( NS_ConvertUTF8toUTF16 ( message ) . get ( ) ) ;
if ( NS_FAILED ( rv ) ) {
return rv ;
}
return NS_OK ;
}
2001-03-23 02:34:41 +03:00
NS_IMETHODIMP nsPrefBranch : : SetComplexValue ( const char * aPrefName , const nsIID & aType , nsISupports * aValue )
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot SetComplexValue from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2001-09-06 23:30:47 +04:00
nsresult rv = NS_NOINTERFACE ;
2001-03-29 04:48:30 +04:00
2012-06-06 06:08:30 +04:00
// also check nsILocalFile, for backwards compatibility
if ( aType . Equals ( NS_GET_IID ( nsIFile ) ) | | aType . Equals ( NS_GET_IID ( nsILocalFile ) ) ) {
nsCOMPtr < nsIFile > file = do_QueryInterface ( aValue ) ;
2006-10-12 17:25:02 +04:00
if ( ! file )
return NS_NOINTERFACE ;
2012-09-02 06:35:17 +04:00
nsAutoCString descriptorString ;
2001-03-23 02:34:41 +03:00
2002-04-27 09:33:09 +04:00
rv = file - > GetPersistentDescriptor ( descriptorString ) ;
2001-03-23 02:34:41 +03:00
if ( NS_SUCCEEDED ( rv ) ) {
2013-06-04 16:21:06 +04:00
rv = SetCharPrefInternal ( aPrefName , descriptorString . get ( ) ) ;
2001-03-23 02:34:41 +03:00
}
return rv ;
}
2002-04-09 18:18:39 +04:00
if ( aType . Equals ( NS_GET_IID ( nsIRelativeFilePref ) ) ) {
nsCOMPtr < nsIRelativeFilePref > relFilePref = do_QueryInterface ( aValue ) ;
if ( ! relFilePref )
return NS_NOINTERFACE ;
2013-06-04 16:21:06 +04:00
2012-06-06 06:08:30 +04:00
nsCOMPtr < nsIFile > file ;
2002-04-09 18:18:39 +04:00
relFilePref - > GetFile ( getter_AddRefs ( file ) ) ;
if ( ! file )
2006-10-12 17:25:02 +04:00
return NS_NOINTERFACE ;
2012-09-02 06:35:17 +04:00
nsAutoCString relativeToKey ;
2002-04-09 18:18:39 +04:00
( void ) relFilePref - > GetRelativeToKey ( relativeToKey ) ;
2012-06-06 06:08:30 +04:00
nsCOMPtr < nsIFile > relativeToFile ;
2002-04-09 18:18:39 +04:00
nsCOMPtr < nsIProperties > directoryService ( do_GetService ( NS_DIRECTORY_SERVICE_CONTRACTID , & rv ) ) ;
if ( NS_FAILED ( rv ) )
return rv ;
2012-06-06 06:08:30 +04:00
rv = directoryService - > Get ( relativeToKey . get ( ) , NS_GET_IID ( nsIFile ) , getter_AddRefs ( relativeToFile ) ) ;
2002-04-09 18:18:39 +04:00
if ( NS_FAILED ( rv ) )
return rv ;
2012-09-02 06:35:17 +04:00
nsAutoCString relDescriptor ;
2002-04-09 18:18:39 +04:00
rv = file - > GetRelativeDescriptor ( relativeToFile , relDescriptor ) ;
if ( NS_FAILED ( rv ) )
return rv ;
2013-06-04 16:21:06 +04:00
2012-09-02 06:35:17 +04:00
nsAutoCString descriptorString ;
2002-04-09 18:18:39 +04:00
descriptorString . Append ( ' [ ' ) ;
descriptorString . Append ( relativeToKey ) ;
descriptorString . Append ( ' ] ' ) ;
descriptorString . Append ( relDescriptor ) ;
2013-06-04 16:21:06 +04:00
return SetCharPrefInternal ( aPrefName , descriptorString . get ( ) ) ;
2002-04-09 18:18:39 +04:00
}
2002-08-06 04:53:19 +04:00
if ( aType . Equals ( NS_GET_IID ( nsISupportsString ) ) ) {
nsCOMPtr < nsISupportsString > theString = do_QueryInterface ( aValue ) ;
2001-03-23 02:34:41 +03:00
if ( theString ) {
2013-05-02 00:21:23 +04:00
nsString wideString ;
2001-03-23 02:34:41 +03:00
2002-08-27 01:20:34 +04:00
rv = theString - > GetData ( wideString ) ;
2001-03-23 02:34:41 +03:00
if ( NS_SUCCEEDED ( rv ) ) {
2013-06-04 16:21:06 +04:00
// Check sanity of string length before any lengthy conversion
rv = CheckSanityOfStringLength ( aPrefName , wideString ) ;
if ( NS_FAILED ( rv ) ) {
return rv ;
2013-05-02 00:21:23 +04:00
}
2013-06-04 16:21:06 +04:00
rv = SetCharPrefInternal ( aPrefName , NS_ConvertUTF16toUTF8 ( wideString ) . get ( ) ) ;
2001-03-23 02:34:41 +03:00
}
}
return rv ;
}
if ( aType . Equals ( NS_GET_IID ( nsIPrefLocalizedString ) ) ) {
nsCOMPtr < nsIPrefLocalizedString > theString = do_QueryInterface ( aValue ) ;
if ( theString ) {
nsXPIDLString wideString ;
rv = theString - > GetData ( getter_Copies ( wideString ) ) ;
if ( NS_SUCCEEDED ( rv ) ) {
2013-06-04 16:21:06 +04:00
// Check sanity of string length before any lengthy conversion
rv = CheckSanityOfStringLength ( aPrefName , wideString ) ;
if ( NS_FAILED ( rv ) ) {
return rv ;
2013-05-02 00:21:23 +04:00
}
2013-06-04 16:21:06 +04:00
rv = SetCharPrefInternal ( aPrefName , NS_ConvertUTF16toUTF8 ( wideString ) . get ( ) ) ;
2001-03-23 02:34:41 +03:00
}
}
return rv ;
}
NS_WARNING ( " nsPrefBranch::SetComplexValue - Unsupported interface type " ) ;
return NS_NOINTERFACE ;
}
NS_IMETHODIMP nsPrefBranch : : ClearUserPref ( const char * aPrefName )
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot ClearUserPref from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
return PREF_ClearUserPref ( pref ) ;
2001-03-23 02:34:41 +03:00
}
2011-09-29 10:19:26 +04:00
NS_IMETHODIMP nsPrefBranch : : PrefHasUserValue ( const char * aPrefName , bool * _retval )
2001-06-09 00:31:34 +04:00
{
NS_ENSURE_ARG_POINTER ( _retval ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
* _retval = PREF_HasUserPref ( pref ) ;
return NS_OK ;
2001-06-09 00:31:34 +04:00
}
2001-03-23 02:34:41 +03:00
NS_IMETHODIMP nsPrefBranch : : LockPref ( const char * aPrefName )
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot LockPref from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
2011-10-17 18:59:28 +04:00
return PREF_LockPref ( pref , true ) ;
2001-03-23 02:34:41 +03:00
}
2011-09-29 10:19:26 +04:00
NS_IMETHODIMP nsPrefBranch : : PrefIsLocked ( const char * aPrefName , bool * _retval )
2001-03-23 02:34:41 +03:00
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot check PrefIsLocked from content process: " , aPrefName ) ;
2010-09-28 01:23:35 +04:00
NS_ENSURE_ARG_POINTER ( _retval ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
* _retval = PREF_PrefIsLocked ( pref ) ;
return NS_OK ;
2001-03-23 02:34:41 +03:00
}
NS_IMETHODIMP nsPrefBranch : : UnlockPref ( const char * aPrefName )
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot UnlockPref from content process: " , aPrefName ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aPrefName ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aPrefName ) ;
2011-10-17 18:59:28 +04:00
return PREF_LockPref ( pref , false ) ;
2001-03-23 02:34:41 +03:00
}
2001-03-29 04:48:30 +04:00
/* void resetBranch (in string startingAt); */
NS_IMETHODIMP nsPrefBranch : : ResetBranch ( const char * aStartingAt )
2001-03-23 02:34:41 +03:00
{
2001-03-29 04:48:30 +04:00
return NS_ERROR_NOT_IMPLEMENTED ;
2001-03-23 02:34:41 +03:00
}
NS_IMETHODIMP nsPrefBranch : : DeleteBranch ( const char * aStartingAt )
{
2013-12-04 03:18:09 +04:00
ENSURE_MAIN_PROCESS ( " Cannot DeleteBranch from content process: " , aStartingAt ) ;
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aStartingAt ) ;
2010-06-09 03:43:54 +04:00
const char * pref = getPrefName ( aStartingAt ) ;
return PREF_DeleteBranch ( pref ) ;
2001-03-23 02:34:41 +03:00
}
2012-08-22 19:56:38 +04:00
NS_IMETHODIMP nsPrefBranch : : GetChildList ( const char * aStartingAt , uint32_t * aCount , char * * * aChildArray )
2001-03-23 02:34:41 +03:00
{
2010-05-26 04:13:47 +04:00
char * * outArray ;
2012-08-22 19:56:38 +04:00
int32_t numPrefs ;
int32_t dwIndex ;
2001-03-23 02:34:41 +03:00
EnumerateData ed ;
2010-05-28 22:09:15 +04:00
nsAutoTArray < nsCString , 32 > prefArray ;
2001-03-23 02:34:41 +03:00
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aStartingAt ) ;
2001-03-23 02:34:41 +03:00
NS_ENSURE_ARG_POINTER ( aCount ) ;
NS_ENSURE_ARG_POINTER ( aChildArray ) ;
2012-07-30 18:20:58 +04:00
* aChildArray = nullptr ;
2010-05-28 22:09:15 +04:00
* aCount = 0 ;
2010-09-28 01:23:35 +04:00
if ( ! gHashTable . ops )
return NS_ERROR_NOT_INITIALIZED ;
2010-05-28 22:09:15 +04:00
2010-09-28 01:23:35 +04:00
// this will contain a list of all the pref name strings
// allocate on the stack for speed
ed . parent = getPrefName ( aStartingAt ) ;
ed . pref_list = & prefArray ;
PL_DHashTableEnumerate ( & gHashTable , pref_enumChild , & ed ) ;
2001-03-23 02:34:41 +03:00
// now that we've built up the list, run the callback on
// all the matching elements
2010-05-28 22:09:15 +04:00
numPrefs = prefArray . Length ( ) ;
2001-03-23 02:34:41 +03:00
2001-06-27 01:14:12 +04:00
if ( numPrefs ) {
outArray = ( char * * ) nsMemory : : Alloc ( numPrefs * sizeof ( char * ) ) ;
if ( ! outArray )
return NS_ERROR_OUT_OF_MEMORY ;
2001-03-23 02:34:41 +03:00
2001-06-27 01:14:12 +04:00
for ( dwIndex = 0 ; dwIndex < numPrefs ; + + dwIndex ) {
2001-07-05 21:51:27 +04:00
// we need to lop off mPrefRoot in case the user is planning to pass this
// back to us because if they do we are going to add mPrefRoot again.
2010-05-28 22:09:15 +04:00
const nsCString & element = prefArray [ dwIndex ] ;
outArray [ dwIndex ] = ( char * ) nsMemory : : Clone (
element . get ( ) + mPrefRootLength , element . Length ( ) - mPrefRootLength + 1 ) ;
2001-06-27 01:14:12 +04:00
if ( ! outArray [ dwIndex ] ) {
// we ran out of memory... this is annoying
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY ( dwIndex , outArray ) ;
return NS_ERROR_OUT_OF_MEMORY ;
}
2001-03-23 02:34:41 +03:00
}
2001-06-27 01:14:12 +04:00
* aChildArray = outArray ;
2010-05-28 22:09:15 +04:00
}
2001-03-23 02:34:41 +03:00
* aCount = numPrefs ;
2001-06-27 01:14:12 +04:00
2001-03-23 02:34:41 +03:00
return NS_OK ;
}
2011-09-29 10:19:26 +04:00
NS_IMETHODIMP nsPrefBranch : : AddObserver ( const char * aDomain , nsIObserver * aObserver , bool aHoldWeak )
2001-03-23 02:34:41 +03:00
{
2010-07-17 01:10:01 +04:00
PrefCallback * pCallback ;
2001-12-06 22:49:38 +03:00
const char * pref ;
2001-04-12 03:07:03 +04:00
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aDomain ) ;
NS_ENSURE_ARG ( aObserver ) ;
2001-03-23 02:34:41 +03:00
2001-10-23 00:54:48 +04:00
// hold a weak reference to the observer if so requested
if ( aHoldWeak ) {
nsCOMPtr < nsISupportsWeakReference > weakRefFactory = do_QueryInterface ( aObserver ) ;
if ( ! weakRefFactory ) {
// the caller didn't give us a object that supports weak reference... tell them
return NS_ERROR_INVALID_ARG ;
}
2010-07-17 01:10:01 +04:00
// Construct a PrefCallback with a weak reference to the observer.
pCallback = new PrefCallback ( aDomain , weakRefFactory , this ) ;
2001-10-23 00:54:48 +04:00
} else {
2010-07-17 01:10:01 +04:00
// Construct a PrefCallback with a strong reference to the observer.
pCallback = new PrefCallback ( aDomain , aObserver , this ) ;
}
if ( mObservers . Get ( pCallback ) ) {
NS_WARNING ( " Ignoring duplicate observer. " ) ;
delete pCallback ;
return NS_OK ;
2001-10-23 00:54:48 +04:00
}
2001-04-25 00:32:16 +04:00
2012-05-18 21:30:49 +04:00
mObservers . Put ( pCallback , pCallback ) ;
2001-03-23 02:34:41 +03:00
2001-12-06 22:49:38 +03:00
// We must pass a fully qualified preference name to the callback
2012-07-30 18:20:58 +04:00
// aDomain == nullptr is the only possible failure, and we trapped it with
2010-10-08 01:00:17 +04:00
// NS_ENSURE_ARG above.
2010-07-17 01:10:01 +04:00
pref = getPrefName ( aDomain ) ;
2001-12-06 22:49:38 +03:00
PREF_RegisterCallback ( pref , NotifyObserver , pCallback ) ;
2001-03-23 02:34:41 +03:00
return NS_OK ;
}
NS_IMETHODIMP nsPrefBranch : : RemoveObserver ( const char * aDomain , nsIObserver * aObserver )
{
2010-10-08 01:00:17 +04:00
NS_ENSURE_ARG ( aDomain ) ;
NS_ENSURE_ARG ( aObserver ) ;
2001-03-23 02:34:41 +03:00
2010-07-17 01:10:01 +04:00
nsresult rv = NS_OK ;
// If we're in the middle of a call to freeObserverList, don't process this
// RemoveObserver call -- the observer in question will be removed soon, if
// it hasn't been already.
//
// It's important that we don't touch mObservers in any way -- even a Get()
// which retuns null might cause the hashtable to resize itself, which will
// break the Enumerator in freeObserverList.
if ( mFreeingObserverList )
2001-03-23 02:34:41 +03:00
return NS_OK ;
2010-07-17 01:10:01 +04:00
// Remove the relevant PrefCallback from mObservers and get an owning
// pointer to it. Unregister the callback first, and then let the owning
// pointer go out of scope and destroy the callback.
PrefCallback key ( aDomain , aObserver , this ) ;
nsAutoPtr < PrefCallback > pCallback ;
mObservers . RemoveAndForget ( & key , pCallback ) ;
if ( pCallback ) {
2012-07-30 18:20:58 +04:00
// aDomain == nullptr is the only possible failure, trapped above
2010-07-17 01:10:01 +04:00
const char * pref = getPrefName ( aDomain ) ;
rv = PREF_UnregisterCallback ( pref , NotifyObserver , pCallback ) ;
}
return rv ;
2001-03-23 02:34:41 +03:00
}
2014-01-04 19:02:17 +04:00
NS_IMETHODIMP nsPrefBranch : : Observe ( nsISupports * aSubject , const char * aTopic , const char16_t * someData )
2001-10-23 00:54:48 +04:00
{
// watch for xpcom shutdown and free our observers to eliminate any cyclic references
if ( ! nsCRT : : strcmp ( aTopic , NS_XPCOM_SHUTDOWN_OBSERVER_ID ) ) {
freeObserverList ( ) ;
}
return NS_OK ;
}
2010-07-17 01:10:01 +04:00
/* static */
2013-12-11 03:10:01 +04:00
void nsPrefBranch : : NotifyObserver ( const char * newpref , void * data )
2001-03-23 02:34:41 +03:00
{
2010-07-17 01:10:01 +04:00
PrefCallback * pCallback = ( PrefCallback * ) data ;
nsCOMPtr < nsIObserver > observer = pCallback - > GetObserver ( ) ;
if ( ! observer ) {
// The observer has expired. Let's remove this callback.
pCallback - > GetPrefBranch ( ) - > RemoveExpiredCallback ( pCallback ) ;
2013-12-11 03:10:01 +04:00
return ;
2010-07-17 01:10:01 +04:00
}
2001-12-06 22:49:38 +03:00
// remove any root this string may contain so as to not confuse the observer
// by passing them something other than what they passed us as a topic
2012-08-22 19:56:38 +04:00
uint32_t len = pCallback - > GetPrefBranch ( ) - > GetRootLength ( ) ;
2012-09-02 06:35:17 +04:00
nsAutoCString suffix ( newpref + len ) ;
2001-04-12 03:07:03 +04:00
2010-07-17 01:10:01 +04:00
observer - > Observe ( static_cast < nsIPrefBranch * > ( pCallback - > GetPrefBranch ( ) ) ,
2006-01-10 15:20:17 +03:00
NS_PREFBRANCH_PREFCHANGE_TOPIC_ID ,
NS_ConvertASCIItoUTF16 ( suffix ) . get ( ) ) ;
2001-03-23 02:34:41 +03:00
}
2010-07-17 01:10:01 +04:00
PLDHashOperator
FreeObserverFunc ( PrefCallback * aKey ,
nsAutoPtr < PrefCallback > & aCallback ,
void * aArgs )
2010-07-15 04:39:22 +04:00
{
2010-07-17 01:10:01 +04:00
// Calling NS_RELEASE below might trigger a call to
// nsPrefBranch::RemoveObserver, since some classes remove themselves from
// the pref branch on destruction. We don't need to worry about this causing
// double-frees, however, because freeObserverList sets mFreeingObserverList
// to true, which prevents RemoveObserver calls from doing anything.
2010-08-19 01:38:05 +04:00
2010-07-17 01:10:01 +04:00
nsPrefBranch * prefBranch = aCallback - > GetPrefBranch ( ) ;
const char * pref = prefBranch - > getPrefName ( aCallback - > GetDomain ( ) . get ( ) ) ;
PREF_UnregisterCallback ( pref , nsPrefBranch : : NotifyObserver , aCallback ) ;
return PL_DHASH_REMOVE ;
2010-07-17 01:10:01 +04:00
}
2010-07-15 04:39:22 +04:00
2010-07-17 01:10:01 +04:00
void nsPrefBranch : : freeObserverList ( void )
2010-07-17 01:10:01 +04:00
{
2010-07-17 01:10:01 +04:00
// We need to prevent anyone from modifying mObservers while we're
// enumerating over it. In particular, some clients will call
// RemoveObserver() when they're destructed; we need to keep those calls from
// touching mObservers.
2011-10-17 18:59:28 +04:00
mFreeingObserverList = true ;
2012-07-30 18:20:58 +04:00
mObservers . Enumerate ( & FreeObserverFunc , nullptr ) ;
2011-10-17 18:59:28 +04:00
mFreeingObserverList = false ;
2010-07-17 01:10:01 +04:00
}
2010-08-19 01:38:05 +04:00
2010-07-17 01:10:01 +04:00
void
nsPrefBranch : : RemoveExpiredCallback ( PrefCallback * aCallback )
{
NS_PRECONDITION ( aCallback - > IsExpired ( ) , " Callback should be expired. " ) ;
mObservers . Remove ( aCallback ) ;
2010-08-19 01:38:05 +04:00
}
2010-07-17 01:10:01 +04:00
2014-01-04 19:02:17 +04:00
nsresult nsPrefBranch : : GetDefaultFromPropertiesFile ( const char * aPrefName , char16_t * * return_buf )
2001-04-13 03:28:43 +04:00
{
nsresult rv ;
// the default value contains a URL to a .properties file
nsXPIDLCString propertyFileURL ;
2011-10-17 18:59:28 +04:00
rv = PREF_CopyCharPref ( aPrefName , getter_Copies ( propertyFileURL ) , true ) ;
2001-04-13 03:28:43 +04:00
if ( NS_FAILED ( rv ) )
return rv ;
2010-05-14 13:24:41 +04:00
2001-04-13 03:28:43 +04:00
nsCOMPtr < nsIStringBundleService > bundleService =
2010-05-14 13:24:41 +04:00
mozilla : : services : : GetStringBundleService ( ) ;
if ( ! bundleService )
return NS_ERROR_FAILURE ;
2001-04-13 03:28:43 +04:00
nsCOMPtr < nsIStringBundle > bundle ;
2001-04-28 01:30:24 +04:00
rv = bundleService - > CreateBundle ( propertyFileURL ,
2001-04-13 03:28:43 +04:00
getter_AddRefs ( bundle ) ) ;
if ( NS_FAILED ( rv ) )
return rv ;
2003-09-18 06:57:13 +04:00
// string names are in unicode
2001-04-13 03:28:43 +04:00
nsAutoString stringId ;
2005-02-06 15:39:31 +03:00
stringId . AssignASCII ( aPrefName ) ;
2001-04-13 03:28:43 +04:00
2001-06-30 15:02:25 +04:00
return bundle - > GetStringFromName ( stringId . get ( ) , return_buf ) ;
2001-04-13 03:28:43 +04:00
}
2001-03-23 02:34:41 +03:00
const char * nsPrefBranch : : getPrefName ( const char * aPrefName )
{
2010-10-08 01:00:17 +04:00
NS_ASSERTION ( aPrefName , " null pref name! " ) ;
2001-03-23 02:34:41 +03:00
// for speed, avoid strcpy if we can:
if ( mPrefRoot . IsEmpty ( ) )
return aPrefName ;
// isn't there a better way to do this? this is really kind of gross.
mPrefRoot . Truncate ( mPrefRootLength ) ;
2010-10-08 01:00:17 +04:00
mPrefRoot . Append ( aPrefName ) ;
2001-03-23 02:34:41 +03:00
return mPrefRoot . get ( ) ;
}
2008-10-10 19:04:34 +04:00
static PLDHashOperator
2001-12-04 04:52:44 +03:00
pref_enumChild ( PLDHashTable * table , PLDHashEntryHdr * heh ,
2012-08-22 19:56:38 +04:00
uint32_t i , void * arg )
2001-09-06 23:30:47 +04:00
{
2007-07-08 11:08:04 +04:00
PrefHashEntry * he = static_cast < PrefHashEntry * > ( heh ) ;
EnumerateData * d = reinterpret_cast < EnumerateData * > ( arg ) ;
2010-05-28 22:09:15 +04:00
if ( strncmp ( he - > key , d - > parent , strlen ( d - > parent ) ) = = 0 ) {
d - > pref_list - > AppendElement ( he - > key ) ;
2001-09-06 23:30:47 +04:00
}
2001-12-04 04:52:44 +03:00
return PL_DHASH_NEXT ;
2001-09-06 23:30:47 +04:00
}
2002-04-09 18:18:39 +04:00
//----------------------------------------------------------------------------
// nsPrefLocalizedString
//----------------------------------------------------------------------------
2001-03-23 02:34:41 +03:00
nsPrefLocalizedString : : nsPrefLocalizedString ( )
{
}
nsPrefLocalizedString : : ~ nsPrefLocalizedString ( )
{
}
2001-04-04 00:11:54 +04:00
/*
* nsISupports Implementation
*/
2013-07-19 06:23:44 +04:00
NS_IMPL_ADDREF ( nsPrefLocalizedString )
NS_IMPL_RELEASE ( nsPrefLocalizedString )
2001-04-04 00:11:54 +04:00
NS_INTERFACE_MAP_BEGIN ( nsPrefLocalizedString )
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS ( nsISupports , nsIPrefLocalizedString )
NS_INTERFACE_MAP_ENTRY ( nsIPrefLocalizedString )
2002-08-06 04:53:19 +04:00
NS_INTERFACE_MAP_ENTRY ( nsISupportsString )
2001-04-04 00:11:54 +04:00
NS_INTERFACE_MAP_END
nsresult nsPrefLocalizedString : : Init ( )
{
nsresult rv ;
2002-08-06 04:53:19 +04:00
mUnicodeString = do_CreateInstance ( NS_SUPPORTS_STRING_CONTRACTID , & rv ) ;
2001-04-04 00:11:54 +04:00
return rv ;
}
2002-08-27 01:20:34 +04:00
NS_IMETHODIMP
2014-01-04 19:02:17 +04:00
nsPrefLocalizedString : : GetData ( char16_t * * _retval )
2002-08-27 01:20:34 +04:00
{
nsAutoString data ;
nsresult rv = GetData ( data ) ;
if ( NS_FAILED ( rv ) )
return rv ;
* _retval = ToNewUnicode ( data ) ;
if ( ! * _retval )
return NS_ERROR_OUT_OF_MEMORY ;
return NS_OK ;
}
NS_IMETHODIMP
2014-01-04 19:02:17 +04:00
nsPrefLocalizedString : : SetData ( const char16_t * aData )
2002-08-27 01:20:34 +04:00
{
2005-07-01 05:48:41 +04:00
if ( ! aData )
return SetData ( EmptyString ( ) ) ;
2002-08-27 01:20:34 +04:00
return SetData ( nsDependentString ( aData ) ) ;
}
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
nsPrefLocalizedString : : SetDataWithLength ( uint32_t aLength ,
2014-01-04 19:02:17 +04:00
const char16_t * aData )
2002-08-27 01:20:34 +04:00
{
2005-07-01 05:48:41 +04:00
if ( ! aData )
return SetData ( EmptyString ( ) ) ;
2011-12-09 12:35:41 +04:00
return SetData ( Substring ( aData , aLength ) ) ;
2002-08-27 01:20:34 +04:00
}
2002-04-09 18:18:39 +04:00
//----------------------------------------------------------------------------
// nsRelativeFilePref
//----------------------------------------------------------------------------
2014-04-27 11:06:00 +04:00
NS_IMPL_ISUPPORTS ( nsRelativeFilePref , nsIRelativeFilePref )
2002-04-09 18:18:39 +04:00
nsRelativeFilePref : : nsRelativeFilePref ( )
{
}
nsRelativeFilePref : : ~ nsRelativeFilePref ( )
{
}
2012-06-06 06:08:30 +04:00
NS_IMETHODIMP nsRelativeFilePref : : GetFile ( nsIFile * * aFile )
2002-04-09 18:18:39 +04:00
{
2010-05-26 04:13:47 +04:00
NS_ENSURE_ARG_POINTER ( aFile ) ;
* aFile = mFile ;
NS_IF_ADDREF ( * aFile ) ;
return NS_OK ;
2002-04-09 18:18:39 +04:00
}
2012-06-06 06:08:30 +04:00
NS_IMETHODIMP nsRelativeFilePref : : SetFile ( nsIFile * aFile )
2002-04-09 18:18:39 +04:00
{
2010-05-26 04:13:47 +04:00
mFile = aFile ;
return NS_OK ;
2002-04-09 18:18:39 +04:00
}
NS_IMETHODIMP nsRelativeFilePref : : GetRelativeToKey ( nsACString & aRelativeToKey )
{
2010-05-26 04:13:47 +04:00
aRelativeToKey . Assign ( mRelativeToKey ) ;
return NS_OK ;
2002-04-09 18:18:39 +04:00
}
NS_IMETHODIMP nsRelativeFilePref : : SetRelativeToKey ( const nsACString & aRelativeToKey )
{
2010-05-26 04:13:47 +04:00
mRelativeToKey . Assign ( aRelativeToKey ) ;
return NS_OK ;
2002-04-09 18:18:39 +04:00
}
2013-12-04 03:18:09 +04:00
2014-08-26 03:56:33 +04:00
# undef ENSURE_MAIN_PROCESS