Created attachment 147873 [details]
Test html file that shows the bug when pressing the html button.
This happens in the webkit nightly and the webkit versions for Chromium 20. The problem does not occur in Safari 5.1.7 for Chrome 19.
window.getMatchedCSSRules() should return rule object(s) that have a valid parentStyleSheet property. Recent webkit versions make this api always return a null parentStyleSheet property.
Attached is a simple test file. Pressing the button will force a call to window.getMatchedCSSRules() and will display the parentStyleSheet properties value. In Chrome 19 and Safari 5.1.7, the property is non-null. In the webkit nightly it is null.
Does this affect any live web sites?
(In reply to comment #1)
> Does this affect any live web sites?
Per this bug: https://bugs.webkit.org/show_bug.cgi?id=79653 I would say yes. It does affect us, but we aren't live yet.
After a brief investigation it looks like changeset 112923 has quite a bit of refactoring in this area of CSS in webcore. I think this bug is just an artifact of that effort.
In short, StyleResolver::sortAndTransferMatchedRules() calls
and is not passing in the parent stylesheet. I think this call to createCSSOMWrapper should pass in the parent but I don't think it is available to the StyleResolver class. Fixing this will require making the parent sheet pointer available to the StyleResolver. This change should probably be done by the people heading the refactoring effort as it will depend on their new class design.
Also, StyleRule.h includes the following lines
// FIXME: There shouldn't be any need for the null parent version.
PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
PassRefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
I agree with the FIXME comment that there should be no default value for the parentSheet parameter. Is there ever a case where a rule should have a null parentSheet/parentRule? If this default value is removed, the resulting errors will indicate the areas that need to be addressed.
I hope that helps.
Okay, our project is no longer under NDA, we are open source and our alpha release is out so I can share it as an example of a web site/chrome extension that relies heavily on getMatchedCSSRules(...)
Our extension is available on the chrome web store here https://chrome.google.com/webstore/detail/jjdndclgmfdgpiccmlamlicfjmkognne
We had to add a workaround for this bug. When we detect a null parent we have to manually search through the rules to find the matching parent style sheet. This workaround is not 100% reliable so getting this bug fixed is very important to us as is the continued support of the getMatchedCSSRules() api.