Bug 616414: Notify content processes when a pref has been cleared. r=dwitte

This commit is contained in:
Chris Jones 2011-01-05 22:54:47 -06:00
parent 90a196eb79
commit 76417aec7b
6 changed files with 46 additions and 6 deletions

View File

@ -492,6 +492,18 @@ ContentChild::RecvPreferenceUpdate(const PrefTuple& aPref)
return true;
}
bool
ContentChild::RecvClearUserPreference(const nsCString& aPrefName)
{
nsCOMPtr<nsIPrefServiceInternal> prefs = do_GetService("@mozilla.org/preferences-service;1");
if (!prefs)
return false;
prefs->ClearContentPref(aPrefName);
return true;
}
bool
ContentChild::RecvNotifyAlertsObserver(const nsCString& aType, const nsString& aData)
{

View File

@ -118,6 +118,7 @@ public:
nsresult AddRemoteAlertObserver(const nsString& aData, nsIObserver* aObserver);
virtual bool RecvPreferenceUpdate(const PrefTuple& aPref);
virtual bool RecvClearUserPreference(const nsCString& aPrefName);
virtual bool RecvNotifyAlertsObserver(const nsCString& aType, const nsString& aData);

View File

@ -372,14 +372,26 @@ ContentParent::Observe(nsISupports* aSubject,
// We know prefs are ASCII here.
NS_LossyConvertUTF16toASCII strData(aData);
PrefTuple pref;
nsCOMPtr<nsIPrefServiceInternal> prefService =
do_GetService("@mozilla.org/preferences-service;1");
prefService->MirrorPreference(strData, &pref);
if (!SendPreferenceUpdate(pref))
return NS_ERROR_NOT_AVAILABLE;
PRBool prefHasValue;
prefService->PrefHasUserValue(strData, &prefHasValue);
if (prefHasValue) {
// Pref was created, or previously existed and its value
// changed.
PrefTuple pref;
nsresult rv = prefService->MirrorPreference(strData, &pref);
NS_ASSERTION(NS_SUCCEEDED(rv), "Pref has value but can't mirror?");
if (!SendPreferenceUpdate(pref)) {
return NS_ERROR_NOT_AVAILABLE;
}
} else {
// Pref wasn't found. It was probably removed.
if (!SendClearUserPreference(strData)) {
return NS_ERROR_NOT_AVAILABLE;
}
}
}
else if (!strcmp(aTopic, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC)) {
NS_ConvertUTF16toUTF8 dataStr(aData);

View File

@ -104,6 +104,7 @@ child:
async NotifyVisited(URI uri);
PreferenceUpdate(PrefTuple pref);
ClearUserPreference(nsCString prefName);
NotifyAlertsObserver(nsCString topic, nsString data);

View File

@ -163,7 +163,7 @@ interface nsIPrefService : nsISupports
};
[scriptable, uuid(37577836-e3fc-4a5e-b5d1-92a17fe0e7f7)]
[scriptable, uuid(08c8cd2f-8345-45ee-938d-37ee6d3661b2)]
interface nsIPrefServiceInternal : nsISupports
{
/**
@ -181,7 +181,9 @@ interface nsIPrefServiceInternal : nsISupports
[noscript] void mirrorPreferences(in nsPreferencesArrayPtr aArray);
[noscript] void mirrorPreference(in ACString aPrefName, in nsPreferencePtr aPref);
[noscript] boolean prefHasUserValue(in ACString aPrefName);
[noscript] void setPreference(in nsPreferencePtrConst aPref);
[noscript] void clearContentPref(in ACString aPrefName);
};
%{C++

View File

@ -350,11 +350,23 @@ NS_IMETHODIMP nsPrefService::ReadExtensionPrefs(nsILocalFile *aFile)
return rv;
}
NS_IMETHODIMP nsPrefService::PrefHasUserValue(const nsACString& aPrefName,
PRBool* aHasValue)
{
*aHasValue = PREF_HasUserPref(aPrefName.BeginReading());
return NS_OK;
}
NS_IMETHODIMP nsPrefService::SetPreference(const PrefTuple *aPref)
{
return pref_SetPrefTuple(*aPref, PR_TRUE);
}
NS_IMETHODIMP nsPrefService::ClearContentPref(const nsACString& aPrefName)
{
return PREF_ClearUserPref(aPrefName.BeginReading());
}
NS_IMETHODIMP nsPrefService::MirrorPreference(const nsACString& aPrefName,
PrefTuple *aPref)
{