Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1351)

Side by Side Diff: Source/core/fetch/CSSStyleSheetResource.cpp

Issue 733993002: CSS: Drop the quirks-mode exception for CSS MIME types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Tests. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/fetch/CSSStyleSheetResource.h ('k') | Source/core/inspector/InspectorPageAgent.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 ASSERT(c->resourceClientType() == StyleSheetResourceClient::expectedType()); 70 ASSERT(c->resourceClientType() == StyleSheetResourceClient::expectedType());
71 // Resource::didAddClient() must be before setCSSStyleSheet(), 71 // Resource::didAddClient() must be before setCSSStyleSheet(),
72 // because setCSSStyleSheet() may cause scripts to be executed, which could destroy 'c' if it is an instance of HTMLLinkElement. 72 // because setCSSStyleSheet() may cause scripts to be executed, which could destroy 'c' if it is an instance of HTMLLinkElement.
73 // see the comment of HTMLLinkElement::setCSSStyleSheet. 73 // see the comment of HTMLLinkElement::setCSSStyleSheet.
74 Resource::didAddClient(c); 74 Resource::didAddClient(c);
75 75
76 if (!isLoading()) 76 if (!isLoading())
77 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(m_resourceRe quest.url(), m_response.url(), encoding(), this); 77 static_cast<StyleSheetResourceClient*>(c)->setCSSStyleSheet(m_resourceRe quest.url(), m_response.url(), encoding(), this);
78 } 78 }
79 79
80 const String CSSStyleSheetResource::sheetText(bool enforceMIMEType, bool* hasVal idMIMEType) const 80 const String CSSStyleSheetResource::sheetText(bool* hasValidMIMEType) const
81 { 81 {
82 ASSERT(!isPurgeable()); 82 ASSERT(!isPurgeable());
83 83
84 if (!m_data || m_data->isEmpty() || !canUseSheet(enforceMIMEType, hasValidMI METype)) 84 if (!m_data || m_data->isEmpty() || !canUseSheet(hasValidMIMEType))
85 return String(); 85 return String();
86 86
87 if (!m_decodedSheetText.isNull()) 87 if (!m_decodedSheetText.isNull())
88 return m_decodedSheetText; 88 return m_decodedSheetText;
89 89
90 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory 90 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory
91 return decodedText(); 91 return decodedText();
92 } 92 }
93 93
94 const AtomicString CSSStyleSheetResource::mimeType() const 94 const AtomicString CSSStyleSheetResource::mimeType() const
(...skipping 23 matching lines...) Expand all
118 { 118 {
119 if (!m_parsedStyleSheetCache) 119 if (!m_parsedStyleSheetCache)
120 return; 120 return;
121 121
122 m_parsedStyleSheetCache->removedFromMemoryCache(); 122 m_parsedStyleSheetCache->removedFromMemoryCache();
123 m_parsedStyleSheetCache.clear(); 123 m_parsedStyleSheetCache.clear();
124 124
125 setDecodedSize(0); 125 setDecodedSize(0);
126 } 126 }
127 127
128 bool CSSStyleSheetResource::canUseSheet(bool enforceMIMEType, bool* hasValidMIME Type) const 128 bool CSSStyleSheetResource::canUseSheet(bool* hasValidMIMEType) const
129 { 129 {
130 if (errorOccurred()) 130 if (errorOccurred())
131 return false; 131 return false;
132 132
133 if (!enforceMIMEType && !hasValidMIMEType)
134 return true;
135
136 // This check exactly matches Firefox. Note that we grab the Content-Type 133 // This check exactly matches Firefox. Note that we grab the Content-Type
137 // header directly because we want to see what the value is BEFORE content 134 // header directly because we want to see what the value is BEFORE content
138 // sniffing. Firefox does this by setting a "type hint" on the channel. 135 // sniffing. Firefox does this by setting a "type hint" on the channel.
139 // This implementation should be observationally equivalent. 136 // This implementation should be observationally equivalent.
140 // 137 //
141 // This code defaults to allowing the stylesheet for non-HTTP protocols so 138 // This code defaults to allowing the stylesheet for non-HTTP protocols so
142 // folks can use standards mode for local HTML documents. 139 // folks can use standards mode for local HTML documents.
143 bool typeOK = mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/cs s") || equalIgnoringCase(mimeType(), "application/x-unknown-content-type"); 140 bool typeOK = mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/cs s") || equalIgnoringCase(mimeType(), "application/x-unknown-content-type");
144 if (hasValidMIMEType) 141 if (hasValidMIMEType)
145 *hasValidMIMEType = typeOK; 142 *hasValidMIMEType = typeOK;
146 if (!enforceMIMEType)
147 return true;
148 return typeOK; 143 return typeOK;
149 } 144 }
150 145
151 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS tyleSheet(const CSSParserContext& context) 146 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS tyleSheet(const CSSParserContext& context)
152 { 147 {
153 if (!m_parsedStyleSheetCache) 148 if (!m_parsedStyleSheetCache)
154 return nullptr; 149 return nullptr;
155 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { 150 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
156 m_parsedStyleSheetCache->removedFromMemoryCache(); 151 m_parsedStyleSheetCache->removedFromMemoryCache();
157 m_parsedStyleSheetCache.clear(); 152 m_parsedStyleSheetCache.clear();
(...skipping 18 matching lines...) Expand all
176 171
177 if (m_parsedStyleSheetCache) 172 if (m_parsedStyleSheetCache)
178 m_parsedStyleSheetCache->removedFromMemoryCache(); 173 m_parsedStyleSheetCache->removedFromMemoryCache();
179 m_parsedStyleSheetCache = sheet; 174 m_parsedStyleSheetCache = sheet;
180 m_parsedStyleSheetCache->addedToMemoryCache(); 175 m_parsedStyleSheetCache->addedToMemoryCache();
181 176
182 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); 177 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
183 } 178 }
184 179
185 } 180 }
OLDNEW
« no previous file with comments | « Source/core/fetch/CSSStyleSheetResource.h ('k') | Source/core/inspector/InspectorPageAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698