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>
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.
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.
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.
25 #include "core/fetch/DocumentResource.h"
27 #include "core/dom/XMLDocument.h"
28 #include "core/fetch/FetchRequest.h"
29 #include "core/fetch/ResourceFetcher.h"
30 #include "platform/SharedBuffer.h"
31 #include "wtf/text/StringBuilder.h"
35 ResourcePtr
<DocumentResource
> DocumentResource::fetchSVGDocument(FetchRequest
& request
, ResourceFetcher
* fetcher
)
37 ASSERT(request
.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
);
38 request
.mutableResourceRequest().setRequestContext(WebURLRequest::RequestContextImage
);
39 return toDocumentResource(fetcher
->requestResource(request
, SVGDocumentResourceFactory()));
42 DocumentResource::DocumentResource(const ResourceRequest
& request
, Type type
)
43 : Resource(request
, type
)
44 , m_decoder(TextResourceDecoder::create("application/xml"))
46 // FIXME: We'll support more types to support HTMLImports.
47 ASSERT(type
== SVGDocument
);
50 DocumentResource::~DocumentResource()
54 DEFINE_TRACE(DocumentResource
)
56 visitor
->trace(m_document
);
57 Resource::trace(visitor
);
60 void DocumentResource::setEncoding(const String
& chs
)
62 m_decoder
->setEncoding(chs
, TextResourceDecoder::EncodingFromHTTPHeader
);
65 String
DocumentResource::encoding() const
67 return m_decoder
->encoding().name();
70 void DocumentResource::checkNotify()
73 StringBuilder decodedText
;
74 decodedText
.append(m_decoder
->decode(m_data
->data(), m_data
->size()));
75 decodedText
.append(m_decoder
->flush());
76 // We don't need to create a new frame because the new document belongs to the parent UseElement.
77 m_document
= createDocument(response().url());
78 m_document
->setContent(decodedText
.toString());
80 Resource::checkNotify();
83 PassRefPtrWillBeRawPtr
<Document
> DocumentResource::createDocument(const KURL
& url
)
87 return XMLDocument::createSVG(DocumentInit(url
));
89 // FIXME: We'll add more types to support HTMLImports.