darin@apple.com | 640fa30 | 2008-02-15 05:03:55 +0000 | [diff] [blame] | 1 | /* |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 2 | * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
jfbastien@apple.com | bcea987 | 2017-12-04 23:34:57 +0000 | [diff] [blame] | 3 | * Copyright (C) 2004-2017 Apple Inc. All rights reserved. |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 19 | */ |
weinig | b35e93c | 2007-01-15 01:08:44 +0000 | [diff] [blame] | 20 | |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | #include "CSSImageValue.h" |
| 23 | |
hyatt@apple.com | 77758fd | 2016-12-08 00:34:02 +0000 | [diff] [blame] | 24 | #include "CSSMarkup.h" |
| 25 | #include "CSSPrimitiveValue.h" |
weinig | b35e93c | 2007-01-15 01:08:44 +0000 | [diff] [blame] | 26 | #include "CSSValueKeywords.h" |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 27 | #include "CachedImage.h" |
abarth@webkit.org | 17d66c6 | 2010-09-08 10:26:02 +0000 | [diff] [blame] | 28 | #include "CachedResourceLoader.h" |
commit-queue@webkit.org | 5e7ea1b | 2012-10-22 23:35:28 +0000 | [diff] [blame] | 29 | #include "CachedResourceRequest.h" |
commit-queue@webkit.org | 864dbda | 2012-11-16 12:21:57 +0000 | [diff] [blame] | 30 | #include "CachedResourceRequestInitiators.h" |
hyatt@apple.com | f368f1d | 2016-12-17 20:08:34 +0000 | [diff] [blame] | 31 | #include "DeprecatedCSSOMPrimitiveValue.h" |
yurys@chromium.org | 3f4777f | 2012-08-06 14:09:59 +0000 | [diff] [blame] | 32 | #include "Document.h" |
commit-queue@webkit.org | 864dbda | 2012-11-16 12:21:57 +0000 | [diff] [blame] | 33 | #include "Element.h" |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 34 | |
| 35 | namespace WebCore { |
| 36 | |
youenn@apple.com | 35065da | 2018-11-29 23:06:43 +0000 | [diff] [blame] | 37 | CSSImageValue::CSSImageValue(URL&& url, LoadedFromOpaqueSource loadedFromOpaqueSource) |
kling@webkit.org | 7a07e16 | 2012-03-20 12:38:45 +0000 | [diff] [blame] | 38 | : CSSValue(ImageClass) |
aestes@apple.com | 905b0d9 | 2016-10-03 20:27:33 +0000 | [diff] [blame] | 39 | , m_url(WTFMove(url)) |
andreas.kling@nokia.com | 5fd2a71 | 2011-11-07 21:19:45 +0000 | [diff] [blame] | 40 | , m_accessedImage(false) |
youenn@apple.com | 35065da | 2018-11-29 23:06:43 +0000 | [diff] [blame] | 41 | , m_loadedFromOpaqueSource(loadedFromOpaqueSource) |
andreas.kling@nokia.com | 5fd2a71 | 2011-11-07 21:19:45 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
antti@apple.com | 18efcb1 | 2016-08-30 15:06:19 +0000 | [diff] [blame] | 45 | CSSImageValue::CSSImageValue(CachedImage& image) |
kling@webkit.org | 7a07e16 | 2012-03-20 12:38:45 +0000 | [diff] [blame] | 46 | : CSSValue(ImageClass) |
antti@apple.com | 18efcb1 | 2016-08-30 15:06:19 +0000 | [diff] [blame] | 47 | , m_url(image.url()) |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 48 | , m_cachedImage(&image) |
timothy_horton@apple.com | ad938aa | 2011-12-08 23:06:15 +0000 | [diff] [blame] | 49 | , m_accessedImage(true) |
| 50 | { |
| 51 | } |
| 52 | |
darin@apple.com | 6b9561a | 2013-12-12 08:58:50 +0000 | [diff] [blame] | 53 | |
dbates@webkit.org | f21f3ae | 2017-10-19 23:48:45 +0000 | [diff] [blame] | 54 | CSSImageValue::~CSSImageValue() = default; |
simon.fraser@apple.com | bf85018 | 2010-08-26 22:15:58 +0000 | [diff] [blame] | 55 | |
antti@apple.com | 18efcb1 | 2016-08-30 15:06:19 +0000 | [diff] [blame] | 56 | bool CSSImageValue::isPending() const |
| 57 | { |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 58 | return !m_accessedImage; |
commit-queue@webkit.org | 142e49b | 2016-09-02 16:26:40 +0000 | [diff] [blame] | 59 | } |
| 60 | |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 61 | CachedImage* CSSImageValue::loadImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options) |
commit-queue@webkit.org | 142e49b | 2016-09-02 16:26:40 +0000 | [diff] [blame] | 62 | { |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 63 | if (!m_accessedImage) { |
| 64 | m_accessedImage = true; |
commit-queue@webkit.org | 142e49b | 2016-09-02 16:26:40 +0000 | [diff] [blame] | 65 | |
youenn@apple.com | 35065da | 2018-11-29 23:06:43 +0000 | [diff] [blame] | 66 | ResourceLoaderOptions loadOptions = options; |
| 67 | loadOptions.loadedFromOpaqueSource = m_loadedFromOpaqueSource; |
| 68 | CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url.string())), loadOptions); |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 69 | if (m_initiatorName.isEmpty()) |
| 70 | request.setInitiator(cachedResourceRequestInitiators().css); |
| 71 | else |
| 72 | request.setInitiator(m_initiatorName); |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 73 | |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 74 | if (options.mode == FetchOptions::Mode::Cors) { |
commit-queue@webkit.org | 858242f | 2016-10-13 10:34:15 +0000 | [diff] [blame] | 75 | ASSERT(loader.document()); |
| 76 | request.updateForAccessControl(*loader.document()); |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 77 | } |
jfbastien@apple.com | bcea987 | 2017-12-04 23:34:57 +0000 | [diff] [blame] | 78 | m_cachedImage = loader.requestImage(WTFMove(request)).value_or(nullptr); |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 79 | } |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 80 | return m_cachedImage.get(); |
eseidel | 13a6422 | 2006-05-16 05:33:34 +0000 | [diff] [blame] | 81 | } |
| 82 | |
cdumez@apple.com | 73750cc | 2017-06-19 19:53:16 +0000 | [diff] [blame] | 83 | bool CSSImageValue::traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const |
antti@apple.com | 99ddb94 | 2012-08-05 21:03:42 +0000 | [diff] [blame] | 84 | { |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 85 | if (!m_cachedImage) |
antti@apple.com | 99ddb94 | 2012-08-05 21:03:42 +0000 | [diff] [blame] | 86 | return false; |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 87 | return handler(*m_cachedImage); |
antti@apple.com | 99ddb94 | 2012-08-05 21:03:42 +0000 | [diff] [blame] | 88 | } |
| 89 | |
commit-queue@webkit.org | b4b784a | 2013-02-11 11:00:54 +0000 | [diff] [blame] | 90 | bool CSSImageValue::equals(const CSSImageValue& other) const |
| 91 | { |
| 92 | return m_url == other.m_url; |
| 93 | } |
| 94 | |
timothy_horton@apple.com | df4356a | 2013-09-04 20:13:30 +0000 | [diff] [blame] | 95 | String CSSImageValue::customCSSText() const |
kling@webkit.org | 7a07e16 | 2012-03-20 12:38:45 +0000 | [diff] [blame] | 96 | { |
hyatt@apple.com | 77758fd | 2016-12-08 00:34:02 +0000 | [diff] [blame] | 97 | return serializeURL(m_url); |
kling@webkit.org | 7a07e16 | 2012-03-20 12:38:45 +0000 | [diff] [blame] | 98 | } |
| 99 | |
commit-queue@webkit.org | 37d24ee | 2017-07-21 21:20:25 +0000 | [diff] [blame] | 100 | Ref<DeprecatedCSSOMValue> CSSImageValue::createDeprecatedCSSOMWrapper(CSSStyleDeclaration& styleDeclaration) const |
kling@webkit.org | 86db712 | 2012-05-03 18:08:08 +0000 | [diff] [blame] | 101 | { |
| 102 | // NOTE: We expose CSSImageValues as URI primitive values in CSSOM to maintain old behavior. |
commit-queue@webkit.org | 37d24ee | 2017-07-21 21:20:25 +0000 | [diff] [blame] | 103 | return DeprecatedCSSOMPrimitiveValue::create(CSSPrimitiveValue::create(m_url, CSSPrimitiveValue::CSS_URI), styleDeclaration); |
kling@webkit.org | 86db712 | 2012-05-03 18:08:08 +0000 | [diff] [blame] | 104 | } |
| 105 | |
simon.fraser@apple.com | 6686478 | 2018-04-27 17:59:25 +0000 | [diff] [blame] | 106 | bool CSSImageValue::knownToBeOpaque(const RenderElement& renderer) const |
junov@google.com | f3d27f2 | 2012-11-23 18:43:51 +0000 | [diff] [blame] | 107 | { |
antti@apple.com | c78f9d4 | 2016-09-04 13:42:42 +0000 | [diff] [blame] | 108 | if (!m_cachedImage) |
| 109 | return false; |
simon.fraser@apple.com | 6686478 | 2018-04-27 17:59:25 +0000 | [diff] [blame] | 110 | return m_cachedImage->currentFrameKnownToBeOpaque(&renderer); |
junov@google.com | f3d27f2 | 2012-11-23 18:43:51 +0000 | [diff] [blame] | 111 | } |
| 112 | |
weinig | b35e93c | 2007-01-15 01:08:44 +0000 | [diff] [blame] | 113 | } // namespace WebCore |