| 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 20 matching lines...) Expand all Loading... |
| 31 #include "platform/text/TextEncodingDetector.h" | 31 #include "platform/text/TextEncodingDetector.h" |
| 32 | 32 |
| 33 #include "third_party/ced/src/compact_enc_det/compact_enc_det.h" | 33 #include "third_party/ced/src/compact_enc_det/compact_enc_det.h" |
| 34 #include "wtf/text/TextEncoding.h" | 34 #include "wtf/text/TextEncoding.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 bool detectTextEncoding(const char* data, | 38 bool detectTextEncoding(const char* data, |
| 39 size_t length, | 39 size_t length, |
| 40 const char* hintEncodingName, | 40 const char* hintEncodingName, |
| 41 const char* hintUrl, |
| 42 const char* hintUserLanguage, |
| 41 WTF::TextEncoding* detectedEncoding) { | 43 WTF::TextEncoding* detectedEncoding) { |
| 42 *detectedEncoding = WTF::TextEncoding(); | 44 *detectedEncoding = WTF::TextEncoding(); |
| 45 Language language; |
| 46 LanguageFromCode(hintUserLanguage, &language); |
| 43 int consumedBytes; | 47 int consumedBytes; |
| 44 bool isReliable; | 48 bool isReliable; |
| 45 Encoding encoding = CompactEncDet::DetectEncoding( | 49 Encoding encoding = CompactEncDet::DetectEncoding( |
| 46 data, length, nullptr, nullptr, nullptr, | 50 data, length, hintUrl, nullptr, nullptr, |
| 47 EncodingNameAliasToEncoding(hintEncodingName), UNKNOWN_LANGUAGE, | 51 EncodingNameAliasToEncoding(hintEncodingName), language, |
| 48 CompactEncDet::WEB_CORPUS, | 52 CompactEncDet::WEB_CORPUS, |
| 49 false, // Include 7-bit encodings to detect ISO-2022-JP | 53 false, // Include 7-bit encodings to detect ISO-2022-JP |
| 50 &consumedBytes, &isReliable); | 54 &consumedBytes, &isReliable); |
| 51 if (encoding == UNKNOWN_ENCODING) | 55 if (encoding == UNKNOWN_ENCODING) |
| 52 return false; | 56 return false; |
| 53 | 57 |
| 54 // 7-bit encodings (except ISO-2022-JP) are not supported in WHATWG encoding | 58 // 7-bit encodings (except ISO-2022-JP) are not supported in WHATWG encoding |
| 55 // standard. Mark them as ASCII to keep the raw bytes intact. | 59 // standard. Mark them as ASCII to keep the raw bytes intact. |
| 56 switch (encoding) { | 60 switch (encoding) { |
| 57 case HZ_GB_2312: | 61 case HZ_GB_2312: |
| 58 case ISO_2022_KR: | 62 case ISO_2022_KR: |
| 59 case ISO_2022_CN: | 63 case ISO_2022_CN: |
| 60 case UTF7: | 64 case UTF7: |
| 61 encoding = ASCII_7BIT; | 65 encoding = ASCII_7BIT; |
| 62 break; | 66 break; |
| 63 default: | 67 default: |
| 64 break; | 68 break; |
| 65 } | 69 } |
| 66 *detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding)); | 70 *detectedEncoding = WTF::TextEncoding(MimeEncodingName(encoding)); |
| 67 return true; | 71 return true; |
| 68 } | 72 } |
| 69 | 73 |
| 70 } // namespace blink | 74 } // namespace blink |
| OLD | NEW |