mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 23:28:30 +00:00
afea1b3ff8
- Bug 559303 - Consolidate strBuf and longStrBuf in the tokenizer. r=wchen. (b385e7635) - Bug 489820 part 1 - Make charRefBuf non-growable and have the same lifetime as the tokenizer. r=wchen. (5c9a2c402) - Bug 489820 part 2 - Grow buffers to the worst-case size before tokenizing; fix comments. r=wchen. (7dad72a9a) - Bug 1176668 - Fix overflow avoidance in numeric character reference handling. r=wchen. (f9cdb2b5b) - Bug 1171309 - Remove PREF_Init()'s return value. r=bsmedberg. (245dd4436) - Bug 916101 - Show entire pref name when wanring about size, r=mossop (61245be0f) - add back crashrep, it is not defined anyway (4995d8d3e) - Bug 1195123: Restructure logic (pulling out "!") for SVG image rejection, to make it clearer that it matches the comment. r=longsonr (57e3698f6) - Bug 629682 - Add a better warning message for SVG-as-an-image external resources being blocked. r=dholbert (35ea836e4) - remove useless cast (abb30e8ac) - add internal CSP preload check from TFF (14c4d843e) - Bug 1167650 - Expose DOMRequest and DOMCursor to workers. r=bent (468365262) - Bug 1154041 - Enable child process memory report logging by default on B2G. r=erahm (141254fc5) - namespace (515b42704) - Bug 1164587 - Get rid of Fault() in the cycle collector. r=smaug (9587d4971)
131 lines
4.1 KiB
C++
131 lines
4.1 KiB
C++
/* 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/. */
|
|
|
|
#include "nsHtml5StringParser.h"
|
|
#include "nsHtml5TreeOpExecutor.h"
|
|
#include "nsHtml5TreeBuilder.h"
|
|
#include "nsHtml5Tokenizer.h"
|
|
#include "nsIContent.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIDOMDocumentFragment.h"
|
|
#include "nsHtml5DependentUTF16Buffer.h"
|
|
|
|
NS_IMPL_ISUPPORTS0(nsHtml5StringParser)
|
|
|
|
nsHtml5StringParser::nsHtml5StringParser()
|
|
: mBuilder(new nsHtml5OplessBuilder())
|
|
, mTreeBuilder(new nsHtml5TreeBuilder(mBuilder))
|
|
, mTokenizer(new nsHtml5Tokenizer(mTreeBuilder, false))
|
|
{
|
|
MOZ_COUNT_CTOR(nsHtml5StringParser);
|
|
mTokenizer->setInterner(&mAtomTable);
|
|
}
|
|
|
|
nsHtml5StringParser::~nsHtml5StringParser()
|
|
{
|
|
MOZ_COUNT_DTOR(nsHtml5StringParser);
|
|
}
|
|
|
|
nsresult
|
|
nsHtml5StringParser::ParseFragment(const nsAString& aSourceBuffer,
|
|
nsIContent* aTargetNode,
|
|
nsIAtom* aContextLocalName,
|
|
int32_t aContextNamespace,
|
|
bool aQuirks,
|
|
bool aPreventScriptExecution)
|
|
{
|
|
NS_ENSURE_TRUE(aSourceBuffer.Length() <= INT32_MAX,
|
|
NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsIDocument* doc = aTargetNode->OwnerDoc();
|
|
nsIURI* uri = doc->GetDocumentURI();
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
mTreeBuilder->setFragmentContext(aContextLocalName,
|
|
aContextNamespace,
|
|
aTargetNode,
|
|
aQuirks);
|
|
|
|
#ifdef DEBUG
|
|
if (!aPreventScriptExecution) {
|
|
NS_ASSERTION(!aTargetNode->IsInDoc(),
|
|
"If script execution isn't prevented, "
|
|
"the target node must not be in doc.");
|
|
nsCOMPtr<nsIDOMDocumentFragment> domFrag = do_QueryInterface(aTargetNode);
|
|
NS_ASSERTION(domFrag,
|
|
"If script execution isn't prevented, must parse to DOM fragment.");
|
|
}
|
|
#endif
|
|
|
|
mTreeBuilder->SetPreventScriptExecution(aPreventScriptExecution);
|
|
|
|
return Tokenize(aSourceBuffer, doc, true);
|
|
}
|
|
|
|
nsresult
|
|
nsHtml5StringParser::ParseDocument(const nsAString& aSourceBuffer,
|
|
nsIDocument* aTargetDoc,
|
|
bool aScriptingEnabledForNoscriptParsing)
|
|
{
|
|
MOZ_ASSERT(!aTargetDoc->GetFirstChild());
|
|
|
|
NS_ENSURE_TRUE(aSourceBuffer.Length() <= INT32_MAX,
|
|
NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mTreeBuilder->setFragmentContext(nullptr,
|
|
kNameSpaceID_None,
|
|
nullptr,
|
|
false);
|
|
|
|
mTreeBuilder->SetPreventScriptExecution(true);
|
|
|
|
return Tokenize(aSourceBuffer, aTargetDoc, aScriptingEnabledForNoscriptParsing);
|
|
}
|
|
|
|
nsresult
|
|
nsHtml5StringParser::Tokenize(const nsAString& aSourceBuffer,
|
|
nsIDocument* aDocument,
|
|
bool aScriptingEnabledForNoscriptParsing) {
|
|
|
|
nsIURI* uri = aDocument->GetDocumentURI();
|
|
|
|
mBuilder->Init(aDocument, uri, nullptr, nullptr);
|
|
|
|
mBuilder->SetParser(this);
|
|
mBuilder->SetNodeInfoManager(aDocument->NodeInfoManager());
|
|
|
|
// Mark the parser as *not* broken by passing NS_OK
|
|
nsresult rv = mBuilder->MarkAsBroken(NS_OK);
|
|
|
|
mTreeBuilder->setScriptingEnabled(aScriptingEnabledForNoscriptParsing);
|
|
mTreeBuilder->setIsSrcdocDocument(aDocument->IsSrcdocDocument());
|
|
mBuilder->Start();
|
|
mTokenizer->start();
|
|
if (!aSourceBuffer.IsEmpty()) {
|
|
bool lastWasCR = false;
|
|
nsHtml5DependentUTF16Buffer buffer(aSourceBuffer);
|
|
while (buffer.hasMore()) {
|
|
buffer.adjust(lastWasCR);
|
|
lastWasCR = false;
|
|
if (buffer.hasMore()) {
|
|
if (!mTokenizer->EnsureBufferSpace(buffer.getLength())) {
|
|
rv = mBuilder->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
|
|
break;
|
|
}
|
|
lastWasCR = mTokenizer->tokenizeBuffer(&buffer);
|
|
if (NS_FAILED(rv = mBuilder->IsBroken())) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (NS_SUCCEEDED(rv)) {
|
|
mTokenizer->eof();
|
|
}
|
|
mTokenizer->end();
|
|
mBuilder->Finish();
|
|
mAtomTable.Clear();
|
|
return rv;
|
|
}
|