campd/fxdt-adapters — pull request #45 by captainbrosset (2014-09-23 13:06:25+00:00)
Title: Delay getting stylesheets until the document is loaded (Fix #31)

Listing stylesheets is one of the things that behave very differently between chrome and safari. One protocol emits `stylesheet-added/removed` events, the other requires to call a `getAllStyleSheets` command. It would make sense to have feature detection and then have 2 `sheet-store` implementations, instead of trying to merge to very different approaches into one.

So the case where the devtools gets connected to the protocol after the page has loaded is simple, but when you reload the page, that's when problems start because we need to make sure we ask for the list stylesheets when they're actually available.
For instance, ios' `getAllStyleSheets` command will return an empty list if asked too early. And on chrome, there's no guarantee that the toolbox will ask for the list of stylesheets after all `stylesheet-added` events have been received.

My plan for this fix was to delay responding to the style-editor panel until we're sure that all stylesheets are known.

I believe this would all be very much simpler if our style-editor would react to stylesheet added/removed events instead. This will happen with [bug 947119](https://bugzilla.mozilla.org/show_bug.cgi?id=947119). This way, we wouldn't need the panel to know when the page navigates, but instead, it would just be listening to new and removed stylesheets.

Anyway, here it is. At least we have something displayed in the style-editor when the page is reloaded.