Title: [282403] trunk
Revision
282403
Author
da...@apple.com
Date
2021-09-14 12:59:52 -0700 (Tue, 14 Sep 2021)

Log Message

URLs in CSS variables must be resolved against the base URL of the stylesheet, not the document
https://bugs.webkit.org/show_bug.cgi?id=230243

Reviewed by Antti Koivisto.

Source/WebCore:

Test: fast/css/variables/url-with-variable-is-sheet-relative.html

* css/CSSPendingSubstitutionValue.h: Removed baseURL, since CSSVariableReferenceValue now
contains an appropriate parsing context, which includes the base URL.

* css/CSSVariableReferenceValue.cpp:
(WebCore::CSSVariableReferenceValue::CSSVariableReferenceValue): Store a CSSParserContext.
(WebCore::CSSVariableReferenceValue::create): Ditto.
* css/CSSVariableReferenceValue.h: Updated for the above.

* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseValueWithVariableReferences): Use the context from the
variable reference, not the current one in the parser.

* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseValueStart): Pass a parser context when creating a
CSSVariableReferenceValue.
* css/parser/CSSVariableParser.cpp:
(WebCore::CSSVariableParser::parseDeclarationValue): Ditto.

* style/StyleBuilder.cpp:
(WebCore::Style::Builder::resolvedVariableValue): Remove the special case for
CSSPendingSubstitutionValue since CSSParser::parseValueWithVariableReferences
now takes care of this.

LayoutTests:

* fast/css/variables/support/styles/url-with-variable-is-sheet-relative.css: Added 10 more test cases.
* fast/css/variables/url-with-variable-is-sheet-relative-expected.html: Ditto.
* fast/css/variables/url-with-variable-is-sheet-relative.html: Ditto.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (282402 => 282403)


--- trunk/LayoutTests/ChangeLog	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/LayoutTests/ChangeLog	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,3 +1,14 @@
+2021-09-14  Darin Adler  <da...@apple.com>
+
+        URLs in CSS variables must be resolved against the base URL of the stylesheet, not the document
+        https://bugs.webkit.org/show_bug.cgi?id=230243
+
+        Reviewed by Antti Koivisto.
+
+        * fast/css/variables/support/styles/url-with-variable-is-sheet-relative.css: Added 10 more test cases.
+        * fast/css/variables/url-with-variable-is-sheet-relative-expected.html: Ditto.
+        * fast/css/variables/url-with-variable-is-sheet-relative.html: Ditto.
+
 2021-09-14  Arcady Goldmints-Orlov  <agoldmi...@igalia.com>
 
         [GLIB] Create platform specific baselines for new web platform tests imported in r282287

Modified: trunk/LayoutTests/fast/css/variables/support/styles/url-with-variable-is-sheet-relative.css (282402 => 282403)


--- trunk/LayoutTests/fast/css/variables/support/styles/url-with-variable-is-sheet-relative.css	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/LayoutTests/fast/css/variables/support/styles/url-with-variable-is-sheet-relative.css	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,19 +1,20 @@
 :root {
     --red: red;
+    --red-gradient: linear-gradient(red, red);
+    --square: url('../images/600x600-green-square.png');
 }
 
-section {
-    height: 600px;
-    width: 600px;
-    margin: 20px;
-}
+section { height: 20px; width: 600px; margin: 10px; }
 
-.test-with-var {
-    background: url('../images/600x600-green-square.png') var(--red);
-    background-size: 100%;
-}
-
-.test-without-var {
-    background: url('../images/600x600-green-square.png') red;
-    background-size: 100%;
-}
+.test-0 { background: url('../images/600x600-green-square.png'); }
+.test-1 { background: url('../images/600x600-green-square.png') red; }
+.test-2 { background: url('../images/600x600-green-square.png') var(--red); }
+.test-3 { background: var(--square); }
+.test-4 { background: var(--square) red; }
+.test-5 { background: var(--square) var(--red); }
+.test-6 { background-image: url('../images/600x600-green-square.png'); }
+.test-7 { background-image: url('../images/600x600-green-square.png'), linear-gradient(red, red); }
+.test-8 { background-image: url('../images/600x600-green-square.png'), var(--red-gradient); }
+.test-9 { background-image: var(--square); }
+.test-10 { background-image: var(--square), linear-gradient(red, red); }
+.test-11 { background-image: var(--square), var(--red-gradient); }

Modified: trunk/LayoutTests/fast/css/variables/url-with-variable-is-sheet-relative-expected.html (282402 => 282403)


--- trunk/LayoutTests/fast/css/variables/url-with-variable-is-sheet-relative-expected.html	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/LayoutTests/fast/css/variables/url-with-variable-is-sheet-relative-expected.html	2021-09-14 19:59:52 UTC (rev 282403)
@@ -4,10 +4,17 @@
     <link href="" rel="stylesheet">
 </head>
 <body>
-<main>
-    <section class="test-without-var">
-    </section>
-</main>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
+    <section class="test-0"></section>
 </body>
 </html>
-

Modified: trunk/LayoutTests/fast/css/variables/url-with-variable-is-sheet-relative.html (282402 => 282403)


--- trunk/LayoutTests/fast/css/variables/url-with-variable-is-sheet-relative.html	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/LayoutTests/fast/css/variables/url-with-variable-is-sheet-relative.html	2021-09-14 19:59:52 UTC (rev 282403)
@@ -4,10 +4,17 @@
     <link href="" rel="stylesheet">
 </head>
 <body>
-<main>
-    <section class="test-with-var">
-    </section>
-</main>
+    <section class="test-0"></section>
+    <section class="test-1"></section>
+    <section class="test-2"></section>
+    <section class="test-3"></section>
+    <section class="test-4"></section>
+    <section class="test-5"></section>
+    <section class="test-6"></section>
+    <section class="test-7"></section>
+    <section class="test-8"></section>
+    <section class="test-9"></section>
+    <section class="test-10"></section>
+    <section class="test-11"></section>
 </body>
 </html>
-

Modified: trunk/Source/WebCore/ChangeLog (282402 => 282403)


--- trunk/Source/WebCore/ChangeLog	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/ChangeLog	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,3 +1,35 @@
+2021-09-14  Darin Adler  <da...@apple.com>
+
+        URLs in CSS variables must be resolved against the base URL of the stylesheet, not the document
+        https://bugs.webkit.org/show_bug.cgi?id=230243
+
+        Reviewed by Antti Koivisto.
+
+        Test: fast/css/variables/url-with-variable-is-sheet-relative.html
+
+        * css/CSSPendingSubstitutionValue.h: Removed baseURL, since CSSVariableReferenceValue now
+        contains an appropriate parsing context, which includes the base URL.
+
+        * css/CSSVariableReferenceValue.cpp:
+        (WebCore::CSSVariableReferenceValue::CSSVariableReferenceValue): Store a CSSParserContext.
+        (WebCore::CSSVariableReferenceValue::create): Ditto.
+        * css/CSSVariableReferenceValue.h: Updated for the above.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::parseValueWithVariableReferences): Use the context from the
+        variable reference, not the current one in the parser.
+
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::CSSPropertyParser::parseValueStart): Pass a parser context when creating a
+        CSSVariableReferenceValue.
+        * css/parser/CSSVariableParser.cpp:
+        (WebCore::CSSVariableParser::parseDeclarationValue): Ditto.
+
+        * style/StyleBuilder.cpp:
+        (WebCore::Style::Builder::resolvedVariableValue): Remove the special case for
+        CSSPendingSubstitutionValue since CSSParser::parseValueWithVariableReferences
+        now takes care of this.
+
 2021-09-14  Alan Bujtas  <za...@apple.com>
 
         [LFC][IFC] Introduce InlineInvalidation/InlineDamage

Modified: trunk/Source/WebCore/css/CSSPendingSubstitutionValue.h (282402 => 282403)


--- trunk/Source/WebCore/css/CSSPendingSubstitutionValue.h	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/css/CSSPendingSubstitutionValue.h	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,5 +1,5 @@
 // Copyright 2015 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2021 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -29,42 +29,35 @@
 
 #pragma once
 
-#include "CSSPropertyNames.h"
 #include "CSSValue.h"
-#include "CSSVariableReferenceValue.h"
 
 namespace WebCore {
 
 class CSSPendingSubstitutionValue : public CSSValue {
 public:
-    static Ref<CSSPendingSubstitutionValue> create(CSSPropertyID shorthandPropertyId, Ref<CSSVariableReferenceValue>&& shorthandValue, const URL& baseURL)
+    static Ref<CSSPendingSubstitutionValue> create(CSSPropertyID shorthandPropertyId, Ref<CSSVariableReferenceValue>&& shorthandValue)
     {
-        return adoptRef(*new CSSPendingSubstitutionValue(shorthandPropertyId, WTFMove(shorthandValue), baseURL));
+        return adoptRef(*new CSSPendingSubstitutionValue(shorthandPropertyId, WTFMove(shorthandValue)));
     }
 
     CSSVariableReferenceValue& shorthandValue() const { return m_shorthandValue; }
     CSSPropertyID shorthandPropertyId() const { return m_shorthandPropertyId; }
-    const URL& baseURL() const { return m_baseURL; }
 
     bool equals(const CSSPendingSubstitutionValue& other) const { return m_shorthandValue.ptr() == other.m_shorthandValue.ptr(); }
     static String customCSSText() { return emptyString(); }
 
 private:
-    CSSPendingSubstitutionValue(CSSPropertyID shorthandPropertyId, Ref<CSSVariableReferenceValue>&& shorthandValue, const URL& baseURL)
+    CSSPendingSubstitutionValue(CSSPropertyID shorthandPropertyId, Ref<CSSVariableReferenceValue>&& shorthandValue)
         : CSSValue(PendingSubstitutionValueClass)
         , m_shorthandPropertyId(shorthandPropertyId)
         , m_shorthandValue(WTFMove(shorthandValue))
-        , m_baseURL(baseURL)
     {
     }
 
     const CSSPropertyID m_shorthandPropertyId;
     Ref<CSSVariableReferenceValue> m_shorthandValue;
-    // This is the base URL that should be used in resolution of this value when necessary, e.g. for the `url()` function.
-    const URL m_baseURL;
 };
 
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSPendingSubstitutionValue, isPendingSubstitutionValue())
-

Modified: trunk/Source/WebCore/css/CSSVariableReferenceValue.cpp (282402 => 282403)


--- trunk/Source/WebCore/css/CSSVariableReferenceValue.cpp	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/css/CSSVariableReferenceValue.cpp	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,5 +1,5 @@
 // Copyright 2015 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016-2020 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2021 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -40,15 +40,16 @@
 
 static bool resolveTokenRange(CSSParserTokenRange, Vector<CSSParserToken>&, Style::BuilderState&);
 
-CSSVariableReferenceValue::CSSVariableReferenceValue(Ref<CSSVariableData>&& data)
+CSSVariableReferenceValue::CSSVariableReferenceValue(Ref<CSSVariableData>&& data, const CSSParserContext& context)
     : CSSValue(VariableReferenceClass)
     , m_data(WTFMove(data))
+    , m_context(context)
 {
 }
 
-Ref<CSSVariableReferenceValue> CSSVariableReferenceValue::create(const CSSParserTokenRange& range)
+Ref<CSSVariableReferenceValue> CSSVariableReferenceValue::create(const CSSParserTokenRange& range, const CSSParserContext& context)
 {
-    return adoptRef(*new CSSVariableReferenceValue(CSSVariableData::create(range)));
+    return adoptRef(*new CSSVariableReferenceValue(CSSVariableData::create(range), context));
 }
 
 bool CSSVariableReferenceValue::equals(const CSSVariableReferenceValue& other) const

Modified: trunk/Source/WebCore/css/CSSVariableReferenceValue.h (282402 => 282403)


--- trunk/Source/WebCore/css/CSSVariableReferenceValue.h	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/css/CSSVariableReferenceValue.h	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,5 +1,5 @@
 // Copyright 2015 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016-2020 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2021 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -29,6 +29,7 @@
 
 #pragma once
 
+#include "CSSParserContext.h"
 #include "CSSValue.h"
 
 namespace WebCore {
@@ -42,23 +43,24 @@
 
 class CSSVariableReferenceValue : public CSSValue {
 public:
-    static Ref<CSSVariableReferenceValue> create(const CSSParserTokenRange&);
+    static Ref<CSSVariableReferenceValue> create(const CSSParserTokenRange&, const CSSParserContext&);
 
     bool equals(const CSSVariableReferenceValue&) const;
     String customCSSText() const;
 
     RefPtr<CSSVariableData> resolveVariableReferences(Style::BuilderState&) const;
+    const CSSParserContext& context() const { return m_context; }
 
-    // The maximum number of tokens that may be produced by a var()
-    // reference or var() fallback value.
+    // The maximum number of tokens that may be produced by a var() reference or var() fallback value.
     // https://drafts.csswg.org/css-variables/#long-variables
     static constexpr size_t maxSubstitutionTokens = 65536;
 
 private:
-    explicit CSSVariableReferenceValue(Ref<CSSVariableData>&&);
+    explicit CSSVariableReferenceValue(Ref<CSSVariableData>&&, const CSSParserContext&);
 
     Ref<CSSVariableData> m_data;
     mutable String m_stringValue;
+    const CSSParserContext m_context;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (282402 => 282403)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2003 Lars Knoll (kn...@kde.org)
  * Copyright (C) 2005 Allan Sandfeld Jensen (k...@carewolf.com)
- * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2007 Nicholas Shanks <web...@nickshanks.com>
  * Copyright (C) 2008 Eric Seidel <e...@webkit.org>
  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
@@ -195,7 +195,7 @@
             return nullptr;
 
         ParsedPropertyVector parsedProperties;
-        if (!CSSPropertyParser::parseValue(shorthandID, false, resolvedData->tokens(), m_context, parsedProperties, StyleRuleType::Style))
+        if (!CSSPropertyParser::parseValue(shorthandID, false, resolvedData->tokens(), substitution.shorthandValue().context(), parsedProperties, StyleRuleType::Style))
             return nullptr;
 
         for (auto& property : parsedProperties) {
@@ -214,7 +214,7 @@
         auto resolvedData = valueWithReferences.resolveVariableReferences(builderState);
         if (!resolvedData)
             return nullptr;
-        return CSSPropertyParser::parseSingleValue(propID, resolvedData->tokens(), m_context);
+        return CSSPropertyParser::parseSingleValue(propID, resolvedData->tokens(), valueWithReferences.context());
     }
 
     const auto& customPropValue = downcast<CSSCustomPropertyValue>(value);
@@ -222,20 +222,19 @@
 
     auto& name = downcast<CSSCustomPropertyValue>(value).name();
     auto* registered = builderState.document().getCSSRegisteredCustomPropertySet().get(name);
-    auto& syntax = registered ? registered->syntax : "*";
+    auto& syntax = registered ? registered->syntax : "*"_s;
     auto resolvedData = valueWithReferences.resolveVariableReferences(builderState);
-
     if (!resolvedData)
         return nullptr;
 
     // FIXME handle REM cycles.
     HashSet<CSSPropertyID> dependencies;
-    CSSPropertyParser::collectParsedCustomPropertyValueDependencies(syntax, false, dependencies, resolvedData->tokens(), m_context);
+    CSSPropertyParser::collectParsedCustomPropertyValueDependencies(syntax, false, dependencies, resolvedData->tokens(), valueWithReferences.context());
 
     for (auto id : dependencies)
         builderState.builder().applyProperty(id);
 
-    return CSSPropertyParser::parseTypedCustomPropertyValue(name, syntax, resolvedData->tokens(), builderState, m_context);
+    return CSSPropertyParser::parseTypedCustomPropertyValue(name, syntax, resolvedData->tokens(), builderState, valueWithReferences.context());
 }
 
 Vector<double> CSSParser::parseKeyframeKeyList(const String& selector)

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (282402 => 282403)


--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,5 +1,5 @@
 // Copyright 2015 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2021 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -321,9 +321,9 @@
     }
 
     if (CSSVariableParser::containsValidVariableReferences(originalRange, m_context)) {
-        auto variable = CSSVariableReferenceValue::create(originalRange);
+        auto variable = CSSVariableReferenceValue::create(originalRange, m_context);
         if (isShorthand)
-            addExpandedPropertyForValue(propertyID, CSSPendingSubstitutionValue::create(propertyID, WTFMove(variable), m_context.baseURL), important);
+            addExpandedPropertyForValue(propertyID, CSSPendingSubstitutionValue::create(propertyID, WTFMove(variable)), important);
         else
             addProperty(propertyID, CSSPropertyInvalid, WTFMove(variable), important);
         return true;

Modified: trunk/Source/WebCore/css/parser/CSSVariableParser.cpp (282402 => 282403)


--- trunk/Source/WebCore/css/parser/CSSVariableParser.cpp	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/css/parser/CSSVariableParser.cpp	2021-09-14 19:59:52 UTC (rev 282403)
@@ -1,5 +1,5 @@
 // Copyright 2015 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2021 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -190,7 +190,7 @@
     if (type == CSSValueInvalid)
         return nullptr;
     if (type == CSSValueInternalVariableValue)
-        return CSSCustomPropertyValue::createUnresolved(variableName, CSSVariableReferenceValue::create(range));
+        return CSSCustomPropertyValue::createUnresolved(variableName, CSSVariableReferenceValue::create(range, parserContext));
     return CSSCustomPropertyValue::createUnresolved(variableName, type);
 }
 

Modified: trunk/Source/WebCore/style/StyleBuilder.cpp (282402 => 282403)


--- trunk/Source/WebCore/style/StyleBuilder.cpp	2021-09-14 19:53:45 UTC (rev 282402)
+++ trunk/Source/WebCore/style/StyleBuilder.cpp	2021-09-14 19:59:52 UTC (rev 282403)
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (kn...@kde.org)
  * Copyright (C) 2004-2005 Allan Sandfeld Jensen (k...@carewolf.com)
  * Copyright (C) 2006, 2007 Nicholas Shanks (web...@nickshanks.com)
- * Copyright (C) 2005-2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2021 Apple Inc. All rights reserved.
  * Copyright (C) 2007 Alexey Proskuryakov <a...@webkit.org>
  * Copyright (C) 2007, 2008 Eric Seidel <e...@webkit.org>
  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
@@ -32,7 +32,6 @@
 
 #include "CSSFontSelector.h"
 #include "CSSPaintImageValue.h"
-#include "CSSPendingSubstitutionValue.h"
 #include "CSSValuePool.h"
 #include "HTMLElement.h"
 #include "PaintWorkletGlobalScope.h"
@@ -368,16 +367,9 @@
     return *variableValue;
 }
 
-RefPtr<CSSValue> Builder::resolvedVariableValue(CSSPropertyID propID, const CSSValue& value)
+RefPtr<CSSValue> Builder::resolvedVariableValue(CSSPropertyID propertyID, const CSSValue& value)
 {
-    if (value.isPendingSubstitutionValue()) {
-        auto& substitutionValue = downcast<CSSPendingSubstitutionValue>(value);
-        CSSParser parser(CSSParserContext(m_state.document(), substitutionValue.baseURL()));
-        return parser.parseValueWithVariableReferences(propID, value, m_state);
-    }
-    
-    CSSParser parser(m_state.document());
-    return parser.parseValueWithVariableReferences(propID, value, m_state);
+    return CSSParser(m_state.document()).parseValueWithVariableReferences(propertyID, value, m_state);
 }
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to