Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: Source/core/fetch/TextResourceDecoder.h

Issue 69823002: Move ownership of the TextResourceDecoder to DecodedDataDocumentParser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/dom/DocumentParser.cpp ('k') | Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1999 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) 3 Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
4 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 4 Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 }; 45 };
46 46
47 static PassRefPtr<TextResourceDecoder> create(const String& mimeType, const WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncodingDetec tor = false) 47 static PassRefPtr<TextResourceDecoder> create(const String& mimeType, const WTF::TextEncoding& defaultEncoding = WTF::TextEncoding(), bool usesEncodingDetec tor = false)
48 { 48 {
49 return adoptRef(new TextResourceDecoder(mimeType, defaultEncoding, usesE ncodingDetector)); 49 return adoptRef(new TextResourceDecoder(mimeType, defaultEncoding, usesE ncodingDetector));
50 } 50 }
51 ~TextResourceDecoder(); 51 ~TextResourceDecoder();
52 52
53 void setEncoding(const WTF::TextEncoding&, EncodingSource); 53 void setEncoding(const WTF::TextEncoding&, EncodingSource);
54 const WTF::TextEncoding& encoding() const { return m_encoding; } 54 const WTF::TextEncoding& encoding() const { return m_encoding; }
55 bool encodingWasDetectedHeuristically() const
56 {
57 return m_source == AutoDetectedEncoding
58 || m_source == EncodingFromContentSniffing;
59 }
55 60
56 String decode(const char* data, size_t length); 61 String decode(const char* data, size_t length);
57 String flush(); 62 String flush();
58 63
59 void setHintEncoding(const TextResourceDecoder* hintDecoder) 64 void setHintEncoding(const WTF::TextEncoding& encoding)
60 { 65 {
61 // hintEncoding is for use with autodetection, which should be 66 m_hintEncoding = encoding.name();
62 // only invoked when hintEncoding comes from auto-detection.
63 if (hintDecoder && hintDecoder->wasDetectedHueristically())
64 m_hintEncoding = hintDecoder->encoding().name();
65 } 67 }
66 68
67 void useLenientXMLDecoding() { m_useLenientXMLDecoding = true; } 69 void useLenientXMLDecoding() { m_useLenientXMLDecoding = true; }
68 bool sawError() const { return m_sawError; } 70 bool sawError() const { return m_sawError; }
69 71
70 private: 72 private:
71 TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& default Encoding, bool usesEncodingDetector); 73 TextResourceDecoder(const String& mimeType, const WTF::TextEncoding& default Encoding, bool usesEncodingDetector);
72 74
73 enum ContentType { PlainText, HTML, XML, CSS }; // PlainText only checks for BOM. 75 enum ContentType { PlainText, HTML, XML, CSS }; // PlainText only checks for BOM.
74 static ContentType determineContentType(const String& mimeType); 76 static ContentType determineContentType(const String& mimeType);
75 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text Encoding& defaultEncoding); 77 static const WTF::TextEncoding& defaultEncoding(ContentType, const WTF::Text Encoding& defaultEncoding);
76 78
77 bool wasDetectedHueristically() const { return m_source == AutoDetectedEncod ing || m_source == EncodingFromContentSniffing; }
78
79 size_t checkForBOM(const char*, size_t); 79 size_t checkForBOM(const char*, size_t);
80 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer); 80 bool checkForCSSCharset(const char*, size_t, bool& movedDataToBuffer);
81 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer); 81 bool checkForXMLCharset(const char*, size_t, bool& movedDataToBuffer);
82 void checkForMetaCharset(const char*, size_t); 82 void checkForMetaCharset(const char*, size_t);
83 void detectJapaneseEncoding(const char*, size_t); 83 void detectJapaneseEncoding(const char*, size_t);
84 bool shouldAutoDetect() const; 84 bool shouldAutoDetect() const;
85 85
86 ContentType m_contentType; 86 ContentType m_contentType;
87 WTF::TextEncoding m_encoding; 87 WTF::TextEncoding m_encoding;
88 OwnPtr<TextCodec> m_codec; 88 OwnPtr<TextCodec> m_codec;
89 EncodingSource m_source; 89 EncodingSource m_source;
90 const char* m_hintEncoding; 90 const char* m_hintEncoding;
91 Vector<char> m_buffer; 91 Vector<char> m_buffer;
92 bool m_checkedForBOM; 92 bool m_checkedForBOM;
93 bool m_checkedForCSSCharset; 93 bool m_checkedForCSSCharset;
94 bool m_checkedForXMLCharset; 94 bool m_checkedForXMLCharset;
95 bool m_checkedForMetaCharset; 95 bool m_checkedForMetaCharset;
96 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors. 96 bool m_useLenientXMLDecoding; // Don't stop on XML decoding errors.
97 bool m_sawError; 97 bool m_sawError;
98 bool m_usesEncodingDetector; 98 bool m_usesEncodingDetector;
99 99
100 OwnPtr<HTMLMetaCharsetParser> m_charsetParser; 100 OwnPtr<HTMLMetaCharsetParser> m_charsetParser;
101 }; 101 };
102 102
103 } 103 }
104 104
105 #endif 105 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/DocumentParser.cpp ('k') | Source/core/loader/DocumentLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698