Bug 638379 - Part 3: Remove workaround for unreliable inputErrorBehavior. r=hsivonen
This commit is contained in:
@@ -302,7 +302,6 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
|
||||
return WriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
|
||||
}
|
||||
|
||||
@@ -335,7 +334,6 @@ nsHtml5StreamParser::SetupDecodingFromBom(const char* aCharsetName, const char*
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = convManager->GetUnicodeDecoderRaw(aDecoderCharsetName, getter_AddRefs(mUnicodeDecoder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
|
||||
mCharset.Assign(aCharsetName);
|
||||
mCharsetSource = kCharsetFromByteOrderMark;
|
||||
mFeedChardet = false;
|
||||
@@ -718,8 +716,6 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
||||
convManager->GetUnicodeDecoder(mCharset.get(),
|
||||
getter_AddRefs(mUnicodeDecoder));
|
||||
if (mUnicodeDecoder) {
|
||||
mUnicodeDecoder->SetInputErrorBehavior(
|
||||
nsIUnicodeDecoder::kOnError_Recover);
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
mMetaScanner = nullptr;
|
||||
@@ -749,8 +745,6 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
||||
countToSniffingLimit);
|
||||
mMetaScanner->sniff(&readable, getter_AddRefs(mUnicodeDecoder), mCharset);
|
||||
if (mUnicodeDecoder) {
|
||||
mUnicodeDecoder->SetInputErrorBehavior(
|
||||
nsIUnicodeDecoder::kOnError_Recover);
|
||||
// meta scan successful
|
||||
mCharsetSource = kCharsetFromMetaPrescan;
|
||||
mFeedChardet = false;
|
||||
@@ -770,8 +764,6 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
||||
mMetaScanner->sniff(&readable, getter_AddRefs(mUnicodeDecoder), mCharset);
|
||||
if (mUnicodeDecoder) {
|
||||
// meta scan successful
|
||||
mUnicodeDecoder->SetInputErrorBehavior(
|
||||
nsIUnicodeDecoder::kOnError_Recover);
|
||||
mCharsetSource = kCharsetFromMetaPrescan;
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
@@ -824,6 +816,7 @@ nsHtml5StreamParser::WriteStreamBytes(const uint8_t* aFromSegment,
|
||||
// pair.
|
||||
|
||||
nsresult convResult = mUnicodeDecoder->Convert((const char*)aFromSegment, &byteCount, mLastBuffer->getBuffer() + end, &utf16Count);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(convResult));
|
||||
|
||||
end += utf16Count;
|
||||
mLastBuffer->setEnd(end);
|
||||
@@ -834,57 +827,7 @@ nsHtml5StreamParser::WriteStreamBytes(const uint8_t* aFromSegment,
|
||||
"The Unicode decoder wrote too much data.");
|
||||
NS_ASSERTION(byteCount >= -1, "The decoder consumed fewer than -1 bytes.");
|
||||
|
||||
if (NS_FAILED(convResult)) {
|
||||
// Using the more generic NS_FAILED test above in case there are still
|
||||
// decoders around that don't use NS_ERROR_ILLEGAL_INPUT properly.
|
||||
NS_ASSERTION(convResult == NS_ERROR_ILLEGAL_INPUT,
|
||||
"The decoder signaled an error other than NS_ERROR_ILLEGAL_INPUT.");
|
||||
|
||||
// There's an illegal byte in the input. It's now the responsibility
|
||||
// of this calling code to output a U+FFFD REPLACEMENT CHARACTER and
|
||||
// reset the decoder.
|
||||
|
||||
if (totalByteCount < (int32_t)aCount) {
|
||||
// advance over the bad byte
|
||||
++totalByteCount;
|
||||
++aFromSegment;
|
||||
} else {
|
||||
NS_NOTREACHED("The decoder signaled an error but consumed all input.");
|
||||
// Recovering from this situation in case there are still broken
|
||||
// decoders, since nsScanner had recovery code, too.
|
||||
totalByteCount = (int32_t)aCount;
|
||||
}
|
||||
|
||||
// Emit the REPLACEMENT CHARACTER
|
||||
if (end >= NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE) {
|
||||
nsRefPtr<nsHtml5OwningUTF16Buffer> newBuf =
|
||||
nsHtml5OwningUTF16Buffer::FalliblyCreate(
|
||||
NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE);
|
||||
if (!newBuf) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mLastBuffer = (mLastBuffer->next = newBuf.forget());
|
||||
end = 0;
|
||||
}
|
||||
mLastBuffer->getBuffer()[end] = 0xFFFD;
|
||||
++end;
|
||||
mLastBuffer->setEnd(end);
|
||||
if (end >= NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE) {
|
||||
nsRefPtr<nsHtml5OwningUTF16Buffer> newBuf =
|
||||
nsHtml5OwningUTF16Buffer::FalliblyCreate(
|
||||
NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE);
|
||||
if (!newBuf) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mLastBuffer = (mLastBuffer->next = newBuf.forget());
|
||||
}
|
||||
|
||||
mUnicodeDecoder->Reset();
|
||||
if (totalByteCount == (int32_t)aCount) {
|
||||
*aWriteCount = (uint32_t)totalByteCount;
|
||||
return NS_OK;
|
||||
}
|
||||
} else if (convResult == NS_PARTIAL_MORE_OUTPUT) {
|
||||
if (convResult == NS_PARTIAL_MORE_OUTPUT) {
|
||||
nsRefPtr<nsHtml5OwningUTF16Buffer> newBuf =
|
||||
nsHtml5OwningUTF16Buffer::FalliblyCreate(
|
||||
NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE);
|
||||
@@ -1011,9 +954,7 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
|
||||
rv = convManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
|
||||
// if we failed to get a decoder, there will be fallback, so don't propagate
|
||||
// the error.
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
|
||||
} else {
|
||||
if (NS_FAILED(rv)) {
|
||||
mCharsetSource = kCharsetFromWeakDocTypeDefault;
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
Reference in New Issue
Block a user