56501 - Dealing with NOSCRIPT contents

r=jst
sr=scc, vidur
This commit is contained in:
harishd%netscape.com 2000-10-15 17:30:08 +00:00
Родитель 7119d71e0c
Коммит 35a0081e8f
6 изменённых файлов: 118 добавлений и 78 удалений

Просмотреть файл

@ -644,7 +644,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
// printf("token: %p\n",aToken);
if(mSkipTarget){ //handle a preexisting target...
if(mSkipTarget){ //handle a preexisting target...
if((theTag==mSkipTarget) && (eToken_end==theType)){
mSkipTarget=eHTMLTag_unknown; //stop skipping.
//mTokenizer->PushTokenFront(aToken); //push the end token...
@ -658,7 +658,32 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
return result;
}
}
else if(mDTDState==NS_HTMLPARSER_ALTERNATECONTENT) {
if(eHTMLTag_noscript!=theTag || theType!=eToken_end) {
// attribute source is a part of start token.
if(theType!=eToken_attribute) {
aToken->AppendSource(mScratch);
}
IF_FREE(aToken);
return result;
}
else {
// If you're here then we have seen a /noscript.
// After handling the text token intentionally
// fall thro' such that /noscript gets handled.
CTextToken theTextToken(mScratch);
result=HandleStartToken(&theTextToken);
if(NS_FAILED(result)) {
return result;
}
mScratch.Truncate();
mScratch.SetCapacity(0);
}
}
/* ---------------------------------------------------------------------------------
This section of code is used to "move" misplaced content from one location in
our document model to another. (Consider what would happen if we found a <P> tag
@ -666,7 +691,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
deque until we can deal with it.
---------------------------------------------------------------------------------
*/
if(!execSkipContent && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) {
if(!execSkipContent) {
switch(theTag) {
case eHTMLTag_html:
@ -1224,7 +1249,7 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode
STOP_TIMER()
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillHandleStartTag(), this=%p\n", this));
if(mParser && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) {
if(mParser) {
CObserverService* theService=mParser->GetObserverService();
if(theService) {
@ -1661,8 +1686,7 @@ eHTMLTags FindAutoCloseTargetForEndTag(eHTMLTags aCurrentTag,nsDTDContext& aCont
PRInt32 theChildIndex=GetIndexOfChildOrSynonym(aContext,aCurrentTag);
if(kNotFound<theChildIndex) {
if((thePrevTag==aContext[theChildIndex]) ||
(eHTMLTag_noscript==aCurrentTag)){ //bug 54571
if(thePrevTag==aContext[theChildIndex]){
return aContext[theChildIndex];
}
@ -2324,7 +2348,7 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) {
mLineNumber += aNode.mSkippedContent->CountChar(kNewLine);
return NS_OK;
}
/***********************************************************************************
The preceeding tables determine the set of elements each tag can contain...
***********************************************************************************/
@ -3186,17 +3210,16 @@ nsresult CNavDTD::OpenNoscript(const nsIParserNode *aNode,nsEntryStack* aStyleSt
if(result==NS_HTMLPARSER_ALTERNATECONTENT) {
// We're here because the sink has identified that
// JS is enabled and therefore noscript content should
// not be treated as a regular content,i.e., make sure
// that head elements are handled correctly and may be
// residual style.
mDTDState=result;
// Though NS_HTMLPARSER_ALTERNATECONTENT is a succeeded message we don't want to propagate it
// because there are lots of places where we don't check for succeeded result instead
// we check for NS_OK. Also, this message is pertinent to the DTD only
result=NS_OK;
// not be treated as a regular content
++mHasOpenNoXXX;
mScratch.Truncate();
mScratch.SetCapacity(0);
mBodyContext->Push(aNode,aStyleStack);
mDTDState=result;
result=NS_OK;
}
mHasOpenNoXXX++;
mBodyContext->Push(aNode,aStyleStack);
}
}
@ -3758,26 +3781,24 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){
// within NOSCRIPT and since JS is enanbled we should not process
// this content. However, when JS is disabled alternate content
// would become regular content.
if(mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) {
result=OpenHead(aNode);
if(NS_OK==result) {
if(eHTMLTag_title==theTag) {
result=OpenHead(aNode);
if(NS_OK==result) {
if(eHTMLTag_title==theTag) {
const nsString& theString=aNode->GetSkippedContent();
PRInt32 theLen=theString.Length();
CBufDescriptor theBD(theString.GetUnicode(), PR_TRUE, theLen+1, theLen);
nsAutoString theString2(theBD);
const nsString& theString=aNode->GetSkippedContent();
PRInt32 theLen=theString.Length();
CBufDescriptor theBD(theString.GetUnicode(), PR_TRUE, theLen+1, theLen);
nsAutoString theString2(theBD);
theString2.CompressWhitespace();
theString2.CompressWhitespace();
STOP_TIMER()
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
mSink->SetTitle(theString2);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
START_TIMER()
STOP_TIMER()
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
mSink->SetTitle(theString2);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
START_TIMER()
}
else result=AddLeaf(aNode);
}
else result=AddLeaf(aNode);
// XXX If the return value tells us to block, go
// ahead and close the tag out anyway, since its
// contents will be consumed.
@ -3792,12 +3813,11 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){
// the AddLeaf.
if (rv != NS_OK) {
result = rv;
}
}
}
}
else result=AddLeaf(aNode);
}
}
}
return result;
}

Просмотреть файл

@ -869,7 +869,7 @@ void InitializeElementTable(void) {
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,0,
/*parent,incl,exclgroups*/ kBlock, kFlowEntity|kSelf, kNone,
/*special props, prop-range*/ 0, kNoPropRange,
/*special props, prop-range*/ kLegalOpen, kNoPropRange,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown);
Initialize(

Просмотреть файл

@ -694,7 +694,7 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
//XXX - Find a better soution to record content
//Added _plaintext to fix bug 46054.
if((eHTMLTag_textarea==theTag || eHTMLTag_xmp==theTag || eHTMLTag_plaintext==theTag) && !mRecordTrailingContent) {
if((eHTMLTag_textarea==theTag || eHTMLTag_xmp==theTag || eHTMLTag_plaintext==theTag || eHTMLTag_noscript==theTag) && !mRecordTrailingContent) {
mRecordTrailingContent=PR_TRUE;
}

Просмотреть файл

@ -644,7 +644,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
// printf("token: %p\n",aToken);
if(mSkipTarget){ //handle a preexisting target...
if(mSkipTarget){ //handle a preexisting target...
if((theTag==mSkipTarget) && (eToken_end==theType)){
mSkipTarget=eHTMLTag_unknown; //stop skipping.
//mTokenizer->PushTokenFront(aToken); //push the end token...
@ -658,7 +658,32 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
return result;
}
}
else if(mDTDState==NS_HTMLPARSER_ALTERNATECONTENT) {
if(eHTMLTag_noscript!=theTag || theType!=eToken_end) {
// attribute source is a part of start token.
if(theType!=eToken_attribute) {
aToken->AppendSource(mScratch);
}
IF_FREE(aToken);
return result;
}
else {
// If you're here then we have seen a /noscript.
// After handling the text token intentionally
// fall thro' such that /noscript gets handled.
CTextToken theTextToken(mScratch);
result=HandleStartToken(&theTextToken);
if(NS_FAILED(result)) {
return result;
}
mScratch.Truncate();
mScratch.SetCapacity(0);
}
}
/* ---------------------------------------------------------------------------------
This section of code is used to "move" misplaced content from one location in
our document model to another. (Consider what would happen if we found a <P> tag
@ -666,7 +691,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
deque until we can deal with it.
---------------------------------------------------------------------------------
*/
if(!execSkipContent && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) {
if(!execSkipContent) {
switch(theTag) {
case eHTMLTag_html:
@ -1224,7 +1249,7 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode
STOP_TIMER()
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillHandleStartTag(), this=%p\n", this));
if(mParser && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) {
if(mParser) {
CObserverService* theService=mParser->GetObserverService();
if(theService) {
@ -1661,8 +1686,7 @@ eHTMLTags FindAutoCloseTargetForEndTag(eHTMLTags aCurrentTag,nsDTDContext& aCont
PRInt32 theChildIndex=GetIndexOfChildOrSynonym(aContext,aCurrentTag);
if(kNotFound<theChildIndex) {
if((thePrevTag==aContext[theChildIndex]) ||
(eHTMLTag_noscript==aCurrentTag)){ //bug 54571
if(thePrevTag==aContext[theChildIndex]){
return aContext[theChildIndex];
}
@ -2324,7 +2348,7 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) {
mLineNumber += aNode.mSkippedContent->CountChar(kNewLine);
return NS_OK;
}
/***********************************************************************************
The preceeding tables determine the set of elements each tag can contain...
***********************************************************************************/
@ -3186,17 +3210,16 @@ nsresult CNavDTD::OpenNoscript(const nsIParserNode *aNode,nsEntryStack* aStyleSt
if(result==NS_HTMLPARSER_ALTERNATECONTENT) {
// We're here because the sink has identified that
// JS is enabled and therefore noscript content should
// not be treated as a regular content,i.e., make sure
// that head elements are handled correctly and may be
// residual style.
mDTDState=result;
// Though NS_HTMLPARSER_ALTERNATECONTENT is a succeeded message we don't want to propagate it
// because there are lots of places where we don't check for succeeded result instead
// we check for NS_OK. Also, this message is pertinent to the DTD only
result=NS_OK;
// not be treated as a regular content
++mHasOpenNoXXX;
mScratch.Truncate();
mScratch.SetCapacity(0);
mBodyContext->Push(aNode,aStyleStack);
mDTDState=result;
result=NS_OK;
}
mHasOpenNoXXX++;
mBodyContext->Push(aNode,aStyleStack);
}
}
@ -3758,26 +3781,24 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){
// within NOSCRIPT and since JS is enanbled we should not process
// this content. However, when JS is disabled alternate content
// would become regular content.
if(mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) {
result=OpenHead(aNode);
if(NS_OK==result) {
if(eHTMLTag_title==theTag) {
result=OpenHead(aNode);
if(NS_OK==result) {
if(eHTMLTag_title==theTag) {
const nsString& theString=aNode->GetSkippedContent();
PRInt32 theLen=theString.Length();
CBufDescriptor theBD(theString.GetUnicode(), PR_TRUE, theLen+1, theLen);
nsAutoString theString2(theBD);
const nsString& theString=aNode->GetSkippedContent();
PRInt32 theLen=theString.Length();
CBufDescriptor theBD(theString.GetUnicode(), PR_TRUE, theLen+1, theLen);
nsAutoString theString2(theBD);
theString2.CompressWhitespace();
theString2.CompressWhitespace();
STOP_TIMER()
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
mSink->SetTitle(theString2);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
START_TIMER()
STOP_TIMER()
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
mSink->SetTitle(theString2);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
START_TIMER()
}
else result=AddLeaf(aNode);
}
else result=AddLeaf(aNode);
// XXX If the return value tells us to block, go
// ahead and close the tag out anyway, since its
// contents will be consumed.
@ -3792,12 +3813,11 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){
// the AddLeaf.
if (rv != NS_OK) {
result = rv;
}
}
}
}
else result=AddLeaf(aNode);
}
}
}
return result;
}

Просмотреть файл

@ -869,7 +869,7 @@ void InitializeElementTable(void) {
/*rootnodes,endrootnodes*/ &gRootTags,&gRootTags,
/*autoclose starttags and endtags*/ 0,0,0,0,
/*parent,incl,exclgroups*/ kBlock, kFlowEntity|kSelf, kNone,
/*special props, prop-range*/ 0, kNoPropRange,
/*special props, prop-range*/ kLegalOpen, kNoPropRange,
/*special parents,kids,skip*/ 0,0,eHTMLTag_unknown);
Initialize(

Просмотреть файл

@ -694,7 +694,7 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
//XXX - Find a better soution to record content
//Added _plaintext to fix bug 46054.
if((eHTMLTag_textarea==theTag || eHTMLTag_xmp==theTag || eHTMLTag_plaintext==theTag) && !mRecordTrailingContent) {
if((eHTMLTag_textarea==theTag || eHTMLTag_xmp==theTag || eHTMLTag_plaintext==theTag || eHTMLTag_noscript==theTag) && !mRecordTrailingContent) {
mRecordTrailingContent=PR_TRUE;
}