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

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

Issue 1706243002: Don't use SVG resource documents with an unrecognized MIME-type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use testharness; add unit test for extractMIMETypeFromMediaType Created 4 years, 9 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
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 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "core/fetch/CSSStyleSheetResource.h" 27 #include "core/fetch/CSSStyleSheetResource.h"
28 28
29 #include "core/css/StyleSheetContents.h" 29 #include "core/css/StyleSheetContents.h"
30 #include "core/fetch/FetchRequest.h" 30 #include "core/fetch/FetchRequest.h"
31 #include "core/fetch/ResourceClientWalker.h" 31 #include "core/fetch/ResourceClientWalker.h"
32 #include "core/fetch/ResourceFetcher.h" 32 #include "core/fetch/ResourceFetcher.h"
33 #include "core/fetch/StyleSheetResourceClient.h" 33 #include "core/fetch/StyleSheetResourceClient.h"
34 #include "platform/SharedBuffer.h" 34 #include "platform/SharedBuffer.h"
35 #include "platform/network/HTTPParsers.h"
36 #include "wtf/CurrentTime.h" 35 #include "wtf/CurrentTime.h"
37 36
38 namespace blink { 37 namespace blink {
39 38
40 PassRefPtrWillBeRawPtr<CSSStyleSheetResource> CSSStyleSheetResource::fetch(Fetch Request& request, ResourceFetcher* fetcher) 39 PassRefPtrWillBeRawPtr<CSSStyleSheetResource> CSSStyleSheetResource::fetch(Fetch Request& request, ResourceFetcher* fetcher)
41 { 40 {
42 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone ); 41 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone );
43 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textStyle); 42 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon textStyle);
44 return toCSSStyleSheetResource(fetcher->requestResource(request, CSSStyleShe etResourceFactory())); 43 return toCSSStyleSheetResource(fetcher->requestResource(request, CSSStyleShe etResourceFactory()));
45 } 44 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck)) 97 if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck))
99 return String(); 98 return String();
100 99
101 if (!m_decodedSheetText.isNull()) 100 if (!m_decodedSheetText.isNull())
102 return m_decodedSheetText; 101 return m_decodedSheetText;
103 102
104 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory 103 // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory
105 return decodedText(); 104 return decodedText();
106 } 105 }
107 106
108 const AtomicString CSSStyleSheetResource::mimeType() const
109 {
110 return extractMIMETypeFromMediaType(response().httpHeaderField(HTTPNames::Co ntent_Type)).lower();
111 }
112
113 void CSSStyleSheetResource::checkNotify() 107 void CSSStyleSheetResource::checkNotify()
114 { 108 {
115 // Decode the data to find out the encoding and keep the sheet text around d uring checkNotify() 109 // Decode the data to find out the encoding and keep the sheet text around d uring checkNotify()
116 if (m_data) 110 if (m_data)
117 m_decodedSheetText = decodedText(); 111 m_decodedSheetText = decodedText();
118 112
119 ResourceClientWalker<StyleSheetResourceClient> w(m_clients); 113 ResourceClientWalker<StyleSheetResourceClient> w(m_clients);
120 while (StyleSheetResourceClient* c = w.next()) 114 while (StyleSheetResourceClient* c = w.next())
121 c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), encoding( ), this); 115 c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), encoding( ), this);
122 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate. 116 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate.
(...skipping 23 matching lines...) Expand all
146 140
147 // This check exactly matches Firefox. Note that we grab the Content-Type 141 // This check exactly matches Firefox. Note that we grab the Content-Type
148 // header directly because we want to see what the value is BEFORE content 142 // header directly because we want to see what the value is BEFORE content
149 // sniffing. Firefox does this by setting a "type hint" on the channel. 143 // sniffing. Firefox does this by setting a "type hint" on the channel.
150 // This implementation should be observationally equivalent. 144 // This implementation should be observationally equivalent.
151 // 145 //
152 // This code defaults to allowing the stylesheet for non-HTTP protocols so 146 // This code defaults to allowing the stylesheet for non-HTTP protocols so
153 // folks can use standards mode for local HTML documents. 147 // folks can use standards mode for local HTML documents.
154 if (mimeTypeCheck == MIMETypeCheck::Lax) 148 if (mimeTypeCheck == MIMETypeCheck::Lax)
155 return true; 149 return true;
156 return mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/css") || equalIgnoringCase(mimeType(), "application/x-unknown-content-type"); 150 AtomicString contentType = httpContentType();
151 return contentType.isEmpty() || equalIgnoringCase(contentType, "text/css") | | equalIgnoringCase(contentType, "application/x-unknown-content-type");
157 } 152 }
158 153
159 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS tyleSheet(const CSSParserContext& context) 154 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS tyleSheet(const CSSParserContext& context)
160 { 155 {
161 if (!m_parsedStyleSheetCache) 156 if (!m_parsedStyleSheetCache)
162 return nullptr; 157 return nullptr;
163 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { 158 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
164 m_parsedStyleSheetCache->removedFromMemoryCache(); 159 m_parsedStyleSheetCache->removedFromMemoryCache();
165 m_parsedStyleSheetCache.clear(); 160 m_parsedStyleSheetCache.clear();
166 return nullptr; 161 return nullptr;
(...skipping 17 matching lines...) Expand all
184 179
185 if (m_parsedStyleSheetCache) 180 if (m_parsedStyleSheetCache)
186 m_parsedStyleSheetCache->removedFromMemoryCache(); 181 m_parsedStyleSheetCache->removedFromMemoryCache();
187 m_parsedStyleSheetCache = sheet; 182 m_parsedStyleSheetCache = sheet;
188 m_parsedStyleSheetCache->addedToMemoryCache(); 183 m_parsedStyleSheetCache->addedToMemoryCache();
189 184
190 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); 185 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());
191 } 186 }
192 187
193 } // namespace blink 188 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CSSStyleSheetResource.h ('k') | third_party/WebKit/Source/core/fetch/DocumentResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698