зеркало из https://github.com/mozilla/gecko-dev.git
Updates to the future preferences API based on the latest round of feedback.
This commit is contained in:
Родитель
db15c70246
Коммит
1037f46c0d
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIObserver.idl"
|
||||
|
||||
[scriptable, uuid(56c35506-f14b-11d3-99d3-ddbfac2ccf65)]
|
||||
interface nsIPrefBranch : nsISupports
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
* Brian Nesse <bnesse@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIPrefBranch.idl"
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIObserver.idl"
|
||||
|
||||
[scriptable, uuid(24ef9578-1dd2-11b2-b439-fcc3d2b4fa20)]
|
||||
interface nsIPrefBranchInternal : nsIPrefBranch
|
||||
interface nsIPrefBranchInternal : nsISupports
|
||||
{
|
||||
/*
|
||||
* Listeners
|
||||
|
|
|
@ -43,7 +43,15 @@ interface nsIPrefLocalizedString : nsISupports
|
|||
|
||||
%{C++
|
||||
|
||||
#define NS_SUPPORTS_PREFLOCALIZEDSTRING_CONTRACTID "@mozilla.org/supports-preflocalizedstring;1"
|
||||
#define NS_SUPPORTS_PREFLOCALIZEDSTRING_CLASSNAME "Supports PrefLocalizedString"
|
||||
#define NS_PREFLOCALIZEDSTRING_CID \
|
||||
{ /* {064d9cee-1dd2-11b2-83e3-d25ab0193c26} */ \
|
||||
0x064d9cee, \
|
||||
0x1dd2, \
|
||||
0x11b2, \
|
||||
{ 0x83, 0xe3, 0xd2, 0x5a, 0xb0, 0x19, 0x3c, 0x26 } \
|
||||
}
|
||||
|
||||
#define NS_PREFLOCALIZEDSTRING_CONTRACTID "@mozilla.org/pref-localizedstring;1"
|
||||
#define NS_PREFLOCALIZEDSTRING_CLASSNAME "Pref LocalizedString"
|
||||
|
||||
%}
|
||||
|
|
|
@ -286,7 +286,7 @@ NS_IMETHODIMP nsPrefBranch::GetComplexValue(const char *aPrefName, const nsIID &
|
|||
}
|
||||
|
||||
if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) {
|
||||
nsCOMPtr<nsIPrefLocalizedString> theString(do_CreateInstance(NS_SUPPORTS_PREFLOCALIZEDSTRING_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIPrefLocalizedString> theString(do_CreateInstance(NS_PREFLOCALIZEDSTRING_CONTRACTID, &rv));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = theString->SetData(NS_ConvertASCIItoUCS2(utf8String).get());
|
||||
|
@ -626,9 +626,8 @@ nsresult nsPrefBranch::QueryObserver(const char *aPrefName)
|
|||
|
||||
#pragma mark -
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsPrefLocalizedString, nsIPrefLocalizedString)
|
||||
|
||||
nsPrefLocalizedString::nsPrefLocalizedString()
|
||||
: mUnicodeString(nsnull)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -640,3 +639,26 @@ nsPrefLocalizedString::nsPrefLocalizedString()
|
|||
nsPrefLocalizedString::~nsPrefLocalizedString()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nsISupports Implementation
|
||||
*/
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsPrefLocalizedString)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsPrefLocalizedString)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsPrefLocalizedString)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefLocalizedString)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIPrefLocalizedString)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWString)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
nsresult nsPrefLocalizedString::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
mUnicodeString = do_CreateInstance(NS_SUPPORTS_WSTRING_CONTRACTID, &rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class nsPrefBranch : public nsIPrefBranchInternal
|
||||
class nsPrefBranch : public nsIPrefBranch,
|
||||
public nsIPrefBranchInternal
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -58,7 +59,8 @@ private:
|
|||
};
|
||||
|
||||
|
||||
class nsPrefLocalizedString : public nsIPrefLocalizedString
|
||||
class nsPrefLocalizedString : public nsIPrefLocalizedString,
|
||||
public nsISupportsWString
|
||||
{
|
||||
public:
|
||||
nsPrefLocalizedString();
|
||||
|
@ -66,6 +68,9 @@ public:
|
|||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_FORWARD_NSISUPPORTSWSTRING(mUnicodeString->)
|
||||
NS_FORWARD_NSISUPPORTSPRIMITIVE(mUnicodeString->)
|
||||
|
||||
nsresult Init();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupportsWString> mUnicodeString;
|
||||
|
|
|
@ -36,7 +36,6 @@ class nsIFileSpec; // needed for prefapi_private_data.h inclusion
|
|||
|
||||
// supporting lock files
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
|
||||
|
@ -44,7 +43,7 @@ class nsIFileSpec; // needed for prefapi_private_data.h inclusion
|
|||
#include "nsIJSRuntimeService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
|
||||
// lose these if possible (supporting _nsIFileToFileSpec)
|
||||
// lose these if possible (supporting nsIFileToFileSpec)
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
|
||||
|
@ -54,7 +53,7 @@ class nsIFileSpec; // needed for prefapi_private_data.h inclusion
|
|||
#define INITIAL_MAX_DEFAULT_PREF_FILES 10
|
||||
|
||||
// Prototypes
|
||||
static nsresult _nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec);
|
||||
static nsresult nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec);
|
||||
static PRBool verifyFileHash(char* buf, long buflen);
|
||||
static nsresult openPrefFile(nsIFile* aFile, PRBool aIsErrorFatal, PRBool aVerifyHash,
|
||||
PRBool aIsGlobalContext, PRBool aSkipFirstLine);
|
||||
|
@ -83,16 +82,6 @@ nsPrefService::nsPrefService()
|
|||
nsPrefService::~nsPrefService()
|
||||
{
|
||||
PREF_Cleanup();
|
||||
|
||||
if (gLockInfoRead) {
|
||||
if (gLockFileName) {
|
||||
PR_DELETE(gLockFileName);
|
||||
}
|
||||
if (gLockVendor) {
|
||||
PR_DELETE(gLockVendor);
|
||||
}
|
||||
gLockInfoRead = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,6 +97,7 @@ NS_INTERFACE_MAP_BEGIN(nsPrefService)
|
|||
NS_INTERFACE_MAP_ENTRY(nsIPrefService)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIPrefBranch)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIPrefBranchInternal)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
|
@ -115,7 +105,7 @@ NS_INTERFACE_MAP_END
|
|||
* nsIPrefService Implementation
|
||||
*/
|
||||
|
||||
NS_IMETHODIMP nsPrefService::Init()
|
||||
nsresult nsPrefService::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
@ -158,56 +148,7 @@ NS_IMETHODIMP nsPrefService::Observe(nsISupports *aSubject, const PRUnichar *aTo
|
|||
|
||||
NS_IMETHODIMP nsPrefService::ReadConfigFile()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 fileNameLen;
|
||||
PRUint32 vendorLen;
|
||||
|
||||
gLockFileName = nsnull;
|
||||
gLockVendor = nsnull;
|
||||
|
||||
if (gLockInfoRead)
|
||||
return rv;
|
||||
|
||||
gLockInfoRead = PR_TRUE;
|
||||
|
||||
rv = mRootBranch->GetCharPref("general.config.filename", &gLockFileName);
|
||||
if (NS_SUCCEEDED(rv) && (gLockFileName)) {
|
||||
#ifdef NS_DEBUG
|
||||
printf("\ngLockFileName %s \n", gLockFileName);
|
||||
#endif
|
||||
rv = mRootBranch->GetCharPref("general.config.vendor", &gLockVendor);
|
||||
if (NS_SUCCEEDED(rv) && (gLockVendor)) {
|
||||
// if we got here, we have a lockfile pref and a vendor pref
|
||||
#ifdef NS_DEBUG
|
||||
printf("\ngLockVendor %s \n", gLockVendor);
|
||||
#endif
|
||||
fileNameLen = PL_strlen(gLockFileName);
|
||||
vendorLen = PL_strlen(gLockVendor);
|
||||
if (PL_strncmp(gLockFileName, gLockVendor, fileNameLen -4) != 0) {
|
||||
// configuration filename and vendor name do not match
|
||||
rv = NS_ERROR_FAILURE;
|
||||
} else {
|
||||
nsCOMPtr<nsIFile> lockFile;
|
||||
|
||||
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(lockFile));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
#ifdef XP_MAC
|
||||
rv = lockFile->Append("Essential Files");
|
||||
#endif
|
||||
rv = lockFile->Append(gLockFileName);
|
||||
rv = openPrefFile(lockFile, PR_TRUE, PR_TRUE, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No vendor name specified, hence cannot verify it
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
} else {
|
||||
// config file is not specified, hence no need to read it.
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
return rv;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPrefService::ReadUserPrefs(nsIFile *aFile)
|
||||
|
@ -283,6 +224,30 @@ NS_IMETHODIMP nsPrefService::GetDefaultBranch(const char *aPrefRoot, nsIPrefBran
|
|||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
// Forward these methods through the nsIPrefBranchInternal headers
|
||||
|
||||
NS_IMETHODIMP nsPrefService::AddObserver(const char *aDomain, nsIObserver *aObserver)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefBranch = do_QueryInterface(mRootBranch, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = prefBranch->AddObserver(aDomain, aObserver);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPrefService::RemoveObserver(const char *aDomain, nsIObserver *aObserver)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefBranch = do_QueryInterface(mRootBranch, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = prefBranch->RemoveObserver(aDomain, aObserver);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
|
||||
nsresult nsPrefService::useDefaultPrefFile()
|
||||
|
@ -336,7 +301,9 @@ static nsresult openPrefFile(nsIFile* aFile, PRBool aIsErrorFatal, PRBool aVerif
|
|||
nsCOMPtr<nsIFileSpec> fileSpec;
|
||||
nsresult rv;
|
||||
|
||||
rv = _nsIFileToFileSpec(aFile, getter_AddRefs(fileSpec));
|
||||
JS_BeginRequest(gMochaContext);
|
||||
rv = nsIFileToFileSpec(aFile, getter_AddRefs(fileSpec));
|
||||
JS_EndRequest(gMochaContext);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
@ -409,7 +376,7 @@ static nsresult savePrefFile(nsIFile* aFile)
|
|||
return NS_OK;
|
||||
|
||||
// TODO: Convert the rest of this code to nsIFile and avoid this conversion to nsIFileSpec
|
||||
rv = _nsIFileToFileSpec(aFile, getter_AddRefs(fileSpec));
|
||||
rv = nsIFileToFileSpec(aFile, getter_AddRefs(fileSpec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
@ -446,7 +413,7 @@ static nsresult savePrefFile(nsIFile* aFile)
|
|||
// So discouraged is the use of nsIFileSpec, nobody wanted to have this routine be
|
||||
// public - It might lead to continued use of nsIFileSpec. Right now, this code has
|
||||
// such a need for it, here it is. Let's stop having to use it though.
|
||||
static nsresult _nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec)
|
||||
static nsresult nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -579,7 +546,7 @@ extern "C" JSBool pref_InitInitialObjects()
|
|||
rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(aFile));
|
||||
if (NS_FAILED(rv))
|
||||
return JS_FALSE;
|
||||
rv = _nsIFileToFileSpec(aFile, getter_AddRefs(defaultPrefDir));
|
||||
rv = nsIFileToFileSpec(aFile, getter_AddRefs(defaultPrefDir));
|
||||
if (NS_FAILED(rv))
|
||||
return JS_FALSE;
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
*/
|
||||
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
@ -29,22 +31,24 @@ class nsIFile;
|
|||
|
||||
class nsPrefService : public nsIPrefService,
|
||||
public nsIObserver,
|
||||
public nsIPrefBranch
|
||||
public nsIPrefBranch,
|
||||
public nsIPrefBranchInternal
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPREFSERVICE
|
||||
NS_FORWARD_NSIPREFBRANCH(mRootBranch->)
|
||||
NS_DECL_NSIPREFBRANCHINTERNAL
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsPrefService();
|
||||
virtual ~nsPrefService();
|
||||
|
||||
NS_METHOD Init();
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
NS_METHOD useDefaultPrefFile();
|
||||
NS_METHOD useUserPrefFile();
|
||||
nsresult useDefaultPrefFile();
|
||||
nsresult useUserPrefFile();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIPrefBranch> mRootBranch;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsPrefService.h"
|
||||
#include "nsPrefBranch.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
// remove this when nsPref goes away
|
||||
|
@ -30,6 +31,7 @@ extern "C" nsresult nsPrefConstructor(nsISupports *aOuter, REFNSIID aIID, void *
|
|||
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefService, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefLocalizedString, Init)
|
||||
|
||||
// The list of components we register
|
||||
static nsModuleComponentInfo components[] =
|
||||
|
@ -41,6 +43,13 @@ static nsModuleComponentInfo components[] =
|
|||
nsPrefServiceConstructor
|
||||
},
|
||||
|
||||
{
|
||||
NS_PREFLOCALIZEDSTRING_CLASSNAME,
|
||||
NS_PREFLOCALIZEDSTRING_CID,
|
||||
NS_PREFLOCALIZEDSTRING_CONTRACTID,
|
||||
nsPrefLocalizedStringConstructor
|
||||
},
|
||||
|
||||
{ // remove this when nsPref goes away
|
||||
NS_PREF_CLASSNAME,
|
||||
NS_PREF_CID,
|
||||
|
@ -50,3 +59,4 @@ static nsModuleComponentInfo components[] =
|
|||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsPrefModule", components);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче