Open Bug 772401 Opened 12 years ago Updated 2 years ago

user-style-sheets category is prone to race conditions

Categories

(Core :: CSS Parsing and Computation, defect)

defect

Tracking

()

People

(Reporter: jwkbugzilla, Unassigned)

References

()

Details

The stylesheet service currently looks at the user-style-sheets category only once, when it initializes (this aspect of the implementation hasn't been changed ever since bug 179006 introduced it). This assumes that stylesheet service initializes after all the extensions had the chance to initialize and register in the category. However, the assumption fails in at least the following scenarios:

* A bootstrapped extension accesses the stylesheet service from its startup() method and indirectly causes it to initialize - this happens before other extensions initialize.
* Firefox checks for extension updates when starting up after a browser update - this also triggers stylesheet service initialization even though no extensions initialized yet.
* A bootstrapped extension is trying to use user-style-sheets category - this will completely fail for mid-session installs and uninstalls.

The issue can be seen with Wheelclear which is a minimalistic add-on basically only registering a user stylesheet:

* Create a new browser profile.
* Install Wheelclear 1.0 from https://addons.mozilla.org/addon/wheelclear/versions/1.0
* Restart browser
* Type something into the text field on about:home, then use the mouse wheel when the mouse pointer points to that text field. Observe that the text is cleared (Wheelclear works).
* Now close the browser, edit prefs.js in the profile and change extensions.lastAppVersion and extensions.lastPlatformVersion preferences to some different value, e.g. "1.0".
* Start the browser again.
* Type something into the text field on about:home, then use the mouse wheel when the mouse pointer points to that text field.

Expected result:
The text field is cleared as usually.

Actual result:
The text field contents don't change. In fact, DOM Inspector shows that resource://wheelclear/wheelclear.css user stylesheet didn't apply to the text field.

The obvious solution would be to have the stylesheet service extend nsCategoryListener class to get notified whenever category entries are added or removed - and it should add or remove the stylesheets accordingly.
Whiteboard: [mentor=bz]
Relevant code pointers:
http://mxr.mozilla.org/mozilla-central/source/layout/base/nsStyleSheetService.cpp - stylesheet service

http://hg.mozilla.org/mozilla-central/file/f7c89de3ab43/xpcom/glue/nsCategoryCache.h#l23 - nsCategoryListener

The stylesheet service currently calls RegisterFromEnumerator from Init, which enumerates the relevant categories once. By extending the listener, we should be able to avoid the whole enumerator thing and just doing the loading and registering when an entry is added, unregister when an entry is removed, and probably unregister everything when the category is cleared. We'll also need to create an nsCategoryObserver for the relevant categories that points to the service object.
I am working on this.
Mentor: bzbarsky
Whiteboard: [mentor=bz]
Mentor: bzbarsky
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.