OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
7 | 7 |
8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
(...skipping 10 matching lines...) Expand all Loading... |
21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
22 | 22 |
23 This class provides all functionality needed for loading images, style | 23 This class provides all functionality needed for loading images, style |
24 sheets and html pages from the web. It has a memory cache for these objects. | 24 sheets and html pages from the web. It has a memory cache for these objects. |
25 */ | 25 */ |
26 | 26 |
27 #include "core/loader/resource/CSSStyleSheetResource.h" | 27 #include "core/loader/resource/CSSStyleSheetResource.h" |
28 | 28 |
29 #include "core/css/StyleSheetContents.h" | 29 #include "core/css/StyleSheetContents.h" |
30 #include "core/loader/resource/StyleSheetResourceClient.h" | 30 #include "core/loader/resource/StyleSheetResourceClient.h" |
| 31 #include "platform/HTTPNames.h" |
31 #include "platform/SharedBuffer.h" | 32 #include "platform/SharedBuffer.h" |
32 #include "platform/loader/fetch/FetchRequest.h" | 33 #include "platform/loader/fetch/FetchRequest.h" |
33 #include "platform/loader/fetch/MemoryCache.h" | 34 #include "platform/loader/fetch/MemoryCache.h" |
34 #include "platform/loader/fetch/ResourceClientWalker.h" | 35 #include "platform/loader/fetch/ResourceClientWalker.h" |
35 #include "platform/loader/fetch/ResourceFetcher.h" | 36 #include "platform/loader/fetch/ResourceFetcher.h" |
| 37 #include "platform/weborigin/SecurityPolicy.h" |
36 #include "wtf/CurrentTime.h" | 38 #include "wtf/CurrentTime.h" |
37 | 39 |
38 namespace blink { | 40 namespace blink { |
39 | 41 |
40 CSSStyleSheetResource* CSSStyleSheetResource::fetch(FetchRequest& request, | 42 CSSStyleSheetResource* CSSStyleSheetResource::fetch(FetchRequest& request, |
41 ResourceFetcher* fetcher) { | 43 ResourceFetcher* fetcher) { |
42 DCHECK_EQ(request.resourceRequest().frameType(), | 44 DCHECK_EQ(request.resourceRequest().frameType(), |
43 WebURLRequest::FrameTypeNone); | 45 WebURLRequest::FrameTypeNone); |
44 request.setRequestContext(WebURLRequest::RequestContextStyle); | 46 request.setRequestContext(WebURLRequest::RequestContextStyle); |
45 CSSStyleSheetResource* resource = toCSSStyleSheetResource( | 47 CSSStyleSheetResource* resource = toCSSStyleSheetResource( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // setCSSStyleSheet() may cause scripts to be executed, which could destroy | 94 // setCSSStyleSheet() may cause scripts to be executed, which could destroy |
93 // 'c' if it is an instance of HTMLLinkElement. see the comment of | 95 // 'c' if it is an instance of HTMLLinkElement. see the comment of |
94 // HTMLLinkElement::setCSSStyleSheet. | 96 // HTMLLinkElement::setCSSStyleSheet. |
95 Resource::didAddClient(c); | 97 Resource::didAddClient(c); |
96 | 98 |
97 if (hasClient(c) && m_didNotifyFirstData) | 99 if (hasClient(c) && m_didNotifyFirstData) |
98 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); | 100 static_cast<StyleSheetResourceClient*>(c)->didAppendFirstData(this); |
99 | 101 |
100 // |c| might be removed in didAppendFirstData, so ensure it is still a client. | 102 // |c| might be removed in didAppendFirstData, so ensure it is still a client. |
101 if (hasClient(c) && !isLoading()) { | 103 if (hasClient(c) && !isLoading()) { |
| 104 ReferrerPolicy referrerPolicy = ReferrerPolicyDefault; |
| 105 String referrerPolicyHeader = |
| 106 response().httpHeaderField(HTTPNames::Referrer_Policy); |
| 107 if (!referrerPolicyHeader.isNull()) { |
| 108 SecurityPolicy::referrerPolicyFromHeaderValue( |
| 109 referrerPolicyHeader, DoNotSupportReferrerPolicyLegacyKeywords, |
| 110 &referrerPolicy); |
| 111 } |
102 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet( | 112 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet( |
103 resourceRequest().url(), response().url(), encoding(), this); | 113 resourceRequest().url(), response().url(), referrerPolicy, encoding(), |
| 114 this); |
104 } | 115 } |
105 } | 116 } |
106 | 117 |
107 const String CSSStyleSheetResource::sheetText( | 118 const String CSSStyleSheetResource::sheetText( |
108 MIMETypeCheck mimeTypeCheck) const { | 119 MIMETypeCheck mimeTypeCheck) const { |
109 if (!canUseSheet(mimeTypeCheck)) | 120 if (!canUseSheet(mimeTypeCheck)) |
110 return String(); | 121 return String(); |
111 | 122 |
112 // Use cached decoded sheet text when available | 123 // Use cached decoded sheet text when available |
113 if (!m_decodedSheetText.isNull()) { | 124 if (!m_decodedSheetText.isNull()) { |
(...skipping 18 matching lines...) Expand all Loading... |
132 while (StyleSheetResourceClient* c = w.next()) | 143 while (StyleSheetResourceClient* c = w.next()) |
133 c->didAppendFirstData(this); | 144 c->didAppendFirstData(this); |
134 m_didNotifyFirstData = true; | 145 m_didNotifyFirstData = true; |
135 } | 146 } |
136 | 147 |
137 void CSSStyleSheetResource::checkNotify() { | 148 void CSSStyleSheetResource::checkNotify() { |
138 // Decode the data to find out the encoding and cache the decoded sheet text. | 149 // Decode the data to find out the encoding and cache the decoded sheet text. |
139 if (data()) | 150 if (data()) |
140 setDecodedSheetText(decodedText()); | 151 setDecodedSheetText(decodedText()); |
141 | 152 |
| 153 ReferrerPolicy referrerPolicy = ReferrerPolicyDefault; |
| 154 String referrerPolicyHeader = |
| 155 response().httpHeaderField(HTTPNames::Referrer_Policy); |
| 156 if (!referrerPolicyHeader.isNull()) { |
| 157 SecurityPolicy::referrerPolicyFromHeaderValue( |
| 158 referrerPolicyHeader, DoNotSupportReferrerPolicyLegacyKeywords, |
| 159 &referrerPolicy); |
| 160 } |
| 161 |
142 ResourceClientWalker<StyleSheetResourceClient> w(clients()); | 162 ResourceClientWalker<StyleSheetResourceClient> w(clients()); |
143 while (StyleSheetResourceClient* c = w.next()) { | 163 while (StyleSheetResourceClient* c = w.next()) { |
144 markClientFinished(c); | 164 markClientFinished(c); |
145 c->setCSSStyleSheet(resourceRequest().url(), response().url(), encoding(), | 165 c->setCSSStyleSheet(resourceRequest().url(), response().url(), |
146 this); | 166 referrerPolicy, encoding(), this); |
147 } | 167 } |
148 | 168 |
149 // Clear raw bytes as now we have the full decoded sheet text. | 169 // Clear raw bytes as now we have the full decoded sheet text. |
150 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) | 170 // We wait for all LinkStyle::setCSSStyleSheet to run (at least once) |
151 // as SubresourceIntegrity checks require raw bytes. | 171 // as SubresourceIntegrity checks require raw bytes. |
152 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, | 172 // Note that LinkStyle::setCSSStyleSheet can be called from didAddClient too, |
153 // but is safe as we should have a cached ResourceIntegrityDisposition. | 173 // but is safe as we should have a cached ResourceIntegrityDisposition. |
154 clearData(); | 174 clearData(); |
155 } | 175 } |
156 | 176 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 244 } |
225 | 245 |
226 void CSSStyleSheetResource::updateDecodedSize() { | 246 void CSSStyleSheetResource::updateDecodedSize() { |
227 size_t decodedSize = m_decodedSheetText.charactersSizeInBytes(); | 247 size_t decodedSize = m_decodedSheetText.charactersSizeInBytes(); |
228 if (m_parsedStyleSheetCache) | 248 if (m_parsedStyleSheetCache) |
229 decodedSize += m_parsedStyleSheetCache->estimatedSizeInBytes(); | 249 decodedSize += m_parsedStyleSheetCache->estimatedSizeInBytes(); |
230 setDecodedSize(decodedSize); | 250 setDecodedSize(decodedSize); |
231 } | 251 } |
232 | 252 |
233 } // namespace blink | 253 } // namespace blink |
OLD | NEW |