| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 Copyright (C) 2010 Rob Buis <rwlbuis@gmail.com> | |
| 3 Copyright (C) 2011 Cosmin Truta <ctruta@gmail.com> | |
| 4 Copyright (C) 2012 University of Szeged | |
| 5 Copyright (C) 2012 Renata Hodovan <reni@webkit.org> | |
| 6 | |
| 7 This library is free software; you can redistribute it and/or | |
| 8 modify it under the terms of the GNU Library General Public | |
| 9 License as published by the Free Software Foundation; either | |
| 10 version 2 of the License, or (at your option) any later version. | |
| 11 | |
| 12 This library is distributed in the hope that it will be useful, | |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 Library General Public License for more details. | |
| 16 | |
| 17 You should have received a copy of the GNU Library General Public License | |
| 18 along with this library; see the file COPYING.LIB. If not, write to | |
| 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 20 Boston, MA 02110-1301, USA. | |
| 21 */ | |
| 22 | |
| 23 #include "core/fetch/DocumentResource.h" | |
| 24 | |
| 25 #include "core/dom/XMLDocument.h" | |
| 26 #include "core/fetch/FetchRequest.h" | |
| 27 #include "core/fetch/ResourceFetcher.h" | |
| 28 #include "platform/SharedBuffer.h" | |
| 29 #include "wtf/text/StringBuilder.h" | |
| 30 | |
| 31 namespace blink { | |
| 32 | |
| 33 DocumentResource* DocumentResource::fetchSVGDocument(FetchRequest& request, | |
| 34 ResourceFetcher* fetcher) { | |
| 35 DCHECK_EQ(request.resourceRequest().frameType(), | |
| 36 WebURLRequest::FrameTypeNone); | |
| 37 request.mutableResourceRequest().setRequestContext( | |
| 38 WebURLRequest::RequestContextImage); | |
| 39 return toDocumentResource( | |
| 40 fetcher->requestResource(request, SVGDocumentResourceFactory())); | |
| 41 } | |
| 42 | |
| 43 DocumentResource::DocumentResource(const ResourceRequest& request, | |
| 44 Type type, | |
| 45 const ResourceLoaderOptions& options) | |
| 46 : TextResource(request, type, options, "application/xml", String()) { | |
| 47 // FIXME: We'll support more types to support HTMLImports. | |
| 48 DCHECK_EQ(type, SVGDocument); | |
| 49 } | |
| 50 | |
| 51 DocumentResource::~DocumentResource() {} | |
| 52 | |
| 53 DEFINE_TRACE(DocumentResource) { | |
| 54 visitor->trace(m_document); | |
| 55 Resource::trace(visitor); | |
| 56 } | |
| 57 | |
| 58 void DocumentResource::checkNotify() { | |
| 59 if (data() && mimeTypeAllowed()) { | |
| 60 // We don't need to create a new frame because the new document belongs to | |
| 61 // the parent UseElement. | |
| 62 m_document = createDocument(response().url()); | |
| 63 m_document->setContent(decodedText()); | |
| 64 } | |
| 65 Resource::checkNotify(); | |
| 66 } | |
| 67 | |
| 68 bool DocumentResource::mimeTypeAllowed() const { | |
| 69 DCHECK_EQ(getType(), SVGDocument); | |
| 70 AtomicString mimeType = response().mimeType(); | |
| 71 if (response().isHTTP()) | |
| 72 mimeType = httpContentType(); | |
| 73 return mimeType == "image/svg+xml" || mimeType == "text/xml" || | |
| 74 mimeType == "application/xml" || mimeType == "application/xhtml+xml"; | |
| 75 } | |
| 76 | |
| 77 Document* DocumentResource::createDocument(const KURL& url) { | |
| 78 switch (getType()) { | |
| 79 case SVGDocument: | |
| 80 return XMLDocument::createSVG(DocumentInit(url)); | |
| 81 default: | |
| 82 // FIXME: We'll add more types to support HTMLImports. | |
| 83 NOTREACHED(); | |
| 84 return nullptr; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 } // namespace blink | |
| OLD | NEW |