void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) { ASSERT(!rule->isCharsetRule()); if (rule->isImportRule()) { // Parser enforces that @import rules come before anything else except @charset. ASSERT(m_childRules.isEmpty()); m_importRules.append(static_cast<StyleRuleImport*>(rule.get())); m_importRules.last()->setParentStyleSheet(this); m_importRules.last()->requestStyleSheet(); return; } #if ENABLE(RESOLUTION_MEDIA_QUERY) // Add warning message to inspector if dpi/dpcm values are used for screen media. if (rule->isMediaRule()) reportMediaQueryWarningIfNeeded(singleOwnerDocument(), static_cast<StyleRuleMedia*>(rule.get())->mediaQueries()); #endif // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369> // If we're adding a rule with a huge number of selectors, split it up into multiple rules if (rule->isStyleRule() && toStyleRule(rule.get())->selectorList().componentCount() > RuleData::maximumSelectorComponentCount) { Vector<RefPtr<StyleRule>> rules = toStyleRule(rule.get())->splitIntoMultipleRulesWithMaximumSelectorComponentCount(RuleData::maximumSelectorComponentCount); m_childRules.appendVector(rules); return; } m_childRules.append(rule); }
void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cachedStyleSheet) { bool hasValidMIMEType = true; String sheetText = cachedStyleSheet->sheetText(&hasValidMIMEType); if (!hasValidMIMEType) { ASSERT(sheetText.isNull()); if (auto* document = singleOwnerDocument()) { if (auto* page = document->page()) page->console().addMessage(MessageSource::Security, MessageLevel::Error, "Did not parse stylesheet at '" + cachedStyleSheet->url().stringCenterEllipsizedToLength() + "' because its MIME type was invalid."); } return; } CSSParser p(parserContext()); p.parseSheet(this, sheetText, TextPosition(), nullptr, true); if (m_parserContext.needsSiteSpecificQuirks && isStrictParserMode(m_parserContext.mode)) { // Work around <https://bugs.webkit.org/show_bug.cgi?id=28350>. DEPRECATED_DEFINE_STATIC_LOCAL(const String, mediaWikiKHTMLFixesStyleSheet, (ASCIILiteral("/* KHTML fix stylesheet */\n/* work around the horizontal scrollbars */\n#column-content { margin-left: 0; }\n\n"))); // There are two variants of KHTMLFixes.css. One is equal to mediaWikiKHTMLFixesStyleSheet, // while the other lacks the second trailing newline. if (baseURL().string().endsWith("/KHTMLFixes.css") && !sheetText.isNull() && mediaWikiKHTMLFixesStyleSheet.startsWith(sheetText) && sheetText.length() >= mediaWikiKHTMLFixesStyleSheet.length() - 1) clearRules(); }
void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) { ASSERT(!rule->isCharsetRule()); if (rule->isImportRule()) { // Parser enforces that @import rules come before anything else except @charset. ASSERT(m_childRules.isEmpty()); m_importRules.append(static_cast<StyleRuleImport*>(rule.get())); m_importRules.last()->setParentStyleSheet(this); m_importRules.last()->requestStyleSheet(); return; } // Add warning message to inspector if dpi/dpcm values are used for screen media. if (rule->isMediaRule()) reportMediaQueryWarningIfNeeded(singleOwnerDocument(), static_cast<StyleRuleMedia*>(rule.get())->mediaQueries()); m_childRules.append(rule); }