| OLD | NEW |
| 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) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All
rights reserved. | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All
rights reserved. |
| 4 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) | 4 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) |
| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 // When encoding comes from meta tag (i.e. it cannot be XML files sent via X
HR), | 140 // When encoding comes from meta tag (i.e. it cannot be XML files sent via X
HR), |
| 141 // treat x-user-defined as windows-1252 (bug 18270) | 141 // treat x-user-defined as windows-1252 (bug 18270) |
| 142 if (source == EncodingFromMetaTag && !strcasecmp(encoding.name(), "x-user-de
fined")) | 142 if (source == EncodingFromMetaTag && !strcasecmp(encoding.name(), "x-user-de
fined")) |
| 143 m_encoding = "windows-1252"; | 143 m_encoding = "windows-1252"; |
| 144 else if (source == EncodingFromMetaTag || source == EncodingFromXMLHeader ||
source == EncodingFromCSSCharset) | 144 else if (source == EncodingFromMetaTag || source == EncodingFromXMLHeader ||
source == EncodingFromCSSCharset) |
| 145 m_encoding = encoding.closestByteBasedEquivalent(); | 145 m_encoding = encoding.closestByteBasedEquivalent(); |
| 146 else | 146 else |
| 147 m_encoding = encoding; | 147 m_encoding = encoding; |
| 148 | 148 |
| 149 m_codec.clear(); | 149 m_codec.reset(); |
| 150 m_source = source; | 150 m_source = source; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Returns the position of the encoding string. | 153 // Returns the position of the encoding string. |
| 154 static int findXMLEncoding(const char* str, int len, int& encodingLength) | 154 static int findXMLEncoding(const char* str, int len, int& encodingLength) |
| 155 { | 155 { |
| 156 int pos = find(str, len, "encoding"); | 156 int pos = find(str, len, "encoding"); |
| 157 if (pos == -1) | 157 if (pos == -1) |
| 158 return -1; | 158 return -1; |
| 159 pos += 8; | 159 pos += 8; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return; | 337 return; |
| 338 } | 338 } |
| 339 | 339 |
| 340 if (!m_charsetParser) | 340 if (!m_charsetParser) |
| 341 m_charsetParser = HTMLMetaCharsetParser::create(); | 341 m_charsetParser = HTMLMetaCharsetParser::create(); |
| 342 | 342 |
| 343 if (!m_charsetParser->checkForMetaCharset(data, length)) | 343 if (!m_charsetParser->checkForMetaCharset(data, length)) |
| 344 return; | 344 return; |
| 345 | 345 |
| 346 setEncoding(m_charsetParser->encoding(), EncodingFromMetaTag); | 346 setEncoding(m_charsetParser->encoding(), EncodingFromMetaTag); |
| 347 m_charsetParser.clear(); | 347 m_charsetParser.reset(); |
| 348 m_checkedForMetaCharset = true; | 348 m_checkedForMetaCharset = true; |
| 349 return; | 349 return; |
| 350 } | 350 } |
| 351 | 351 |
| 352 // We use the encoding detector in two cases: | 352 // We use the encoding detector in two cases: |
| 353 // 1. Encoding detector is turned ON and no other encoding source is | 353 // 1. Encoding detector is turned ON and no other encoding source is |
| 354 // available (that is, it's DefaultEncoding). | 354 // available (that is, it's DefaultEncoding). |
| 355 // 2. Encoding detector is turned ON and the encoding is set to | 355 // 2. Encoding detector is turned ON and the encoding is set to |
| 356 // the encoding of the parent frame, which is also auto-detected. | 356 // the encoding of the parent frame, which is also auto-detected. |
| 357 // Note that condition #2 is NOT satisfied unless parent-child frame | 357 // Note that condition #2 is NOT satisfied unless parent-child frame |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 WTF::TextEncoding detectedEncoding; | 429 WTF::TextEncoding detectedEncoding; |
| 430 if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding,
&detectedEncoding)) | 430 if (detectTextEncoding(m_buffer.data(), m_buffer.size(), m_hintEncoding,
&detectedEncoding)) |
| 431 setEncoding(detectedEncoding, EncodingFromContentSniffing); | 431 setEncoding(detectedEncoding, EncodingFromContentSniffing); |
| 432 } | 432 } |
| 433 | 433 |
| 434 if (!m_codec) | 434 if (!m_codec) |
| 435 m_codec = newTextCodec(m_encoding); | 435 m_codec = newTextCodec(m_encoding); |
| 436 | 436 |
| 437 String result = m_codec->decode(m_buffer.data(), m_buffer.size(), FetchEOF,
m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 437 String result = m_codec->decode(m_buffer.data(), m_buffer.size(), FetchEOF,
m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
| 438 m_buffer.clear(); | 438 m_buffer.clear(); |
| 439 m_codec.clear(); | 439 m_codec.reset(); |
| 440 m_checkedForBOM = false; // Skip BOM again when re-decoding. | 440 m_checkedForBOM = false; // Skip BOM again when re-decoding. |
| 441 return result; | 441 return result; |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace blink | 444 } // namespace blink |
| OLD | NEW |