source: webkit/trunk/Source/WebCore/css/StyleRuleImport.h

Last change on this file was 288879, checked in by Oriol Brufau, 3 years ago

[css-cascade] Fix removal of not yet loaded CSS @import
https://bugs.webkit.org/show_bug.cgi?id=235930

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Add new test.

  • web-platform-tests/css/css-cascade/import-removal-expected.html: Added.
  • web-platform-tests/css/css-cascade/import-removal.html: Added.

Source/WebCore:

When removing a not yet loaded CSS @import, the hasPendingSheet() flag
was not cleared. This resulted in a completely blank page.
This patch makes sure to cancel the load before deleting the rule.

Test: imported/w3c/web-platform-tests/css/css-cascade/import-removal.html

  • css/StyleRuleImport.cpp:

(WebCore::StyleRuleImport::cancelLoad):

  • css/StyleRuleImport.h:
  • css/StyleSheetContents.cpp:

(WebCore::StyleSheetContents::wrapperDeleteRule):

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2 * (C) 1999-2003 Lars Knoll ([email protected])
3 * (C) 2002-2003 Dirk Mueller ([email protected])
4 * Copyright (C) 2002, 2006, 2008, 2012 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#pragma once
23
24#include "CachedResourceHandle.h"
25#include "CachedStyleSheetClient.h"
26#include "StyleRule.h"
27#include <wtf/TypeCasts.h>
28
29namespace WebCore {
30
31class CachedCSSStyleSheet;
32class MediaQuerySet;
33class StyleSheetContents;
34
35class StyleRuleImport final : public StyleRuleBase {
36 WTF_MAKE_FAST_ALLOCATED;
37public:
38 static Ref<StyleRuleImport> create(const String& href, Ref<MediaQuerySet>&&, std::optional<CascadeLayerName>&&);
39
40 ~StyleRuleImport();
41
42 StyleSheetContents* parentStyleSheet() const { return m_parentStyleSheet; }
43 void setParentStyleSheet(StyleSheetContents* sheet) { ASSERT(sheet); m_parentStyleSheet = sheet; }
44 void clearParentStyleSheet() { m_parentStyleSheet = 0; }
45 void cancelLoad();
46
47 String href() const { return m_strHref; }
48 StyleSheetContents* styleSheet() const { return m_styleSheet.get(); }
49
50 bool isLoading() const;
51 MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
52
53 void requestStyleSheet();
54 const CachedCSSStyleSheet* cachedCSSStyleSheet() const { return m_cachedSheet.get(); }
55
56 const std::optional<CascadeLayerName>& cascadeLayerName() const { return m_cascadeLayerName; }
57
58private:
59 // NOTE: We put the CachedStyleSheetClient in a member instead of inheriting from it
60 // to avoid adding a vptr to StyleRuleImport.
61 class ImportedStyleSheetClient final : public CachedStyleSheetClient {
62 public:
63 ImportedStyleSheetClient(StyleRuleImport* ownerRule) : m_ownerRule(ownerRule) { }
64 virtual ~ImportedStyleSheetClient() = default;
65 void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet) final
66 {
67 m_ownerRule->setCSSStyleSheet(href, baseURL, charset, sheet);
68 }
69 private:
70 StyleRuleImport* m_ownerRule;
71 };
72
73 void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet*);
74 friend class ImportedStyleSheetClient;
75
76 StyleRuleImport(const String& href, Ref<MediaQuerySet>&&, std::optional<CascadeLayerName>&&);
77
78 StyleSheetContents* m_parentStyleSheet { nullptr };
79
80 ImportedStyleSheetClient m_styleSheetClient;
81 String m_strHref;
82 RefPtr<MediaQuerySet> m_mediaQueries;
83 RefPtr<StyleSheetContents> m_styleSheet;
84 std::optional<CascadeLayerName> m_cascadeLayerName;
85 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
86 bool m_loading { false };
87};
88
89} // namespace WebCore
90
91SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleImport)
92 static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isImportRule(); }
93SPECIALIZE_TYPE_TRAITS_END()
Note: See TracBrowser for help on using the repository browser.