зеркало из https://github.com/mozilla/gecko-dev.git
Bug 919935 - Add a deCOMtaminated way to instantiate nsIUnicodeDecoders and nsIUnicodeEncoders. r=emk.
This commit is contained in:
Родитель
565f47bc12
Коммит
7b95f9e668
|
@ -24,7 +24,7 @@
|
|||
#include "nsJSUtils.h"
|
||||
#include "nsIAsyncVerifyRedirectCallback.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "nsIChannelPolicy.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
@ -264,13 +264,7 @@ EventSource::Init(nsISupports* aOwner,
|
|||
Preferences::GetInt("dom.server-events.default-reconnection-time",
|
||||
DEFAULT_RECONNECTION_TIME_VALUE);
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> convManager =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = convManager->GetUnicodeDecoderRaw("UTF-8",
|
||||
getter_AddRefs(mUnicodeDecoder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mUnicodeDecoder = EncodingUtils::DecoderForEncoding("UTF-8");
|
||||
|
||||
// the constructor should throw a SYNTAX_ERROR only if it fails resolving the
|
||||
// url parameter, so we don't care about the InitChannelAndRequestEventSource
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "nsError.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsIDOMMessageEvent.h"
|
||||
|
|
|
@ -83,7 +83,6 @@
|
|||
#include "nsICategoryManager.h"
|
||||
#include "nsIChannelEventSink.h"
|
||||
#include "nsIChannelPolicy.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsICharsetDetectionObserver.h"
|
||||
#include "nsICharsetDetector.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICharsetDetector.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIClassInfo.h"
|
||||
#include "nsIConverterInputStream.h"
|
||||
#include "nsIDocument.h"
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsDOMFile.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIConverterInputStream.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIFile.h"
|
||||
|
@ -535,14 +534,9 @@ nsDOMFileReader::ConvertStream(const char *aFileData,
|
|||
nsAString &aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICharsetConverterManager> charsetConverter =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
|
||||
rv = charsetConverter->GetUnicodeDecoderRaw(aCharset,
|
||||
getter_AddRefs(unicodeDecoder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder =
|
||||
EncodingUtils::DecoderForEncoding(aCharset);
|
||||
|
||||
int32_t destLength;
|
||||
rv = unicodeDecoder->GetMaxLength(aFileData, aDataLen, &destLength);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "nsScriptLoader.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIContent.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
@ -1182,37 +1181,30 @@ nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
|
|||
|
||||
nsAutoCString charset;
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> charsetConv =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID);
|
||||
|
||||
nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
|
||||
|
||||
if (DetectByteOrderMark(aData, aLength, charset)) {
|
||||
// charset is now "UTF-8" or "UTF-16". The UTF-16 decoder will re-sniff
|
||||
// the BOM for endianness. Both the UTF-16 and the UTF-8 decoder will
|
||||
// take care of swallowing the BOM.
|
||||
charsetConv->GetUnicodeDecoderRaw(charset.get(),
|
||||
getter_AddRefs(unicodeDecoder));
|
||||
unicodeDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
}
|
||||
|
||||
if (!unicodeDecoder &&
|
||||
aChannel &&
|
||||
NS_SUCCEEDED(aChannel->GetContentCharset(charset)) &&
|
||||
EncodingUtils::FindEncodingForLabel(charset, charset)) {
|
||||
charsetConv->GetUnicodeDecoderRaw(charset.get(),
|
||||
getter_AddRefs(unicodeDecoder));
|
||||
unicodeDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
}
|
||||
|
||||
if (!unicodeDecoder &&
|
||||
EncodingUtils::FindEncodingForLabel(aHintCharset, charset)) {
|
||||
charsetConv->GetUnicodeDecoderRaw(charset.get(),
|
||||
getter_AddRefs(unicodeDecoder));
|
||||
unicodeDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
}
|
||||
|
||||
if (!unicodeDecoder && aDocument) {
|
||||
charset = aDocument->GetDocumentCharacterSet();
|
||||
charsetConv->GetUnicodeDecoderRaw(charset.get(),
|
||||
getter_AddRefs(unicodeDecoder));
|
||||
unicodeDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
}
|
||||
|
||||
if (!unicodeDecoder) {
|
||||
|
@ -1220,8 +1212,7 @@ nsScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
|
|||
// fallback in the old code was ISO-8859-1, which behaved like
|
||||
// windows-1252. Saying windows-1252 for clarity and for compliance
|
||||
// with the Encoding Standard.
|
||||
charsetConv->GetUnicodeDecoderRaw("windows-1252",
|
||||
getter_AddRefs(unicodeDecoder));
|
||||
unicodeDecoder = EncodingUtils::DecoderForEncoding("windows-1252");
|
||||
}
|
||||
|
||||
int32_t unicodeLength = 0;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/Util.h"
|
||||
#include "nsDOMBlobBuilder.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMProgressEvent.h"
|
||||
#include "nsIJARChannel.h"
|
||||
|
@ -58,6 +57,7 @@
|
|||
#include "jsfriendapi.h"
|
||||
#include "GeckoProfiler.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
|
@ -633,13 +633,9 @@ nsXMLHttpRequest::DetectCharset()
|
|||
mResponseCharset.AssignLiteral("UTF-8");
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(mResponseCharset);
|
||||
|
||||
return ccm->GetUnicodeDecoderRaw(mResponseCharset.get(),
|
||||
getter_AddRefs(mDecoder));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -724,20 +720,7 @@ nsXMLHttpRequest::GetResponseText(nsString& aResponseText, ErrorResult& aRv)
|
|||
mResponseCharset = mResponseXML->GetDocumentCharacterSet();
|
||||
mResponseText.Truncate();
|
||||
mResponseBodyDecodedPos = 0;
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
aRv = ccm->GetUnicodeDecoderRaw(mResponseCharset.get(),
|
||||
getter_AddRefs(mDecoder));
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(mResponseCharset);
|
||||
}
|
||||
|
||||
NS_ASSERTION(mResponseBodyDecodedPos < mResponseBody.Length(),
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsLinebreakConverter.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIMultiplexInputStream.h"
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include "mozilla/Util.h" // ArrayLength
|
||||
#include "nsUConvPropertySearch.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -44,5 +47,27 @@ EncodingUtils::IsAsciiCompatible(const nsACString& aPreferredName)
|
|||
aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7"));
|
||||
}
|
||||
|
||||
already_AddRefed<nsIUnicodeDecoder>
|
||||
EncodingUtils::DecoderForEncoding(const nsACString& aEncoding)
|
||||
{
|
||||
nsAutoCString contractId(NS_UNICODEDECODER_CONTRACTID_BASE);
|
||||
contractId.Append(aEncoding);
|
||||
|
||||
nsCOMPtr<nsIUnicodeDecoder> decoder = do_CreateInstance(contractId.get());
|
||||
MOZ_ASSERT(decoder, "Tried to create decoder for unknown encoding.");
|
||||
return decoder.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIUnicodeEncoder>
|
||||
EncodingUtils::EncoderForEncoding(const nsACString& aEncoding)
|
||||
{
|
||||
nsAutoCString contractId(NS_UNICODEENCODER_CONTRACTID_BASE);
|
||||
contractId.Append(aEncoding);
|
||||
|
||||
nsCOMPtr<nsIUnicodeEncoder> encoder = do_CreateInstance(contractId.get());
|
||||
MOZ_ASSERT(encoder, "Tried to create encoder for unknown encoding.");
|
||||
return encoder.forget();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#include "nsDataHashtable.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIUnicodeDecoder;
|
||||
class nsIUnicodeEncoder;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
@ -62,6 +65,50 @@ public:
|
|||
*/
|
||||
static bool IsAsciiCompatible(const nsACString& aPreferredName);
|
||||
|
||||
/**
|
||||
* Instantiates a decoder for an encoding. The input must be a
|
||||
* Gecko-canonical encoding name.
|
||||
* @param aEncoding a Gecko-canonical encoding name
|
||||
* @return a decoder
|
||||
*/
|
||||
static already_AddRefed<nsIUnicodeDecoder>
|
||||
DecoderForEncoding(const char* aEncoding)
|
||||
{
|
||||
nsDependentCString encoding(aEncoding);
|
||||
return DecoderForEncoding(encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a decoder for an encoding. The input must be a
|
||||
* Gecko-canonical encoding name
|
||||
* @param aEncoding a Gecko-canonical encoding name
|
||||
* @return a decoder
|
||||
*/
|
||||
static already_AddRefed<nsIUnicodeDecoder>
|
||||
DecoderForEncoding(const nsACString& aEncoding);
|
||||
|
||||
/**
|
||||
* Instantiates an encoder for an encoding. The input must be a
|
||||
* Gecko-canonical encoding name.
|
||||
* @param aEncoding a Gecko-canonical encoding name
|
||||
* @return an encoder
|
||||
*/
|
||||
static already_AddRefed<nsIUnicodeEncoder>
|
||||
EncoderForEncoding(const char* aEncoding)
|
||||
{
|
||||
nsDependentCString encoding(aEncoding);
|
||||
return EncoderForEncoding(encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates an encoder for an encoding. The input must be a
|
||||
* Gecko-canonical encoding name.
|
||||
* @param aEncoding a Gecko-canonical encoding name
|
||||
* @return an encoder
|
||||
*/
|
||||
static already_AddRefed<nsIUnicodeEncoder>
|
||||
EncoderForEncoding(const nsACString& aEncoding);
|
||||
|
||||
private:
|
||||
EncodingUtils() MOZ_DELETE;
|
||||
};
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include "mozilla/dom/TextDecoder.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -34,18 +32,7 @@ TextDecoder::Init(const nsAString& aEncoding, const bool aFatal,
|
|||
mFatal = aFatal;
|
||||
|
||||
// Create a decoder object for mEncoding.
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID);
|
||||
if (!ccm) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
ccm->GetUnicodeDecoderRaw(mEncoding.get(), getter_AddRefs(mDecoder));
|
||||
if (!mDecoder) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(mEncoding);
|
||||
|
||||
if (mFatal) {
|
||||
mDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include "mozilla/dom/TextEncoder.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -33,18 +31,7 @@ TextEncoder::Init(const nsAString& aEncoding, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
// Create an encoder object for mEncoding.
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID);
|
||||
if (!ccm) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
ccm->GetUnicodeEncoderRaw(mEncoding.get(), getter_AddRefs(mEncoder));
|
||||
if (!mEncoder) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
mEncoder = EncodingUtils::EncoderForEncoding(mEncoding);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
|
|
|
@ -6,14 +6,15 @@
|
|||
|
||||
#include "jsapi.h"
|
||||
#include "js/OldDebugAPI.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsJSON.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsStringStream.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "mozilla/dom/EncodingUtils.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsXPCOMStrings.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
@ -24,6 +25,8 @@
|
|||
#include "mozilla/Maybe.h"
|
||||
#include <algorithm>
|
||||
|
||||
using mozilla::dom::EncodingUtils;
|
||||
|
||||
#define JSON_STREAM_BUFSIZE 4096
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsJSON)
|
||||
|
@ -275,11 +278,7 @@ nsJSONWriter::SetCharset(const char* aCharset)
|
|||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mStream) {
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = ccm->GetUnicodeEncoder(aCharset, getter_AddRefs(mEncoder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mEncoder = EncodingUtils::EncoderForEncoding(aCharset);
|
||||
rv = mEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Signal,
|
||||
nullptr, '\0');
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -601,11 +600,7 @@ nsJSONListener::ProcessBytes(const char* aBuffer, uint32_t aByteLength)
|
|||
// We should have a unicode charset by now
|
||||
rv = CheckCharset(charset.get());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = ccm->GetUnicodeDecoderRaw(charset.get(), getter_AddRefs(mDecoder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mDecoder = EncodingUtils::DecoderForEncoding(charset);
|
||||
|
||||
// consume the sniffed bytes
|
||||
rv = ConsumeConverted(mSniffBuffer.get(), mSniffBuffer.Length());
|
||||
|
|
|
@ -23,11 +23,14 @@ interface nsIUnicodeEncoder;
|
|||
interface nsIUTF8StringEnumerator;
|
||||
|
||||
/**
|
||||
* DON'T ADD NEW USES OF THIS INTERFACE TO MOZILLA-CENTRAL. Use
|
||||
* mozilla::dom::EncodingUtils instead.
|
||||
*
|
||||
* Here Charsets are identified by ASCII strings. Charset alias
|
||||
* resolution is provided by default in most methods. "Raw"
|
||||
* versions that do not need this resolution are also provided.
|
||||
*
|
||||
* @deprecated Use mozilla::dom::EncodingUtils in mozilla-central instead.
|
||||
* @created 21/Feb/2000
|
||||
* @author Catalin Rotaru [CATA]
|
||||
*/
|
||||
|
|
|
@ -7,9 +7,6 @@
|
|||
#include "mozilla/DebugOnly.h"
|
||||
|
||||
#include "nsHtml5StreamParser.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsEncoderDecoderUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsHtml5Tokenizer.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
|
@ -304,17 +301,7 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const
|
|||
{
|
||||
NS_ASSERTION(IsParserThread(), "Wrong thread!");
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = convManager->GetUnicodeDecoderRaw(mCharset.get(),
|
||||
getter_AddRefs(mUnicodeDecoder));
|
||||
if (rv == NS_ERROR_UCONV_NOCONV) {
|
||||
mCharset.AssignLiteral("windows-1252"); // lower case is the raw form
|
||||
mCharsetSource = kCharsetFromFallback;
|
||||
rv = convManager->GetUnicodeDecoderRaw(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mUnicodeDecoder = EncodingUtils::DecoderForEncoding(mCharset);
|
||||
if (mSniffingBuffer) {
|
||||
uint32_t writeCount;
|
||||
rv = WriteStreamBytes(mSniffingBuffer, mSniffingLength, &writeCount);
|
||||
|
@ -332,19 +319,15 @@ nsresult
|
|||
nsHtml5StreamParser::SetupDecodingFromBom(const char* aDecoderCharsetName)
|
||||
{
|
||||
NS_ASSERTION(IsParserThread(), "Wrong thread!");
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = convManager->GetUnicodeDecoderRaw(aDecoderCharsetName, getter_AddRefs(mUnicodeDecoder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mCharset.Assign(aDecoderCharsetName);
|
||||
mUnicodeDecoder = EncodingUtils::DecoderForEncoding(mCharset);
|
||||
mCharsetSource = kCharsetFromByteOrderMark;
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
mSniffingBuffer = nullptr;
|
||||
mMetaScanner = nullptr;
|
||||
mBomState = BOM_SNIFFING_OVER;
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -987,16 +970,7 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
|
|||
mFeedChardet = false;
|
||||
|
||||
// Instantiate the converter here to avoid BOM sniffing.
|
||||
nsCOMPtr<nsICharsetConverterManager> convManager =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = convManager->GetUnicodeDecoderRaw(mCharset.get(),
|
||||
getter_AddRefs(mUnicodeDecoder));
|
||||
// if we failed to get a decoder, there will be fallback, so don't propagate
|
||||
// the error.
|
||||
if (NS_FAILED(rv)) {
|
||||
mCharsetSource = kCharsetFromFallback;
|
||||
}
|
||||
mUnicodeDecoder = EncodingUtils::DecoderForEncoding(mCharset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "nsIChannel.h"
|
||||
#include "nsICachingChannel.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "CNavDTD.h"
|
||||
#include "prenv.h"
|
||||
|
@ -128,36 +127,6 @@ public:
|
|||
|
||||
//-------------- End ParseContinue Event Definition ------------------------
|
||||
|
||||
nsICharsetConverterManager* nsParser::sCharsetConverterManager = nullptr;
|
||||
|
||||
/**
|
||||
* This gets called when the htmlparser module is initialized.
|
||||
*/
|
||||
// static
|
||||
nsresult
|
||||
nsParser::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> charsetConverter =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
charsetConverter.swap(sCharsetConverterManager);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This gets called when the htmlparser module is shutdown.
|
||||
*/
|
||||
// static
|
||||
void nsParser::Shutdown()
|
||||
{
|
||||
NS_IF_RELEASE(sCharsetConverterManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
*/
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class nsICharsetConverterManager;
|
||||
class nsIDTD;
|
||||
class nsScanner;
|
||||
class nsIRunnable;
|
||||
|
@ -300,10 +299,6 @@ class nsParser : public nsIParser,
|
|||
*/
|
||||
void HandleParserContinueEvent(class nsParserContinueEvent *);
|
||||
|
||||
static nsICharsetConverterManager* GetCharsetConverterManager() {
|
||||
return sCharsetConverterManager;
|
||||
}
|
||||
|
||||
virtual void Reset() {
|
||||
Cleanup();
|
||||
Initialize();
|
||||
|
@ -398,8 +393,6 @@ protected:
|
|||
|
||||
bool mProcessingNetworkData;
|
||||
bool mIsAboutBlank;
|
||||
|
||||
static nsICharsetConverterManager* sCharsetConverterManager;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -84,7 +84,7 @@ Initialize()
|
|||
nsHTMLTags::TestTagTable();
|
||||
#endif
|
||||
|
||||
return nsParser::Init();
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -92,7 +92,6 @@ Shutdown()
|
|||
{
|
||||
nsHTMLTags::ReleaseTable();
|
||||
nsHTMLEntities::ReleaseTable();
|
||||
nsParser::Shutdown();
|
||||
}
|
||||
|
||||
static mozilla::Module kParserModule = {
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
#include "nsScanner.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIFile.h"
|
||||
|
@ -132,19 +130,10 @@ nsresult nsScanner::SetDocumentCharset(const nsACString& aCharset , int32_t aSou
|
|||
|
||||
mCharset.Assign(charsetName);
|
||||
|
||||
NS_ASSERTION(nsParser::GetCharsetConverterManager(),
|
||||
"Must have the charset converter manager!");
|
||||
mUnicodeDecoder = EncodingUtils::DecoderForEncoding(mCharset);
|
||||
mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
|
||||
|
||||
nsresult res = nsParser::GetCharsetConverterManager()->
|
||||
GetUnicodeDecoderRaw(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
|
||||
if (NS_SUCCEEDED(res) && mUnicodeDecoder)
|
||||
{
|
||||
// We need to detect conversion error of character to support XML
|
||||
// encoding error.
|
||||
mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);
|
||||
}
|
||||
|
||||
return res;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "nsIDOMNode.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsPoint.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIDocument.h"
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#include "nsWindow.h"
|
||||
#include "nsILoadContext.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsBaseFilePicker.h"
|
||||
#include "nsString.h"
|
||||
#include "nsdefs.h"
|
||||
|
|
|
@ -34,9 +34,6 @@
|
|||
|
||||
#include "nsAppShellService.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
#include "nsILoadContext.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче