Commit 763a19de authored by ap@apple.com's avatar ap@apple.com
Browse files

REGRESSION(r126717): It made inspector/styles/media-queries.html fail/flakey

        https://bugs.webkit.org/show_bug.cgi?id=95070

        Roll out r126717, and another change that depends on it.
        r126717: Remove parent pointer from StyleSheetContents and StyleRuleImport
        r127123: Cache and share parsed imported stylesheets

        * css/CSSImportRule.cpp:
        * css/CSSImportRule.h:
        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::willMutateRules):
        (WebCore::CSSStyleSheet::reattachChildRuleCSSOMWrappers):
        (WebCore::CSSStyleSheet::insertRule):
        (WebCore::CSSStyleSheet::ownerDocument):
        * css/CSSStyleSheet.h:
        (WebCore::CSSStyleSheet::clearOwnerRule):
        * css/StyleRuleImport.cpp:
        (WebCore::StyleRuleImport::StyleRuleImport):
        (WebCore::StyleRuleImport::~StyleRuleImport):
        (WebCore::StyleRuleImport::setCSSStyleSheet):
        (WebCore::StyleRuleImport::isLoading):
        (WebCore::StyleRuleImport::requestStyleSheet):
        * css/StyleRuleImport.h:
        (WebCore::StyleRuleImport::parentStyleSheet):
        (WebCore::StyleRuleImport::setParentStyleSheet):
        (WebCore::StyleRuleImport::clearParentStyleSheet):
        (ImportedStyleSheetClient):
        (WebCore::StyleRuleImport::ImportedStyleSheetClient::ImportedStyleSheetClient):
        (WebCore::StyleRuleImport::ImportedStyleSheetClient::~ImportedStyleSheetClient):
        (WebCore::StyleRuleImport::ImportedStyleSheetClient::setCSSStyleSheet):
        * css/StyleSheetContents.cpp:
        (WebCore::StyleSheetContents::StyleSheetContents):
        (WebCore::StyleSheetContents::isCacheable):
        (WebCore::StyleSheetContents::parserAppendRule):
        (WebCore::StyleSheetContents::clearRules):
        (WebCore::StyleSheetContents::wrapperInsertRule):
        (WebCore::StyleSheetContents::wrapperDeleteRule):
        (WebCore::StyleSheetContents::parseAuthorStyleSheet):
        (WebCore::StyleSheetContents::parseStringAtLine):
        (WebCore::StyleSheetContents::checkLoaded):
        (WebCore::StyleSheetContents::notifyLoadedSheet):
        (WebCore::StyleSheetContents::startLoadingDynamicSheet):
        (WebCore::StyleSheetContents::rootStyleSheet):
        (WebCore::StyleSheetContents::singleOwnerNode):
        (WebCore::StyleSheetContents::singleOwnerDocument):
        (WebCore::StyleSheetContents::parentStyleSheet):
        * css/StyleSheetContents.h:
        (WebCore::StyleSheetContents::create):
        (StyleSheetContents):
        (WebCore::StyleSheetContents::ownerRule):
        (WebCore::StyleSheetContents::clearOwnerRule):
        * dom/ProcessingInstruction.cpp:
        (WebCore::ProcessingInstruction::parseStyleSheet):
        * dom/StyleElement.cpp:
        (WebCore::StyleElement::createSheet):
        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::setCSSStyleSheet):
        * loader/cache/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::saveParsedStyleSheet):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128637 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a8149ebf
2012-09-14 Alexey Proskuryakov <ap@apple.com>
REGRESSION(r126717): It made inspector/styles/media-queries.html fail/flakey
https://bugs.webkit.org/show_bug.cgi?id=95070
Roll out r126717, and another change that depends on it.
r126717: Remove parent pointer from StyleSheetContents and StyleRuleImport
r127123: Cache and share parsed imported stylesheets
* css/CSSImportRule.cpp:
* css/CSSImportRule.h:
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::willMutateRules):
(WebCore::CSSStyleSheet::reattachChildRuleCSSOMWrappers):
(WebCore::CSSStyleSheet::insertRule):
(WebCore::CSSStyleSheet::ownerDocument):
* css/CSSStyleSheet.h:
(WebCore::CSSStyleSheet::clearOwnerRule):
* css/StyleRuleImport.cpp:
(WebCore::StyleRuleImport::StyleRuleImport):
(WebCore::StyleRuleImport::~StyleRuleImport):
(WebCore::StyleRuleImport::setCSSStyleSheet):
(WebCore::StyleRuleImport::isLoading):
(WebCore::StyleRuleImport::requestStyleSheet):
* css/StyleRuleImport.h:
(WebCore::StyleRuleImport::parentStyleSheet):
(WebCore::StyleRuleImport::setParentStyleSheet):
(WebCore::StyleRuleImport::clearParentStyleSheet):
(ImportedStyleSheetClient):
(WebCore::StyleRuleImport::ImportedStyleSheetClient::ImportedStyleSheetClient):
(WebCore::StyleRuleImport::ImportedStyleSheetClient::~ImportedStyleSheetClient):
(WebCore::StyleRuleImport::ImportedStyleSheetClient::setCSSStyleSheet):
* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::StyleSheetContents):
(WebCore::StyleSheetContents::isCacheable):
(WebCore::StyleSheetContents::parserAppendRule):
(WebCore::StyleSheetContents::clearRules):
(WebCore::StyleSheetContents::wrapperInsertRule):
(WebCore::StyleSheetContents::wrapperDeleteRule):
(WebCore::StyleSheetContents::parseAuthorStyleSheet):
(WebCore::StyleSheetContents::parseStringAtLine):
(WebCore::StyleSheetContents::checkLoaded):
(WebCore::StyleSheetContents::notifyLoadedSheet):
(WebCore::StyleSheetContents::startLoadingDynamicSheet):
(WebCore::StyleSheetContents::rootStyleSheet):
(WebCore::StyleSheetContents::singleOwnerNode):
(WebCore::StyleSheetContents::singleOwnerDocument):
(WebCore::StyleSheetContents::parentStyleSheet):
* css/StyleSheetContents.h:
(WebCore::StyleSheetContents::create):
(StyleSheetContents):
(WebCore::StyleSheetContents::ownerRule):
(WebCore::StyleSheetContents::clearOwnerRule):
* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::parseStyleSheet):
* dom/StyleElement.cpp:
(WebCore::StyleElement::createSheet):
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::setCSSStyleSheet):
* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::saveParsedStyleSheet):
2012-09-14 Ojan Vafai <ojan@chromium.org>
 
Simplify some code in RenderBox::computePercentageLogicalHeight
......@@ -86,13 +86,6 @@ void CSSImportRule::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectIn
info.addInstrumentedMember(m_styleSheetCSSOMWrapper);
}
void CSSImportRule::reattachStyleSheetContents()
{
ASSERT(m_styleSheetCSSOMWrapper);
ASSERT(!parentStyleSheet() || parentStyleSheet()->contents()->hasOneClient());
m_importRule->reattachStyleSheetContents(m_styleSheetCSSOMWrapper->contents());
}
CSSStyleSheet* CSSImportRule::styleSheet() const
{
if (!m_importRule->styleSheet())
......
......@@ -45,8 +45,6 @@ public:
void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
void reattachStyleSheetContents();
private:
CSSImportRule(StyleRuleImport*, CSSStyleSheet*);
......
......@@ -36,7 +36,6 @@
#include "SVGNames.h"
#include "SecurityOrigin.h"
#include "StyleRule.h"
#include "StyleRuleImport.h"
#include "StyleSheetContents.h"
#include "WebCoreMemoryInstrumentation.h"
#include <wtf/text/StringBuilder.h>
......@@ -151,7 +150,7 @@ void CSSStyleSheet::willMutateRules()
m_contents->setMutable();
// Any existing CSSOM wrappers need to be connected to the copied child rules.
reattachCSSOMWrappers();
reattachChildRuleCSSOMWrappers();
}
void CSSStyleSheet::didMutateRules()
......@@ -170,11 +169,8 @@ void CSSStyleSheet::didMutate()
owner->styleResolverChanged(DeferRecalcStyle);
}
void CSSStyleSheet::reattachCSSOMWrappers()
void CSSStyleSheet::reattachChildRuleCSSOMWrappers()
{
if (m_ownerRule)
m_ownerRule->reattachStyleSheetContents();
for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
if (!m_childRuleCSSOMWrappers[i])
continue;
......@@ -287,10 +283,7 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
if (!success) {
ec = HIERARCHY_REQUEST_ERR;
return 0;
}
if (rule->isImportRule())
static_cast<StyleRuleImport*>(rule.get())->requestStyleSheet(rootStyleSheet(), m_contents->parserContext());
}
if (!m_childRuleCSSOMWrappers.isEmpty())
m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
......@@ -377,17 +370,11 @@ CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const
return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
}
CSSStyleSheet* CSSStyleSheet::rootStyleSheet() const
Document* CSSStyleSheet::ownerDocument() const
{
const CSSStyleSheet* root = this;
while (root->parentStyleSheet())
root = root->parentStyleSheet();
return const_cast<CSSStyleSheet*>(root);
}
Document* CSSStyleSheet::ownerDocument() const
{
const CSSStyleSheet* root = rootStyleSheet();
return root->ownerNode() ? root->ownerNode()->document() : 0;
}
......
......@@ -80,7 +80,6 @@ public:
virtual bool isLoading() const OVERRIDE;
void clearOwnerRule() { m_ownerRule = 0; }
CSSStyleSheet* rootStyleSheet() const;
Document* ownerDocument() const;
MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
void setMediaQueries(PassRefPtr<MediaQuerySet>);
......@@ -102,6 +101,7 @@ public:
void didMutate();
void clearChildRuleCSSOMWrappers();
void reattachChildRuleCSSOMWrappers();
StyleSheetContents* contents() const { return m_contents.get(); }
......@@ -115,7 +115,6 @@ private:
virtual String type() const { return "text/css"; }
bool canAccessRules() const;
void reattachCSSOMWrappers();
RefPtr<StyleSheetContents> m_contents;
bool m_isInlineStylesheet;
......
......@@ -32,12 +32,6 @@
namespace WebCore {
StyleRuleImport::LoadContext::LoadContext(CSSStyleSheet* rootStyleSheet, const CSSParserContext& parentParserContext)
: rootStyleSheet(rootStyleSheet)
, parentParserContext(parentParserContext)
{
}
PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefPtr<MediaQuerySet> media)
{
return adoptRef(new StyleRuleImport(href, media));
......@@ -45,9 +39,12 @@ PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefP
StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> media)
: StyleRuleBase(Import, 0)
, m_parentStyleSheet(0)
, m_styleSheetClient(this)
, m_strHref(href)
, m_mediaQueries(media)
, m_cachedSheet(0)
, m_loading(false)
{
if (!m_mediaQueries)
m_mediaQueries = MediaQuerySet::create(String());
......@@ -55,90 +52,83 @@ StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> m
StyleRuleImport::~StyleRuleImport()
{
if (m_styleSheet)
m_styleSheet->clearOwnerRule();
if (m_cachedSheet)
m_cachedSheet->removeClient(this);
m_cachedSheet->removeClient(&m_styleSheetClient);
}
void StyleRuleImport::setCSSStyleSheet(const String& url, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*)
void StyleRuleImport::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* cachedStyleSheet)
{
ASSERT(m_loadContext);
ASSERT(!m_styleSheet);
ASSERT(m_cachedSheet);
OwnPtr<LoadContext> loadContext = m_loadContext.release();
if (m_styleSheet)
m_styleSheet->clearOwnerRule();
CSSParserContext parserContext = loadContext->parentParserContext;
CSSParserContext context = m_parentStyleSheet ? m_parentStyleSheet->parserContext() : CSSStrictMode;
context.charset = charset;
if (!baseURL.isNull())
parserContext.baseURL = baseURL;
parserContext.charset = charset;
#if ENABLE(PARSED_STYLE_SHEET_CACHING)
m_styleSheet = m_cachedSheet->restoreParsedStyleSheet(parserContext);
#endif
if (!m_styleSheet) {
m_styleSheet = StyleSheetContents::create(url, parserContext);
m_styleSheet->parseAuthorStyleSheet(m_cachedSheet.get(), loadContext->rootStyleSheet.get());
}
loadContext->rootStyleSheet->contents()->checkLoadCompleted();
context.baseURL = baseURL;
#if ENABLE(PARSED_STYLE_SHEET_CACHING)
if (m_styleSheet->isCacheable())
m_cachedSheet->saveParsedStyleSheet(m_styleSheet);
#endif
}
m_styleSheet = StyleSheetContents::create(this, href, context);
bool StyleRuleImport::isLoading() const
{
return m_loadContext || (m_styleSheet && m_styleSheet->isLoading());
Document* document = m_parentStyleSheet ? m_parentStyleSheet->singleOwnerDocument() : 0;
m_styleSheet->parseAuthorStyleSheet(cachedStyleSheet, document ? document->securityOrigin() : 0);
m_loading = false;
if (m_parentStyleSheet) {
m_parentStyleSheet->notifyLoadedSheet(cachedStyleSheet);
m_parentStyleSheet->checkLoaded();
}
}
bool StyleRuleImport::hadLoadError() const
bool StyleRuleImport::isLoading() const
{
return m_cachedSheet && m_cachedSheet->errorOccurred();
return m_loading || (m_styleSheet && m_styleSheet->isLoading());
}
void StyleRuleImport::requestStyleSheet(CSSStyleSheet* rootSheet, const CSSParserContext& parserContext)
void StyleRuleImport::requestStyleSheet()
{
ASSERT(!rootSheet->parentStyleSheet());
ASSERT(!m_cachedSheet);
Node* ownerNode = rootSheet->ownerNode();
if (!ownerNode)
if (!m_parentStyleSheet)
return;
Document* document = ownerNode->document();
KURL resolvedURL;
if (!parserContext.baseURL.isNull())
resolvedURL = KURL(parserContext.baseURL, m_strHref);
else
resolvedURL = document->completeURL(m_strHref);
StyleSheetContents* rootSheetContents = rootSheet->contents();
if (rootSheetContents->hasImportCycle(this, resolvedURL, document->baseURL()))
Document* document = m_parentStyleSheet->singleOwnerDocument();
if (!document)
return;
ResourceRequest request(resolvedURL);
CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
if (rootSheetContents->isUserStyleSheet())
m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request, parserContext.charset);
else
m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request, parserContext.charset);
if (!m_cachedSheet)
if (!cachedResourceLoader)
return;
// 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 (rootSheetContents->loadCompleted())
ownerNode->startLoadingDynamicSheet();
m_loadContext = adoptPtr(new LoadContext(rootSheet, parserContext));
m_cachedSheet->addClient(this);
}
void StyleRuleImport::reattachStyleSheetContents(StyleSheetContents* contents)
{
m_styleSheet = contents;
KURL absURL;
if (!m_parentStyleSheet->baseURL().isNull())
// use parent styleheet's URL as the base URL
absURL = KURL(m_parentStyleSheet->baseURL(), m_strHref);
else
absURL = document->completeURL(m_strHref);
// Check for a cycle in our import chain. If we encounter a stylesheet
// in our parent chain with the same URL, then just bail.
StyleSheetContents* rootSheet = m_parentStyleSheet;
for (StyleSheetContents* sheet = m_parentStyleSheet; sheet; sheet = sheet->parentStyleSheet()) {
if (equalIgnoringFragmentIdentifier(absURL, sheet->baseURL())
|| equalIgnoringFragmentIdentifier(absURL, document->completeURL(sheet->originalURL())))
return;
rootSheet = sheet;
}
ResourceRequest request(absURL);
if (m_parentStyleSheet->isUserStyleSheet())
m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request, m_parentStyleSheet->charset());
else
m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request, m_parentStyleSheet->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 (m_parentStyleSheet && m_parentStyleSheet->loadCompleted() && rootSheet == m_parentStyleSheet)
m_parentStyleSheet->startLoadingDynamicSheet();
m_loading = true;
m_cachedSheet->addClient(&m_styleSheetClient);
}
}
void StyleRuleImport::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
......
......@@ -22,7 +22,6 @@
#ifndef StyleRuleImport_h
#define StyleRuleImport_h
#include "CSSParserMode.h"
#include "CachedResourceHandle.h"
#include "CachedStyleSheetClient.h"
#include "StyleRule.h"
......@@ -33,42 +32,55 @@ class CachedCSSStyleSheet;
class MediaQuerySet;
class StyleSheetContents;
class StyleRuleImport : public StyleRuleBase, public CachedStyleSheetClient {
class StyleRuleImport : public StyleRuleBase {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassRefPtr<StyleRuleImport> create(const String& href, PassRefPtr<MediaQuerySet>);
virtual ~StyleRuleImport();
~StyleRuleImport();
StyleSheetContents* parentStyleSheet() const { return m_parentStyleSheet; }
void setParentStyleSheet(StyleSheetContents* sheet) { ASSERT(sheet); m_parentStyleSheet = sheet; }
void clearParentStyleSheet() { m_parentStyleSheet = 0; }
String href() const { return m_strHref; }
StyleSheetContents* styleSheet() const { return m_styleSheet.get(); }
bool isLoading() const;
bool hadLoadError() const;
MediaQuerySet* mediaQueries() { return m_mediaQueries.get(); }
void requestStyleSheet(CSSStyleSheet* rootSheet, const CSSParserContext&);
void requestStyleSheet();
void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
void reattachStyleSheetContents(StyleSheetContents*);
private:
// NOTE: We put the CachedStyleSheetClient in a member instead of inheriting from it
// to avoid adding a vptr to StyleRuleImport.
class ImportedStyleSheetClient : public CachedStyleSheetClient {
public:
ImportedStyleSheetClient(StyleRuleImport* ownerRule) : m_ownerRule(ownerRule) { }
virtual ~ImportedStyleSheetClient() { }
virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
{
m_ownerRule->setCSSStyleSheet(href, baseURL, charset, sheet);
}
private:
StyleRuleImport* m_ownerRule;
};
void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*);
friend class ImportedStyleSheetClient;
StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet>);
virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*);
StyleSheetContents* m_parentStyleSheet;
ImportedStyleSheetClient m_styleSheetClient;
String m_strHref;
RefPtr<MediaQuerySet> m_mediaQueries;
RefPtr<StyleSheetContents> m_styleSheet;
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
struct LoadContext {
LoadContext(CSSStyleSheet* rootStyleSheet, const CSSParserContext& parentParserContext);
RefPtr<CSSStyleSheet> rootStyleSheet;
CSSParserContext parentParserContext;
};
OwnPtr<LoadContext> m_loadContext;
bool m_loading;
};
} // namespace WebCore
......
......@@ -54,9 +54,11 @@ unsigned StyleSheetContents::estimatedSizeInBytes() const
return size;
}
StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParserContext& context)
: m_originalURL(originalURL)
StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
: m_ownerRule(ownerRule)
, m_originalURL(originalURL)
, m_loadCompleted(false)
, m_isUserStyleSheet(ownerRule && ownerRule->parentStyleSheet() && ownerRule->parentStyleSheet()->isUserStyleSheet())
, m_hasSyntacticallyValidCSSHeader(true)
, m_didLoadErrorOccur(false)
, m_usesRemUnits(false)
......@@ -68,6 +70,7 @@ StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParse
StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
: RefCounted<StyleSheetContents>()
, m_ownerRule(0)
, m_originalURL(o.m_originalURL)
, m_encodingFromCharsetRule(o.m_encodingFromCharsetRule)
, m_importRules(o.m_importRules.size())
......@@ -101,6 +104,9 @@ bool StyleSheetContents::isCacheable() const
// FIXME: Support copying import rules.
if (!m_importRules.isEmpty())
return false;
// FIXME: Support cached stylesheets in import rules.
if (m_ownerRule)
return false;
// This would require dealing with multiple clients for load callbacks.
if (!m_loadCompleted)
return false;
......@@ -123,6 +129,8 @@ void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
// 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;
}
m_childRules.append(rule);
......@@ -161,6 +169,10 @@ void StyleSheetContents::clearCharsetRule()
void StyleSheetContents::clearRules()
{
for (unsigned i = 0; i < m_importRules.size(); ++i) {
ASSERT(m_importRules.at(i)->parentStyleSheet() == this);
m_importRules[i]->clearParentStyleSheet();
}
m_importRules.clear();
m_childRules.clear();
clearCharsetRule();
......@@ -195,6 +207,9 @@ bool StyleSheetContents::wrapperInsertRule(PassRefPtr<StyleRuleBase> rule, unsig
if (!rule->isImportRule())
return false;
m_importRules.insert(childVectorIndex, static_cast<StyleRuleImport*>(rule.get()));
m_importRules[childVectorIndex]->setParentStyleSheet(this);
m_importRules[childVectorIndex]->requestStyleSheet();
// FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded.
return true;
}
// Inserting @import rule after a non-import rule is not allowed.
......@@ -220,6 +235,7 @@ void StyleSheetContents::wrapperDeleteRule(unsigned index)
--childVectorIndex;
}
if (childVectorIndex < m_importRules.size()) {
m_importRules[childVectorIndex]->clearParentStyleSheet();
m_importRules.remove(childVectorIndex);
return;
}
......@@ -250,22 +266,8 @@ const AtomicString& StyleSheetContents::determineNamespace(const AtomicString& p
return it->second;
}
void StyleSheetContents::requestImportedStyleSheets(CSSStyleSheet* rootSheet)
{
ASSERT(!rootSheet->parentStyleSheet());
for (unsigned i = 0; i < m_importRules.size(); ++i)
m_importRules[i]->requestStyleSheet(rootSheet, parserContext());
}
void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cachedStyleSheet, CSSStyleSheet* rootSheet)
void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cachedStyleSheet, const SecurityOrigin* securityOrigin)
{
if (cachedStyleSheet->errorOccurred()) {
m_didLoadErrorOccur = true;
return;
}
Document* ownerDocument = rootSheet->ownerDocument();
if (!ownerDocument)
return;
// Check to see if we should enforce the MIME type of the CSS resource in strict mode.
// Running in iWeb 2 is one example of where we don't want to - <rdar://problem/6099748>
bool enforceMIMEType = isStrictParserMode(m_parserContext.mode) && m_parserContext.enforcesCSSMIMETypeInNoQuirksMode;
......@@ -279,7 +281,6 @@ void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cached
// to at least start with a syntactically valid CSS rule.
// This prevents an attacker playing games by injecting CSS strings into HTML, XML, JSON, etc. etc.
if (!hasValidMIMEType && !hasSyntacticallyValidCSSHeader()) {
const SecurityOrigin* securityOrigin = ownerDocument->securityOrigin();
bool isCrossOriginCSS = !securityOrigin || !securityOrigin->canRequest(baseURL());
if (isCrossOriginCSS) {
clearRules();
......@@ -292,13 +293,9 @@ void StyleSheetContents::parseAuthorStyleSheet(const CachedCSSStyleSheet* cached
// 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) {
&& sheetText.length() >= mediaWikiKHTMLFixesStyleSheet.length() - 1)
clearRules();
return;
}
}
requestImportedStyleSheets(rootSheet);
}
bool StyleSheetContents::parseString(const String& sheetText)
......@@ -311,10 +308,6 @@ bool StyleSheetContents::parseStringAtLine(const String& sheetText, int startLin
CSSParser p(parserContext());
p.parseSheet(this, sheetText, startLineNumber);
if (!m_clients.isEmpty()) {
ASSERT(m_clients.size() == 1);
requestImportedStyleSheets(m_clients[0]);
}
return true;
}
......@@ -327,70 +320,66 @@ bool StyleSheetContents::isLoading() const
return false;
}
bool StyleSheetContents::checkImportedSheetLoadCompleted()
{
for (unsigned i = 0; i < m_importRules.size(); ++i) {
StyleRuleImport* importRule = m_importRules[i].get();
if (importRule->isLoading())
return false;
if (importRule->styleSheet() && !importRule->styleSheet()->checkImportedSheetLoadCompleted())
return false;
if (importRule->hadLoadError())
m_didLoadErrorOccur = true;
}
m_loadCompleted = true;
return true;
}
void StyleSheetContents::checkLoadCompleted()
void StyleSheetContents::checkLoaded()
{
if (m_clients.isEmpty())
return;
if (!checkImportedSheetLoadCompleted())
if (isLoading())
return;
RefPtr<StyleSheetContents> protect(this);
ASSERT(hasOneClient());
ASSERT(!m_clients[0]->parentStyleSheet());
RefPtr<Node> ownerNode = m_clients[0]->ownerNode();
if (!ownerNode)
// Avoid |this| being deleted by scripts that run via
// ScriptableDocumentParser::executeScriptsWaitingForStylesheets().
// See <rdar://problem/6622300>.
RefPtr<StyleSheetContents> protector(this);
StyleSheetContents* parentSheet = parentStyleSheet();
if (parentSheet) {
parentSheet->checkLoaded();
m_loadCompleted = true;
return;
}
RefPtr<Node> ownerNode = singleOwnerNode();
if (!ownerNode) {
m_loadCompleted = true;
return;
}
m_loadCompleted = ownerNode->sheetLoaded();
if (m_loadCompleted)
ownerNode->notifyLoadedSheetAndAllCriticalSubresources(m_didLoadErrorOccur);
}
bool StyleSheetContents::getAncestors(const StyleRuleImport* importRule, Vector<const StyleSheetContents