Bug 1446097. Switch to "set" as the canonical nsGkAtoms name of the string "set", so it matches the actual tag name "set" in SVG. r=hsivonen,njn

Most of the noise is from the fact that clang-format on parser/html/*.{h,cpp}
reformatted all sorts of stuff.  Not running it caused lots of format changes
from the generator... I guess we changed the format rules since the last time
this got run?

MozReview-Commit-ID: IA2G87zUIKN
This commit is contained in:
Boris Zbarsky
2018-03-16 11:26:06 -04:00
parent 4f8ec3af2d
commit 051041fc49
80 changed files with 12758 additions and 5466 deletions

View File

@@ -56,7 +56,8 @@ nsHtml5StreamParser::InitializeStatics()
*
* To work around this limitation, runnables posted by the main thread to the
* parser thread hold their reference to the stream parser in an
* nsHtml5StreamParserPtr. Upon creation, nsHtml5StreamParserPtr addrefs the object it holds
* nsHtml5StreamParserPtr. Upon creation, nsHtml5StreamParserPtr addrefs the
* object it holds
* just like a regular nsRefPtr. This is OK, since the creation of the
* runnable and the nsHtml5StreamParserPtr happens on the main thread.
*
@@ -77,8 +78,7 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsHtml5StreamParser)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsHtml5StreamParser)
NS_INTERFACE_TABLE_HEAD(nsHtml5StreamParser)
NS_INTERFACE_TABLE(nsHtml5StreamParser,
nsICharsetDetectionObserver)
NS_INTERFACE_TABLE(nsHtml5StreamParser, nsICharsetDetectionObserver)
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsHtml5StreamParser)
NS_INTERFACE_MAP_END
@@ -102,12 +102,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHtml5StreamParser)
// hack: count the strongly owned edge wrapped in the runnable
if (tmp->mExecutorFlusher) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mExecutorFlusher->mExecutor");
cb.NoteXPCOMChild(static_cast<nsIContentSink*> (tmp->mExecutor));
cb.NoteXPCOMChild(static_cast<nsIContentSink*>(tmp->mExecutor));
}
// hack: count the strongly owned edge wrapped in the runnable
if (tmp->mLoadFlusher) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mLoadFlusher->mExecutor");
cb.NoteXPCOMChild(static_cast<nsIContentSink*> (tmp->mExecutor));
cb.NoteXPCOMChild(static_cast<nsIContentSink*>(tmp->mExecutor));
}
// hack: count self if held by mChardet
if (tmp->mChardet) {
@@ -118,36 +118,40 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
class nsHtml5ExecutorFlusher : public Runnable
{
private:
RefPtr<nsHtml5TreeOpExecutor> mExecutor;
public:
explicit nsHtml5ExecutorFlusher(nsHtml5TreeOpExecutor* aExecutor)
: Runnable("nsHtml5ExecutorFlusher")
, mExecutor(aExecutor)
{}
NS_IMETHOD Run() override
{
if (!mExecutor->isInList()) {
mExecutor->RunFlushLoop();
}
return NS_OK;
private:
RefPtr<nsHtml5TreeOpExecutor> mExecutor;
public:
explicit nsHtml5ExecutorFlusher(nsHtml5TreeOpExecutor* aExecutor)
: Runnable("nsHtml5ExecutorFlusher")
, mExecutor(aExecutor)
{
}
NS_IMETHOD Run() override
{
if (!mExecutor->isInList()) {
mExecutor->RunFlushLoop();
}
return NS_OK;
}
};
class nsHtml5LoadFlusher : public Runnable
{
private:
RefPtr<nsHtml5TreeOpExecutor> mExecutor;
public:
explicit nsHtml5LoadFlusher(nsHtml5TreeOpExecutor* aExecutor)
: Runnable("nsHtml5LoadFlusher")
, mExecutor(aExecutor)
{}
NS_IMETHOD Run() override
{
mExecutor->FlushSpeculativeLoads();
return NS_OK;
}
private:
RefPtr<nsHtml5TreeOpExecutor> mExecutor;
public:
explicit nsHtml5LoadFlusher(nsHtml5TreeOpExecutor* aExecutor)
: Runnable("nsHtml5LoadFlusher")
, mExecutor(aExecutor)
{
}
NS_IMETHOD Run() override
{
mExecutor->FlushSpeculativeLoads();
return NS_OK;
}
};
nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
@@ -160,11 +164,11 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
, mReparseForbidden(false)
, mLastBuffer(nullptr) // Will be filled when starting
, mExecutor(aExecutor)
, mTreeBuilder(new nsHtml5TreeBuilder((aMode == VIEW_SOURCE_HTML ||
aMode == VIEW_SOURCE_XML) ?
nullptr : mExecutor->GetStage(),
aMode == NORMAL ?
mExecutor->GetStage() : nullptr))
, mTreeBuilder(new nsHtml5TreeBuilder(
(aMode == VIEW_SOURCE_HTML || aMode == VIEW_SOURCE_XML)
? nullptr
: mExecutor->GetStage(),
aMode == NORMAL ? mExecutor->GetStage() : nullptr))
, mTokenizer(new nsHtml5Tokenizer(mTreeBuilder, aMode == VIEW_SOURCE_XML))
, mTokenizerMutex("nsHtml5StreamParser mTokenizerMutex")
, mOwner(aOwner)
@@ -200,7 +204,7 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
if (aMode == VIEW_SOURCE_HTML || aMode == VIEW_SOURCE_XML) {
nsHtml5Highlighter* highlighter =
new nsHtml5Highlighter(mExecutor->GetStage());
mTokenizer->EnableViewSource(highlighter); // takes ownership
mTokenizer->EnableViewSource(highlighter); // takes ownership
mTreeBuilder->EnableViewSource(highlighter); // doesn't own
}
@@ -215,7 +219,7 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
detectorContractID += detectorName;
if ((mChardet = do_CreateInstance(detectorContractID.get()))) {
(void) mChardet->Init(this);
(void)mChardet->Init(this);
mFeedChardet = true;
}
}
@@ -249,8 +253,8 @@ nsresult
nsHtml5StreamParser::GetChannel(nsIChannel** aChannel)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
return mRequest ? CallQueryInterface(mRequest, aChannel) :
NS_ERROR_NOT_AVAILABLE;
return mRequest ? CallQueryInterface(mRequest, aChannel)
: NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
@@ -259,23 +263,22 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
NS_ASSERTION(IsParserThread(), "Wrong thread!");
if (aConf == eBestAnswer || aConf == eSureAnswer) {
mFeedChardet = false; // just in case
auto encoding = Encoding::ForLabelNoReplacement(
nsDependentCString(aCharset));
auto encoding =
Encoding::ForLabelNoReplacement(nsDependentCString(aCharset));
if (!encoding) {
return NS_OK;
}
if (HasDecoder()) {
if (mEncoding == encoding) {
NS_ASSERTION(mCharsetSource < kCharsetFromAutoDetection,
"Why are we running chardet at all?");
"Why are we running chardet at all?");
mCharsetSource = kCharsetFromAutoDetection;
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
} else {
// We've already committed to a decoder. Request a reload from the
// docshell.
mTreeBuilder->NeedsCharsetSwitchTo(WrapNotNull(encoding),
kCharsetFromAutoDetection,
0);
mTreeBuilder->NeedsCharsetSwitchTo(
WrapNotNull(encoding), kCharsetFromAutoDetection, 0);
FlushTreeOpsAndDisarmTimer();
Interrupt();
}
@@ -319,9 +322,10 @@ nsHtml5StreamParser::SetViewSourceTitle(nsIURI* aURL)
}
nsresult
nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const uint8_t* aFromSegment, // can be null
uint32_t aCount,
uint32_t* aWriteCount)
nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
const uint8_t* aFromSegment, // can be null
uint32_t aCount,
uint32_t* aWriteCount)
{
NS_ASSERTION(IsParserThread(), "Wrong thread!");
nsresult rv = NS_OK;
@@ -409,10 +413,7 @@ nsHtml5StreamParser::SniffBOMlessUTF16BasicLatin(const uint8_t* aFromSegment,
mCharsetSource = kCharsetFromIrreversibleAutoDetection;
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
mFeedChardet = false;
mTreeBuilder->MaybeComplainAboutCharset("EncBomlessUtf16",
true,
0);
mTreeBuilder->MaybeComplainAboutCharset("EncBomlessUtf16", true, 0);
}
void
@@ -433,7 +434,7 @@ nsHtml5StreamParser::SetEncodingFromExpat(const char16_t* aEncoding)
// right away and let the encoding be set to UTF-8 which we'd default to
// anyway.
}
mEncoding = UTF_8_ENCODING; // XML defaults to UTF-8 without a BOM
mEncoding = UTF_8_ENCODING; // XML defaults to UTF-8 without a BOM
mCharsetSource = kCharsetFromMetaTag; // means confident
}
@@ -442,7 +443,8 @@ nsHtml5StreamParser::SetEncodingFromExpat(const char16_t* aEncoding)
// expat.h in nsHtml5StreamParser.h. Doing that would cause naming conflicts.
// Using a separate user data struct also avoids bloating nsHtml5StreamParser
// by one pointer.
struct UserData {
struct UserData
{
XML_Parser mExpat;
nsHtml5StreamParser* mStreamParser;
};
@@ -457,30 +459,28 @@ HandleXMLDeclaration(void* aUserData,
{
UserData* ud = static_cast<UserData*>(aUserData);
ud->mStreamParser->SetEncodingFromExpat(
reinterpret_cast<const char16_t*>(aEncoding));
reinterpret_cast<const char16_t*>(aEncoding));
XML_StopParser(ud->mExpat, false);
}
static void
HandleStartElement(void* aUserData,
const XML_Char* aName,
const XML_Char **aAtts)
const XML_Char** aAtts)
{
UserData* ud = static_cast<UserData*>(aUserData);
XML_StopParser(ud->mExpat, false);
}
static void
HandleEndElement(void* aUserData,
const XML_Char* aName)
HandleEndElement(void* aUserData, const XML_Char* aName)
{
UserData* ud = static_cast<UserData*>(aUserData);
XML_StopParser(ud->mExpat, false);
}
static void
HandleComment(void* aUserData,
const XML_Char* aName)
HandleComment(void* aUserData, const XML_Char* aName)
{
UserData* ud = static_cast<UserData*>(aUserData);
XML_StopParser(ud->mExpat, false);
@@ -496,26 +496,26 @@ HandleProcessingInstruction(void* aUserData,
}
nsresult
nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be null
uint32_t aCount,
uint32_t* aWriteCount,
uint32_t aCountToSniffingLimit)
nsHtml5StreamParser::FinalizeSniffing(
const uint8_t* aFromSegment, // can be null
uint32_t aCount,
uint32_t* aWriteCount,
uint32_t aCountToSniffingLimit)
{
NS_ASSERTION(IsParserThread(), "Wrong thread!");
NS_ASSERTION(mCharsetSource < kCharsetFromParentForced,
"Should not finalize sniffing when using forced charset.");
"Should not finalize sniffing when using forced charset.");
if (mMode == VIEW_SOURCE_XML) {
static const XML_Memory_Handling_Suite memsuite =
{
(void *(*)(size_t))moz_xmalloc,
(void *(*)(void *, size_t))moz_xrealloc,
free
};
static const XML_Memory_Handling_Suite memsuite = {
(void* (*)(size_t))moz_xmalloc,
(void* (*)(void*, size_t))moz_xrealloc,
free
};
static const char16_t kExpatSeparator[] = { 0xFFFF, '\0' };
static const char16_t kISO88591[] =
{ 'I', 'S', 'O', '-', '8', '8', '5', '9', '-', '1', '\0' };
static const char16_t kISO88591[] = { 'I', 'S', 'O', '-', '8', '8',
'5', '9', '-', '1', '\0' };
UserData ud;
ud.mStreamParser = this;
@@ -550,8 +550,7 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul
mSniffingLength,
false);
}
if (status == XML_STATUS_OK &&
mCharsetSource < kCharsetFromMetaTag &&
if (status == XML_STATUS_OK && mCharsetSource < kCharsetFromMetaTag &&
aFromSegment) {
status = XML_Parse(ud.mExpat,
reinterpret_cast<const char*>(aFromSegment),
@@ -569,15 +568,15 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul
mCharsetSource = kCharsetFromMetaTag; // means confident
}
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount,
aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
// meta scan failed.
if (mCharsetSource >= kCharsetFromHintPrevDoc) {
mFeedChardet = false;
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
// Check for BOMless UTF-16 with Basic
// Latin content for compat with IE. See bug 631751.
@@ -588,7 +587,8 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul
bool dontFeed;
nsresult rv;
if (mSniffingBuffer) {
rv = mChardet->DoIt((const char*)mSniffingBuffer.get(), mSniffingLength, &dontFeed);
rv = mChardet->DoIt(
(const char*)mSniffingBuffer.get(), mSniffingLength, &dontFeed);
mFeedChardet = !dontFeed;
NS_ENSURE_SUCCESS(rv, rv);
}
@@ -620,17 +620,16 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul
mEncoding = WINDOWS_1252_ENCODING;
mCharsetSource = kCharsetFromFallback;
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
} else if (mMode == LOAD_AS_DATA &&
mCharsetSource == kCharsetFromFallback) {
} else if (mMode == LOAD_AS_DATA && mCharsetSource == kCharsetFromFallback) {
NS_ASSERTION(mReparseForbidden, "Reparse should be forbidden for XHR");
NS_ASSERTION(!mFeedChardet, "Should not feed chardet for XHR");
NS_ASSERTION(mEncoding == UTF_8_ENCODING,
"XHR should default to UTF-8");
NS_ASSERTION(mEncoding == UTF_8_ENCODING, "XHR should default to UTF-8");
// Now mark charset source as non-weak to signal that we have a decision
mCharsetSource = kCharsetFromDocTypeDefault;
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
}
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
nsresult
@@ -667,7 +666,8 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
break;
case SEEN_UTF_16_LE_FIRST_BYTE:
if (aFromSegment[i] == 0xFE) {
rv = SetupDecodingFromBom(UTF_16LE_ENCODING); // upper case is the raw form
rv = SetupDecodingFromBom(
UTF_16LE_ENCODING); // upper case is the raw form
NS_ENSURE_SUCCESS(rv, rv);
uint32_t count = aCount - (i + 1);
rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
@@ -679,7 +679,8 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
break;
case SEEN_UTF_16_BE_FIRST_BYTE:
if (aFromSegment[i] == 0xFF) {
rv = SetupDecodingFromBom(UTF_16BE_ENCODING); // upper case is the raw form
rv = SetupDecodingFromBom(
UTF_16BE_ENCODING); // upper case is the raw form
NS_ENSURE_SUCCESS(rv, rv);
uint32_t count = aCount - (i + 1);
rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
@@ -698,7 +699,8 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
break;
case SEEN_UTF_8_SECOND_BYTE:
if (aFromSegment[i] == 0xBF) {
rv = SetupDecodingFromBom(UTF_8_ENCODING); // upper case is the raw form
rv =
SetupDecodingFromBom(UTF_8_ENCODING); // upper case is the raw form
NS_ENSURE_SUCCESS(rv, rv);
uint32_t count = aCount - (i + 1);
rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
@@ -721,8 +723,7 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
MOZ_ASSERT(mCharsetSource != kCharsetFromOtherComponent,
"kCharsetFromOtherComponent is for XSLT.");
if (mBomState == BOM_SNIFFING_OVER &&
mCharsetSource == kCharsetFromChannel) {
if (mBomState == BOM_SNIFFING_OVER && mCharsetSource == kCharsetFromChannel) {
// There was no BOM and the charset came from channel. mEncoding
// still contains the charset from the channel as set by an
// earlier call to SetDocumentCharset(), since we didn't find a BOM and
@@ -730,23 +731,22 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
// we don't come here but check <meta> for XSS-dangerous charsets first.)
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
if (!mMetaScanner && (mMode == NORMAL ||
mMode == VIEW_SOURCE_HTML ||
mMode == LOAD_AS_DATA)) {
if (!mMetaScanner &&
(mMode == NORMAL || mMode == VIEW_SOURCE_HTML || mMode == LOAD_AS_DATA)) {
mMetaScanner = new nsHtml5MetaScanner(mTreeBuilder);
}
if (mSniffingLength + aCount >= NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE) {
// this is the last buffer
uint32_t countToSniffingLimit =
NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE - mSniffingLength;
NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE - mSniffingLength;
if (mMode == NORMAL || mMode == VIEW_SOURCE_HTML || mMode == LOAD_AS_DATA) {
nsHtml5ByteReadable readable(aFromSegment, aFromSegment +
countToSniffingLimit);
nsHtml5ByteReadable readable(aFromSegment,
aFromSegment + countToSniffingLimit);
nsAutoCString charset;
auto encoding = mMetaScanner->sniff(&readable);
// Due to the way nsHtml5Portability reports OOM, ask the tree buider
@@ -779,8 +779,8 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
return FinalizeSniffing(aFromSegment, aCount, aWriteCount,
countToSniffingLimit);
return FinalizeSniffing(
aFromSegment, aCount, aWriteCount, countToSniffingLimit);
}
// not the last buffer
@@ -797,24 +797,23 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
// meta scan successful; honor overrides unless meta is XSS-dangerous
if ((mCharsetSource == kCharsetFromParentForced ||
mCharsetSource == kCharsetFromUserForced) &&
(encoding->IsAsciiCompatible() ||
encoding == ISO_2022_JP_ENCODING)) {
(encoding->IsAsciiCompatible() || encoding == ISO_2022_JP_ENCODING)) {
// Honor override
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
mEncoding = WrapNotNull(encoding);
mCharsetSource = kCharsetFromMetaPrescan;
mFeedChardet = false;
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
aCount, aWriteCount);
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
aFromSegment, aCount, aWriteCount);
}
}
if (!mSniffingBuffer) {
mSniffingBuffer =
MakeUniqueFallible<uint8_t[]>(NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE);
mSniffingBuffer = MakeUniqueFallible<uint8_t[]>(
NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE);
if (!mSniffingBuffer) {
return NS_ERROR_OUT_OF_MEMORY;
}
@@ -881,7 +880,8 @@ public:
NS_IMETHOD Run() override
{
nsJSContext::MaybeRunNextCollectorSlice(mDocShell, JS::gcreason::HTML_PARSER);
nsJSContext::MaybeRunNextCollectorSlice(mDocShell,
JS::gcreason::HTML_PARSER);
return NS_OK;
}
@@ -910,8 +910,8 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
// For View Source, the parser should run with scripts "enabled" if a normal
// load would have scripts enabled.
bool scriptingEnabled = mMode == LOAD_AS_DATA ?
false : mExecutor->IsScriptEnabled();
bool scriptingEnabled =
mMode == LOAD_AS_DATA ? false : mExecutor->IsScriptEnabled();
mOwner->StartTokenizer(scriptingEnabled);
bool isSrcdoc = false;
@@ -922,8 +922,8 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
}
mTreeBuilder->setIsSrcdocDocument(isSrcdoc);
mTreeBuilder->setScriptingEnabled(scriptingEnabled);
mTreeBuilder->SetPreventScriptExecution(!((mMode == NORMAL) &&
scriptingEnabled));
mTreeBuilder->SetPreventScriptExecution(
!((mMode == NORMAL) && scriptingEnabled));
mTokenizer->start();
mExecutor->Start();
mExecutor->StartReadingFromStage();
@@ -973,7 +973,8 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
if (NS_SUCCEEDED(rv)) {
// Non-HTTP channels are bogus enough that we let them work with unlabeled
// runnables for now. Asserting for HTTP channels only.
MOZ_ASSERT(mDocGroup || mMode == LOAD_AS_DATA, "How come the doc group is still null?");
MOZ_ASSERT(mDocGroup || mMode == LOAD_AS_DATA,
"How come the doc group is still null?");
nsAutoCString method;
Unused << httpChannel->GetRequestMethod(method);
@@ -1077,7 +1078,8 @@ nsHtml5StreamParser::DoStopRequest()
mChardet->Done();
}
MOZ_ASSERT(mUnicodeDecoder, "Should have a decoder after finalizing sniffing.");
MOZ_ASSERT(mUnicodeDecoder,
"Should have a decoder after finalizing sniffing.");
// mLastBuffer should always point to a buffer of the size
// NS_HTML5_STREAM_PARSER_READ_BUFFER_SIZE.
@@ -1113,7 +1115,6 @@ nsHtml5StreamParser::DoStopRequest()
}
}
if (IsTerminatedOrInterrupted()) {
return;
}
@@ -1123,26 +1124,27 @@ nsHtml5StreamParser::DoStopRequest()
class nsHtml5RequestStopper : public Runnable
{
private:
nsHtml5StreamParserPtr mStreamParser;
private:
nsHtml5StreamParserPtr mStreamParser;
public:
explicit nsHtml5RequestStopper(nsHtml5StreamParser* aStreamParser)
: Runnable("nsHtml5RequestStopper")
, mStreamParser(aStreamParser)
{}
NS_IMETHOD Run() override
{
mozilla::MutexAutoLock autoLock(mStreamParser->mTokenizerMutex);
mStreamParser->DoStopRequest();
return NS_OK;
}
public:
explicit nsHtml5RequestStopper(nsHtml5StreamParser* aStreamParser)
: Runnable("nsHtml5RequestStopper")
, mStreamParser(aStreamParser)
{
}
NS_IMETHOD Run() override
{
mozilla::MutexAutoLock autoLock(mStreamParser->mTokenizerMutex);
mStreamParser->DoStopRequest();
return NS_OK;
}
};
nsresult
nsHtml5StreamParser::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult status)
nsISupports* aContext,
nsresult status)
{
NS_ASSERTION(mRequest == aRequest, "Got Stop on wrong stream.");
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@@ -1184,7 +1186,8 @@ nsHtml5StreamParser::DoDataAvailable(const uint8_t* aBuffer, uint32_t aLength)
MarkAsBroken(rv);
return;
}
NS_ASSERTION(writeCount == aLength, "Wrong number of stream bytes written/sniffed.");
NS_ASSERTION(writeCount == aLength,
"Wrong number of stream bytes written/sniffed.");
if (IsTerminatedOrInterrupted()) {
return;
@@ -1210,26 +1213,27 @@ nsHtml5StreamParser::DoDataAvailable(const uint8_t* aBuffer, uint32_t aLength)
class nsHtml5DataAvailable : public Runnable
{
private:
nsHtml5StreamParserPtr mStreamParser;
UniquePtr<uint8_t[]> mData;
uint32_t mLength;
private:
nsHtml5StreamParserPtr mStreamParser;
UniquePtr<uint8_t[]> mData;
uint32_t mLength;
public:
nsHtml5DataAvailable(nsHtml5StreamParser* aStreamParser,
UniquePtr<uint8_t[]> aData,
uint32_t aLength)
: Runnable("nsHtml5DataAvailable")
, mStreamParser(aStreamParser)
, mData(Move(aData))
, mLength(aLength)
{}
NS_IMETHOD Run() override
{
mozilla::MutexAutoLock autoLock(mStreamParser->mTokenizerMutex);
mStreamParser->DoDataAvailable(mData.get(), mLength);
return NS_OK;
}
public:
nsHtml5DataAvailable(nsHtml5StreamParser* aStreamParser,
UniquePtr<uint8_t[]> aData,
uint32_t aLength)
: Runnable("nsHtml5DataAvailable")
, mStreamParser(aStreamParser)
, mData(Move(aData))
, mLength(aLength)
{
}
NS_IMETHOD Run() override
{
mozilla::MutexAutoLock autoLock(mStreamParser->mTokenizerMutex);
mStreamParser->DoDataAvailable(mData.get(), mLength);
return NS_OK;
}
};
nsresult
@@ -1252,15 +1256,15 @@ nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
if (!data) {
return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
}
rv = aInStream->Read(reinterpret_cast<char*>(data.get()),
aLength, &totalRead);
rv =
aInStream->Read(reinterpret_cast<char*>(data.get()), aLength, &totalRead);
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(totalRead <= aLength, "Read more bytes than were available?");
nsCOMPtr<nsIRunnable> dataAvailable = new nsHtml5DataAvailable(this,
Move(data),
totalRead);
if (NS_FAILED(mEventTarget->Dispatch(dataAvailable, nsIThread::DISPATCH_NORMAL))) {
nsCOMPtr<nsIRunnable> dataAvailable =
new nsHtml5DataAvailable(this, Move(data), totalRead);
if (NS_FAILED(
mEventTarget->Dispatch(dataAvailable, nsIThread::DISPATCH_NORMAL))) {
NS_WARNING("Dispatching DataAvailable event failed.");
}
return rv;
@@ -1269,8 +1273,8 @@ nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
mozilla::MutexAutoLock autoLock(mTokenizerMutex);
// Read directly from response buffer.
rv = aInStream->ReadSegments(CopySegmentsToParser, this, aLength,
&totalRead);
rv =
aInStream->ReadSegments(CopySegmentsToParser, this, aLength, &totalRead);
if (NS_FAILED(rv)) {
NS_WARNING("Failed reading response data to parser");
return rv;
@@ -1280,12 +1284,12 @@ nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
}
/* static */ nsresult
nsHtml5StreamParser::CopySegmentsToParser(nsIInputStream *aInStream,
void *aClosure,
const char *aFromSegment,
nsHtml5StreamParser::CopySegmentsToParser(nsIInputStream* aInStream,
void* aClosure,
const char* aFromSegment,
uint32_t aToOffset,
uint32_t aCount,
uint32_t *aWriteCount)
uint32_t* aWriteCount)
{
nsHtml5StreamParser* parser = static_cast<nsHtml5StreamParser*>(aClosure);
@@ -1296,47 +1300,42 @@ nsHtml5StreamParser::CopySegmentsToParser(nsIInputStream *aInStream,
}
const Encoding*
nsHtml5StreamParser::PreferredForInternalEncodingDecl(const nsACString& aEncoding)
nsHtml5StreamParser::PreferredForInternalEncodingDecl(
const nsACString& aEncoding)
{
const Encoding* newEncoding = Encoding::ForLabel(aEncoding);
if (!newEncoding) {
// the encoding name is bogus
mTreeBuilder->MaybeComplainAboutCharset("EncMetaUnsupported",
true,
mTokenizer->getLineNumber());
mTreeBuilder->MaybeComplainAboutCharset(
"EncMetaUnsupported", true, mTokenizer->getLineNumber());
return nullptr;
}
if (newEncoding == UTF_16BE_ENCODING ||
newEncoding == UTF_16LE_ENCODING) {
mTreeBuilder->MaybeComplainAboutCharset("EncMetaUtf16",
true,
mTokenizer->getLineNumber());
if (newEncoding == UTF_16BE_ENCODING || newEncoding == UTF_16LE_ENCODING) {
mTreeBuilder->MaybeComplainAboutCharset(
"EncMetaUtf16", true, mTokenizer->getLineNumber());
newEncoding = UTF_8_ENCODING;
}
if (newEncoding == X_USER_DEFINED_ENCODING) {
// WebKit/Blink hack for Indian and Armenian legacy sites
mTreeBuilder->MaybeComplainAboutCharset("EncMetaUserDefined",
true,
mTokenizer->getLineNumber());
mTreeBuilder->MaybeComplainAboutCharset(
"EncMetaUserDefined", true, mTokenizer->getLineNumber());
newEncoding = WINDOWS_1252_ENCODING;
}
if (newEncoding == mEncoding) {
if (mCharsetSource < kCharsetFromMetaPrescan) {
if (mInitialEncodingWasFromParentFrame) {
mTreeBuilder->MaybeComplainAboutCharset("EncLateMetaFrame",
false,
mTokenizer->getLineNumber());
mTreeBuilder->MaybeComplainAboutCharset(
"EncLateMetaFrame", false, mTokenizer->getLineNumber());
} else {
mTreeBuilder->MaybeComplainAboutCharset("EncLateMeta",
false,
mTokenizer->getLineNumber());
mTreeBuilder->MaybeComplainAboutCharset(
"EncLateMeta", false, mTokenizer->getLineNumber());
}
}
mCharsetSource = kCharsetFromMetaTag; // become confident
mFeedChardet = false; // don't feed chardet when confident
mFeedChardet = false; // don't feed chardet when confident
return nullptr;
}
@@ -1350,7 +1349,8 @@ nsHtml5StreamParser::internalEncodingDeclaration(nsHtml5String aEncoding)
// nsHtml5MetaScanner::tryCharset. Unfortunately, the
// trickery with member fields there leads to some copy-paste reuse. :-(
NS_ASSERTION(IsParserThread(), "Wrong thread!");
if (mCharsetSource >= kCharsetFromMetaTag) { // this threshold corresponds to "confident" in the HTML5 spec
if (mCharsetSource >= kCharsetFromMetaTag) { // this threshold corresponds to
// "confident" in the HTML5 spec
return false;
}
@@ -1369,18 +1369,16 @@ nsHtml5StreamParser::internalEncodingDeclaration(nsHtml5String aEncoding)
// PreferredForInternalEncodingDecl so that if that method calls
// MaybeComplainAboutCharset, its charset complaint wins over the one
// below.
mTreeBuilder->MaybeComplainAboutCharset("EncLateMetaTooLate",
true,
mTokenizer->getLineNumber());
mTreeBuilder->MaybeComplainAboutCharset(
"EncLateMetaTooLate", true, mTokenizer->getLineNumber());
return false; // not reparsing even if we wanted to
}
// Avoid having the chardet ask for another restart after this restart
// request.
mFeedChardet = false;
mTreeBuilder->NeedsCharsetSwitchTo(WrapNotNull(encoding),
kCharsetFromMetaTag,
mTokenizer->getLineNumber());
mTreeBuilder->NeedsCharsetSwitchTo(
WrapNotNull(encoding), kCharsetFromMetaTag, mTokenizer->getLineNumber());
FlushTreeOpsAndDisarmTimer();
Interrupt();
// the tree op executor will cause the stream parser to terminate
@@ -1445,8 +1443,7 @@ nsHtml5StreamParser::ParseAvailableData()
// that need flushing may have been flushed earlier even if the
// flush right above here did nothing.
nsCOMPtr<nsIRunnable> runnable(mLoadFlusher);
if (NS_FAILED(
DispatchToMain(runnable.forget()))) {
if (NS_FAILED(DispatchToMain(runnable.forget()))) {
NS_WARNING("failed to dispatch load flush event");
}
}
@@ -1466,17 +1463,14 @@ nsHtml5StreamParser::ParseAvailableData()
// no text and only an image or a Flash embed get the more
// severe message from the next if block. The message is
// technically accurate, though.
mTreeBuilder->MaybeComplainAboutCharset("EncNoDeclarationFrame",
false,
0);
mTreeBuilder->MaybeComplainAboutCharset(
"EncNoDeclarationFrame", false, 0);
} else if (mMode == NORMAL) {
mTreeBuilder->MaybeComplainAboutCharset("EncNoDeclaration",
true,
0);
mTreeBuilder->MaybeComplainAboutCharset(
"EncNoDeclaration", true, 0);
} else if (mMode == PLAIN_TEXT) {
mTreeBuilder->MaybeComplainAboutCharset("EncNoDeclarationPlain",
true,
0);
mTreeBuilder->MaybeComplainAboutCharset(
"EncNoDeclarationPlain", true, 0);
}
}
if (NS_SUCCEEDED(mTreeBuilder->IsBroken())) {
@@ -1553,7 +1547,8 @@ public:
explicit nsHtml5StreamParserContinuation(nsHtml5StreamParser* aStreamParser)
: Runnable("nsHtml5StreamParserContinuation")
, mStreamParser(aStreamParser)
{}
{
}
NS_IMETHOD Run() override
{
mozilla::MutexAutoLock autoLock(mStreamParser->mTokenizerMutex);
@@ -1570,13 +1565,13 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
NS_ASSERTION(!(mMode == VIEW_SOURCE_HTML || mMode == VIEW_SOURCE_XML),
"ContinueAfterScripts called in view source mode!");
"ContinueAfterScripts called in view source mode!");
if (NS_FAILED(mExecutor->IsBroken())) {
return;
}
#ifdef DEBUG
mExecutor->AssertStageEmpty();
#endif
#ifdef DEBUG
mExecutor->AssertStageEmpty();
#endif
bool speculationFailed = false;
{
mozilla::MutexAutoLock speculationAutoLock(mSpeculationMutex);
@@ -1591,7 +1586,8 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
// We've got a failed speculation :-(
MaybeDisableFutureSpeculation();
Interrupt(); // Make the parser thread release the tokenizer mutex sooner
// now fall out of the speculationAutoLock into the tokenizerAutoLock block
// now fall out of the speculationAutoLock into the tokenizerAutoLock
// block
} else {
// We've got a successful speculation!
if (mSpeculations.Length() > 1) {
@@ -1599,9 +1595,11 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
// no need to bother the parser thread.
speculation->FlushToSink(mExecutor);
NS_ASSERTION(!mExecutor->IsScriptExecuting(),
"ParseUntilBlocked() was supposed to ensure we don't come "
"here when scripts are executing.");
NS_ASSERTION(mExecutor->IsInFlushLoop(), "How are we here if "
"ParseUntilBlocked() was supposed to ensure we don't come "
"here when scripts are executing.");
NS_ASSERTION(
mExecutor->IsInFlushLoop(),
"How are we here if "
"RunFlushLoop() didn't call ParseUntilBlocked() which is the "
"only caller of this method?");
mSpeculations.RemoveElementAt(0);
@@ -1618,11 +1616,12 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
}
{
mozilla::MutexAutoLock tokenizerAutoLock(mTokenizerMutex);
#ifdef DEBUG
#ifdef DEBUG
{
mAtomTable.SetPermittedLookupEventTarget(GetMainThreadSerialEventTarget());
mAtomTable.SetPermittedLookupEventTarget(
GetMainThreadSerialEventTarget());
}
#endif
#endif
// In principle, the speculation mutex should be acquired here,
// but there's no point, because the parser thread only acquires it
// when it has also acquired the tokenizer mutex and we are already
@@ -1640,7 +1639,8 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
mExecutor->GetDocument(),
nsContentUtils::eDOM_PROPERTIES,
"SpeculationFailed",
nullptr, 0,
nullptr,
0,
nullptr,
EmptyString(),
speculation->GetStartLineNumber());
@@ -1655,7 +1655,7 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
// run here synchronously on the main thread...
mTreeBuilder->flushCharacters(); // empty the pending buffer
mTreeBuilder->ClearOps(); // now get rid of the failed ops
mTreeBuilder->ClearOps(); // now get rid of the failed ops
mTreeBuilder->SetOpSink(mExecutor->GetStage());
mExecutor->StartReadingFromStage();
@@ -1670,9 +1670,11 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
// the current speculation
mSpeculations.ElementAt(0)->FlushToSink(mExecutor);
NS_ASSERTION(!mExecutor->IsScriptExecuting(),
"ParseUntilBlocked() was supposed to ensure we don't come "
"here when scripts are executing.");
NS_ASSERTION(mExecutor->IsInFlushLoop(), "How are we here if "
"ParseUntilBlocked() was supposed to ensure we don't come "
"here when scripts are executing.");
NS_ASSERTION(
mExecutor->IsInFlushLoop(),
"How are we here if "
"RunFlushLoop() didn't call ParseUntilBlocked() which is the "
"only caller of this method?");
mSpeculations.RemoveElementAt(0);
@@ -1692,10 +1694,10 @@ nsHtml5StreamParser::ContinueAfterScripts(nsHtml5Tokenizer* aTokenizer,
if (NS_FAILED(mEventTarget->Dispatch(event, nsIThread::DISPATCH_NORMAL))) {
NS_WARNING("Failed to dispatch nsHtml5StreamParserContinuation");
}
// A stream event might run before this event runs, but that's harmless.
#ifdef DEBUG
mAtomTable.SetPermittedLookupEventTarget(mEventTarget);
#endif
// A stream event might run before this event runs, but that's harmless.
#ifdef DEBUG
mAtomTable.SetPermittedLookupEventTarget(mEventTarget);
#endif
}
}
@@ -1718,7 +1720,8 @@ public:
explicit nsHtml5TimerKungFu(nsHtml5StreamParser* aStreamParser)
: Runnable("nsHtml5TimerKungFu")
, mStreamParser(aStreamParser)
{}
{
}
NS_IMETHOD Run() override
{
mozilla::MutexAutoLock flushTimerLock(mStreamParser->mFlushTimerMutex);
@@ -1746,7 +1749,8 @@ nsHtml5StreamParser::DropTimer()
*
* This DropTimer method addresses these issues. This method must be called
* on the main thread before the destructor of this class is reached.
* The nsHtml5TimerKungFu object has an nsHtml5StreamParserPtr that addrefs this
* The nsHtml5TimerKungFu object has an nsHtml5StreamParserPtr that addrefs
* this
* stream parser object to keep it alive until the runnable is done.
* The runnable cancels the timer on the parser thread, drops the timer
* and lets nsHtml5StreamParserPtr send a runnable back to the main thread to
@@ -1766,7 +1770,7 @@ nsHtml5StreamParser::DropTimer()
void
nsHtml5StreamParser::TimerCallback(nsITimer* aTimer, void* aClosure)
{
(static_cast<nsHtml5StreamParser*> (aClosure))->TimerFlush();
(static_cast<nsHtml5StreamParser*>(aClosure))->TimerFlush();
}
void
@@ -1791,8 +1795,7 @@ nsHtml5StreamParser::TimerFlush()
mTreeBuilder->Flush(); // delete useless ops
if (mTokenizer->FlushViewSource()) {
nsCOMPtr<nsIRunnable> runnable(mExecutorFlusher);
if (NS_FAILED(
DispatchToMain(runnable.forget()))) {
if (NS_FAILED(DispatchToMain(runnable.forget()))) {
NS_WARNING("failed to dispatch executor flush event");
}
}
@@ -1801,8 +1804,7 @@ nsHtml5StreamParser::TimerFlush()
// going to arrive. Send data to the main thread.
if (mTreeBuilder->Flush(true)) {
nsCOMPtr<nsIRunnable> runnable(mExecutorFlusher);
if (NS_FAILED(
DispatchToMain(runnable.forget()))) {
if (NS_FAILED(DispatchToMain(runnable.forget()))) {
NS_WARNING("failed to dispatch executor flush event");
}
}
@@ -1831,5 +1833,6 @@ nsHtml5StreamParser::DispatchToMain(already_AddRefed<nsIRunnable>&& aRunnable)
if (mDocGroup) {
return mDocGroup->Dispatch(TaskCategory::Network, Move(aRunnable));
}
return SchedulerGroup::UnlabeledDispatch(TaskCategory::Network, Move(aRunnable));
return SchedulerGroup::UnlabeledDispatch(TaskCategory::Network,
Move(aRunnable));
}