~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/loader/TextResourceDecoder.h

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of the KDE libraries
 
3
 
 
4
    Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
 
5
    Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
 
6
    Copyright (C) 2006 Apple Computer, Inc.
 
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., 59 Temple Place - Suite 330,
 
21
    Boston, MA 02111-1307, USA.
 
22
 
 
23
*/
 
24
 
 
25
#ifndef TextResourceDecoder_h
 
26
#define TextResourceDecoder_h
 
27
 
 
28
#include "PlatformString.h"
 
29
#include "Shared.h"
 
30
#include "TextDecoder.h"
 
31
#include <wtf/Vector.h>
 
32
 
 
33
namespace WebCore {
 
34
 
 
35
class TextResourceDecoder : public Shared<TextResourceDecoder> {
 
36
public:
 
37
    enum EncodingSource {
 
38
        DefaultEncoding,
 
39
        AutoDetectedEncoding,
 
40
        EncodingFromXMLHeader,
 
41
        EncodingFromMetaTag,
 
42
        EncodingFromCSSCharset,
 
43
        EncodingFromHTTPHeader,
 
44
        UserChosenEncoding
 
45
    };
 
46
 
 
47
    TextResourceDecoder(const String& mimeType, const TextEncoding& defaultEncoding = TextEncoding());
 
48
    ~TextResourceDecoder();
 
49
 
 
50
    void setEncoding(const TextEncoding&, EncodingSource);
 
51
    const TextEncoding& encoding() const { return m_decoder.encoding(); }
 
52
 
 
53
    String decode(const char* data, size_t length);
 
54
    String flush();
 
55
 
 
56
private:
 
57
    enum ContentType { PlainText, HTML, XML, CSS }; // PlainText is equivalent to directly using TextDecoder.
 
58
    static ContentType determineContentType(const String& mimeType);
 
59
    static const TextEncoding& defaultEncoding(ContentType, const TextEncoding& defaultEncoding);
 
60
 
 
61
    void checkForBOM(const char*, size_t);
 
62
    bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer);
 
63
    bool checkForHeadCharset(const char*, size_t, bool& movedDataToBuffer);
 
64
    void detectJapaneseEncoding(const char*, size_t);
 
65
 
 
66
    ContentType m_contentType;
 
67
    TextDecoder m_decoder;
 
68
    EncodingSource m_source;
 
69
    Vector<char> m_buffer;
 
70
    bool m_checkedForBOM;
 
71
    bool m_checkedForCSSCharset;
 
72
    bool m_checkedForHeadCharset;
 
73
};
 
74
 
 
75
}
 
76
 
 
77
#endif