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

Side by Side Diff: third_party/WebKit/Source/core/fetch/DocumentResource.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) 2010 Rob Buis <rwlbuis@gmail.com> 2 Copyright (C) 2010 Rob Buis <rwlbuis@gmail.com>
3 Copyright (C) 2011 Cosmin Truta <ctruta@gmail.com> 3 Copyright (C) 2011 Cosmin Truta <ctruta@gmail.com>
4 Copyright (C) 2012 University of Szeged 4 Copyright (C) 2012 University of Szeged
5 Copyright (C) 2012 Renata Hodovan <reni@webkit.org> 5 Copyright (C) 2012 Renata Hodovan <reni@webkit.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader); 60 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
61 } 61 }
62 62
63 String DocumentResource::encoding() const 63 String DocumentResource::encoding() const
64 { 64 {
65 return m_decoder->encoding().name(); 65 return m_decoder->encoding().name();
66 } 66 }
67 67
68 void DocumentResource::checkNotify() 68 void DocumentResource::checkNotify()
69 { 69 {
70 if (m_data) { 70 if (m_data && mimeTypeAllowed()) {
71 StringBuilder decodedText; 71 StringBuilder decodedText;
72 decodedText.append(m_decoder->decode(m_data->data(), m_data->size())); 72 decodedText.append(m_decoder->decode(m_data->data(), m_data->size()));
73 decodedText.append(m_decoder->flush()); 73 decodedText.append(m_decoder->flush());
74 // We don't need to create a new frame because the new document belongs to the parent UseElement. 74 // We don't need to create a new frame because the new document belongs to the parent UseElement.
75 m_document = createDocument(response().url()); 75 m_document = createDocument(response().url());
76 m_document->setContent(decodedText.toString()); 76 m_document->setContent(decodedText.toString());
77 } 77 }
78 Resource::checkNotify(); 78 Resource::checkNotify();
79 } 79 }
80 80
81 bool DocumentResource::mimeTypeAllowed() const
82 {
83 ASSERT(type() == SVGDocument);
84 AtomicString mimeType = response().mimeType();
85 if (response().isHTTP())
86 mimeType = httpContentType();
87 return mimeType == "image/svg+xml"
88 || mimeType == "text/xml"
89 || mimeType == "application/xml"
90 || mimeType == "application/xhtml+xml";
91 }
92
81 PassRefPtrWillBeRawPtr<Document> DocumentResource::createDocument(const KURL& ur l) 93 PassRefPtrWillBeRawPtr<Document> DocumentResource::createDocument(const KURL& ur l)
82 { 94 {
83 switch (type()) { 95 switch (type()) {
84 case SVGDocument: 96 case SVGDocument:
85 return XMLDocument::createSVG(DocumentInit(url)); 97 return XMLDocument::createSVG(DocumentInit(url));
86 default: 98 default:
87 // FIXME: We'll add more types to support HTMLImports. 99 // FIXME: We'll add more types to support HTMLImports.
88 ASSERT_NOT_REACHED(); 100 ASSERT_NOT_REACHED();
89 return nullptr; 101 return nullptr;
90 } 102 }
91 } 103 }
92 104
93 } // namespace blink 105 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/DocumentResource.h ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698