Bug 715739 - Make document.write from inside a script-created parser not add to the wyciwyg channel. r=smaug.

This commit is contained in:
Henri Sivonen
2012-01-20 13:16:27 +02:00
parent 82cb66d309
commit 40e41c5d2b
6 changed files with 10 additions and 48 deletions

View File

@@ -1628,7 +1628,7 @@ nsHTMLDocument::Close()
}
++mWriteLevel;
nsresult rv = mParser->Parse(EmptyString(), mParser->GetRootContextKey(),
nsresult rv = mParser->Parse(EmptyString(), nsnull,
GetContentTypeInternal(), true);
--mWriteLevel;
@@ -1730,8 +1730,8 @@ nsHTMLDocument::WriteCommon(JSContext *cx,
static NS_NAMED_LITERAL_STRING(new_line, "\n");
// Save the data in cache
if (mWyciwygChannel) {
// Save the data in cache if the write isn't from within the doc
if (mWyciwygChannel && !key) {
if (!aText.IsEmpty()) {
mWyciwygChannel->WriteToCacheEntry(aText);
}
@@ -2256,7 +2256,7 @@ nsHTMLDocument::GenerateParserKey(void)
// Make scripts that aren't inserted by the active parser of this document
// participate in the context of the script that document.open()ed
// this document.
return mParser->GetRootContextKey();
return nsnull;
}
}
return script;

View File

@@ -214,7 +214,7 @@ nsHtml5Parser::IsComplete()
NS_IMETHODIMP
nsHtml5Parser::Parse(nsIURI* aURL,
nsIRequestObserver* aObserver,
void* aKey,
void* aKey, // legacy; ignored
nsDTDMode aMode) // legacy; ignored
{
/*
@@ -229,7 +229,6 @@ nsHtml5Parser::Parse(nsIURI* aURL,
mStreamParser->SetViewSourceTitle(aURL); // In case we're viewing source
mExecutor->SetStreamParser(mStreamParser);
mExecutor->SetParser(this);
mRootContextKey = aKey;
return NS_OK;
}
@@ -284,7 +283,7 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
return NS_OK;
}
if (aLastCall && aSourceBuffer.IsEmpty() && aKey == GetRootContextKey()) {
if (aLastCall && aSourceBuffer.IsEmpty() && !aKey) {
// document.close()
NS_ASSERTION(!mStreamParser,
"Had stream parser but got document.close().");
@@ -406,7 +405,7 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
mLastWasCR = false;
if (stackBuffer.hasMore()) {
PRInt32 lineNumberSave;
bool inRootContext = (!mStreamParser && (aKey == mRootContextKey));
bool inRootContext = (!mStreamParser && !aKey);
if (inRootContext) {
mTokenizer->setLineNumber(mRootContextLineNumber);
} else {
@@ -533,15 +532,6 @@ nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
return NS_OK;
}
/**
* This magic value is passed to the previous method on document.close()
*/
NS_IMETHODIMP_(void *)
nsHtml5Parser::GetRootContextKey()
{
return mRootContextKey;
}
NS_IMETHODIMP
nsHtml5Parser::Terminate()
{
@@ -667,7 +657,6 @@ nsHtml5Parser::Reset()
mStreamParser = nsnull;
mRootContextLineNumber = 1;
mParserInsertedScriptsBeingEvaluated = 0;
mRootContextKey = nsnull;
mAtomTable.Clear(); // should be already cleared in the fragment case anyway
// Portable parser objects
mFirstBuffer->next = nsnull;
@@ -804,8 +793,7 @@ nsHtml5Parser::ParseUntilBlocked()
mFirstBuffer->adjust(mLastWasCR);
mLastWasCR = false;
if (mFirstBuffer->hasMore()) {
bool inRootContext = (!mStreamParser &&
(mFirstBuffer->key == mRootContextKey));
bool inRootContext = (!mStreamParser && !mFirstBuffer->key);
if (inRootContext) {
mTokenizer->setLineNumber(mRootContextLineNumber);
}

View File

@@ -186,11 +186,6 @@ class nsHtml5Parser : public nsIParser,
bool aLastCall,
nsDTDMode aMode = eDTDMode_autodetect);
/**
* Gets the key passed to initial Parse()
*/
NS_IMETHOD_(void *) GetRootContextKey();
/**
* Stops the parser prematurely
*/

View File

@@ -55,8 +55,8 @@
#include "nsIAtom.h"
#define NS_IPARSER_IID \
{ 0x0c8c3998, 0x9959, 0x496e, \
{ 0xbd, 0xd9, 0x0b, 0x6f, 0xc4, 0x1c, 0x3b, 0x87 } }
{ 0x30ffba62, 0x0928, 0x4503, \
{ 0xa8, 0x95, 0xd1, 0x32, 0x76, 0x40, 0x2a, 0x2a } }
// {41421C60-310A-11d4-816F-000064657374}
#define NS_IDEBUG_DUMP_CONTENT_IID \
@@ -232,10 +232,6 @@ class nsIParser : public nsISupports {
bool aLastCall,
nsDTDMode aMode = eDTDMode_autodetect) = 0;
// Return a key, suitable for passing into one of the Parse methods above,
// that will cause this parser to use the root context.
NS_IMETHOD_(void *) GetRootContextKey() = 0;
NS_IMETHOD Terminate(void) = 0;
/**

View File

@@ -1075,21 +1075,6 @@ nsParser::SetUnusedInput(nsString& aBuffer)
mUnusedInput = aBuffer;
}
NS_IMETHODIMP_(void *)
nsParser::GetRootContextKey()
{
CParserContext* pc = mParserContext;
if (!pc) {
return nsnull;
}
while (pc->mPrevContext) {
pc = pc->mPrevContext;
}
return pc->mKey;
}
/**
* Call this when you want to *force* the parser to terminate the
* parsing process altogether. This is binary -- so once you terminate

View File

@@ -199,8 +199,6 @@ class nsParser : public nsIParser,
bool aLastCall,
nsDTDMode aMode = eDTDMode_autodetect);
NS_IMETHOD_(void *) GetRootContextKey();
/**
* This method needs documentation
*/