Bug 1369020 - Remove nsContentUtils::ConvertStringFromEncoding and nsContentUtils::CheckForBOM. r=hsivonen

MozReview-Commit-ID: E0w8BsP1Rof
This commit is contained in:
Masatoshi Kimura
2017-06-16 21:11:03 +09:00
parent 20ff482d11
commit bbe33d305d
11 changed files with 106 additions and 185 deletions

View File

@@ -34,16 +34,14 @@
#include "mozilla/CondVar.h"
#include "mozilla/Mutex.h"
#include "nsCharsetSource.h"
#include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsIHTMLContentSink.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/dom/ScriptLoader.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/dom/ScriptLoader.h"
#include "mozilla/Encoding.h"
using namespace mozilla;
using mozilla::dom::EncodingUtils;
#define NS_PARSER_FLAG_OBSERVERS_ENABLED 0x00000004
#define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008
@@ -1334,23 +1332,27 @@ ParserWriteFunc(nsIInputStream* in,
pws->mNeedCharsetCheck = false;
int32_t source;
nsAutoCString preferred;
nsAutoCString maybePrefer;
pws->mParser->GetDocumentCharset(preferred, source);
// This code was bogus when I found it. It expects the BOM or the XML
// declaration to be entirely in the first network buffer. -- hsivonen
if (nsContentUtils::CheckForBOM(buf, count, maybePrefer)) {
const Encoding* encoding;
size_t bomLength;
Tie(encoding, bomLength) = Encoding::ForBOM(MakeSpan(buf, count));
Unused << bomLength;
if (encoding) {
// The decoder will swallow the BOM. The UTF-16 will re-sniff for
// endianness. The value of preferred is now "UTF-8", "UTF-16LE"
// or "UTF-16BE".
preferred.Assign(maybePrefer);
encoding->Name(preferred);
source = kCharsetFromByteOrderMark;
} else if (source < kCharsetFromChannel) {
nsAutoCString declCharset;
if (ExtractCharsetFromXmlDeclaration(buf, count, declCharset)) {
if (EncodingUtils::FindEncodingForLabel(declCharset, maybePrefer)) {
preferred.Assign(maybePrefer);
encoding = Encoding::ForLabel(declCharset);
if (encoding) {
encoding->Name(preferred);
source = kCharsetFromMetaTag;
}
}