Skip to content

Commit 4326534

Browse files
committed
Bug 1261841 part 2 - Use encoding_rs instead of uconv. r=emk,mystor.
MozReview-Commit-ID: 15Y5GTX98bv
1 parent 5326afd commit 4326534

File tree

178 files changed

+3558
-4172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+3558
-4172
lines changed

browser/components/migration/360seProfileMigrator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Object.defineProperty(Qihoo360seProfileMigrator.prototype, "sourceProfiles", {
234234
throw new Error("360 Secure Browser's 'login.ini' file could not be read.");
235235
}
236236

237-
let loginIniInUtf8 = copyToTempUTF8File(loginIni, "gbk");
237+
let loginIniInUtf8 = copyToTempUTF8File(loginIni, "GBK");
238238
let loginIniObj = parseINIStrings(loginIniInUtf8);
239239
try {
240240
loginIniInUtf8.remove(false);

browser/components/preferences/fonts.xul

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
<prefpane id="FontsDialogPane"
2626
class="largeDialogContainer"
2727
helpTopic="prefs-fonts-and-colors">
28-
28+
2929
<preferences id="fontPreferences">
3030
<preference id="font.language.group" name="font.language.group" type="wstring"/>
3131
<preference id="browser.display.use_document_fonts"
3232
name="browser.display.use_document_fonts"
3333
type="int"/>
3434
<preference id="intl.charset.fallback.override" name="intl.charset.fallback.override" type="string"/>
3535
</preferences>
36-
36+
3737
<stringbundle id="bundlePreferences" src="chrome://browser/locale/preferences/preferences.properties"/>
3838
<script type="application/javascript" src="chrome://mozapps/content/preferences/fontbuilder.js"/>
3939
<script type="application/javascript" src="chrome://browser/content/preferences/fonts.js"/>
@@ -79,15 +79,15 @@
7979
</menupopup>
8080
</menulist>
8181
</caption>
82-
82+
8383
<grid>
8484
<columns>
8585
<column/>
8686
<column flex="1"/>
8787
<column/>
8888
<column/>
8989
</columns>
90-
90+
9191
<rows>
9292
<row>
9393
<separator class="thin"/>
@@ -107,7 +107,7 @@
107107
<label value="&size.label;"
108108
accesskey="&sizeProportional.accesskey;"
109109
control="sizeVar"/>
110-
</hbox>
110+
</hbox>
111111
<menulist id="sizeVar" delayprefsave="true">
112112
<menupopup>
113113
<menuitem value="9" label="9"/>
@@ -164,7 +164,7 @@
164164
<label value="&size.label;"
165165
accesskey="&sizeMonospace.accesskey;"
166166
control="sizeMono"/>
167-
</hbox>
167+
</hbox>
168168
<menulist id="sizeMono" delayprefsave="true">
169169
<menupopup>
170170
<menuitem value="9" label="9"/>
@@ -237,7 +237,7 @@
237237
<separator/>
238238
<separator class="groove"/>
239239
<hbox>
240-
<checkbox id="useDocumentFonts"
240+
<checkbox id="useDocumentFonts"
241241
label="&allowPagesToUseOwn.label;" accesskey="&allowPagesToUseOwn.accesskey;"
242242
preference="browser.display.use_document_fonts"
243243
onsyncfrompreference="return gFontsDialog.readUseDocumentFonts();"
@@ -260,6 +260,8 @@
260260
<menuitem label="&languages.customize.Fallback.baltic;" value="windows-1257"/>
261261
<menuitem label="&languages.customize.Fallback.ceiso;" value="ISO-8859-2"/>
262262
<menuitem label="&languages.customize.Fallback.cewindows;" value="windows-1250"/>
263+
<!-- Using gbk instead of GBK for compat with previously-stored prefs.
264+
The value gets normalized in dom/encoding/FallbackEncoding.cpp. -->
263265
<menuitem label="&languages.customize.Fallback.simplified;" value="gbk"/>
264266
<menuitem label="&languages.customize.Fallback.traditional;" value="Big5"/>
265267
<menuitem label="&languages.customize.Fallback.cyrillic;" value="windows-1251"/>

docshell/base/nsDocShell.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11583,18 +11583,16 @@ nsDocShell::ScrollToAnchor(bool aCurHasRef, bool aNewHasRef,
1158311583
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
1158411584
nsIDocument* doc = mContentViewer->GetDocument();
1158511585
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
11586-
const nsACString& aCharset = doc->GetDocumentCharacterSet();
11586+
const nsACString& charset = doc->GetDocumentCharacterSet();
1158711587

1158811588
nsCOMPtr<nsITextToSubURI> textToSubURI =
1158911589
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
1159011590
NS_ENSURE_SUCCESS(rv, rv);
1159111591

1159211592
// Unescape and convert to unicode
11593-
nsXPIDLString uStr;
11593+
nsAutoString uStr;
1159411594

11595-
rv = textToSubURI->UnEscapeAndConvert(PromiseFlatCString(aCharset).get(),
11596-
PromiseFlatCString(aNewHash).get(),
11597-
getter_Copies(uStr));
11595+
rv = textToSubURI->UnEscapeAndConvert(charset, aNewHash, uStr);
1159811596
NS_ENSURE_SUCCESS(rv, rv);
1159911597

1160011598
// Ignore return value of GoToAnchor, since it will return an error

dom/base/BodyUtil.cpp

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "nsError.h"
88
#include "nsString.h"
99
#include "nsIGlobalObject.h"
10-
#include "nsIUnicodeDecoder.h"
10+
#include "mozilla/Encoding.h"
1111

1212
#include "nsCharSeparatedTokenizer.h"
1313
#include "nsDOMString.h"
@@ -17,7 +17,6 @@
1717
#include "nsStringStream.h"
1818

1919
#include "mozilla/ErrorResult.h"
20-
#include "mozilla/dom/EncodingUtils.h"
2120
#include "mozilla/dom/Exceptions.h"
2221
#include "mozilla/dom/FetchUtil.h"
2322
#include "mozilla/dom/File.h"
@@ -31,53 +30,6 @@ namespace dom {
3130

3231
namespace {
3332

34-
class StreamDecoder final
35-
{
36-
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
37-
nsString mDecoded;
38-
39-
public:
40-
StreamDecoder()
41-
: mDecoder(EncodingUtils::DecoderForEncoding("UTF-8"))
42-
{
43-
MOZ_ASSERT(mDecoder);
44-
}
45-
46-
nsresult
47-
AppendText(const char* aSrcBuffer, uint32_t aSrcBufferLen)
48-
{
49-
int32_t destBufferLen;
50-
nsresult rv =
51-
mDecoder->GetMaxLength(aSrcBuffer, aSrcBufferLen, &destBufferLen);
52-
if (NS_WARN_IF(NS_FAILED(rv))) {
53-
return rv;
54-
}
55-
56-
if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible)) {
57-
return NS_ERROR_OUT_OF_MEMORY;
58-
}
59-
60-
char16_t* destBuffer = mDecoded.BeginWriting() + mDecoded.Length();
61-
int32_t totalChars = mDecoded.Length();
62-
63-
int32_t srcLen = (int32_t) aSrcBufferLen;
64-
int32_t outLen = destBufferLen;
65-
rv = mDecoder->Convert(aSrcBuffer, &srcLen, destBuffer, &outLen);
66-
MOZ_ASSERT(NS_SUCCEEDED(rv));
67-
68-
totalChars += outLen;
69-
mDecoded.SetLength(totalChars);
70-
71-
return NS_OK;
72-
}
73-
74-
nsString&
75-
GetText()
76-
{
77-
return mDecoded;
78-
}
79-
};
80-
8133
// Reads over a CRLF and positions start after it.
8234
static bool
8335
PushOverLine(nsACString::const_iterator& aStart,
@@ -535,13 +487,11 @@ nsresult
535487
BodyUtil::ConsumeText(uint32_t aInputLength, uint8_t* aInput,
536488
nsString& aText)
537489
{
538-
StreamDecoder decoder;
539-
nsresult rv = decoder.AppendText(reinterpret_cast<char*>(aInput),
540-
aInputLength);
541-
if (NS_WARN_IF(NS_FAILED(rv))) {
490+
nsresult rv =
491+
UTF_8_ENCODING->DecodeWithBOMRemoval(MakeSpan(aInput, aInputLength), aText);
492+
if (NS_FAILED(rv)) {
542493
return rv;
543494
}
544-
aText = decoder.GetText();
545495
return NS_OK;
546496
}
547497

dom/base/EventSource.cpp

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,20 @@
3737
#include "nsIThreadRetargetableRequest.h"
3838
#include "nsIAsyncVerifyRedirectCallback.h"
3939
#include "nsIScriptError.h"
40-
#include "mozilla/dom/EncodingUtils.h"
4140
#include "nsIContentSecurityPolicy.h"
4241
#include "nsContentUtils.h"
4342
#include "mozilla/Preferences.h"
4443
#include "xpcpublic.h"
4544
#include "nsWrapperCacheInlines.h"
4645
#include "mozilla/Attributes.h"
4746
#include "nsError.h"
47+
#include "mozilla/Encoding.h"
4848

4949
namespace mozilla {
5050
namespace dom {
5151

5252
using namespace workers;
5353

54-
#define REPLACEMENT_CHAR (char16_t)0xFFFD
55-
#define BOM_CHAR (char16_t)0xFEFF
5654
#define SPACE_CHAR (char16_t)0x0020
5755
#define CR_CHAR (char16_t)0x000D
5856
#define LF_CHAR (char16_t)0x000A
@@ -213,13 +211,7 @@ class EventSourceImpl final : public nsIObserver
213211
*
214212
* PARSE_STATE_OFF -> PARSE_STATE_BEGIN_OF_STREAM
215213
*
216-
* PARSE_STATE_BEGIN_OF_STREAM -> PARSE_STATE_BOM_WAS_READ |
217-
* PARSE_STATE_CR_CHAR |
218-
* PARSE_STATE_BEGIN_OF_LINE |
219-
* PARSE_STATE_COMMENT |
220-
* PARSE_STATE_FIELD_NAME
221-
*
222-
* PARSE_STATE_BOM_WAS_READ -> PARSE_STATE_CR_CHAR |
214+
* PARSE_STATE_BEGIN_OF_STREAM -> PARSE_STATE_CR_CHAR |
223215
* PARSE_STATE_BEGIN_OF_LINE |
224216
* PARSE_STATE_COMMENT |
225217
* PARSE_STATE_FIELD_NAME
@@ -255,7 +247,6 @@ class EventSourceImpl final : public nsIObserver
255247
enum ParserStatus {
256248
PARSE_STATE_OFF = 0,
257249
PARSE_STATE_BEGIN_OF_STREAM,
258-
PARSE_STATE_BOM_WAS_READ,
259250
PARSE_STATE_CR_CHAR,
260251
PARSE_STATE_COMMENT,
261252
PARSE_STATE_FIELD_NAME,
@@ -285,8 +276,7 @@ class EventSourceImpl final : public nsIObserver
285276
UniquePtr<Message> mCurrentMessage;
286277
nsDeque mMessagesToDispatch;
287278
ParserStatus mStatus;
288-
nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
289-
nsresult mLastConvertionResult;
279+
mozilla::UniquePtr<mozilla::Decoder> mUnicodeDecoder;
290280
nsString mLastFieldName;
291281
nsString mLastFieldValue;
292282

@@ -351,7 +341,6 @@ EventSourceImpl::EventSourceImpl(EventSource* aEventSource)
351341
: mEventSource(aEventSource)
352342
, mReconnectionTime(0)
353343
, mStatus(PARSE_STATE_OFF)
354-
, mLastConvertionResult(NS_OK)
355344
, mMutex("EventSourceImpl::mMutex")
356345
, mFrozen(false)
357346
, mGoingToDispatchAllMessages(false)
@@ -598,7 +587,7 @@ EventSourceImpl::Init(nsIPrincipal* aPrincipal,
598587
Preferences::GetInt("dom.server-events.default-reconnection-time",
599588
DEFAULT_RECONNECTION_TIME_VALUE);
600589

601-
mUnicodeDecoder = EncodingUtils::DecoderForEncoding("UTF-8");
590+
mUnicodeDecoder = UTF_8_ENCODING->NewDecoderWithBOMRemoval();
602591

603592
// the constructor should throw a SYNTAX_ERROR only if it fails resolving the
604593
// url parameter, so we don't care about the InitChannelAndRequestEventSource
@@ -730,27 +719,27 @@ EventSourceImpl::ParseSegment(const char* aBuffer, uint32_t aLength)
730719
if (IsClosed()) {
731720
return;
732721
}
733-
int32_t srcCount, outCount;
734-
char16_t out[2];
735-
const char* p = aBuffer;
736-
const char* end = aBuffer + aLength;
737-
738-
do {
739-
srcCount = aLength - (p - aBuffer);
740-
outCount = 2;
741-
742-
mLastConvertionResult =
743-
mUnicodeDecoder->Convert(p, &srcCount, out, &outCount);
744-
MOZ_ASSERT(mLastConvertionResult != NS_ERROR_ILLEGAL_INPUT);
745-
746-
for (int32_t i = 0; i < outCount; ++i) {
747-
nsresult rv = ParseCharacter(out[i]);
722+
char16_t buffer[1024];
723+
auto dst = MakeSpan(buffer);
724+
auto src = AsBytes(MakeSpan(aBuffer, aLength));
725+
// XXX EOF handling is https://bugzilla.mozilla.org/show_bug.cgi?id=1369018
726+
for (;;) {
727+
uint32_t result;
728+
size_t read;
729+
size_t written;
730+
bool hadErrors;
731+
Tie(result, read, written, hadErrors) =
732+
mUnicodeDecoder->DecodeToUTF16(src, dst, false);
733+
Unused << hadErrors;
734+
for (auto c : dst.To(written)) {
735+
nsresult rv = ParseCharacter(c);
748736
NS_ENSURE_SUCCESS_VOID(rv);
749737
}
750-
p = p + srcCount;
751-
} while (p < end &&
752-
mLastConvertionResult != NS_PARTIAL_MORE_INPUT &&
753-
mLastConvertionResult != NS_OK);
738+
if (result == kInputEmpty) {
739+
return;
740+
}
741+
src = src.From(read);
742+
}
754743
}
755744

756745
class DataAvailableRunnable final : public Runnable
@@ -1163,10 +1152,9 @@ EventSourceImpl::ResetDecoder()
11631152
{
11641153
AssertIsOnTargetThread();
11651154
if (mUnicodeDecoder) {
1166-
mUnicodeDecoder->Reset();
1155+
UTF_8_ENCODING->NewDecoderWithBOMRemovalInto(*mUnicodeDecoder);
11671156
}
11681157
mStatus = PARSE_STATE_OFF;
1169-
mLastConvertionResult = NS_OK;
11701158
ClearFields();
11711159
}
11721160

@@ -1682,22 +1670,6 @@ EventSourceImpl::ParseCharacter(char16_t aChr)
16821670
break;
16831671

16841672
case PARSE_STATE_BEGIN_OF_STREAM:
1685-
if (aChr == BOM_CHAR) {
1686-
mStatus = PARSE_STATE_BOM_WAS_READ; // ignore it
1687-
} else if (aChr == CR_CHAR) {
1688-
mStatus = PARSE_STATE_CR_CHAR;
1689-
} else if (aChr == LF_CHAR) {
1690-
mStatus = PARSE_STATE_BEGIN_OF_LINE;
1691-
} else if (aChr == COLON_CHAR) {
1692-
mStatus = PARSE_STATE_COMMENT;
1693-
} else {
1694-
mLastFieldName += aChr;
1695-
mStatus = PARSE_STATE_FIELD_NAME;
1696-
}
1697-
1698-
break;
1699-
1700-
case PARSE_STATE_BOM_WAS_READ:
17011673
if (aChr == CR_CHAR) {
17021674
mStatus = PARSE_STATE_CR_CHAR;
17031675
} else if (aChr == LF_CHAR) {

dom/base/EventSource.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "nsIHttpChannel.h"
2525
#include "nsWeakReference.h"
2626
#include "nsDeque.h"
27-
#include "nsIUnicodeDecoder.h"
2827

2928
class nsPIDOMWindowInner;
3029

dom/base/FormData.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
#include "mozilla/dom/File.h"
1111
#include "mozilla/dom/Directory.h"
1212
#include "mozilla/dom/HTMLFormElement.h"
13+
#include "mozilla/Encoding.h"
1314

1415
#include "MultipartBlobImpl.h"
1516

1617
using namespace mozilla;
1718
using namespace mozilla::dom;
1819

1920
FormData::FormData(nsISupports* aOwner)
20-
: HTMLFormSubmission(NS_LITERAL_CSTRING("UTF-8"), nullptr)
21+
: HTMLFormSubmission(WrapNotNull(UTF_8_ENCODING), nullptr)
2122
, mOwner(aOwner)
2223
{
2324
}
@@ -401,7 +402,7 @@ NS_IMETHODIMP
401402
FormData::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
402403
nsACString& aContentTypeWithCharset, nsACString& aCharset)
403404
{
404-
FSMultipartFormData fs(NS_LITERAL_CSTRING("UTF-8"), nullptr);
405+
FSMultipartFormData fs(WrapNotNull(UTF_8_ENCODING), nullptr);
405406

406407
for (uint32_t i = 0; i < mFormData.Length(); ++i) {
407408
if (mFormData[i].wasNullBlob) {

dom/base/WebSocket.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "nsError.h"
3434
#include "nsIScriptObjectPrincipal.h"
3535
#include "nsIURL.h"
36-
#include "nsIUnicodeEncoder.h"
3736
#include "nsThreadUtils.h"
3837
#include "nsIPromptFactory.h"
3938
#include "nsIWindowWatcher.h"

0 commit comments

Comments
 (0)