How does "about:config" work?
I have a question related to using "about:config" to view preferences in firefox.
If I type "about:config" into firefox location bar, it displays a list of preferences. Even though the list is quite long, it seems incomplete. I noticed that some preferences are stored in sqlite database. And developers from IRC channel told me that those preferences without default values are left out as well.
I guess my question is that how exactly does "about:config" work? Does it read preferences from a file/a couple of files (preferences are statically hard-coded)? Or call some functions to dynamically concatenate strings to generate preferences (preferences are dynamically generated)? Or some other mechanisms? In addition, if I want to study the source code of "about:config", where (which file, which function) should I look at? Thanks!
-Dongpu
All Replies (11)
ideato দ্বারা পরিমিত
Hi, I read through both links. They seem helpful at explaining the meaning of various preferences, but not exactly about how does "about:config" work. What I am actually interested in is whether "about:config" reads statically hard-coded preferences from a file/files or it dynamic generates preferences.
Also, I have another question regarding to the second link. In the article, it states that some preferences are not in "about:config" and users have to manually add it, such as "browser.cache.memory.capacity". I am wondering how to determine the name of a preference that is not in "about:config" but do actually exist? Thanks!
-Dongpu
As far as I know preferences are loaded from javascript files. On startup Firefox looks for a numer of *.js files and also scans some directories for the contents of *.js files. These directories can be on disk or in the omni.jar container. The file prefs.js contains all values of prefs that have a user-defined value. Default values are not saved on disk. On startup the contents of pref.js is executed as javascipt and this loads the user-defined values. When Firefoxs exits, it writes the user-defined values back to the prefs.js file as lines of javascript code. This is why you should not modify the prefs.js file while Firefox is running.
See http://mxr.mozilla.org/mozilla-central/source/modules/libpref/src/Preferences.cpp#966
There are also prefs that are hidden by default and need to be created manually with a user set value to have their effect.
Such prefs won't show on the about:config page until they are created manually by you.
Some examples of prefs that do not exist by default and need to be created to have values other than the default.
Hi knorretje, you mentioned that the preference files are executed as javascript on at firefox startup. I saw there are two functions "pref()" and "user_pref()" are mainly used. I am curious about those two functions. Do you know where are the definitions of "pref()" and "user_pref()". Thanks!
Hi cor-el, I am little bit confused why there are preferences that don't exist by default. What will happen if the preference didn't get created by user manually, but firefox still trying to access it. For example, I think it is possible for firefox to try to access "ui.SpellCheckerUnderline" before user manually insert it into "about:config". How does firefox treat non-exist preferences differently than those that are already exist? Which part of the source code should I focus on in order to spot the differences? Thanks!
Hello jindongpu,
I am sorry that I do not know all the details. But I found this page, which seems to indicate that the source of the about:config page is in
chrome://global/content/config.xul
http://mxr.mozilla.org/mozilla-central/source/docshell/base/nsAboutRedirector.cpp
See also:
- view-source:chrome://global/content/config.js
- http://mxr.mozilla.org/mozilla-release/source/toolkit/components/viewconfig/content/config.js
- http://mxr.mozilla.org/mozilla-release/source/extensions/pref/autoconfig/src/prefcalls.js
cor-el দ্বারা পরিমিত
Hi cor-el, thanks for the links. They are really helpful!
I am glad that I found the method definitions for "pref()", "defaultPref()", and "lockPref()" in prefcall.js file. However, I didn't see the method definition for "user_pref()", which is heavily used in the user preference file prefs.js under the profile folder. Do you know why the definition for "user_pref()" is missing? Or it is located somewhere else? Thanks!
Actually is the prefcalls.js file only used to read mozilla.cfg on startup to redefine or lock prefs.
You can look at his file instead:
See also:
Hi cor-el, thanks for the links! I looked at prefread.cpp. It seems to be the parser that parses the prefs.js and other default preferences file using some kind of state machine. It changes its state depending on the current character.
Since the parser scans through the file char by char, I am not sure why the preference files are stored as Javascript files. Isn't a simple plain ASCII file with key-value pair much easier to parse? Why storing preferences in Javascript files not other formats? Thanks!