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> 2012-09-14 Ojan Vafai <ojan@chromium.org>
   
Simplify some code in RenderBox::computePercentageLogicalHeight Simplify some code in RenderBox::computePercentageLogicalHeight
...@@ -86,13 +86,6 @@ void CSSImportRule::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectIn ...@@ -86,13 +86,6 @@ void CSSImportRule::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectIn
info.addInstrumentedMember(m_styleSheetCSSOMWrapper); 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 CSSStyleSheet* CSSImportRule::styleSheet() const
{ {
if (!m_importRule->styleSheet()) if (!m_importRule->styleSheet())
......
...@@ -45,8 +45,6 @@ public: ...@@ -45,8 +45,6 @@ public:
void reportDescendantMemoryUsage(MemoryObjectInfo*) const; void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
void reattachStyleSheetContents();
private: private:
CSSImportRule(StyleRuleImport*, CSSStyleSheet*); CSSImportRule(StyleRuleImport*, CSSStyleSheet*);
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "SVGNames.h" #include "SVGNames.h"
#include "SecurityOrigin.h" #include "SecurityOrigin.h"
#include "StyleRule.h" #include "StyleRule.h"
#include "StyleRuleImport.h"
#include "StyleSheetContents.h" #include "StyleSheetContents.h"
#include "WebCoreMemoryInstrumentation.h" #include "WebCoreMemoryInstrumentation.h"
#include <wtf/text/StringBuilder.h> #include <wtf/text/StringBuilder.h>
...@@ -151,7 +150,7 @@ void CSSStyleSheet::willMutateRules() ...@@ -151,7 +150,7 @@ void CSSStyleSheet::willMutateRules()
m_contents->setMutable(); m_contents->setMutable();
// Any existing CSSOM wrappers need to be connected to the copied child rules. // Any existing CSSOM wrappers need to be connected to the copied child rules.
reattachCSSOMWrappers(); reattachChildRuleCSSOMWrappers();
} }
void CSSStyleSheet::didMutateRules() void CSSStyleSheet::didMutateRules()
...@@ -170,11 +169,8 @@ void CSSStyleSheet::didMutate() ...@@ -170,11 +169,8 @@ void CSSStyleSheet::didMutate()
owner->styleResolverChanged(DeferRecalcStyle); owner->styleResolverChanged(DeferRecalcStyle);
} }
void CSSStyleSheet::reattachCSSOMWrappers() void CSSStyleSheet::reattachChildRuleCSSOMWrappers()
{ {
if (m_ownerRule)
m_ownerRule->reattachStyleSheetContents();
for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
if (!m_childRuleCSSOMWrappers[i]) if (!m_childRuleCSSOMWrappers[i])
continue; continue;
...@@ -287,10 +283,7 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc ...@@ -287,10 +283,7 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
if (!success) { if (!success) {
ec = HIERARCHY_REQUEST_ERR; ec = HIERARCHY_REQUEST_ERR;
return 0; return 0;
} }
if (rule->isImportRule())
static_cast<StyleRuleImport*>(rule.get())->requestStyleSheet(rootStyleSheet(), m_contents->parserContext());
if (!m_childRuleCSSOMWrappers.isEmpty()) if (!m_childRuleCSSOMWrappers.isEmpty())
m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>()); m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
...@@ -377,17 +370,11 @@ CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const ...@@ -377,17 +370,11 @@ CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const
return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0; return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
} }
CSSStyleSheet* CSSStyleSheet::rootStyleSheet() const Document* CSSStyleSheet::ownerDocument() const
{ {
const CSSStyleSheet* root = this; const CSSStyleSheet* root = this;
while (root->parentStyleSheet()) while (root->parentStyleSheet())
root = 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; return root->ownerNode() ? root->ownerNode()->document() : 0;
} }
......
...@@ -80,7 +80,6 @@ public: ...@@ -80,7 +80,6 @@ public:
virtual bool isLoading() const OVERRIDE; virtual bool isLoading() const OVERRIDE;
void clearOwnerRule() { m_ownerRule = 0; } void clearOwnerRule() { m_ownerRule = 0; }
CSSStyleSheet* rootStyleSheet() const;
Document* ownerDocument() const; Document* ownerDocument() const;
MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); } MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
void setMediaQueries(PassRefPtr<MediaQuerySet>); void setMediaQueries(PassRefPtr<MediaQuerySet>);
...@@ -102,6 +101,7 @@ public: ...@@ -102,6 +101,7 @@ public:
void didMutate(); void didMutate();
void clearChildRuleCSSOMWrappers(); void clearChildRuleCSSOMWrappers();
void reattachChildRuleCSSOMWrappers();
StyleSheetContents* contents() const { return m_contents.get(); } StyleSheetContents* contents() const { return m_contents.get(); }
...@@ -115,7 +115,6 @@ private: ...@@ -115,7 +115,6 @@ private:
virtual String type() const { return "text/css"; } virtual String type() const { return "text/css"; }
bool canAccessRules() const; bool canAccessRules() const;
void reattachCSSOMWrappers();
RefPtr<StyleSheetContents> m_contents; RefPtr<StyleSheetContents> m_contents;
bool m_isInlineStylesheet; bool m_isInlineStylesheet;
......
...@@ -32,12 +32,6 @@ ...@@ -32,12 +32,6 @@
namespace WebCore { namespace WebCore {
StyleRuleImport::LoadContext::LoadContext(CSSStyleSheet* rootStyleSheet, const CSSParserContext& parentParserContext)
: rootStyleSheet(rootStyleSheet)
, parentParserContext(parentParserContext)
{
}
PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefPtr<MediaQuerySet> media) PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefPtr<MediaQuerySet> media)
{ {
return adoptRef(new StyleRuleImport(href, media)); return adoptRef(new StyleRuleImport(href, media));
...@@ -45,9 +39,12 @@ PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefP ...@@ -45,9 +39,12 @@ PassRefPtr<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefP
StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> media) StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> media)
: StyleRuleBase(Import, 0) : StyleRuleBase(Import, 0)
, m_parentStyleSheet(0)
, m_styleSheetClient(this)
, m_strHref(href) , m_strHref(href)
, m_mediaQueries(media) , m_mediaQueries(media)
, m_cachedSheet(0) , m_cachedSheet(0)
, m_loading(false)
{ {
if (!m_mediaQueries) if (!m_mediaQueries)
m_mediaQueries = MediaQuerySet::create(String()); m_mediaQueries = MediaQuerySet::create(String());
...@@ -55,90 +52,83 @@ StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> m ...@@ -55,90 +52,83 @@ StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> m
StyleRuleImport::~StyleRuleImport() StyleRuleImport::~StyleRuleImport()
{ {
if (m_styleSheet)
m_styleSheet->clearOwnerRule();
if (m_cachedSheet) 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); if (m_styleSheet)
ASSERT(!m_styleSheet); m_styleSheet->clearOwnerRule();
ASSERT(m_cachedSheet);
OwnPtr<LoadContext> loadContext = m_loadContext.release();
CSSParserContext parserContext = loadContext->parentParserContext; CSSParserContext context = m_parentStyleSheet ? m_parentStyleSheet->parserContext() : CSSStrictMode;
context.charset = charset;
if (!baseURL.isNull()) if (!baseURL.isNull())
parserContext.baseURL = baseURL; context.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();
#if ENABLE(PARSED_STYLE_SHEET_CACHING) m_styleSheet = StyleSheetContents::create(this, href, context);
if (m_styleSheet->isCacheable())
m_cachedSheet->saveParsedStyleSheet(m_styleSheet);
#endif
}
bool StyleRuleImport::isLoading() const Document* document = m_parentStyleSheet ? m_parentStyleSheet->singleOwnerDocument() : 0;
{ m_styleSheet->parseAuthorStyleSheet(cachedStyleSheet, document ? document->securityOrigin() : 0);
return m_loadContext || (m_styleSheet && m_styleSheet->isLoading());
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()); if (!m_parentStyleSheet)
ASSERT(!m_cachedSheet);
Node* ownerNode = rootSheet->ownerNode();
if (!ownerNode)
return; return;
Document* document = ownerNode->document(); Document* document = m_parentStyleSheet->singleOwnerDocument();
if (!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()))
return; return;
ResourceRequest request(resolvedURL);
CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader(); CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
if (rootSheetContents->isUserStyleSheet()) if (!cachedResourceLoader)
m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request, parserContext.charset);
else
m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request, parserContext.charset);
if (!m_cachedSheet)
return; 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) KURL absURL;
{ if (!m_parentStyleSheet->baseURL().isNull())
m_styleSheet = contents; // 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 void StyleRuleImport::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#ifndef StyleRuleImport_h #ifndef StyleRuleImport_h
#define StyleRuleImport_h #define StyleRuleImport_h
#include "CSSParserMode.h"
#include "CachedResourceHandle.h" #include "CachedResourceHandle.h"
#include "CachedStyleSheetClient.h" #include "CachedStyleSheetClient.h"
#include "StyleRule.h" #include "StyleRule.h"
...@@ -33,42 +32,55 @@ class CachedCSSStyleSheet; ...@@ -33,42 +32,55 @@ class CachedCSSStyleSheet;
class MediaQuerySet; class MediaQuerySet;
class StyleSheetContents; class StyleSheetContents;
class StyleRuleImport : public StyleRuleBase, public CachedStyleSheetClient { class StyleRuleImport : public StyleRuleBase {
WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_FAST_ALLOCATED;
public: public:
static PassRefPtr<StyleRuleImport> create(const String& href, PassRefPtr<MediaQuerySet>); 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; } String href() const { return m_strHref; }
StyleSheetContents* styleSheet() const { return m_styleSheet.get(); } StyleSheetContents* styleSheet() const { return m_styleSheet.get(); }
bool isLoading() const; bool isLoading() const;
bool hadLoadError() const;
MediaQuerySet* mediaQueries() { return m_mediaQueries.get(); } MediaQuerySet* mediaQueries() { return m_mediaQueries.get(); }
void requestStyleSheet(CSSStyleSheet* rootSheet, const CSSParserContext&); void requestStyleSheet();
void reportDescendantMemoryUsage(MemoryObjectInfo*) const; void reportDescendantMemoryUsage(MemoryObjectInfo*) const;
void reattachStyleSheetContents(StyleSheetContents*);
private: 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>); 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; String m_strHref;
RefPtr<MediaQuerySet> m_mediaQueries; RefPtr<MediaQuerySet> m_mediaQueries;
RefPtr<StyleSheetContents> m_styleSheet; RefPtr<StyleSheetContents> m_styleSheet;
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
struct LoadContext { bool m_loading;
LoadContext(CSSStyleSheet* rootStyleSheet, const CSSParserContext& parentParserContext);
RefPtr<CSSStyleSheet> rootStyleSheet;
CSSParserContext parentParserContext;
};
OwnPtr<LoadContext> m_loadContext;
}; };
} // namespace WebCore } // namespace WebCore
......
...@@ -54,9 +54,11 @@ unsigned StyleSheetContents::estimatedSizeInBytes() const ...@@ -54,9 +54,11 @@ unsigned StyleSheetContents::estimatedSizeInBytes() const
return size; return size;
} }
StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParserContext& context) StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule, const String& originalURL, const CSSParserContext& context)
: m_originalURL(originalURL) : m_ownerRule(ownerRule)
, m_originalURL(originalURL)
, m_loadCompleted(false) , m_loadCompleted(false)
, m_isUserStyleSheet(ownerRule && ownerRule->parentStyleSheet() && ownerRule->parentStyleSheet()->isUserStyleSheet())
, m_hasSyntacticallyValidCSSHeader(true) , m_hasSyntacticallyValidCSSHeader(true)
, m_didLoadErrorOccur(false) , m_didLoadErrorOccur(false)
, m_usesRemUnits(false) , m_usesRemUnits(false)
...@@ -68,6 +70,7 @@ StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParse ...@@ -68,6 +70,7 @@ StyleSheetContents::StyleSheetContents(const String& originalURL, const CSSParse
StyleSheetContents::StyleSheetContents(const StyleSheetContents& o) StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
: RefCounted<StyleSheetContents>() : RefCounted<StyleSheetContents>()
, m_ownerRule(0)
, m_originalURL(o.m_originalURL) , m_originalURL(o.m_originalURL)
, m_encodingFromCharsetRule(o.m_encodingFromCharsetRule) , m_encodingFromCharsetRule(o.m_encodingFromCharsetRule)
, m_importRules(o.m_importRules.size()) , m_importRules(o.m_importRules.size())
...@@ -101,6 +104,9 @@ bool StyleSheetContents::isCacheable() const ...@@ -101,6 +104,9 @@ bool StyleSheetContents::isCacheable() const
// FIXME: Support copying import rules. // FIXME: Support copying import rules.
if (!m_importRules.isEmpty()) if (!m_importRules.isEmpty())
return false; return false;
// FIXME: Support cached stylesheets in import rules.
if (m_ownerRule)
return false;
// This would require dealing with multiple clients for load callbacks. // This would require dealing with multiple clients for load callbacks.
if (!m_loadCompleted) if (!m_loadCompleted)
return false; return false;
...@@ -123,6 +129,8 @@ void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) ...@@ -123,6 +129,8 @@ void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
// Parser enforces that @import rules come before anything else except @charset. // Parser enforces that @import rules come before anything else except @charset.
ASSERT(m_childRules.isEmpty()); ASSERT(m_childRules.isEmpty());
m_importRules.append(static_cast<StyleRuleImport*>(rule.get())); m_importRules.append(static_cast<StyleRuleImport*>(rule.get()));
m_importRules.last()->setParentStyleSheet(this);
m_importRules.last()->requestStyleSheet();
return; return;
} }
m_childRules.append(rule); m_childRules.append(rule);
...@@ -161,6 +169,10 @@ void StyleSheetContents::clearCharsetRule() ...@@ -161,6 +169,10 @@ void StyleSheetContents::clearCharsetRule()
void StyleSheetContents::clearRules() void StyleSheetContents::clearRules()
{ {
for (unsigned i = 0; i < m_importRules.size(); ++i) {
ASSERT(m_importRules.at(i)->parentStyleSheet() == this);
m_importRules[i]->clearParentStyleSheet();