author | Masatoshi Kimura <VYV03354@nifty.ne.jp> |
Sat, 26 Nov 2011 20:49:31 +0100 | |
changeset 82484 | 62f14bed35a21aba3062eae10c16c4da17c83529 |
parent 82483 | 025b94f0f4cb482b50a2ad87309f3bdf675c9042 |
child 82485 | aa093660a497227e2183da6339c799b38a49b90e |
push id | 519 |
push user | akeybl@mozilla.com |
push date | Wed, 01 Feb 2012 00:38:35 +0000 |
treeherder | mozilla-beta@788ea1ef610b [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | roc |
bugs | 451161 |
milestone | 11.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/configure.in +++ b/configure.in @@ -5930,22 +5930,21 @@ MOZ_ARG_DISABLE_BOOL(xtf, [ --disable-xtf Disable XTF (pluggable xml tags) support], MOZ_XTF=, MOZ_XTF=1 ) if test "$MOZ_XTF"; then AC_DEFINE(MOZ_XTF) fi dnl ======================================================== -dnl Pref extensions (autoconfig and system-pref) +dnl Pref extensions (autoconfig) dnl ======================================================== MOZ_ARG_DISABLE_BOOL(pref-extensions, [ --disable-pref-extensions - Disable pref extensions such as autoconfig and - system-pref], + Disable pref extensions such as autoconfig], MOZ_PREF_EXTENSIONS=, MOZ_PREF_EXTENSIONS=1 ) dnl ======================================================== dnl Searching of system directories for extensions. dnl Note: this switch is meant to be used for test builds dnl whose behavior should not depend on what happens to be dnl installed on the local machine.
--- a/extensions/pref/Makefile.in +++ b/extensions/pref/Makefile.in @@ -40,13 +40,9 @@ DEPTH = ../.. topsrcdir = @top_srcdir@ srcdir = @srcdir@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk DIRS = autoconfig -ifdef MOZ_ENABLE_GTK2 -DIRS += system-pref/src -endif - include $(topsrcdir)/config/rules.mk
--- a/extensions/pref/makefiles.sh +++ b/extensions/pref/makefiles.sh @@ -37,15 +37,8 @@ # ***** END LICENSE BLOCK ***** add_makefiles " extensions/pref/Makefile extensions/pref/autoconfig/Makefile extensions/pref/autoconfig/public/Makefile extensions/pref/autoconfig/src/Makefile " - -if [ "$MOZ_ENABLE_GTK2" ]; then - add_makefiles " - extensions/pref/system-pref/src/Makefile - extensions/pref/system-pref/src/gconf/Makefile - " -fi
deleted file mode 100644 --- a/extensions/pref/system-pref/src/Makefile.in +++ /dev/null @@ -1,67 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Sun Microsystems, Inc. -# Portions created by the Initial Developer are Copyright (C) 2003 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Bolian Yin <bolian.yin@sun.com> -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = system-pref -LIBRARY_NAME = system-pref_s -SHORT_LIBNAME = syspref - -# We want to force the creation of a static lib. -FORCE_STATIC_LIB = 1 -LIBXUL_LIBRARY = 1 - -DIRS = gconf - -CPPSRCS = \ - nsSystemPref.cpp \ - $(NULL) - -EXPORTS = \ - nsSystemPrefLog.h \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - -INCLUDES += \ - -I$(srcdir)/gconf \ - $(NULL)
deleted file mode 100644 --- a/extensions/pref/system-pref/src/gconf/Makefile.in +++ /dev/null @@ -1,75 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Sun Microsystems, Inc. -# Portions created by the Initial Developer are Copyright (C) 2003 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Bolian Yin <bolian.yin@sun.com> -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = system-pref -LIBRARY_NAME = system-pref -LIBXUL_LIBRARY = 1 - - -CPPSRCS = \ - nsSystemPrefService.cpp \ - nsSystemPrefFactory.cpp \ - $(NULL) - -SHARED_LIBRARY_LIBS = ../libsystem-pref_s.a - -EXPORT_LIBRARY = 1 -IS_COMPONENT = 1 -MODULE_NAME = nsSystemPrefModule - -EXPORTS = \ - nsSystemPrefService.h \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - -CFLAGS += $(MOZ_GTK2_CFLAGS) -CXXFLAGS += $(MOZ_GTK2_CFLAGS) - -LOCAL_INCLUDES = -I$(srcdir)/.. - -export:: - $(INSTALL) $(srcdir)/../nsSystemPrefFactory.cpp . - -GARBAGE += nsSystemPrefFactory.cpp
deleted file mode 100644 --- a/extensions/pref/system-pref/src/gconf/gconf_pref_list.inc +++ /dev/null @@ -1,19 +0,0 @@ -/* This file is included as the content of an array - * - * the first column is the mozilla pref name, the second column is the - * the related gconf pref name. - * - *************************************************************************/ - - {"network.proxy.http", "/system/http_proxy/host"}, - {"network.proxy.http_port", "/system/http_proxy/port"}, - {"network.proxy.ftp", "/system/proxy/ftp_host"}, - {"network.proxy.ftp_port", "/system/proxy/ftp_port"}, - {"network.proxy.ssl", "/system/proxy/secure_host"}, - {"network.proxy.ssl_port", "/system/proxy/secure_port"}, - {"network.proxy.socks", "/system/proxy/socks_host"}, - {"network.proxy.socks_port", "/system/proxy/socks_port"}, - {"network.proxy.no_proxies_on", "/system/http_proxy/ignore_hosts"}, - {"network.proxy.autoconfig_url", "/system/proxy/autoconfig_url"}, - {"network.proxy.type", "/system/proxy/mode"}, - {"config.use_system_prefs.accessibility", "/desktop/gnome/interface/accessibility"},
deleted file mode 100644 --- a/extensions/pref/system-pref/src/gconf/nsSystemPrefService.cpp +++ /dev/null @@ -1,915 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2003 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include <glib.h> -#include <glib-object.h> - -#include "plstr.h" -#include "nsCOMPtr.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsIServiceManager.h" -#include "nsIObserver.h" -#include "nsWeakReference.h" - -#include "nsString.h" -#include "nsSystemPrefLog.h" -#include "nsSystemPrefService.h" - -/************************************************************************* - * The strange thing here is that we load the gconf library manually and - * search the function pointers we need. If that process fails, no gconf - * support is available in mozilla. The aim is to make mozilla independent - * on gconf, in both compile time and run time. - ************************************************************************/ - -//gconf types -extern "C" { - - typedef enum { - GCONF_VALUE_INVALID, - GCONF_VALUE_STRING, - GCONF_VALUE_INT, - GCONF_VALUE_FLOAT, - GCONF_VALUE_BOOL, - GCONF_VALUE_SCHEMA, - - GCONF_VALUE_LIST, - GCONF_VALUE_PAIR - - }GConfValueType; - - typedef struct { - GConfValueType type; - }GConfValue; - - typedef void * (*GConfClientGetDefaultType) (void); - typedef bool (*GConfClientGetBoolType) (void *client, const gchar *key, - GError **err); - typedef gchar* (*GConfClientGetStringType) (void *client, const gchar *key, - GError **err); - typedef PRInt32 (*GConfClientGetIntType) (void *client, const gchar *key, - GError **err); - typedef GSList* (*GConfClientGetListType) (void *client, const gchar *key, - GConfValueType list_type, - GError **err); - typedef void (*GConfClientNotifyFuncType) (void* client, guint cnxn_id, - void *entry, - gpointer user_data); - typedef guint (*GConfClientNotifyAddType) (void* client, - const gchar* namespace_section, - GConfClientNotifyFuncType func, - gpointer user_data, - GFreeFunc destroy_notify, - GError** err); - typedef void (*GConfClientNotifyRemoveType) (void *client, - guint cnxn); - typedef void (*GConfClientAddDirType) (void *client, - const gchar *dir, - guint8 preload, - GError **err); - typedef void (*GConfClientRemoveDirType) (void *client, - const gchar *dir, - GError **err); - - typedef const char* (*GConfEntryGetKeyType) (const void *entry); - typedef GConfValue* (*GConfEntryGetValueType) (const void *entry); - - typedef const char* (*GConfValueGetStringType) (const GConfValue *value); - typedef PRInt32 (*GConfValueGetIntType) (const GConfValue *value); - typedef bool (*GConfValueGetBoolType) (const GConfValue *value); - - - static void gconf_key_listener (void* client, guint cnxn_id, - void *entry, gpointer user_data); -} - -struct GConfCallbackData -{ - GConfProxy *proxy; - void * userData; - PRUint32 atom; - PRUint32 notifyId; -}; -////////////////////////////////////////////////////////////////////// -// GConPrxoy is a thin wrapper for easy use of gconf funcs. It loads the -// gconf library and initializes the func pointers for later use. -////////////////////////////////////////////////////////////////////// -class GConfProxy -{ -public: - GConfProxy(nsSystemPrefService* aSysPrefService); - ~GConfProxy(); - bool Init(); - - nsresult GetBoolPref(const char *aMozKey, bool *retval); - nsresult GetCharPref(const char *aMozKey, char **retval); - nsresult GetIntPref(const char *aMozKey, PRInt32 *retval); - - nsresult NotifyAdd (PRUint32 aAtom, void *aUserData); - nsresult NotifyRemove (PRUint32 aAtom, const void *aUserData); - - nsresult GetAtomForMozKey(const char *aMozKey, PRUint32 *aAtom) { - return GetAtom(aMozKey, 0, aAtom); - } - const char *GetMozKey(PRUint32 aAtom) { - return GetKey(aAtom, 0); - } - - void OnNotify(void *aClient, void * aEntry, PRUint32 aNotifyId, - GConfCallbackData *aData); - -private: - void *mGConfClient; - PRLibrary *mGConfLib; - bool mInitialized; - nsSystemPrefService *mSysPrefService; - - //listeners - nsAutoVoidArray *mObservers; - - void InitFuncPtrs(); - //gconf public func ptrs - - //gconf client funcs - GConfClientGetDefaultType GConfClientGetDefault; - GConfClientGetBoolType GConfClientGetBool; - GConfClientGetStringType GConfClientGetString; - GConfClientGetIntType GConfClientGetInt; - GConfClientGetListType GConfClientGetList; - GConfClientNotifyAddType GConfClientNotifyAdd; - GConfClientNotifyRemoveType GConfClientNotifyRemove; - GConfClientAddDirType GConfClientAddDir; - GConfClientRemoveDirType GConfClientRemoveDir; - - //gconf entry funcs - GConfEntryGetValueType GConfEntryGetValue; - GConfEntryGetKeyType GConfEntryGetKey; - - //gconf value funcs - GConfValueGetBoolType GConfValueGetBool; - GConfValueGetStringType GConfValueGetString; - GConfValueGetIntType GConfValueGetInt; - - //pref name translating stuff - nsresult GetAtom(const char *aKey, PRUint8 aNameType, PRUint32 *aAtom); - nsresult GetAtomForGConfKey(const char *aGConfKey, PRUint32 *aAtom) \ - {return GetAtom(aGConfKey, 1, aAtom);} - const char *GetKey(PRUint32 aAtom, PRUint8 aNameType); - const char *GetGConfKey(PRUint32 aAtom) \ - {return GetKey(aAtom, 1); } - inline const char *MozKey2GConfKey(const char *aMozKey); - - //const strings - static const char sPrefGConfKey[]; - static const char sDefaultLibName1[]; - static const char sDefaultLibName2[]; -}; - -struct SysPrefCallbackData { - nsISupports *observer; - bool bIsWeakRef; - PRUint32 prefAtom; -}; - -bool -sysPrefDeleteObserver(void *aElement, void *aData) { - SysPrefCallbackData *pElement = - static_cast<SysPrefCallbackData *>(aElement); - NS_RELEASE(pElement->observer); - nsMemory::Free(pElement); - return true; -} - -NS_IMPL_ISUPPORTS2(nsSystemPrefService, nsIPrefBranch, nsIPrefBranch2) - -/* public */ -nsSystemPrefService::nsSystemPrefService() - :mInitialized(false), - mGConf(nsnull), - mObservers(nsnull) -{ -} - -nsSystemPrefService::~nsSystemPrefService() -{ - mInitialized = false; - - delete mGConf; - if (mObservers) { - (void)mObservers->EnumerateForwards(sysPrefDeleteObserver, nsnull); - delete mObservers; - } -} - -nsresult -nsSystemPrefService::Init() -{ - if (!gSysPrefLog) { - gSysPrefLog = PR_NewLogModule("Syspref"); - if (!gSysPrefLog) return NS_ERROR_OUT_OF_MEMORY; - } - - SYSPREF_LOG(("Init SystemPref Service\n")); - if (mInitialized) - return NS_ERROR_FAILURE; - - if (!mGConf) { - mGConf = new GConfProxy(this); - if (!mGConf->Init()) { - delete mGConf; - mGConf = nsnull; - return NS_ERROR_FAILURE; - } - } - - mInitialized = true; - return NS_OK; -} - -/* readonly attribute string root; */ -NS_IMETHODIMP nsSystemPrefService::GetRoot(char * *aRoot) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* long getPrefType (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::GetPrefType(const char *aPrefName, PRInt32 *_retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* boolean getBoolPref (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::GetBoolPref(const char *aPrefName, bool *_retval) -{ - return mInitialized ? - mGConf->GetBoolPref(aPrefName, _retval) : NS_ERROR_FAILURE; -} - -/* void setBoolPref (in string aPrefName, in long aValue); */ -NS_IMETHODIMP nsSystemPrefService::SetBoolPref(const char *aPrefName, bool aValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* string getCharPref (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::GetCharPref(const char *aPrefName, char **_retval) -{ - return mInitialized ? - mGConf->GetCharPref(aPrefName, _retval) : NS_ERROR_FAILURE; -} - -/* void setCharPref (in string aPrefName, in string aValue); */ -NS_IMETHODIMP nsSystemPrefService::SetCharPref(const char *aPrefName, const char *aValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* long getIntPref (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::GetIntPref(const char *aPrefName, PRInt32 *_retval) -{ - return mInitialized ? - mGConf->GetIntPref(aPrefName, _retval) : NS_ERROR_FAILURE; -} - -/* void setIntPref (in string aPrefName, in long aValue); */ -NS_IMETHODIMP nsSystemPrefService::SetIntPref(const char *aPrefName, PRInt32 aValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void getComplexValue (in string aPrefName, in nsIIDRef aType, [iid_is (aType), retval] out nsQIResult aValue); */ -NS_IMETHODIMP nsSystemPrefService::GetComplexValue(const char *aPrefName, const nsIID & aType, void * *aValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void setComplexValue (in string aPrefName, in nsIIDRef aType, in nsISupports aValue); */ -NS_IMETHODIMP nsSystemPrefService::SetComplexValue(const char *aPrefName, const nsIID & aType, nsISupports *aValue) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void clearUserPref (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::ClearUserPref(const char *aPrefName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void lockPref (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::LockPref(const char *aPrefName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* boolean prefHasUserValue (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::PrefHasUserValue(const char *aPrefName, bool *_retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* boolean prefIsLocked (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::PrefIsLocked(const char *aPrefName, bool *_retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void unlockPref (in string aPrefName); */ -NS_IMETHODIMP nsSystemPrefService::UnlockPref(const char *aPrefName) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void deleteBranch (in string aStartingAt); */ -NS_IMETHODIMP nsSystemPrefService::DeleteBranch(const char *aStartingAt) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void getChildList (in string aStartingAt, [optional] out unsigned long aCount, [array, size_is (aCount), retval] out string aChildArray); */ -NS_IMETHODIMP nsSystemPrefService::GetChildList(const char *aStartingAt, PRUint32 *aCount, char ***aChildArray) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void resetBranch (in string aStartingAt); */ -NS_IMETHODIMP nsSystemPrefService::ResetBranch(const char *aStartingAt) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* void addObserver (in string aDomain, in nsIObserver aObserver, in boolean aHoldWeak); */ -NS_IMETHODIMP nsSystemPrefService::AddObserver(const char *aDomain, nsIObserver *aObserver, bool aHoldWeak) -{ - nsresult rv; - - NS_ENSURE_ARG_POINTER(aDomain); - NS_ENSURE_ARG_POINTER(aObserver); - - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - - PRUint32 prefAtom; - // make sure the pref name is supported - rv = mGConf->GetAtomForMozKey(aDomain, &prefAtom); - NS_ENSURE_SUCCESS(rv, rv); - - if (!mObservers) { - mObservers = new nsAutoVoidArray(); - if (mObservers == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - } - - SysPrefCallbackData *pCallbackData = (SysPrefCallbackData *) - nsMemory::Alloc(sizeof(SysPrefCallbackData)); - if (pCallbackData == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - pCallbackData->bIsWeakRef = aHoldWeak; - pCallbackData->prefAtom = prefAtom; - // hold a weak reference to the observer if so requested - nsCOMPtr<nsISupports> observerRef; - if (aHoldWeak) { - nsCOMPtr<nsISupportsWeakReference> weakRefFactory = - do_QueryInterface(aObserver); - if (!weakRefFactory) { - // the caller didn't give us a object that supports weak reference. - // ... tell them - nsMemory::Free(pCallbackData); - return NS_ERROR_INVALID_ARG; - } - nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(weakRefFactory); - observerRef = tmp; - } else { - observerRef = aObserver; - } - - rv = mGConf->NotifyAdd(prefAtom, pCallbackData); - if (NS_FAILED(rv)) { - nsMemory::Free(pCallbackData); - return rv; - } - - pCallbackData->observer = observerRef; - NS_ADDREF(pCallbackData->observer); - - mObservers->AppendElement(pCallbackData); - return NS_OK; -} - -/* void removeObserver (in string aDomain, in nsIObserver aObserver); */ -NS_IMETHODIMP nsSystemPrefService::RemoveObserver(const char *aDomain, nsIObserver *aObserver) -{ - nsresult rv; - - NS_ENSURE_ARG_POINTER(aDomain); - NS_ENSURE_ARG_POINTER(aObserver); - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - - if (!mObservers) - return NS_OK; - - PRUint32 prefAtom; - // make sure the pref name is supported - rv = mGConf->GetAtomForMozKey(aDomain, &prefAtom); - NS_ENSURE_SUCCESS(rv, rv); - - // need to find the index of observer, so we can remove it - PRIntn count = mObservers->Count(); - if (count <= 0) - return NS_OK; - - PRIntn i; - SysPrefCallbackData *pCallbackData; - for (i = 0; i < count; ++i) { - pCallbackData = (SysPrefCallbackData *)mObservers->ElementAt(i); - if (pCallbackData) { - nsCOMPtr<nsISupports> observerRef; - if (pCallbackData->bIsWeakRef) { - nsCOMPtr<nsISupportsWeakReference> weakRefFactory = - do_QueryInterface(aObserver); - if (weakRefFactory) { - nsCOMPtr<nsIWeakReference> tmp = - do_GetWeakReference(aObserver); - observerRef = tmp; - } - } - if (!observerRef) - observerRef = aObserver; - - if (pCallbackData->observer == observerRef && - pCallbackData->prefAtom == prefAtom) { - rv = mGConf->NotifyRemove(prefAtom, pCallbackData); - if (NS_SUCCEEDED(rv)) { - mObservers->RemoveElementAt(i); - NS_RELEASE(pCallbackData->observer); - nsMemory::Free(pCallbackData); - } - return rv; - } - } - } - return NS_OK; -} - -void -nsSystemPrefService::OnPrefChange(PRUint32 aPrefAtom, void *aData) -{ - if (!mInitialized) - return; - - SysPrefCallbackData *pData = (SysPrefCallbackData *)aData; - if (pData->prefAtom != aPrefAtom) - return; - - nsCOMPtr<nsIObserver> observer; - if (pData->bIsWeakRef) { - nsCOMPtr<nsIWeakReference> weakRef = - do_QueryInterface(pData->observer); - if(weakRef) - observer = do_QueryReferent(weakRef); - if (!observer) { - // this weak referenced observer went away, remove it from the list - nsresult rv = mGConf->NotifyRemove(aPrefAtom, pData); - if (NS_SUCCEEDED(rv)) { - mObservers->RemoveElement(pData); - NS_RELEASE(pData->observer); - nsMemory::Free(pData); - } - return; - } - } - else - observer = do_QueryInterface(pData->observer); - - if (observer) - observer->Observe(static_cast<nsIPrefBranch *>(this), - NS_SYSTEMPREF_PREFCHANGE_TOPIC_ID, - NS_ConvertUTF8toUTF16(mGConf->GetMozKey(aPrefAtom)). - get()); -} - -/************************************************************* - * GConfProxy - * - ************************************************************/ - -struct GConfFuncListType { - const char *FuncName; - PRFuncPtr FuncPtr; -}; - -struct PrefNamePair { - const char *mozPrefName; - const char *gconfPrefName; -}; - -const char -GConfProxy::sPrefGConfKey[] = "accessibility.unix.gconf2.shared-library"; -const char GConfProxy::sDefaultLibName1[] = "libgconf-2.so.4"; -const char GConfProxy::sDefaultLibName2[] = "libgconf-2.so"; - -#define GCONF_FUNCS_POINTER_BEGIN \ - static GConfFuncListType sGConfFuncList[] = { -#define GCONF_FUNCS_POINTER_ADD(func_name) \ - {func_name, nsnull}, -#define GCONF_FUNCS_POINTER_END \ - {nsnull, nsnull}, }; - -GCONF_FUNCS_POINTER_BEGIN - GCONF_FUNCS_POINTER_ADD("gconf_client_get_default") // 0 - GCONF_FUNCS_POINTER_ADD("gconf_client_get_bool") // 1 - GCONF_FUNCS_POINTER_ADD("gconf_client_get_string") //2 - GCONF_FUNCS_POINTER_ADD("gconf_client_get_int") //3 - GCONF_FUNCS_POINTER_ADD("gconf_client_notify_add") //4 - GCONF_FUNCS_POINTER_ADD("gconf_client_notify_remove") //5 - GCONF_FUNCS_POINTER_ADD("gconf_client_add_dir") //6 - GCONF_FUNCS_POINTER_ADD("gconf_client_remove_dir") //7 - GCONF_FUNCS_POINTER_ADD("gconf_entry_get_value") //8 - GCONF_FUNCS_POINTER_ADD("gconf_entry_get_key") //9 - GCONF_FUNCS_POINTER_ADD("gconf_value_get_bool") //10 - GCONF_FUNCS_POINTER_ADD("gconf_value_get_string") //11 - GCONF_FUNCS_POINTER_ADD("gconf_value_get_int") //12 - GCONF_FUNCS_POINTER_ADD("gconf_client_get_list") //13 -GCONF_FUNCS_POINTER_END - -///////////////////////////////////////////////////////////////////////////// -// the list is the mapping table, between mozilla prefs and gconf prefs -// It is expected to include all the pref pairs that are related in mozilla -// and gconf. -// -// Note: the prefs listed here are not neccessarily be read from gconf, they -// are the prefs that could be read from gconf. Mozilla has another -// list (see sSysPrefList in nsSystemPref.cpp) that decide which prefs -// are really read. -////////////////////////////////////////////////////////////////////////////// - -static const PrefNamePair sPrefNameMapping[] = { -#include "gconf_pref_list.inc" - {nsnull, nsnull}, -}; - -bool -gconfDeleteObserver(void *aElement, void *aData) { - nsMemory::Free(aElement); - return true; -} - -GConfProxy::GConfProxy(nsSystemPrefService *aSysPrefService): - mGConfClient(nsnull), - mGConfLib(nsnull), - mInitialized(false), - mSysPrefService(aSysPrefService), - mObservers(nsnull) -{ -} - -GConfProxy::~GConfProxy() -{ - if (mGConfClient) - g_object_unref(G_OBJECT(mGConfClient)); - - if (mObservers) { - (void)mObservers->EnumerateForwards(gconfDeleteObserver, nsnull); - delete mObservers; - } - - // bug 379666: can't unload GConf-2 since it registers atexit handlers - //PR_UnloadLibrary(mGConfLib); -} - -bool -GConfProxy::Init() -{ - SYSPREF_LOG(("GConfProxy:: Init GConfProxy\n")); - if (!mSysPrefService) - return false; - if (mInitialized) - return true; - - nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID); - - if (!pref) - return false; - - nsXPIDLCString gconfLibName; - nsresult rv; - - //check if gconf-2 library is given in prefs - rv = pref->GetCharPref(sPrefGConfKey, getter_Copies(gconfLibName)); - if (NS_SUCCEEDED(rv)) { - //use the library name in the preference - SYSPREF_LOG(("GConf library in prefs is %s\n", gconfLibName.get())); - mGConfLib = PR_LoadLibrary(gconfLibName.get()); - } - else { - SYSPREF_LOG(("GConf library not specified in prefs, try the default: " - "%s and %s\n", sDefaultLibName1, sDefaultLibName2)); - mGConfLib = PR_LoadLibrary(sDefaultLibName1); - if (!mGConfLib) - mGConfLib = PR_LoadLibrary(sDefaultLibName2); - } - - if (!mGConfLib) { - SYSPREF_LOG(("Fail to load GConf library\n")); - return false; - } - - //check every func we need in the gconf library - GConfFuncListType *funcList; - PRFuncPtr func; - for (funcList = sGConfFuncList; funcList->FuncName; ++funcList) { - func = PR_FindFunctionSymbol(mGConfLib, funcList->FuncName); - if (!func) { - SYSPREF_LOG(("Check GConf Func Error: %s", funcList->FuncName)); - goto init_failed_unload; - } - funcList->FuncPtr = func; - } - - InitFuncPtrs(); - - mGConfClient = GConfClientGetDefault(); - - // Don't unload past this point, since GConf's initialization of ORBit - // causes atexit handlers to be registered. - - if (!mGConfClient) { - SYSPREF_LOG(("Fail to Get default gconf client\n")); - goto init_failed; - } - mInitialized = true; - return true; - - init_failed_unload: - PR_UnloadLibrary(mGConfLib); - init_failed: - mGConfLib = nsnull; - return false; -} - -nsresult -GConfProxy::GetBoolPref(const char *aMozKey, bool *retval) -{ - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - *retval = GConfClientGetBool(mGConfClient, MozKey2GConfKey(aMozKey), NULL); - return NS_OK; -} - -nsresult -GConfProxy::GetCharPref(const char *aMozKey, char **retval) -{ - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - - const gchar *gconfkey = MozKey2GConfKey(aMozKey); - - if (!strcmp (aMozKey, "network.proxy.no_proxies_on")) { - GSList *s; - nsCString noproxy; - GSList *gslist = GConfClientGetList(mGConfClient, gconfkey, - GCONF_VALUE_STRING, NULL); - - for (s = gslist; s; s = g_slist_next(s)) { - noproxy += (char *)s->data; - noproxy += ", "; - g_free ((char *)s->data); - } - g_slist_free (gslist); - - *retval = PL_strdup(noproxy.get()); - } else { - gchar *str = GConfClientGetString(mGConfClient, gconfkey, NULL); - if (str) { - *retval = PL_strdup(str); - g_free (str); - } - } - - return NS_OK; -} - -nsresult -GConfProxy::GetIntPref(const char *aMozKey, PRInt32 *retval) -{ - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - if (strcmp (aMozKey, "network.proxy.type") == 0) { - gchar *str; - - str = GConfClientGetString(mGConfClient, - MozKey2GConfKey (aMozKey), NULL); - - if (str) { - if (strcmp (str, "manual") == 0) - *retval = 1; - else if (strcmp (str, "auto") == 0) - *retval = 2; - else - *retval = 0; - - g_free (str); - } else - *retval = 0; - } else { - *retval = GConfClientGetInt(mGConfClient, - MozKey2GConfKey(aMozKey), NULL); - } - - return NS_OK; -} - -nsresult -GConfProxy::NotifyAdd (PRUint32 aAtom, void *aUserData) -{ - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - - const char *gconfKey = GetGConfKey(aAtom); - if (!gconfKey) - return NS_ERROR_FAILURE; - - if (!mObservers) { - mObservers = new nsAutoVoidArray(); - if (mObservers == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - } - - GConfCallbackData *pData = (GConfCallbackData *) - nsMemory::Alloc(sizeof(GConfCallbackData)); - NS_ENSURE_TRUE(pData, NS_ERROR_OUT_OF_MEMORY); - - pData->proxy = this; - pData->userData = aUserData; - pData->atom = aAtom; - mObservers->AppendElement(pData); - - GConfClientAddDir(mGConfClient, gconfKey, - 0, // GCONF_CLIENT_PRELOAD_NONE, don't preload anything - NULL); - - pData->notifyId = GConfClientNotifyAdd(mGConfClient, gconfKey, - gconf_key_listener, pData, - NULL, NULL); - return NS_OK; -} - -nsresult -GConfProxy::NotifyRemove (PRUint32 aAtom, const void *aUserData) -{ - NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE); - - PRIntn count = mObservers->Count(); - if (count <= 0) - return NS_OK; - - PRIntn i; - GConfCallbackData *pData; - for (i = 0; i < count; ++i) { - pData = (GConfCallbackData *)mObservers->ElementAt(i); - if (pData && pData->atom == aAtom && pData->userData == aUserData) { - GConfClientNotifyRemove(mGConfClient, pData->notifyId); - GConfClientRemoveDir(mGConfClient, - GetGConfKey(pData->atom), NULL); - mObservers->RemoveElementAt(i); - nsMemory::Free(pData); - break; - } - } - return NS_OK; -} - -void -GConfProxy::InitFuncPtrs() -{ - //gconf client funcs - GConfClientGetDefault = - (GConfClientGetDefaultType) sGConfFuncList[0].FuncPtr; - GConfClientGetBool = - (GConfClientGetBoolType) sGConfFuncList[1].FuncPtr; - GConfClientGetString = - (GConfClientGetStringType) sGConfFuncList[2].FuncPtr; - GConfClientGetInt = - (GConfClientGetIntType) sGConfFuncList[3].FuncPtr; - GConfClientNotifyAdd = - (GConfClientNotifyAddType) sGConfFuncList[4].FuncPtr; - GConfClientNotifyRemove = - (GConfClientNotifyRemoveType) sGConfFuncList[5].FuncPtr; - GConfClientAddDir = - (GConfClientAddDirType) sGConfFuncList[6].FuncPtr; - GConfClientRemoveDir = - (GConfClientRemoveDirType) sGConfFuncList[7].FuncPtr; - - //gconf entry funcs - GConfEntryGetValue = (GConfEntryGetValueType) sGConfFuncList[8].FuncPtr; - GConfEntryGetKey = (GConfEntryGetKeyType) sGConfFuncList[9].FuncPtr; - - //gconf value funcs - GConfValueGetBool = (GConfValueGetBoolType) sGConfFuncList[10].FuncPtr; - GConfValueGetString = (GConfValueGetStringType) sGConfFuncList[11].FuncPtr; - GConfValueGetInt = (GConfValueGetIntType) sGConfFuncList[12].FuncPtr; - - //gconf client list func - GConfClientGetList = - (GConfClientGetListType) sGConfFuncList[13].FuncPtr; -} - -void -GConfProxy::OnNotify(void *aClient, void * aEntry, PRUint32 aNotifyId, - GConfCallbackData *aData) -{ - if (!mInitialized || !aEntry || (mGConfClient != aClient) || !aData) - return; - - if (GConfEntryGetValue(aEntry) == NULL) - return; - - PRUint32 prefAtom; - nsresult rv = GetAtomForGConfKey(GConfEntryGetKey(aEntry), &prefAtom); - if (NS_FAILED(rv)) - return; - - mSysPrefService->OnPrefChange(prefAtom, aData->userData); -} - -nsresult -GConfProxy::GetAtom(const char *aKey, PRUint8 aNameType, PRUint32 *aAtom) -{ - if (!aKey) - return NS_ERROR_FAILURE; - PRUint32 prefSize = sizeof(sPrefNameMapping) / sizeof(sPrefNameMapping[0]); - for (PRUint32 index = 0; index < prefSize; ++index) { - if (!strcmp((aNameType == 0) ? sPrefNameMapping[index].mozPrefName : - sPrefNameMapping[index].gconfPrefName, aKey)) { - *aAtom = index; - return NS_OK; - } - } - return NS_ERROR_FAILURE; -} - -const char * -GConfProxy::GetKey(PRUint32 aAtom, PRUint8 aNameType) -{ - PRUint32 mapSize = sizeof(sPrefNameMapping) / sizeof(sPrefNameMapping[0]); - if (aAtom >= 0 && aAtom < mapSize) - return (aNameType == 0) ? sPrefNameMapping[aAtom].mozPrefName : - sPrefNameMapping[aAtom].gconfPrefName; - return NULL; -} - -inline const char * -GConfProxy::MozKey2GConfKey(const char *aMozKey) -{ - PRUint32 atom; - nsresult rv = GetAtomForMozKey(aMozKey, &atom); - if (NS_SUCCEEDED(rv)) - return GetGConfKey(atom); - return NULL; -} - -/* static */ -void gconf_key_listener (void* client, guint cnxn_id, - void *entry, gpointer user_data) -{ - SYSPREF_LOG(("...SYSPREF_LOG...key listener get called \n")); - if (!user_data) - return; - GConfCallbackData *pData = reinterpret_cast<GConfCallbackData *> - (user_data); - pData->proxy->OnNotify(client, entry, cnxn_id, pData); -}
deleted file mode 100644 --- a/extensions/pref/system-pref/src/gconf/nsSystemPrefService.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2003 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __SYSTEM_PREF_SERVICE_H__ -#define __SYSTEM_PREF_SERVICE_H__ - -#include "prlink.h" -#include "nsVoidArray.h" -#include "nsWeakPtr.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranch2.h" - -class GConfProxy; - -//////////////////////////////////////////////////////////////////////////// -// nsSystemPrefService provide a interface for read system prefs. It is -// platform related. This directory (system-pref/gconf) impls it for gconf -// on the gconf platform. -//////////////////////////////////////////////////////////////////////////// - -class nsSystemPrefService : public nsIPrefBranch2 -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIPREFBRANCH - NS_DECL_NSIPREFBRANCH2 - - nsSystemPrefService(); - virtual ~nsSystemPrefService(); - nsresult Init(); - - void OnPrefChange(PRUint32 aPrefAtom, void *aData); - -private: - bool mInitialized; - GConfProxy *mGConf; - - //listeners - nsAutoVoidArray *mObservers; -}; - -#define NS_SYSTEMPREF_SERVICE_CID \ - { /* {94f1de09-d0e5-4ca8-94c2-98b049316b7f} */ \ - 0x94f1de09, \ - 0xd0e5, \ - 0x4ca8, \ - { 0x94, 0xc2, 0x98, 0xb0, 0x49, 0x31, 0x6b, 0x7f } \ - } - -#define NS_SYSTEMPREF_SERVICE_CONTRACTID "@mozilla.org/system-preference-service;1" -#define NS_SYSTEMPREF_SERVICE_CLASSNAME "System Preferences Service" - -#define NS_SYSTEMPREF_PREFCHANGE_TOPIC_ID "nsSystemPrefService:pref-changed" - -#endif /* __SYSTEM_PREF_SERVICE_H__ */
deleted file mode 100644 --- a/extensions/pref/system-pref/src/nsSystemPref.cpp +++ /dev/null @@ -1,474 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2003 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsSystemPref.h" -#include "nsIObserverService.h" - -#include "nsSystemPrefLog.h" -#include "nsSystemPrefService.h" -#include "nsString.h" - -const char sSysPrefString[] = "config.use_system_prefs"; -union MozPrefValue { - char * stringVal; - PRInt32 intVal; - bool boolVal; -}; - -struct SysPrefItem { - const char *prefName; // mozilla pref string name - MozPrefValue defaultValue; // store the mozilla default value - bool isLocked; // store the mozilla lock status - SysPrefItem() { - prefName = nsnull; - defaultValue.intVal = 0; - defaultValue.stringVal = nsnull; - defaultValue.boolVal = false; - isLocked = false; - } - void SetPrefName(const char *aPrefName) { - prefName = aPrefName; - } -}; - -// all prefs that mozilla need to read from host system if they are available -static const char *sSysPrefList[] = { - "network.proxy.http", - "network.proxy.http_port", - "network.proxy.ftp", - "network.proxy.ftp_port", - "network.proxy.ssl", - "network.proxy.ssl_port", - "network.proxy.socks", - "network.proxy.socks_port", - "network.proxy.no_proxies_on", - "network.proxy.autoconfig_url", - "network.proxy.type", - "config.use_system_prefs.accessibility", -}; - -PRLogModuleInfo *gSysPrefLog = NULL; - -NS_IMPL_ISUPPORTS2(nsSystemPref, nsIObserver, nsISupportsWeakReference) - -nsSystemPref::nsSystemPref(): - mSysPrefService(nsnull), - mEnabled(false), - mSysPrefs(nsnull) -{ -} - -nsSystemPref::~nsSystemPref() -{ - mSysPrefService = nsnull; - mEnabled = false; - delete [] mSysPrefs; -} - -/////////////////////////////////////////////////////////////////////////////// -// nsSystemPref::Init -// Setup log and listen on NS_PREFSERVICE_READ_TOPIC_ID from pref service -/////////////////////////////////////////////////////////////////////////////// -nsresult -nsSystemPref::Init(void) -{ - nsresult rv; - - if (!gSysPrefLog) { - gSysPrefLog = PR_NewLogModule("Syspref"); - if (!gSysPrefLog) - return NS_ERROR_OUT_OF_MEMORY; - } - - nsCOMPtr<nsIObserverService> observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - - if (observerService) { - rv = observerService->AddObserver(this, NS_PREFSERVICE_READ_TOPIC_ID, - false); - rv = observerService->AddObserver(this, "profile-before-change", - false); - SYSPREF_LOG(("Add Observer for %s\n", NS_PREFSERVICE_READ_TOPIC_ID)); - } - return(rv); -} - -/////////////////////////////////////////////////////////////////////////////// -// nsSystemPref::Observe -// Observe notifications from mozilla pref system and system prefs (if enabled) -/////////////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP -nsSystemPref::Observe(nsISupports *aSubject, - const char *aTopic, - const PRUnichar *aData) -{ - nsresult rv = NS_OK; - - if (!aTopic) - return NS_OK; - - // if we are notified by pref service - // check the system pref settings - if (!nsCRT::strcmp(aTopic, NS_PREFSERVICE_READ_TOPIC_ID)) { - SYSPREF_LOG(("Observed: %s\n", aTopic)); - - nsCOMPtr<nsIPrefBranch2> prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - - rv = prefBranch->GetBoolPref(sSysPrefString, &mEnabled); - if (NS_FAILED(rv)) { - SYSPREF_LOG(("...FAil to Get %s\n", sSysPrefString)); - return rv; - } - - // if there is no system pref service, assume nothing happen to us - mSysPrefService = do_GetService(NS_SYSTEMPREF_SERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv) || !mSysPrefService) { - SYSPREF_LOG(("...No System Pref Service\n")); - return NS_OK; - } - - // listen on its changes - rv = prefBranch->AddObserver(sSysPrefString, this, true); - if (NS_FAILED(rv)) { - SYSPREF_LOG(("...FAil to add observer for %s\n", sSysPrefString)); - return rv; - } - - if (!mEnabled) { - SYSPREF_LOG(("%s is disabled\n", sSysPrefString)); - return NS_OK; - } - SYSPREF_LOG(("%s is enabled\n", sSysPrefString)); - rv = UseSystemPrefs(); - - } - // sSysPrefString value was changed, update ... - else if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && - NS_ConvertUTF8toUTF16(sSysPrefString).Equals(aData)) { - SYSPREF_LOG(("++++++ Notify: topic=%s data=%s\n", - aTopic, NS_ConvertUTF16toUTF8(aData).get())); - - nsCOMPtr<nsIPrefBranch> prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - - bool enabled = mEnabled; - rv = prefBranch->GetBoolPref(sSysPrefString, &mEnabled); - if (enabled != mEnabled) { - if (mEnabled) - //read prefs from system - rv = UseSystemPrefs(); - else - //roll back to mozilla prefs - rv = UseMozillaPrefs(); - } - } - - // if the system pref notify us that some pref has been changed by user - // outside mozilla. We need to read it again. - else if (!nsCRT::strcmp(aTopic, NS_SYSTEMPREF_PREFCHANGE_TOPIC_ID) && - aData) { - NS_ASSERTION(mEnabled, "Should not listen when disabled"); - SYSPREF_LOG(("====== System Pref Notify topic=%s data=%s\n", - aTopic, (char*)aData)); - rv = ReadSystemPref(NS_LossyConvertUTF16toASCII(aData).get()); - return NS_OK; - } else if (!nsCRT::strcmp(aTopic,"profile-before-change")) { - //roll back to mozilla prefs - if (mEnabled) - UseMozillaPrefs(); - mEnabled = false; - mSysPrefService = nsnull; - delete [] mSysPrefs; - mSysPrefs = nsnull; - } else - SYSPREF_LOG(("Not needed topic Received %s\n", aTopic)); - return rv; -} - -/* private */ - -//////////////////////////////////////////////////////////////// -// nsSystemPref::UseSystemPrefs -// Read all the prefs in the table from system, listen for their -// changes in system pref service. -//////////////////////////////////////////////////////////////// -nsresult -nsSystemPref::UseSystemPrefs() -{ - SYSPREF_LOG(("\n====Now Use system prefs==\n")); - nsresult rv = NS_OK; - if (!mSysPrefService) { - return NS_ERROR_FAILURE; - } - - PRIntn sysPrefCount= sizeof(sSysPrefList) / sizeof(sSysPrefList[0]); - - if (!mSysPrefs) { - mSysPrefs = new SysPrefItem[sysPrefCount]; - if (!mSysPrefs) - return NS_ERROR_OUT_OF_MEMORY; - for (PRIntn index = 0; index < sysPrefCount; ++index) - mSysPrefs[index].SetPrefName(sSysPrefList[index]); - } - - for (PRIntn index = 0; index < sysPrefCount; ++index) { - // save mozilla prefs - SaveMozDefaultPref(mSysPrefs[index].prefName, - &mSysPrefs[index].defaultValue, - &mSysPrefs[index].isLocked); - - // get the system prefs - ReadSystemPref(mSysPrefs[index].prefName); - SYSPREF_LOG(("Add Listener on %s\n", mSysPrefs[index].prefName)); - mSysPrefService->AddObserver(mSysPrefs[index].prefName, - this, true); - } - return rv; -} - -////////////////////////////////////////////////////////////////////// -// nsSystemPref::ReadSystemPref -// Read a pref value from system pref service, and lock it in mozilla. -////////////////////////////////////////////////////////////////////// -nsresult -nsSystemPref::ReadSystemPref(const char *aPrefName) -{ - if (!mSysPrefService) - return NS_ERROR_FAILURE; - nsresult rv; - - nsCOMPtr<nsIPrefBranch> prefBranch - (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) - return rv; - - SYSPREF_LOG(("about to read aPrefName %s\n", aPrefName)); - - prefBranch->UnlockPref(aPrefName); - - PRInt32 prefType = nsIPrefBranch::PREF_INVALID; - nsXPIDLCString strValue; - PRInt32 intValue = 0; - bool boolValue = false; - - rv = prefBranch->GetPrefType(aPrefName, &prefType); - if (NS_FAILED(rv)) - return rv; - switch (prefType) { - case nsIPrefBranch::PREF_STRING: - mSysPrefService->GetCharPref(aPrefName, getter_Copies(strValue)); - SYSPREF_LOG(("system value is %s\n", strValue.get())); - - prefBranch->SetCharPref(aPrefName, strValue.get()); - break; - case nsIPrefBranch::PREF_INT: - mSysPrefService->GetIntPref(aPrefName, &intValue); - SYSPREF_LOG(("system value is %d\n", intValue)); - - prefBranch->SetIntPref(aPrefName, intValue); - break; - case nsIPrefBranch::PREF_BOOL: - mSysPrefService->GetBoolPref(aPrefName, &boolValue); - SYSPREF_LOG(("system value is %s\n", boolValue ? "TRUE" : "FALSE")); - - prefBranch->SetBoolPref(aPrefName, boolValue); - break; - default: - SYSPREF_LOG(("Fail to system value for it\n")); - return NS_ERROR_FAILURE; - } - prefBranch->LockPref(aPrefName); - return NS_OK; -} - -////////////////////////////////////////////////////////////////////// -// nsSystemPref::UseMozillaPrefs -// Restore mozilla default prefs, remove system pref listeners -///////////////////////////////////////////////////////////////////// -nsresult -nsSystemPref::UseMozillaPrefs() -{ - nsresult rv = NS_OK; - SYSPREF_LOG(("\n====Now rollback to Mozilla prefs==\n")); - - // if we did not use system prefs, do nothing - if (!mSysPrefService) - return NS_OK; - - PRIntn sysPrefCount= sizeof(sSysPrefList) / sizeof(sSysPrefList[0]); - for (PRIntn index = 0; index < sysPrefCount; ++index) { - // restore mozilla default value and free string memory if needed - RestoreMozDefaultPref(mSysPrefs[index].prefName, - &mSysPrefs[index].defaultValue, - mSysPrefs[index].isLocked); - SYSPREF_LOG(("stop listening on %s\n", mSysPrefs[index].prefName)); - mSysPrefService->RemoveObserver(mSysPrefs[index].prefName, - this); - } - return rv; -} - -//////////////////////////////////////////////////////////////////////////// -// nsSystemPref::RestoreMozDefaultPref -// Save the saved mozilla default value. -// It is also responsible for allocate the string memory when needed, because -// this method know what type of value is stored. -///////////////////////////////////////////////////////////////////////////// -nsresult -nsSystemPref::SaveMozDefaultPref(const char *aPrefName, - MozPrefValue *aPrefValue, - bool *aLocked) -{ - NS_ENSURE_ARG_POINTER(aPrefName); - NS_ENSURE_ARG_POINTER(aPrefValue); - NS_ENSURE_ARG_POINTER(aLocked); - - nsresult rv; - - nsCOMPtr<nsIPrefBranch> prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - - SYSPREF_LOG(("Save Mozilla value for %s\n", aPrefName)); - - PRInt32 prefType = nsIPrefBranch::PREF_INVALID; - nsXPIDLCString strValue; - - rv = prefBranch->GetPrefType(aPrefName, &prefType); - if (NS_FAILED(rv)) - return rv; - switch (prefType) { - case nsIPrefBranch::PREF_STRING: - prefBranch->GetCharPref(aPrefName, - getter_Copies(strValue)); - SYSPREF_LOG(("Mozilla value is %s", strValue.get())); - - if (aPrefValue->stringVal) - PL_strfree(aPrefValue->stringVal); - aPrefValue->stringVal = PL_strdup(strValue.get()); - break; - case nsIPrefBranch::PREF_INT: - prefBranch->GetIntPref(aPrefName, &aPrefValue->intVal); - SYSPREF_LOG(("Mozilla value is %d\n", aPrefValue->intVal)); - - break; - case nsIPrefBranch::PREF_BOOL: - prefBranch->GetBoolPref(aPrefName, &aPrefValue->boolVal); - SYSPREF_LOG(("Mozilla value is %s\n", - aPrefValue->boolVal ? "TRUE" : "FALSE")); - - break; - default: - SYSPREF_LOG(("Fail to Read Mozilla value for it\n")); - return NS_ERROR_FAILURE; - } - rv = prefBranch->PrefIsLocked(aPrefName, aLocked); - SYSPREF_LOG((" (%s).\n", aLocked ? "Locked" : "NOT Locked")); - return rv; -} - -//////////////////////////////////////////////////////////////////////////// -// nsSystemPref::RestoreMozDefaultPref -// Restore the saved mozilla default value to pref service. -// It is also responsible for free the string memory when needed, because -// this method know what type of value is stored. -///////////////////////////////////////////////////////////////////////////// -nsresult -nsSystemPref::RestoreMozDefaultPref(const char *aPrefName, - MozPrefValue *aPrefValue, - bool aLocked) -{ - NS_ENSURE_ARG_POINTER(aPrefName); - - nsresult rv; - - nsCOMPtr<nsIPrefBranch> prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - - SYSPREF_LOG(("Restore Mozilla value for %s\n", aPrefName)); - - PRInt32 prefType = nsIPrefBranch::PREF_INVALID; - rv = prefBranch->GetPrefType(aPrefName, &prefType); - if (NS_FAILED(rv)) - return rv; - - // unlock, if it is locked - prefBranch->UnlockPref(aPrefName); - - switch (prefType) { - case nsIPrefBranch::PREF_STRING: - prefBranch->SetCharPref(aPrefName, - aPrefValue->stringVal); - SYSPREF_LOG(("Mozilla value is %s\n", aPrefValue->stringVal)); - - PL_strfree(aPrefValue->stringVal); - aPrefValue->stringVal = nsnull; - - break; - case nsIPrefBranch::PREF_INT: - prefBranch->SetIntPref(aPrefName, aPrefValue->intVal); - SYSPREF_LOG(("Mozilla value is %d\n", aPrefValue->intVal)); - - break; - case nsIPrefBranch::PREF_BOOL: - prefBranch->SetBoolPref(aPrefName, aPrefValue->boolVal); - SYSPREF_LOG(("Mozilla value is %s\n", - aPrefValue->boolVal ? "TRUE" : "FALSE")); - - break; - default: - SYSPREF_LOG(("Fail to Restore Mozilla value for it\n")); - return NS_ERROR_FAILURE; - } - - // restore its old lock status - if (aLocked) - prefBranch->LockPref(aPrefName); - return NS_OK; -}
deleted file mode 100644 --- a/extensions/pref/system-pref/src/nsSystemPref.h +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2003 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __SYSTEM_PREF_H__ -#define __SYSTEM_PREF_H__ - -#include "nsCOMPtr.h" -#include "nsXPCOM.h" -#include "nsCRT.h" -#include "nsIAppStartupNotifier.h" -#include "nsICategoryManager.h" -#include "nsIServiceManager.h" -#include "nsWeakReference.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch2.h" - -#include <nsIObserver.h> - -union MozPrefValue; -struct SysPrefItem; - -////////////////////////////////////////////////////////////////////////// -// -// nsSystemPref, as an extension of mozilla pref service, reads some mozilla -// prefs from host system when the feature is enabled ("config.system-pref"). -// -// nsSystemPref listens on NS_PREFSERVICE_READ_TOPIC_ID. When notified, -// nsSystemPref will start the nsSystemPrefService (platform specific) to -// read all the interested prefs (listed in sSysPrefList table) from system -// and lock these prefs from user's modification. -// -// This feature will make mozilla integrated better into host platforms. If -// users want to change the prefs read from system, the system provided pref -// editor (i.e. gconf-editor in gnome) should be used. -////////////////////////////////////////////////////////////////////////// - -class nsSystemPref : public nsIObserver, - public nsSupportsWeakReference -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - - nsSystemPref(); - virtual ~nsSystemPref(); - nsresult Init(void); - -private: - // funcs used to load system prefs and save mozilla default prefs - nsresult UseSystemPrefs(); - nsresult ReadSystemPref(const char *aPrefName); - nsresult SaveMozDefaultPref(const char *aPrefName, - MozPrefValue *aPrefVal, - bool *aLocked); - - // funcs used to load mozilla default prefs - nsresult UseMozillaPrefs(); - nsresult RestoreMozDefaultPref(const char *aPrefName, - MozPrefValue *aPrefVal, - bool aLocked); - - nsCOMPtr<nsIPrefBranch2> mSysPrefService; - bool mEnabled; // system pref is enabled or not - SysPrefItem *mSysPrefs; -}; - -#define NS_SYSTEMPREF_CID \ - { /* {549abb24-7c9d-4aba-915e-7ce0b716b32f} */ \ - 0x549abb24, \ - 0x7c9d, \ - 0x4aba, \ - { 0x91, 0x5e, 0x7c, 0xe0, 0xb7, 0x16, 0xb3, 0x2f } \ - } - -#define NS_SYSTEMPREF_CONTRACTID "@mozilla.org/system-preferences;1" -#define NS_SYSTEMPREF_CLASSNAME "System Preferences" - -#endif /* __SYSTEM_PREF_H__ */
deleted file mode 100644 --- a/extensions/pref/system-pref/src/nsSystemPrefFactory.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2003 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsICategoryManager.h" -#include "mozilla/ModuleUtils.h" -#include "nsSystemPref.h" -#include "nsSystemPrefService.h" - -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemPref, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemPrefService, Init) - -NS_DEFINE_NAMED_CID(NS_SYSTEMPREF_CID); -NS_DEFINE_NAMED_CID(NS_SYSTEMPREF_SERVICE_CID); - -static const mozilla::Module::CIDEntry kSysPrefCIDs[] = { - { &kNS_SYSTEMPREF_CID, false, NULL, nsSystemPrefConstructor }, - { &kNS_SYSTEMPREF_SERVICE_CID, false, NULL, nsSystemPrefServiceConstructor }, - { NULL } -}; - -static const mozilla::Module::ContractIDEntry kSysPrefContracts[] = { - { NS_SYSTEMPREF_CONTRACTID, &kNS_SYSTEMPREF_CID }, - { NS_SYSTEMPREF_SERVICE_CONTRACTID, &kNS_SYSTEMPREF_SERVICE_CID }, - { NULL } -}; - -static const mozilla::Module::CategoryEntry kSysPrefCategories[] = { - { APPSTARTUP_CATEGORY, "SystemPref Module", NS_SYSTEMPREF_CONTRACTID }, - { NULL } -}; - -static const mozilla::Module kSysPrefModule = { - mozilla::Module::kVersion, - kSysPrefCIDs, - kSysPrefContracts, - kSysPrefCategories -}; - -NSMODULE_DEFN(nsSystemPrefModule) = &kSysPrefModule;
deleted file mode 100644 --- a/extensions/pref/system-pref/src/nsSystemPrefLog.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2003 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "prlog.h" - -extern PRLogModuleInfo *gSysPrefLog; -#define SYSPREF_LOG(args) PR_LOG(gSysPrefLog, PR_LOG_DEBUG, args)
--- a/toolkit/library/Makefile.in +++ b/toolkit/library/Makefile.in @@ -283,19 +283,16 @@ COMPONENT_LIBS += \ tkautocomplete \ satchel \ pippki \ $(NULL) endif ifdef MOZ_ENABLE_GTK2 COMPONENT_LIBS += widget_gtk2 -ifdef MOZ_PREF_EXTENSIONS -COMPONENT_LIBS += system-pref -endif endif ifdef MOZ_ENABLE_GTK2 ifdef MOZ_X11 STATIC_LIBS += gtkxtbin endif endif
--- a/toolkit/library/nsStaticXULComponents.cpp +++ b/toolkit/library/nsStaticXULComponents.cpp @@ -99,17 +99,16 @@ #define XREMOTE_MODULES MODULE(RemoteServiceModule) #else #define XREMOTE_MODULES #endif #ifdef MOZ_PREF_EXTENSIONS #ifdef MOZ_ENABLE_GTK2 #define SYSTEMPREF_MODULES \ - MODULE(nsSystemPrefModule) \ MODULE(nsAutoConfigModule) #else #define SYSTEMPREF_MODULES MODULE(nsAutoConfigModule) #endif #else #define SYSTEMPREF_MODULES #endif