Commit 8b3ffb03 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Support relative URLs in CSSURLImageValue.

We currently don't support relative URLs. This patch uses ScriptState
to resolve relative URLs. Note that the CSSURLImageValue.url needs to
return the original (relative) url given by the constructor. Since
CSSImageValue already stores the relative url for serialization, we
only need to expose it to CSSURLImageValue.

Bug: 783031
Change-Id: I12b7ae8e98306e4debd6d3b1a9fd1ef1eca9752e
Reviewed-on: https://chromium-review.googlesource.com/760057
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515491}
parent 80b8282d
......@@ -5,7 +5,7 @@
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/testhelper.js"></script>
<div id="testImage3"></div>
<body>
<script>
'use strict';
......@@ -21,15 +21,7 @@ function loadImageResource(imageValue) {
return image;
}
// TODO(crbug.com/783031): Temporary helper function since CSSURLImageValue doesn't
// support relative URLs yet. This can be removed once it does.
function url() {
var c = document.location.href.split('/');
c[c.length - 1] = '../resources/1x1-green.png';
return c.join('/');
}
const gTestUrl = url();
const gTestUrl = '../resources/1x1-green.png';
const gBase64TestUrl = 'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=';
const gBadTestUrl = document.location.href;
......
......@@ -68,6 +68,7 @@ class CORE_EXPORT CSSImageValue : public CSSValue {
CrossOriginAttributeValue = kCrossOriginAttributeNotSet);
const String& Url() const { return absolute_url_; }
const String& RelativeUrl() const { return relative_url_; }
const Referrer& GetReferrer() const { return referrer_; }
......
......@@ -6,6 +6,7 @@
#define CSSURLImageValue_h
#include "core/css/cssom/CSSStyleImageValue.h"
#include "platform/bindings/ScriptState.h"
namespace blink {
......@@ -14,10 +15,14 @@ class CORE_EXPORT CSSURLImageValue final : public CSSStyleImageValue {
DEFINE_WRAPPERTYPEINFO();
public:
static CSSURLImageValue* Create(const AtomicString& url) {
// TODO(crbug.com/783031): This should probably obtain base url information
// (e.g. from execution context) to parse relative URLs correctly.
return new CSSURLImageValue(CSSImageValue::Create(url));
static CSSURLImageValue* Create(ScriptState* script_state,
const AtomicString& url) {
const auto* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context);
// Use absolute URL for CSSImageValue but keep relative URL for
// getter and serialization.
return new CSSURLImageValue(CSSImageValue::Create(
url, execution_context->CompleteURL(url), Referrer()));
}
static CSSURLImageValue* Create(const CSSImageValue* image_value) {
return new CSSURLImageValue(image_value);
......@@ -27,7 +32,7 @@ class CORE_EXPORT CSSURLImageValue final : public CSSStyleImageValue {
const CSSValue* ToCSSValue() const override { return CssImageValue(); }
const String& url() const { return CssImageValue()->Url(); }
const String& url() const { return CssImageValue()->RelativeUrl(); }
private:
explicit CSSURLImageValue(const CSSImageValue* image_value)
......
......@@ -6,6 +6,7 @@
// Spec: https://drafts.css-houdini.org/css-typed-om/#cssurlimagevalue
[
Constructor(USVString url),
ConstructorCallWith=ScriptState,
Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM
] interface CSSURLImageValue : CSSImageValue {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment