OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 DocumentResource* DocumentResource::fetchSVGDocument(FetchRequest& request, Reso
urceFetcher* fetcher) | 33 DocumentResource* DocumentResource::fetchSVGDocument(FetchRequest& request, Reso
urceFetcher* fetcher) |
34 { | 34 { |
35 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); | 35 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); |
36 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textImage); | 36 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textImage); |
37 return toDocumentResource(fetcher->requestResource(request, SVGDocumentResou
rceFactory())); | 37 return toDocumentResource(fetcher->requestResource(request, SVGDocumentResou
rceFactory())); |
38 } | 38 } |
39 | 39 |
40 DocumentResource::DocumentResource(const ResourceRequest& request, Type type, co
nst ResourceLoaderOptions& options) | 40 DocumentResource::DocumentResource(const ResourceRequest& request, Type type, co
nst ResourceLoaderOptions& options) |
41 : Resource(request, type, options) | 41 : TextResource(request, type, options, "application/xml", String()) |
42 , m_decoder(TextResourceDecoder::create("application/xml")) | |
43 { | 42 { |
44 // FIXME: We'll support more types to support HTMLImports. | 43 // FIXME: We'll support more types to support HTMLImports. |
45 ASSERT(type == SVGDocument); | 44 ASSERT(type == SVGDocument); |
46 } | 45 } |
47 | 46 |
48 DocumentResource::~DocumentResource() | 47 DocumentResource::~DocumentResource() |
49 { | 48 { |
50 } | 49 } |
51 | 50 |
52 DEFINE_TRACE(DocumentResource) | 51 DEFINE_TRACE(DocumentResource) |
53 { | 52 { |
54 visitor->trace(m_document); | 53 visitor->trace(m_document); |
55 Resource::trace(visitor); | 54 Resource::trace(visitor); |
56 } | 55 } |
57 | 56 |
58 void DocumentResource::setEncoding(const String& chs) | |
59 { | |
60 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader); | |
61 } | |
62 | |
63 String DocumentResource::encoding() const | |
64 { | |
65 return m_decoder->encoding().name(); | |
66 } | |
67 | |
68 void DocumentResource::checkNotify() | 57 void DocumentResource::checkNotify() |
69 { | 58 { |
70 if (m_data && mimeTypeAllowed()) { | 59 if (m_data && mimeTypeAllowed()) { |
71 StringBuilder decodedText; | |
72 decodedText.append(m_decoder->decode(m_data->data(), m_data->size())); | |
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. | 60 // We don't need to create a new frame because the new document belongs
to the parent UseElement. |
75 m_document = createDocument(response().url()); | 61 m_document = createDocument(response().url()); |
76 m_document->setContent(decodedText.toString()); | 62 m_document->setContent(decodedText()); |
77 } | 63 } |
78 Resource::checkNotify(); | 64 Resource::checkNotify(); |
79 } | 65 } |
80 | 66 |
81 bool DocumentResource::mimeTypeAllowed() const | 67 bool DocumentResource::mimeTypeAllowed() const |
82 { | 68 { |
83 ASSERT(getType() == SVGDocument); | 69 ASSERT(getType() == SVGDocument); |
84 AtomicString mimeType = response().mimeType(); | 70 AtomicString mimeType = response().mimeType(); |
85 if (response().isHTTP()) | 71 if (response().isHTTP()) |
86 mimeType = httpContentType(); | 72 mimeType = httpContentType(); |
87 return mimeType == "image/svg+xml" | 73 return mimeType == "image/svg+xml" |
88 || mimeType == "text/xml" | 74 || mimeType == "text/xml" |
89 || mimeType == "application/xml" | 75 || mimeType == "application/xml" |
90 || mimeType == "application/xhtml+xml"; | 76 || mimeType == "application/xhtml+xml"; |
91 } | 77 } |
92 | 78 |
93 Document* DocumentResource::createDocument(const KURL& url) | 79 Document* DocumentResource::createDocument(const KURL& url) |
94 { | 80 { |
95 switch (getType()) { | 81 switch (getType()) { |
96 case SVGDocument: | 82 case SVGDocument: |
97 return XMLDocument::createSVG(DocumentInit(url)); | 83 return XMLDocument::createSVG(DocumentInit(url)); |
98 default: | 84 default: |
99 // FIXME: We'll add more types to support HTMLImports. | 85 // FIXME: We'll add more types to support HTMLImports. |
100 ASSERT_NOT_REACHED(); | 86 ASSERT_NOT_REACHED(); |
101 return nullptr; | 87 return nullptr; |
102 } | 88 } |
103 } | 89 } |
104 | 90 |
105 } // namespace blink | 91 } // namespace blink |
OLD | NEW |