Bug 1385836 - Remove special cases obsoleted by "replacement" becoming a label of the replacement encoding.
MozReview-Commit-ID: 52uO6AVRHWX
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -352,22 +352,18 @@ nsHTMLDocument::TryCacheCharset(nsICachi
return;
}
nsCString cachedCharset;
rv = aCachingChannel->GetCacheTokenCachedCharset(cachedCharset);
if (NS_FAILED(rv) || cachedCharset.IsEmpty()) {
return;
}
- // The replacement encoding is not ASCII-compatible.
- if (cachedCharset.EqualsLiteral("replacement")) {
- return;
- }
// The canonical names changed, so the cache may have an old name.
- const Encoding* encoding = Encoding::ForLabel(cachedCharset);
+ const Encoding* encoding = Encoding::ForLabelNoReplacement(cachedCharset);
if (!encoding) {
return;
}
// Check IsAsciiCompatible() even in the cache case, because the value
// might be stale and in the case of a stale charset that is not a rough
// ASCII superset, the parser has no way to recover.
if (!encoding->IsAsciiCompatible() && encoding != ISO_2022_JP_ENCODING) {
return;
@@ -731,19 +727,16 @@ nsHTMLDocument::StartDocumentLoad(const
kCharsetFromChannel : charsetSource;
nsAutoCString cachedCharset;
int32_t cachedSource;
rv = wyciwygChannel->GetCharsetAndSource(&cachedSource, cachedCharset);
if (NS_SUCCEEDED(rv)) {
if (cachedSource > charsetSource) {
auto cachedEncoding = Encoding::ForLabel(cachedCharset);
- if (!cachedEncoding && cachedCharset.EqualsLiteral("replacement")) {
- cachedEncoding = REPLACEMENT_ENCODING;
- }
if (cachedEncoding) {
charsetSource = cachedSource;
encoding = WrapNotNull(cachedEncoding);
}
}
} else {
// Don't propagate this error.
rv = NS_OK;
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -3384,25 +3384,20 @@ SetChildForceCharacterSet(nsIContentView
{
auto encoding = static_cast<const Encoding*>(aClosure);
aChild->SetForceCharset(encoding);
}
NS_IMETHODIMP
nsDocumentViewer::SetForceCharacterSet(const nsACString& aForceCharacterSet)
{
- // This method is scriptable, so add-ons could pass in something other
- // than a canonical name. However, in case where the input is a canonical
- // name, "replacement" doesn't survive label resolution. Additionally, the
- // empty string means no hint.
+ // The empty string means no hint.
const Encoding* encoding = nullptr;
if (!aForceCharacterSet.IsEmpty()) {
- if (aForceCharacterSet.EqualsLiteral("replacement")) {
- encoding = REPLACEMENT_ENCODING;
- } else if (!(encoding = Encoding::ForLabel(aForceCharacterSet))) {
+ if (!(encoding = Encoding::ForLabel(aForceCharacterSet))) {
// Reject unknown labels
return NS_ERROR_INVALID_ARG;
}
}
nsDocumentViewer::SetForceCharset(encoding);
return NS_OK;
}
@@ -3467,25 +3462,20 @@ SetChildHintCharacterSet(nsIContentViewe
{
auto encoding = static_cast<const Encoding*>(aClosure);
aChild->SetHintCharset(encoding);
}
NS_IMETHODIMP
nsDocumentViewer::SetHintCharacterSet(const nsACString& aHintCharacterSet)
{
- // This method is scriptable, so add-ons could pass in something other
- // than a canonical name. However, in case where the input is a canonical
- // name, "replacement" doesn't survive label resolution. Additionally, the
- // empty string means no hint.
+ // The empty string means no hint.
const Encoding* encoding = nullptr;
if (!aHintCharacterSet.IsEmpty()) {
- if (aHintCharacterSet.EqualsLiteral("replacement")) {
- encoding = REPLACEMENT_ENCODING;
- } else if (!(encoding = Encoding::ForLabel(aHintCharacterSet))) {
+ if (!(encoding = Encoding::ForLabel(aHintCharacterSet))) {
// Reject unknown labels
return NS_ERROR_INVALID_ARG;
}
}
nsDocumentViewer::SetHintCharset(encoding);
return NS_OK;
}
--- a/netwerk/base/nsUnicharStreamLoader.cpp
+++ b/netwerk/base/nsUnicharStreamLoader.cpp
@@ -173,31 +173,21 @@ nsUnicharStreamLoader::DetermineCharset(
{
nsresult rv = mObserver->OnDetermineCharset(this, mContext,
mRawData, mCharset);
if (NS_FAILED(rv) || mCharset.IsEmpty()) {
// The observer told us nothing useful
mCharset.AssignLiteral("UTF-8");
}
- // Sadly, nsIUnicharStreamLoader is exposed to extensions, so we can't
- // assume mozilla::css::Loader to be the only caller. Special-casing
- // replacement, since it's not invariant under a second label resolution
- // operation.
- if (mCharset.EqualsLiteral("replacement")) {
- mDecoder = REPLACEMENT_ENCODING->NewDecoderWithBOMRemoval();
- } else {
- const Encoding* encoding = Encoding::ForLabelNoReplacement(mCharset);
- if (!encoding) {
- // If we got replacement here, the caller was not mozilla::css::Loader
- // but an extension.
- return NS_ERROR_UCONV_NOCONV;
- }
- mDecoder = encoding->NewDecoderWithBOMRemoval();
+ const Encoding* encoding = Encoding::ForLabel(mCharset);
+ if (!encoding) {
+ return NS_ERROR_UCONV_NOCONV;
}
+ mDecoder = encoding->NewDecoderWithBOMRemoval();
// Process the data into mBuffer
uint32_t dummy;
rv = WriteSegmentFun(nullptr, this,
mRawData.BeginReading(),
0, mRawData.Length(),
&dummy);
mRawData.Truncate();