| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const char* hintEncodingName, WTF::TextEncoding* detectedEncoding) | 39 const char* hintEncodingName, WTF::TextEncoding* detectedEncoding) |
| 40 { | 40 { |
| 41 *detectedEncoding = WTF::TextEncoding(); | 41 *detectedEncoding = WTF::TextEncoding(); |
| 42 int consumedBytes; | 42 int consumedBytes; |
| 43 bool isReliable; | 43 bool isReliable; |
| 44 Encoding encoding = CompactEncDet::DetectEncoding( | 44 Encoding encoding = CompactEncDet::DetectEncoding( |
| 45 data, length, nullptr, nullptr, nullptr, | 45 data, length, nullptr, nullptr, nullptr, |
| 46 EncodingNameAliasToEncoding(hintEncodingName), | 46 EncodingNameAliasToEncoding(hintEncodingName), |
| 47 UNKNOWN_LANGUAGE, | 47 UNKNOWN_LANGUAGE, |
| 48 CompactEncDet::WEB_CORPUS, | 48 CompactEncDet::WEB_CORPUS, |
| 49 false, // Include 7-bit encodings | 49 false, // Include 7-bit encodings to detect ISO-2022-JP |
| 50 &consumedBytes, | 50 &consumedBytes, |
| 51 &isReliable); | 51 &isReliable); |
| 52 if (encoding != UNKNOWN_ENCODING) { | 52 if (encoding == UNKNOWN_ENCODING) |
| 53 *detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding)); | 53 return false; |
| 54 return true; | 54 |
| 55 // 7-bit encodings (except ISO-2022-JP) are not supported in WHATWG encoding |
| 56 // standard. Mark them as ASCII to keep the raw bytes intact. |
| 57 switch (encoding) { |
| 58 case HZ_GB_2312: |
| 59 case ISO_2022_KR: |
| 60 case ISO_2022_CN: |
| 61 case UTF7: |
| 62 encoding = ASCII_7BIT; |
| 63 break; |
| 64 default: |
| 65 break; |
| 55 } | 66 } |
| 56 return false; | 67 *detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding)); |
| 68 return true; |
| 57 } | 69 } |
| 58 | 70 |
| 59 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |