Closed
Bug 271894
Opened 20 years ago
Closed 19 years ago
nsIPrefBranchInternal.addObserver requires the entire pref name
Categories
(Core :: Preferences: Backend, defect)
Core
Preferences: Backend
Tracking
()
RESOLVED
EXPIRED
People
(Reporter: clubstew, Unassigned)
Details
Attachments
(1 file)
1.40 KB,
application/vnd.mozilla.xul+xml
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 When getting or setting preferences you can request a certain branch using nsIPrefService.getBranch and request a certain "tree" by which all access to preferences are scoped from that "tree". When using nsIPrefBranchInternal.addObserver with such a scope (having passed something other than nsnull or an empty string to getBranch) the observer is not notified (i.e., observe is not called). Reproducible: Always Steps to Reproduce: 1. Request a particular branch of preferences: const prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService).getBranch("browser."); 2. QI for the nsIPrefBranchInternal interface. const branch = prefService.QueryInterface( Components.interfaces.nsIPrefBranchInternal); 3. Add an observer for a preference under the "browser." tree. branch.addObserver("active_color", prefObserver, false); 4. Define a prefObserver object with the observe method to handle the notification and simply alert the user. var prefObserver = { observe: function(subject, topic, data) { alert(topic + ": " + data); } } Actual Results: Nothing happened. The alert window is never displayed. Expected Results: The alert window should be displayed with the correct topic and data. The workaround is to not request a particular branch, passing either null or an empty string. Call addObserver with the entire preference name as the first parameter and the observer is notified.
Reporter | ||
Comment 1•20 years ago
|
||
Install this into chrome. I personally keep an "example" directory with its "content" sub-directory set as the base path for an "example" package registered with "chrome.rdf" in the "chrome" directory of my user profile. This displays two labels, one watching for a change as documented by this bug, the other watching for a chance to an entire preference name.
Comment 2•20 years ago
|
||
The prefbranch has a root string set. This makes it not a simple copy of the prefservice, but a new thing. If there are no pointers to this new thing, it goes away. And if it is away, there is nothing that has the observers registered. So the other workaround is to keep a global pointer to the prefbranch.
Comment 3•20 years ago
|
||
The summary is incorrect, since the prefbranch does resolve the pref name correctly; see http://lxr.mozilla.org/seamonkey/source/modules/libpref/src/nsPrefBranch.cpp#648 So the only issue is that there is that the prefbranch goes away here, so can't really notify any observers.
Comment 4•19 years ago
|
||
This is an automated message, with ID "auto-resolve01". This bug has had no comments for a long time. Statistically, we have found that bug reports that have not been confirmed by a second user after three months are highly unlikely to be the source of a fix to the code. While your input is very important to us, our resources are limited and so we are asking for your help in focussing our efforts. If you can still reproduce this problem in the latest version of the product (see below for how to obtain a copy) or, for feature requests, if it's not present in the latest version and you still believe we should implement it, please visit the URL of this bug (given at the top of this mail) and add a comment to that effect, giving more reproduction information if you have it. If it is not a problem any longer, you need take no action. If this bug is not changed in any way in the next two weeks, it will be automatically resolved. Thank you for your help in this matter. The latest beta releases can be obtained from: Firefox: http://www.mozilla.org/projects/firefox/ Thunderbird: http://www.mozilla.org/products/thunderbird/releases/1.5beta1.html Seamonkey: http://www.mozilla.org/projects/seamonkey/
Comment 5•19 years ago
|
||
This bug has been automatically resolved after a period of inactivity (see above comment). If anyone thinks this is incorrect, they should feel free to reopen it.
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → EXPIRED
You need to log in
before you can comment on or make changes to this bug.
Description
•