void CSSImportRule::insertedIntoParent() { CSSStyleSheet* parentSheet = parentStyleSheet(); if (!parentSheet || !parentSheet->document()) return; CachedResourceLoader* cachedResourceLoader = parentSheet->document()->cachedResourceLoader(); if (!cachedResourceLoader) return; String absHref = m_strHref; if (!parentSheet->finalURL().isNull()) // use parent styleheet's URL as the base URL absHref = KURL(parentSheet->finalURL(), m_strHref).string(); // Check for a cycle in our import chain. If we encounter a stylesheet // in our parent chain with the same URL, then just bail. StyleBase* root = this; for (StyleBase* curr = parent(); curr; curr = curr->parent()) { // FIXME: This is wrong if the finalURL was updated via document::updateBaseURL. if (curr->isCSSStyleSheet() && absHref == static_cast<CSSStyleSheet*>(curr)->finalURL().string()) return; root = curr; } if (parentSheet->isUserStyleSheet()) m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(absHref, parentSheet->charset()); else m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(absHref, parentSheet->charset()); if (m_cachedSheet) { // if the import rule is issued dynamically, the sheet may be // removed from the pending sheet count, so let the doc know // the sheet being imported is pending. if (parentSheet && parentSheet->loadCompleted() && root == parentSheet) parentSheet->document()->addPendingSheet(); m_loading = true; m_cachedSheet->addClient(this); } }
unsigned CSSMediaRule::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec) { ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size()); if (index > m_mediaRule->childRules().size()) { // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point. ec = INDEX_SIZE_ERR; return 0; } CSSParser parser(parserContext()); CSSStyleSheet* styleSheet = parentStyleSheet(); RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? styleSheet->contents() : 0, ruleString); if (!newRule) { // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable. ec = SYNTAX_ERR; return 0; } if (newRule->isImportRule()) { // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested // @media rule. They are currently not getting parsed, resulting in a SYNTAX_ERR // to get raised above. // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified // index, e.g., if an @import rule is inserted after a standard rule set or other // at-rule. ec = HIERARCHY_REQUEST_ERR; return 0; } CSSStyleSheet::RuleMutationScope mutationScope(this); m_mediaRule->wrapperInsertRule(index, newRule); m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>()); return index; }
unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionCode& ec) { if (index > m_lstCSSRules->length()) { // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point. ec = INDEX_SIZE_ERR; return 0; } CSSParser p(useStrictParsing()); RefPtr<CSSRule> newRule = p.parseRule(parentStyleSheet(), rule); if (!newRule) { // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable. ec = SYNTAX_ERR; return 0; } if (newRule->isImportRule()) { // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested // @media rule. They are currently not getting parsed, resulting in a SYNTAX_ERR // to get raised above. // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified // index, e.g., if an @import rule is inserted after a standard rule set or other // at-rule. ec = HIERARCHY_REQUEST_ERR; return 0; } newRule->setParent(this); unsigned returnedIndex = m_lstCSSRules->insertRule(newRule.get(), index); // stylesheet() can only return 0 for computed style declarations. stylesheet()->styleSheetChanged(); return returnedIndex; }
DISABLE_CFI_PERF StyleSheetContents* AbstractPropertySetCSSStyleDeclaration::contextStyleSheet() const { CSSStyleSheet* cssStyleSheet = parentStyleSheet(); return cssStyleSheet ? cssStyleSheet->contents() : nullptr; }
StyleSheetContents* AbstractPropertySetCSSStyleDeclaration::contextStyleSheet() const { CSSStyleSheet* cssStyleSheet = parentStyleSheet(); return cssStyleSheet ? cssStyleSheet->contents() : 0; }
const CSSParserContext& CSSRule::parserContext() const { CSSStyleSheet* styleSheet = parentStyleSheet(); return styleSheet ? styleSheet->contents()->parserContext() : strictCSSParserContext(); }
MediaList* CSSImportRule::media() { return m_importRule->mediaQueries()->ensureMediaList(parentStyleSheet()); }
void StyleSheetContents::setHasMediaQueries() { m_hasMediaQueries = true; if (parentStyleSheet()) parentStyleSheet()->setHasMediaQueries(); }
CSSImportRule* CSSStyleSheet::ownerRule() const { return parentStyleSheet() ? parentStyleSheet()->ensureCSSOMWrapper(m_ownerRule) : 0; }