mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 903772: Part 6 - Remove TextDecoderBase. r=emk
This commit is contained in:
parent
93c05d0f88
commit
409764b4e6
@ -34,7 +34,7 @@
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "mozilla/dom/HTMLTemplateElement.h"
|
||||
#include "mozilla/dom/TextDecoderBase.h"
|
||||
#include "mozilla/dom/TextDecoder.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Selection.h"
|
||||
@ -3422,15 +3422,15 @@ nsContentUtils::ConvertStringFromCharset(const nsACString& aCharset,
|
||||
}
|
||||
|
||||
ErrorResult rv;
|
||||
TextDecoderBase decoder;
|
||||
decoder.Init(NS_ConvertUTF8toUTF16(aCharset), false, rv);
|
||||
nsAutoPtr<TextDecoder> decoder(new TextDecoder());
|
||||
decoder->Init(NS_ConvertUTF8toUTF16(aCharset), false, rv);
|
||||
if (rv.Failed()) {
|
||||
rv.ClearMessage();
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
decoder.Decode(aInput.BeginReading(), aInput.Length(), false,
|
||||
aOutput, rv);
|
||||
decoder->Decode(aInput.BeginReading(), aInput.Length(), false,
|
||||
aOutput, rv);
|
||||
return rv.ErrorCode();
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ namespace dom {
|
||||
static const PRUnichar kReplacementChar = static_cast<PRUnichar>(0xFFFD);
|
||||
|
||||
void
|
||||
TextDecoderBase::Init(const nsAString& aEncoding, const bool aFatal,
|
||||
ErrorResult& aRv)
|
||||
TextDecoder::Init(const nsAString& aEncoding, const bool aFatal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsAutoString label(aEncoding);
|
||||
EncodingUtils::TrimSpaceCharacters(label);
|
||||
@ -52,9 +52,9 @@ TextDecoderBase::Init(const nsAString& aEncoding, const bool aFatal,
|
||||
}
|
||||
|
||||
void
|
||||
TextDecoderBase::Decode(const char* aInput, const int32_t aLength,
|
||||
const bool aStream, nsAString& aOutDecodedString,
|
||||
ErrorResult& aRv)
|
||||
TextDecoder::Decode(const char* aInput, const int32_t aLength,
|
||||
const bool aStream, nsAString& aOutDecodedString,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
aOutDecodedString.Truncate();
|
||||
|
||||
@ -101,7 +101,7 @@ TextDecoderBase::Decode(const char* aInput, const int32_t aLength,
|
||||
}
|
||||
|
||||
void
|
||||
TextDecoderBase::GetEncoding(nsAString& aEncoding)
|
||||
TextDecoder::GetEncoding(nsAString& aEncoding)
|
||||
{
|
||||
CopyASCIItoUTF16(mEncoding, aEncoding);
|
||||
nsContentUtils::ASCIIToLower(aEncoding);
|
||||
|
@ -5,14 +5,19 @@
|
||||
#ifndef mozilla_dom_textdecoder_h_
|
||||
#define mozilla_dom_textdecoder_h_
|
||||
|
||||
#include "mozilla/dom/TextDecoderBase.h"
|
||||
#include "mozilla/dom/NonRefcountedDOMObject.h"
|
||||
#include "mozilla/dom/TextDecoderBinding.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ErrorResult;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class TextDecoder MOZ_FINAL
|
||||
: public NonRefcountedDOMObject, public TextDecoderBase
|
||||
: public NonRefcountedDOMObject
|
||||
{
|
||||
public:
|
||||
// The WebIDL constructor.
|
||||
@ -31,12 +36,15 @@ public:
|
||||
}
|
||||
|
||||
TextDecoder()
|
||||
: mFatal(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TextDecoder);
|
||||
}
|
||||
|
||||
virtual
|
||||
~TextDecoder()
|
||||
{}
|
||||
{
|
||||
MOZ_COUNT_DTOR(TextDecoder);
|
||||
}
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope,
|
||||
bool* aTookOwnership)
|
||||
@ -50,22 +58,62 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates provided encoding and throws an exception if invalid encoding.
|
||||
* If no encoding is provided then mEncoding is default initialised to "utf-8".
|
||||
*
|
||||
* @param aEncoding Optional encoding (case insensitive) provided.
|
||||
* Default value is "utf-8" if no encoding is provided.
|
||||
* @param aFatal aFatal, indicates whether to throw an 'EncodingError'
|
||||
* exception or not.
|
||||
* @return aRv EncodingError exception else null.
|
||||
*/
|
||||
void Init(const nsAString& aEncoding, const bool aFatal, ErrorResult& aRv);
|
||||
|
||||
/**
|
||||
* Return the encoding name.
|
||||
*
|
||||
* @param aEncoding, current encoding.
|
||||
*/
|
||||
void GetEncoding(nsAString& aEncoding);
|
||||
|
||||
/**
|
||||
* Decodes incoming byte stream of characters in charset indicated by
|
||||
* encoding.
|
||||
*
|
||||
* The encoding algorithm state is reset if aOptions.mStream is not set.
|
||||
*
|
||||
* If the fatal flag is set then a decoding error will throw EncodingError.
|
||||
* Else the decoder will return a decoded string with replacement
|
||||
* character(s) for unidentified character(s).
|
||||
*
|
||||
* @param aView, incoming byte stream of characters to be decoded to
|
||||
* to UTF-16 code points.
|
||||
* @param aOptions, indicates if streaming or not.
|
||||
* @param aOutDecodedString, decoded string of UTF-16 code points.
|
||||
* @param aRv, error result.
|
||||
*/
|
||||
void Decode(const char* aInput, const int32_t aLength,
|
||||
const bool aStream, nsAString& aOutDecodedString,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void Decode(nsAString& aOutDecodedString,
|
||||
ErrorResult& aRv) {
|
||||
TextDecoderBase::Decode(nullptr, 0, false,
|
||||
aOutDecodedString, aRv);
|
||||
Decode(nullptr, 0, false, aOutDecodedString, aRv);
|
||||
}
|
||||
|
||||
void Decode(const ArrayBufferView& aView,
|
||||
const TextDecodeOptions& aOptions,
|
||||
nsAString& aOutDecodedString,
|
||||
ErrorResult& aRv) {
|
||||
TextDecoderBase::Decode(reinterpret_cast<char*>(aView.Data()),
|
||||
aView.Length(), aOptions.mStream,
|
||||
aOutDecodedString, aRv);
|
||||
Decode(reinterpret_cast<char*>(aView.Data()), aView.Length(),
|
||||
aOptions.mStream, aOutDecodedString, aRv);
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString mEncoding;
|
||||
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
|
||||
bool mFatal;
|
||||
};
|
||||
|
||||
} // dom
|
||||
|
@ -1,76 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_textdecoderbase_h_
|
||||
#define mozilla_dom_textdecoderbase_h_
|
||||
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
class ErrorResult;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class TextDecoderBase
|
||||
{
|
||||
public:
|
||||
TextDecoderBase()
|
||||
: mFatal(false)
|
||||
{}
|
||||
|
||||
virtual
|
||||
~TextDecoderBase()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Validates provided encoding and throws an exception if invalid encoding.
|
||||
* If no encoding is provided then mEncoding is default initialised to "utf-8".
|
||||
*
|
||||
* @param aEncoding Optional encoding (case insensitive) provided.
|
||||
* Default value is "utf-8" if no encoding is provided.
|
||||
* @param aFatal aFatal, indicates whether to throw an 'EncodingError'
|
||||
* exception or not.
|
||||
* @return aRv EncodingError exception else null.
|
||||
*/
|
||||
void Init(const nsAString& aEncoding, const bool aFatal, ErrorResult& aRv);
|
||||
|
||||
/**
|
||||
* Return the encoding name.
|
||||
*
|
||||
* @param aEncoding, current encoding.
|
||||
*/
|
||||
void GetEncoding(nsAString& aEncoding);
|
||||
|
||||
/**
|
||||
* Decodes incoming byte stream of characters in charset indicated by
|
||||
* encoding.
|
||||
*
|
||||
* The encoding algorithm state is reset if aOptions.mStream is not set.
|
||||
*
|
||||
* If the fatal flag is set then a decoding error will throw EncodingError.
|
||||
* Else the decoder will return a decoded string with replacement
|
||||
* character(s) for unidentified character(s).
|
||||
*
|
||||
* @param aView, incoming byte stream of characters to be decoded to
|
||||
* to UTF-16 code points.
|
||||
* @param aOptions, indicates if streaming or not.
|
||||
* @param aOutDecodedString, decoded string of UTF-16 code points.
|
||||
* @param aRv, error result.
|
||||
*/
|
||||
void Decode(const char* aInput, const int32_t aLength,
|
||||
const bool aStream, nsAString& aOutDecodedString,
|
||||
ErrorResult& aRv);
|
||||
|
||||
private:
|
||||
nsCString mEncoding;
|
||||
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
|
||||
bool mFatal;
|
||||
};
|
||||
|
||||
} // dom
|
||||
} // mozilla
|
||||
|
||||
#endif // mozilla_dom_textdecoderbase_h_
|
@ -11,7 +11,6 @@ MODULE = 'dom'
|
||||
EXPORTS.mozilla.dom += [
|
||||
'EncodingUtils.h',
|
||||
'TextDecoder.h',
|
||||
'TextDecoderBase.h',
|
||||
'TextEncoder.h',
|
||||
'TextEncoderBase.h',
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user