I am writing an extension that opens new tabs and I need to save the value of a var in the current tab, such that it will exist even if the user restarts Firefox. How can I do this?
views:
45answers:
1
+1
A:
Use nsIPrefService and nsIPrefBranch.
Something like:
// Get pref service.
nsresult rv;
nsCOMPtr<nsIPrefService> service(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, false);
// Get your extensions branch.
nsCOMPtr<nsIPrefBranch> branch;
service->GetBranch("extensions.YOUREXTENSION.", getter_AddRefs(branch));
NS_ENSURE_SUCCESS(rv, false);
Then you can use GetCharPref() and SetCharPref().
// Get value
char *buf = nsnull;
rv = branch->GetCharPref("YOURPREF", &buf);
To clear a pref, I suspect you would use clearUserPref().
jeffamaphone
2009-08-20 16:15:12
Ok, thanks. And how to remove saved pref?
2009-08-20 16:22:38
Use ClearUserPref()?
jeffamaphone
2009-08-20 16:58:12