| 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 | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All |
| 4 rights reserved. | 4 rights reserved. |
| 5 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) | 5 Copyright (C) 2005, 2006, 2007 Alexey Proskuryakov (ap@nypop.com) |
| 6 | 6 |
| 7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
| 8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
| 9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
| 10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 427 |
| 428 String TextResourceDecoder::decode(const char* data, size_t len) { | 428 String TextResourceDecoder::decode(const char* data, size_t len) { |
| 429 size_t lengthOfBOM = 0; | 429 size_t lengthOfBOM = 0; |
| 430 if (!m_checkedForBOM) { | 430 if (!m_checkedForBOM) { |
| 431 lengthOfBOM = checkForBOM(data, len); | 431 lengthOfBOM = checkForBOM(data, len); |
| 432 | 432 |
| 433 // BOM check can fail when the available data is not enough. | 433 // BOM check can fail when the available data is not enough. |
| 434 if (!m_checkedForBOM) { | 434 if (!m_checkedForBOM) { |
| 435 DCHECK_EQ(0u, lengthOfBOM); | 435 DCHECK_EQ(0u, lengthOfBOM); |
| 436 m_buffer.append(data, len); | 436 m_buffer.append(data, len); |
| 437 return emptyString(); | 437 return emptyString; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 DCHECK_LE(lengthOfBOM, m_buffer.size() + len); | 440 DCHECK_LE(lengthOfBOM, m_buffer.size() + len); |
| 441 | 441 |
| 442 bool movedDataToBuffer = false; | 442 bool movedDataToBuffer = false; |
| 443 | 443 |
| 444 if (m_contentType == CSSContent && !m_checkedForCSSCharset) { | 444 if (m_contentType == CSSContent && !m_checkedForCSSCharset) { |
| 445 if (!checkForCSSCharset(data, len, movedDataToBuffer)) | 445 if (!checkForCSSCharset(data, len, movedDataToBuffer)) |
| 446 return emptyString(); | 446 return emptyString; |
| 447 } | 447 } |
| 448 | 448 |
| 449 // We check XML declaration in HTML content only if there is enough data | 449 // We check XML declaration in HTML content only if there is enough data |
| 450 // available | 450 // available |
| 451 if (((m_contentType == HTMLContent && len >= minimumLengthOfXMLDeclaration) || | 451 if (((m_contentType == HTMLContent && len >= minimumLengthOfXMLDeclaration) || |
| 452 m_contentType == XMLContent) && | 452 m_contentType == XMLContent) && |
| 453 !m_checkedForXMLCharset) { | 453 !m_checkedForXMLCharset) { |
| 454 if (!checkForXMLCharset(data, len, movedDataToBuffer)) | 454 if (!checkForXMLCharset(data, len, movedDataToBuffer)) |
| 455 return emptyString(); | 455 return emptyString; |
| 456 } | 456 } |
| 457 | 457 |
| 458 const char* dataForDecode = data + lengthOfBOM; | 458 const char* dataForDecode = data + lengthOfBOM; |
| 459 size_t lengthForDecode = len - lengthOfBOM; | 459 size_t lengthForDecode = len - lengthOfBOM; |
| 460 | 460 |
| 461 if (!m_buffer.isEmpty()) { | 461 if (!m_buffer.isEmpty()) { |
| 462 if (!movedDataToBuffer) { | 462 if (!movedDataToBuffer) { |
| 463 size_t oldSize = m_buffer.size(); | 463 size_t oldSize = m_buffer.size(); |
| 464 m_buffer.grow(oldSize + len); | 464 m_buffer.grow(oldSize + len); |
| 465 memcpy(m_buffer.data() + oldSize, data, len); | 465 memcpy(m_buffer.data() + oldSize, data, len); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 String result = m_codec->decode( | 512 String result = m_codec->decode( |
| 513 m_buffer.data(), m_buffer.size(), FetchEOF, | 513 m_buffer.data(), m_buffer.size(), FetchEOF, |
| 514 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); | 514 m_contentType == XMLContent && !m_useLenientXMLDecoding, m_sawError); |
| 515 m_buffer.clear(); | 515 m_buffer.clear(); |
| 516 m_codec.reset(); | 516 m_codec.reset(); |
| 517 m_checkedForBOM = false; // Skip BOM again when re-decoding. | 517 m_checkedForBOM = false; // Skip BOM again when re-decoding. |
| 518 return result; | 518 return result; |
| 519 } | 519 } |
| 520 | 520 |
| 521 } // namespace blink | 521 } // namespace blink |
| OLD | NEW |