OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 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 | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/css/CSSImageValue.h" | 22 #include "core/css/CSSImageValue.h" |
23 | 23 |
24 #include "core/css/CSSMarkup.h" | 24 #include "core/css/CSSMarkup.h" |
| 25 #include "core/css/resolver/ElementStyleResources.h" |
25 #include "core/dom/Document.h" | 26 #include "core/dom/Document.h" |
26 #include "core/fetch/FetchInitiatorTypeNames.h" | 27 #include "core/fetch/FetchInitiatorTypeNames.h" |
27 #include "core/fetch/FetchRequest.h" | 28 #include "core/fetch/FetchRequest.h" |
28 #include "core/fetch/ImageResource.h" | 29 #include "core/fetch/ImageResource.h" |
29 #include "core/loader/MixedContentChecker.h" | 30 #include "core/loader/MixedContentChecker.h" |
30 #include "core/style/StyleFetchedImage.h" | 31 #include "core/style/StyleFetchedImage.h" |
31 #include "core/style/StylePendingImage.h" | 32 #include "core/style/StylePendingImage.h" |
32 #include "platform/weborigin/KURL.h" | 33 #include "platform/weborigin/KURL.h" |
33 #include "platform/weborigin/SecurityPolicy.h" | 34 #include "platform/weborigin/SecurityPolicy.h" |
34 | 35 |
35 namespace blink { | 36 namespace blink { |
36 | 37 |
37 CSSImageValue::CSSImageValue(const String& rawValue, const KURL& url, StyleImage
* image) | 38 CSSImageValue::CSSImageValue(const String& rawValue, const String& url, StyleIma
ge* image) |
38 : CSSValue(ImageClass) | 39 : CSSValue(ImageClass) |
39 , m_relativeURL(rawValue) | 40 , m_relativeURL(rawValue) |
40 , m_absoluteURL(url.string()) | 41 , m_absoluteURL(url) |
41 , m_image(image) | 42 , m_image(image) |
42 , m_accessedImage(image) | 43 , m_accessedImage(image) |
43 { | 44 { |
| 45 printf("** Made a CSSImageValue: %s, %s, image? %d, accessed? %d\n", m_relat
iveURL.ascii().data(), m_absoluteURL.ascii().data(), (bool)m_image, m_accessedIm
age); |
44 } | 46 } |
45 | 47 |
46 CSSImageValue::~CSSImageValue() | 48 CSSImageValue::~CSSImageValue() |
47 { | 49 { |
| 50 printf("** Freed a CSSImageValue: %s, %s, image? %d, accessed? %d\n", m_rela
tiveURL.ascii().data(), m_absoluteURL.ascii().data(), (bool)m_image, m_accessedI
mage); |
48 } | 51 } |
49 | 52 |
| 53 |
50 StyleImage* CSSImageValue::cachedOrPendingImage() | 54 StyleImage* CSSImageValue::cachedOrPendingImage() |
51 { | 55 { |
| 56 printf("Ahh old cachedOrPendingImage() function\n"); |
52 if (!m_image) | 57 if (!m_image) |
53 m_image = StylePendingImage::create(this); | 58 m_image = StylePendingImage::create(this); |
54 | 59 |
55 return m_image.get(); | 60 return m_image.get(); |
56 } | 61 } |
57 | 62 |
58 StyleFetchedImage* CSSImageValue::cachedImage(Document* document, const Resource
LoaderOptions& options) | 63 |
| 64 StyleImage* CSSImageValue::cachedOrPendingImage(CSSStyleImageMap& imageMap) |
59 { | 65 { |
| 66 RefPtrWillBeMember<StyleImage>& value = imageMap.getStyleImageEntry(this).st
oredValue->value; |
| 67 if (!value) |
| 68 value = StylePendingImage::create(this); |
| 69 return value.get(); |
| 70 } |
| 71 |
| 72 StyleFetchedImage* CSSImageValue::cachedImage(Document* document, const Resource
LoaderOptions& options, CSSStyleImageMap& imageMap) |
| 73 { |
| 74 printf("Yay new cachedImage() function\n"); |
60 ASSERT(document); | 75 ASSERT(document); |
61 | 76 |
| 77 RefPtrWillBeMember<StyleImage>& value = imageMap.getStyleImageEntry(this).st
oredValue->value; |
62 if (!m_accessedImage) { | 78 if (!m_accessedImage) { |
63 m_accessedImage = true; | 79 m_accessedImage = true; |
64 | 80 |
65 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE
mpty() ? FetchInitiatorTypeNames::css : m_initiatorName, options); | 81 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE
mpty() ? FetchInitiatorTypeNames::css : m_initiatorName, options); |
66 request.mutableResourceRequest().setHTTPReferrer(SecurityPolicy::generat
eReferrer(m_referrer.referrerPolicy, request.url(), m_referrer.referrer)); | 82 request.mutableResourceRequest().setHTTPReferrer(SecurityPolicy::generat
eReferrer(m_referrer.referrerPolicy, request.url(), m_referrer.referrer)); |
67 | 83 |
68 if (options.corsEnabled == IsCORSEnabled) | 84 if (options.corsEnabled == IsCORSEnabled) |
69 request.setCrossOriginAccessControl(document->securityOrigin(), opti
ons.allowCredentials, options.credentialsRequested); | 85 request.setCrossOriginAccessControl(document->securityOrigin(), opti
ons.allowCredentials, options.credentialsRequested); |
70 | 86 |
| 87 printf("Downloading image from %s.\n", m_absoluteURL.ascii().data()); |
71 if (ResourcePtr<ImageResource> cachedImage = ImageResource::fetch(reques
t, document->fetcher())) | 88 if (ResourcePtr<ImageResource> cachedImage = ImageResource::fetch(reques
t, document->fetcher())) |
72 m_image = StyleFetchedImage::create(cachedImage.get(), document); | 89 value = StyleFetchedImage::create(cachedImage.get(), document); |
73 } | 90 } |
74 | 91 |
75 return (m_image && m_image->isImageResource()) ? toStyleFetchedImage(m_image
) : 0; | 92 return (value && value->isImageResource()) ? toStyleFetchedImage(value) : 0; |
76 } | 93 } |
77 | 94 |
78 void CSSImageValue::restoreCachedResourceIfNeeded(Document& document) | 95 void CSSImageValue::restoreCachedResourceIfNeeded(Document& document, CSSStyleIm
ageMap& imageMap) |
79 { | 96 { |
80 if (!m_accessedImage || !m_image->isImageResource() || !document.fetcher()) | 97 RefPtrWillBeMember<StyleImage>& value = imageMap.getStyleImageEntry(this).st
oredValue->value; |
| 98 if (!m_accessedImage || !value->isImageResource() || !document.fetcher()) |
81 return; | 99 return; |
82 if (document.fetcher()->cachedResource(KURL(ParsedURLString, m_absoluteURL))
) | 100 if (document.fetcher()->cachedResource(KURL(ParsedURLString, m_absoluteURL))
) |
83 return; | 101 return; |
84 | 102 |
85 ImageResource* resource = m_image->cachedImage(); | 103 ImageResource* resource = value->cachedImage(); |
86 if (!resource) | 104 if (!resource) |
87 return; | 105 return; |
88 | 106 |
89 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isEmpty
() ? FetchInitiatorTypeNames::css : m_initiatorName, resource->options()); | 107 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isEmpty
() ? FetchInitiatorTypeNames::css : m_initiatorName, resource->options()); |
90 MixedContentChecker::shouldBlockFetch(document.frame(), resource->lastResour
ceRequest(), | 108 MixedContentChecker::shouldBlockFetch(document.frame(), resource->lastResour
ceRequest(), |
91 resource->lastResourceRequest().url(), MixedContentChecker::SendReport); | 109 resource->lastResourceRequest().url(), MixedContentChecker::SendReport); |
92 document.fetcher()->requestLoadStarted(resource, request, ResourceFetcher::R
esourceLoadingFromCache); | 110 document.fetcher()->requestLoadStarted(resource, request, ResourceFetcher::R
esourceLoadingFromCache); |
93 } | 111 } |
94 | 112 |
95 bool CSSImageValue::hasFailedOrCanceledSubresources() const | 113 bool CSSImageValue::hasFailedOrCanceledSubresources() const |
96 { | 114 { |
| 115 printf("Oh no! In hasFailedOrCancelledSubresources\n"); |
97 if (!m_image || !m_image->isImageResource()) | 116 if (!m_image || !m_image->isImageResource()) |
98 return false; | 117 return false; |
99 if (Resource* cachedResource = toStyleFetchedImage(m_image)->cachedImage()) | 118 if (Resource* cachedResource = toStyleFetchedImage(m_image)->cachedImage()) |
100 return cachedResource->loadFailedOrCanceled(); | 119 return cachedResource->loadFailedOrCanceled(); |
101 return true; | 120 return true; |
102 } | 121 } |
103 | 122 |
104 bool CSSImageValue::equals(const CSSImageValue& other) const | 123 bool CSSImageValue::equals(const CSSImageValue& other) const |
105 { | 124 { |
106 return m_absoluteURL == other.m_absoluteURL; | 125 return m_absoluteURL == other.m_absoluteURL; |
107 } | 126 } |
108 | 127 |
109 String CSSImageValue::customCSSText() const | 128 String CSSImageValue::customCSSText() const |
110 { | 129 { |
111 return "url(" + quoteCSSURLIfNeeded(m_absoluteURL) + ")"; | 130 return "url(" + quoteCSSURLIfNeeded(m_absoluteURL) + ")"; |
112 } | 131 } |
113 | 132 |
114 bool CSSImageValue::knownToBeOpaque(const LayoutObject* layoutObject) const | 133 bool CSSImageValue::knownToBeOpaque(const LayoutObject* layoutObject) const |
115 { | 134 { |
116 return m_image ? m_image->knownToBeOpaque(layoutObject) : false; | 135 return m_image ? m_image->knownToBeOpaque(layoutObject) : false; |
117 } | 136 } |
118 | 137 |
119 DEFINE_TRACE_AFTER_DISPATCH(CSSImageValue) | 138 DEFINE_TRACE_AFTER_DISPATCH(CSSImageValue) |
120 { | 139 { |
121 visitor->trace(m_image); | 140 visitor->trace(m_image); |
122 CSSValue::traceAfterDispatch(visitor); | 141 CSSValue::traceAfterDispatch(visitor); |
123 } | 142 } |
124 | 143 |
| 144 /* |
125 void CSSImageValue::reResolveURL(const Document& document) | 145 void CSSImageValue::reResolveURL(const Document& document) |
126 { | 146 { |
127 KURL url = document.completeURL(m_relativeURL); | 147 KURL url = document.completeURL(m_relativeURL); |
128 if (url == m_absoluteURL) | 148 if (url == m_absoluteURL) |
129 return; | 149 return; |
130 m_absoluteURL = url.string(); | 150 m_absoluteURL = url.string(); |
131 m_accessedImage = false; | 151 m_accessedImage = false; |
132 m_image.clear(); | 152 m_image.clear(); |
133 } | 153 } |
| 154 */ |
134 | 155 |
135 } // namespace blink | 156 } // namespace blink |
OLD | NEW |