Bug 89240 - REGRESSION (r112923): getMatchedCSSRules always returning null for parentStyleSheet
Summary: REGRESSION (r112923): getMatchedCSSRules always returning null for parentStyl...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P1 Normal
Assignee: Nobody
URL:
Keywords: Regression
Depends on:
Blocks:
 
Reported: 2012-06-15 12:23 PDT by jmayhew
Modified: 2012-07-11 16:11 PDT (History)
6 users (show)

See Also:


Attachments
Test html file that shows the bug when pressing the html button. (850 bytes, text/html)
2012-06-15 12:23 PDT, jmayhew
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description jmayhew 2012-06-15 12:23:04 PDT
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.
Comment 1 Alexey Proskuryakov 2012-06-18 14:51:24 PDT
Does this affect any live web sites?
Comment 2 jmayhew 2012-06-18 15:14:26 PDT
(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.
Comment 3 jmayhew 2012-06-19 16:51:04 PDT
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 

    m_ruleList->rules().append(m_matchedRules[i]->rule()->createCSSOMWrapper()); 

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.
Comment 4 jmayhew 2012-07-11 16:11:35 PDT
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.