1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
6 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22
23 This class provides all functionality needed for loading images, style sheets and html
24 pages from the web. It has a memory cache for these objects.
25 */
26
27 #include "config.h"
28
29 #if ENABLE(XBL)
30
31 #include "CachedXBLDocument.h"
32
33 #include "CachedResourceClientWalker.h"
34 #include "TextResourceDecoder.h"
35 #include <wtf/Vector.h>
36
37 namespace WebCore {
38
CachedXBLDocument(const String & url)39 CachedXBLDocument::CachedXBLDocument(const String &url)
40 : CachedResource(url, XBL), m_document(0)
41 {
42 // It's XML we want.
43 setAccept("text/xml, application/xml, application/xhtml+xml, text/xsl, application/rss+xml, application/atom+xml");
44
45 m_decoder = new TextResourceDecoder("application/xml");
46 }
47
~CachedXBLDocument()48 CachedXBLDocument::~CachedXBLDocument()
49 {
50 if (m_document)
51 m_document->deref();
52 }
53
ref(CachedResourceClient * c)54 void CachedXBLDocument::ref(CachedResourceClient *c)
55 {
56 CachedResource::ref(c);
57 if (!m_loading)
58 c->setXBLDocument(m_url, m_document);
59 }
60
setEncoding(const String & chs)61 void CachedXBLDocument::setEncoding(const String& chs)
62 {
63 m_decoder->setEncoding(chs, TextResourceDecoder::EncodingFromHTTPHeader);
64 }
65
encoding() const66 String CachedXBLDocument::encoding() const
67 {
68 return m_decoder->encoding().name();
69 }
70
data(Vector<char> & data,bool)71 void CachedXBLDocument::data(Vector<char>& data, bool )
72 {
73 if (!allDataReceived)
74 return;
75
76 ASSERT(!m_document);
77
78 m_document = new XBL::XBLDocument();
79 m_document->ref();
80 m_document->open();
81
82 m_document->write(m_decoder->decode(data.data(), data.size()));
83 setSize(data.size());
84
85 m_document->finishParsing();
86 m_document->close();
87 m_loading = false;
88 checkNotify();
89 }
90
checkNotify()91 void CachedXBLDocument::checkNotify()
92 {
93 if (m_loading)
94 return;
95
96 CachedResourceClientWalker w(m_clients);
97 while (CachedResourceClient *c = w.next())
98 c->setXBLDocument(m_url, m_document);
99 }
100
error()101 void CachedXBLDocument::error()
102 {
103 m_loading = false;
104 m_errorOccurred = true;
105 checkNotify();
106 }
107
108 }
109
110 #endif
111