I wouldn't say it's an hacky way. I mean, the hacky part of the
implementation is the fact that we have to convert the stylesheet file
in a data: URL file (although we have to do that in any case for
`contentStyle`) in order to append at the beginning the `-moz-document`
rules. That's to me it's "hacky".
But even if we don't have that part � let say we have a method to apply
the `-moz-document` without specifying it on the CSS itself � all these
bugs are still present because we use the Stylesheet Service.
The main problem here is that the insertion of scripts with PageMod is
made manually and the styleshees are using the Service, so there are
some differences.
I agree that in our specific case, something that could register a
stylesheet only in a document could be probably easier, because we can
apply manually the same logic we have for the scripts.
I'm a bit afraid, however, that this approach could be slower that what
we have now: at the moment, we register the stylesheet as soon as the
PageMod is created. We don't need to match any "opened" document, so the
CSS is applied immediately as soon as the user open a document that
match the `include` pattern.
However, that doesn't seems the case for the scripts. In regular web
development, when you execute scripts that listen for
"DOMContentLoaded", you can change the content of the page before it is
displayed to the user. Using jetpack, seems not possible: the page will
be displayed and then will be changed like the code runs in parallel.
At the moment is possible fix that behavior using `contentStyle` because
the stylesheets are registered as globals, but I'm worried that this
won't work anymore if we have to apply them manually to a document instance.
I'm not saying I don't want this new method, I want just underline the
needs we have in order to make it.
> - contentStyle doesn't match same document than contentScript rules (I
> think it applies to existing document whereas contentScript doesn't)
Yes, it seems something like that. I guess the bug 708190 will mitigate
that.
> - relative URL are broken.
relative URL are broken in any case, especially for `contentStyle` (not
`contentStyleFile`). Maybe we should mention it in the bug 737003. What
is the base folder for a CSS registered with the Stylesheet Services?
Should we have a way to explicitly force it? I'm thinking about
`contentStyle` specifically.