| Index: Source/core/css/StyleSheetContents.cpp
|
| diff --git a/Source/core/css/StyleSheetContents.cpp b/Source/core/css/StyleSheetContents.cpp
|
| index 091de77e5d1558a339fbf6a2df405a6bb56d64fe..98f378dd6abe174e4e4f6569ac238c65a092ba23 100644
|
| --- a/Source/core/css/StyleSheetContents.cpp
|
| +++ b/Source/core/css/StyleSheetContents.cpp
|
| @@ -66,6 +66,7 @@ StyleSheetContents::StyleSheetContents(StyleRuleImport* ownerRule, const String&
|
| , m_isInMemoryCache(false)
|
| , m_hasFontFaceRule(false)
|
| , m_hasMediaQueries(false)
|
| + , m_hasSingleOwnerDocument(true)
|
| , m_parserContext(context)
|
| {
|
| }
|
| @@ -84,6 +85,7 @@ StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
|
| , m_isInMemoryCache(false)
|
| , m_hasFontFaceRule(o.m_hasFontFaceRule)
|
| , m_hasMediaQueries(o.m_hasMediaQueries)
|
| + , m_hasSingleOwnerDocument(true)
|
| , m_parserContext(o.m_parserContext)
|
| {
|
| ASSERT(o.isCacheable());
|
| @@ -98,15 +100,16 @@ StyleSheetContents::StyleSheetContents(const StyleSheetContents& o)
|
| StyleSheetContents::~StyleSheetContents()
|
| {
|
| #if !ENABLE(OILPAN)
|
| - StyleEngine::removeSheet(this);
|
| clearRules();
|
| #endif
|
| }
|
|
|
| void StyleSheetContents::setHasSyntacticallyValidCSSHeader(bool isValidCss)
|
| {
|
| - if (maybeCacheable() && !isValidCss)
|
| - StyleEngine::removeSheet(this);
|
| + if (!isValidCss) {
|
| + if (Document* document = clientSingleOwnerDocument())
|
| + removeSheetFromCache(document);
|
| + }
|
| m_hasSyntacticallyValidCSSHeader = isValidCss;
|
| }
|
|
|
| @@ -471,8 +474,8 @@ Node* StyleSheetContents::singleOwnerNode() const
|
|
|
| Document* StyleSheetContents::singleOwnerDocument() const
|
| {
|
| - Node* ownerNode = singleOwnerNode();
|
| - return ownerNode ? &ownerNode->document() : 0;
|
| + StyleSheetContents* root = rootStyleSheet();
|
| + return root->clientSingleOwnerDocument();
|
| }
|
|
|
| KURL StyleSheetContents::completeURL(const String& url) const
|
| @@ -520,6 +523,16 @@ bool StyleSheetContents::hasFailedOrCanceledSubresources() const
|
| return childRulesHaveFailedOrCanceledSubresources(m_childRules);
|
| }
|
|
|
| +Document* StyleSheetContents::clientSingleOwnerDocument() const
|
| +{
|
| + if (!m_hasSingleOwnerDocument || clientSize() <= 0)
|
| + return 0;
|
| +
|
| + if (m_loadingClients.size())
|
| + return (*m_loadingClients.begin())->ownerDocument();
|
| + return (*m_completedClients.begin())->ownerDocument();
|
| +}
|
| +
|
| StyleSheetContents* StyleSheetContents::parentStyleSheet() const
|
| {
|
| return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
|
| @@ -528,20 +541,41 @@ StyleSheetContents* StyleSheetContents::parentStyleSheet() const
|
| void StyleSheetContents::registerClient(CSSStyleSheet* sheet)
|
| {
|
| ASSERT(!m_loadingClients.contains(sheet) && !m_completedClients.contains(sheet));
|
| +
|
| + // InspectorCSSAgent::buildObjectForRule and document.implementation.createCSSStyleSheet
|
| + // creates CSSStyleSheet without any owner node.
|
| + if (!sheet->ownerDocument())
|
| + return;
|
| +
|
| + if (Document* document = clientSingleOwnerDocument()) {
|
| + if (sheet->ownerDocument() != document)
|
| + m_hasSingleOwnerDocument = false;
|
| + }
|
| m_loadingClients.add(sheet);
|
| }
|
|
|
| void StyleSheetContents::unregisterClient(CSSStyleSheet* sheet)
|
| {
|
| - ASSERT(m_loadingClients.contains(sheet) || m_completedClients.contains(sheet));
|
| m_loadingClients.remove(sheet);
|
| m_completedClients.remove(sheet);
|
| +
|
| + if (!sheet->ownerDocument() || !m_loadingClients.isEmpty() || !m_completedClients.isEmpty())
|
| + return;
|
| +
|
| + if (m_hasSingleOwnerDocument)
|
| + removeSheetFromCache(sheet->ownerDocument());
|
| + m_hasSingleOwnerDocument = true;
|
| }
|
|
|
| void StyleSheetContents::clientLoadCompleted(CSSStyleSheet* sheet)
|
| {
|
| - ASSERT(m_loadingClients.contains(sheet));
|
| + ASSERT(m_loadingClients.contains(sheet) || !sheet->ownerDocument());
|
| m_loadingClients.remove(sheet);
|
| + // In m_ownerNode->sheetLoaded, the CSSStyleSheet might be detached.
|
| + // (i.e. clearOwnerNode was invoked.)
|
| + // In this case, we don't need to add the stylesheet to completed clients.
|
| + if (!sheet->ownerDocument())
|
| + return;
|
| m_completedClients.add(sheet);
|
| }
|
|
|
| @@ -552,6 +586,15 @@ void StyleSheetContents::clientLoadStarted(CSSStyleSheet* sheet)
|
| m_loadingClients.add(sheet);
|
| }
|
|
|
| +void StyleSheetContents::removeSheetFromCache(Document* document)
|
| +{
|
| + if (!maybeCacheable())
|
| + return;
|
| + if (!document || !document->isActive())
|
| + return;
|
| + document->styleEngine()->removeSheet(this);
|
| +}
|
| +
|
| void StyleSheetContents::addedToMemoryCache()
|
| {
|
| ASSERT(!m_isInMemoryCache);
|
|
|