| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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* hasValidMIMEType) const | 80 const String CSSStyleSheetResource::sheetText(bool enforceMIMEType, bool* hasVal
idMIMEType) const |
| 81 { | 81 { |
| 82 ASSERT(!isPurgeable()); | 82 ASSERT(!isPurgeable()); |
| 83 | 83 |
| 84 if (!m_data || m_data->isEmpty() || !canUseSheet(hasValidMIMEType)) | 84 if (!m_data || m_data->isEmpty() || !canUseSheet(enforceMIMEType, hasValidMI
METype)) |
| 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 Loading... |
| 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* hasValidMIMEType) const | 128 bool CSSStyleSheetResource::canUseSheet(bool enforceMIMEType, bool* hasValidMIME
Type) 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 |
| 133 // This check exactly matches Firefox. Note that we grab the Content-Type | 136 // This check exactly matches Firefox. Note that we grab the Content-Type |
| 134 // header directly because we want to see what the value is BEFORE content | 137 // header directly because we want to see what the value is BEFORE content |
| 135 // sniffing. Firefox does this by setting a "type hint" on the channel. | 138 // sniffing. Firefox does this by setting a "type hint" on the channel. |
| 136 // This implementation should be observationally equivalent. | 139 // This implementation should be observationally equivalent. |
| 137 // | 140 // |
| 138 // This code defaults to allowing the stylesheet for non-HTTP protocols so | 141 // This code defaults to allowing the stylesheet for non-HTTP protocols so |
| 139 // folks can use standards mode for local HTML documents. | 142 // folks can use standards mode for local HTML documents. |
| 140 bool typeOK = mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/cs
s") || equalIgnoringCase(mimeType(), "application/x-unknown-content-type"); | 143 bool typeOK = mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/cs
s") || equalIgnoringCase(mimeType(), "application/x-unknown-content-type"); |
| 141 if (hasValidMIMEType) | 144 if (hasValidMIMEType) |
| 142 *hasValidMIMEType = typeOK; | 145 *hasValidMIMEType = typeOK; |
| 146 if (!enforceMIMEType) |
| 147 return true; |
| 143 return typeOK; | 148 return typeOK; |
| 144 } | 149 } |
| 145 | 150 |
| 146 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS
tyleSheet(const CSSParserContext& context) | 151 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS
tyleSheet(const CSSParserContext& context) |
| 147 { | 152 { |
| 148 if (!m_parsedStyleSheetCache) | 153 if (!m_parsedStyleSheetCache) |
| 149 return nullptr; | 154 return nullptr; |
| 150 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { | 155 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { |
| 151 m_parsedStyleSheetCache->removedFromMemoryCache(); | 156 m_parsedStyleSheetCache->removedFromMemoryCache(); |
| 152 m_parsedStyleSheetCache.clear(); | 157 m_parsedStyleSheetCache.clear(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 171 | 176 |
| 172 if (m_parsedStyleSheetCache) | 177 if (m_parsedStyleSheetCache) |
| 173 m_parsedStyleSheetCache->removedFromMemoryCache(); | 178 m_parsedStyleSheetCache->removedFromMemoryCache(); |
| 174 m_parsedStyleSheetCache = sheet; | 179 m_parsedStyleSheetCache = sheet; |
| 175 m_parsedStyleSheetCache->addedToMemoryCache(); | 180 m_parsedStyleSheetCache->addedToMemoryCache(); |
| 176 | 181 |
| 177 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 182 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
| 178 } | 183 } |
| 179 | 184 |
| 180 } | 185 } |
| OLD | NEW |