From f392a553af43c8dad1e8e448419ca9f8fd87b252 Mon Sep 17 00:00:00 2001 From: "harishd%netscape.com" Date: Fri, 1 Sep 2000 18:17:17 +0000 Subject: [PATCH] 7670 - Enabling NOSCRIPT content. 47827 - Make sure to check DD's hierarchy. r=jst --- htmlparser/robot/nsRobotSink.cpp | 2 + htmlparser/src/CNavDTD.cpp | 159 +++++++--- htmlparser/src/CNavDTD.h | 2 + htmlparser/src/nsElementTable.cpp | 6 +- htmlparser/src/nsHTMLContentSinkStream.cpp | 2 + htmlparser/src/nsHTMLContentSinkStream.h | 2 + htmlparser/src/nsHTMLNullSink.cpp | 2 + htmlparser/src/nsHTMLToTXTSinkStream.cpp | 2 + htmlparser/src/nsHTMLToTXTSinkStream.h | 288 ------------------ htmlparser/src/nsIHTMLContentSink.h | 16 + htmlparser/src/nsIParser.h | 2 + htmlparser/src/nsLoggingSink.h | 2 + htmlparser/src/nsToken.cpp | 1 + htmlparser/src/nsWellFormedDTD.cpp | 2 +- parser/htmlparser/robot/nsRobotSink.cpp | 2 + parser/htmlparser/src/CNavDTD.cpp | 159 +++++++--- parser/htmlparser/src/CNavDTD.h | 2 + parser/htmlparser/src/nsElementTable.cpp | 6 +- .../src/nsHTMLContentSinkStream.cpp | 2 + .../htmlparser/src/nsHTMLContentSinkStream.h | 2 + parser/htmlparser/src/nsHTMLNullSink.cpp | 2 + .../htmlparser/src/nsHTMLToTXTSinkStream.cpp | 2 + parser/htmlparser/src/nsHTMLToTXTSinkStream.h | 288 ------------------ parser/htmlparser/src/nsIHTMLContentSink.h | 16 + parser/htmlparser/src/nsIParser.h | 2 + parser/htmlparser/src/nsLoggingSink.h | 2 + parser/htmlparser/src/nsToken.cpp | 1 + parser/htmlparser/src/nsWellFormedDTD.cpp | 2 +- 28 files changed, 314 insertions(+), 662 deletions(-) diff --git a/htmlparser/robot/nsRobotSink.cpp b/htmlparser/robot/nsRobotSink.cpp index 0f36da569bb..0ebf4280ef1 100644 --- a/htmlparser/robot/nsRobotSink.cpp +++ b/htmlparser/robot/nsRobotSink.cpp @@ -70,6 +70,8 @@ public: NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) { return NS_OK; } + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode){ return NS_OK; } NS_IMETHOD OpenContainer(const nsIParserNode& aNode); NS_IMETHOD CloseContainer(const nsIParserNode& aNode); NS_IMETHOD NotifyError(const nsParserError* aError); diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 67b1f3efb67..cc2abd61e0a 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -686,10 +686,11 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ deque until we can deal with it. --------------------------------------------------------------------------------- */ - if(!execSkipContent) { + if(!execSkipContent && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) { switch(theTag) { case eHTMLTag_html: + case eHTMLTag_noscript: case eHTMLTag_script: case eHTMLTag_markupDecl: break; // simply pass these through to token handler without further ado... @@ -1174,7 +1175,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) { + if(mParser && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) { CObserverService* theService=mParser->GetObserverService(); if(theService) { @@ -1513,11 +1514,6 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { mHasOpenNoXXX++; break; - case eHTMLTag_noscript: - //mHasOpenNoXXX++; // Fix for 33397 - Enable this when we handle NOSCRIPTS. - isTokenHandled=PR_TRUE; // XXX - Throwing NOSCRIPT to the floor...yet another time.. - break; - case eHTMLTag_script: theHeadIsParent=((!mHasOpenBody) || mRequestedHead); mHasOpenScript=PR_TRUE; @@ -3084,7 +3080,76 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode *aNode){ return result; } +/** + * This method would determine how the noscript content + * should be handled. + * + * harishd 08/24/00 + * @param aNode - The noscript node + * return NS_OK if succeeded else ERROR + */ +nsresult CNavDTD::OpenNoscript(const nsIParserNode *aNode,nsEntryStack* aStyleStack) { + nsresult result=NS_OK; + if(mSink) { + STOP_TIMER(); + MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::OpenNoscript(), this=%p\n", this)); + + result=mSink->OpenNoscript(*aNode); + + MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::OpenNoscript(), this=%p\n", this)); + START_TIMER(); + + if(NS_SUCCEEDED(result)) { + 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; + } + mHasOpenNoXXX++; + mBodyContext->Push(aNode,aStyleStack); + } + } + + return result; +} + +/** + * Call this method to stop handling noscript content + * + * harishd 08/24/00 + * @param aNode - The noscript node + * return NS_OK if succeeded else ERROR + */ +nsresult CNavDTD::CloseNoscript(const nsIParserNode *aNode) { + nsresult result=NS_OK; + + if(mSink) { + STOP_TIMER(); + MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseNoscript(), this=%p\n", this)); + + result=mSink->CloseNoscript(*aNode); + + MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseNoscript(), this=%p\n", this)); + START_TIMER(); + + if(NS_SUCCEEDED(result)) { + if(mHasOpenNoXXX > 0) { + mHasOpenNoXXX--; + } + mDTDState=NS_OK; // switch from alternate content state to regular state + } + } + + return result; +} /** * This method does two things: 1st, help construct @@ -3177,6 +3242,10 @@ CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedB CloseHead(aNode); //do this just in case someone left it open... result=HandleScriptToken(aNode); break; + + case eHTMLTag_noscript: + result=OpenNoscript(aNode,aStyleStack); + break; default: isDefaultNode=PR_TRUE; @@ -3246,6 +3315,10 @@ CNavDTD::CloseContainer(const nsIParserNode *aNode,eHTMLTags aTarget,PRBool aClo case eHTMLTag_frameset: result=CloseFrameset(aNode); break; + + case eHTMLTag_noscript: + result=CloseNoscript(aNode); + break; case eHTMLTag_title: default: @@ -3583,7 +3656,7 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode *aNode){ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){ nsresult result=NS_OK; - static eHTMLTags gNoXTags[]={eHTMLTag_noembed,eHTMLTag_noframes,eHTMLTag_noscript}; + static eHTMLTags gNoXTags[]={eHTMLTag_noembed,eHTMLTag_noframes}; eHTMLTags theTag=(eHTMLTags)aNode->GetNodeType(); @@ -3597,42 +3670,50 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){ } if(mSink) { - result=OpenHead(aNode); - if(NS_OK==result) { - if(eHTMLTag_title==theTag) { + // Alternate content => Content that shouldn't get processed + // as a regular content. That is, probably the content is + // 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) { - 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); - // XXX If the return value tells us to block, go - // ahead and close the tag out anyway, since its - // contents will be consumed. - - // Fix for Bug 31392 - // Do not leave a head context open no matter what the result is. - if(mHasOpenHead) { - nsresult rv=CloseHead(aNode); - // XXX Only send along a failure. If the close - // succeeded we still may need to indicate that the - // parser has blocked (i.e. return the result of - // the AddLeaf. - if (rv != NS_OK) { - result = rv; } - } - } + 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. + + // Fix for Bug 31392 + // Do not leave a head context open no matter what the result is. + if(mHasOpenHead) { + nsresult rv=CloseHead(aNode); + // XXX Only send along a failure. If the close + // succeeded we still may need to indicate that the + // parser has blocked (i.e. return the result of + // the AddLeaf. + if (rv != NS_OK) { + result = rv; + } + } + } + } + else result=AddLeaf(aNode); } return result; } diff --git a/htmlparser/src/CNavDTD.h b/htmlparser/src/CNavDTD.h index 10cd47e6a91..d525ca2b314 100644 --- a/htmlparser/src/CNavDTD.h +++ b/htmlparser/src/CNavDTD.h @@ -429,6 +429,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult OpenForm(const nsIParserNode *aNode); nsresult OpenMap(const nsIParserNode *aNode); nsresult OpenFrameset(const nsIParserNode *aNode); + nsresult OpenNoscript(const nsIParserNode *aNode,nsEntryStack* aStyleStack=0); nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,nsEntryStack* aStyleStack=0); /** @@ -444,6 +445,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult CloseForm(const nsIParserNode *aNode); nsresult CloseMap(const nsIParserNode *aNode); nsresult CloseFrameset(const nsIParserNode *aNode); + nsresult CloseNoscript(const nsIParserNode *aNode); /** * The special purpose methods automatically close diff --git a/htmlparser/src/nsElementTable.cpp b/htmlparser/src/nsElementTable.cpp index 30b62653b2c..cbf2d17e57a 100644 --- a/htmlparser/src/nsElementTable.cpp +++ b/htmlparser/src/nsElementTable.cpp @@ -81,7 +81,7 @@ TagList gFormKids={1,{eHTMLTag_keygen}}; TagList gFramesetKids={3,{eHTMLTag_frame,eHTMLTag_frameset,eHTMLTag_noframes}}; TagList gHtmlKids={9,{eHTMLTag_body,eHTMLTag_frameset,eHTMLTag_head,eHTMLTag_map,eHTMLTag_noscript,eHTMLTag_noframes,eHTMLTag_script,eHTMLTag_newline,eHTMLTag_whitespace}}; -TagList gHeadKids={9,{eHTMLTag_base,eHTMLTag_bgsound,eHTMLTag_link,eHTMLTag_meta,eHTMLTag_script,eHTMLTag_style,eHTMLTag_title,eHTMLTag_noembed,eHTMLTag_noscript}}; +TagList gHeadKids={8,{eHTMLTag_base,eHTMLTag_bgsound,eHTMLTag_link,eHTMLTag_meta,eHTMLTag_script,eHTMLTag_style,eHTMLTag_title,eHTMLTag_noembed}}; TagList gLabelKids={1,{eHTMLTag_span}}; TagList gLIKids={2,{eHTMLTag_ol,eHTMLTag_ul}}; @@ -435,7 +435,7 @@ void InitializeElementTable(void) { /*rootnodes,endrootnodes*/ &gRootTags, &gRootTags, /*autoclose starttags and endtags*/ &gDTCloseTags,0,0,0, /*parent,incl,exclgroups*/ kDLChild, kFlowEntity, kNone, - /*special props, prop-range*/ kNoPropagate|kMustCloseSelf,kDefaultPropRange, + /*special props, prop-range*/ kNoPropagate|kMustCloseSelf|kVerifyHierarchy,kDefaultPropRange, /*special parents,kids,skip*/ &gInDL,0,eHTMLTag_unknown); Initialize( @@ -869,7 +869,7 @@ void InitializeElementTable(void) { /*autoclose starttags and endtags*/ 0,0,0,0, /*parent,incl,exclgroups*/ kBlock, kFlowEntity|kSelf, kNone, /*special props, prop-range*/ 0, kNoPropRange, - /*special parents,kids,skip*/ 0,0,eHTMLTag_noscript); + /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); Initialize( /*tag*/ eHTMLTag_object, diff --git a/htmlparser/src/nsHTMLContentSinkStream.cpp b/htmlparser/src/nsHTMLContentSinkStream.cpp index 9f0b5ece5eb..6fae533856a 100644 --- a/htmlparser/src/nsHTMLContentSinkStream.cpp +++ b/htmlparser/src/nsHTMLContentSinkStream.cpp @@ -578,6 +578,8 @@ USE_GENERAL_OPEN_METHOD(OpenMap, eHTMLTag_map) USE_GENERAL_CLOSE_METHOD(CloseMap, eHTMLTag_map) USE_GENERAL_OPEN_METHOD(OpenFrameset, eHTMLTag_frameset) USE_GENERAL_CLOSE_METHOD(CloseFrameset, eHTMLTag_frameset) +USE_GENERAL_OPEN_METHOD(OpenNoscript, eHTMLTag_noscript) +USE_GENERAL_CLOSE_METHOD(CloseNoscript, eHTMLTag_noscript) /** * diff --git a/htmlparser/src/nsHTMLContentSinkStream.h b/htmlparser/src/nsHTMLContentSinkStream.h index 9cca0caa7a3..f39cecc8f5a 100644 --- a/htmlparser/src/nsHTMLContentSinkStream.h +++ b/htmlparser/src/nsHTMLContentSinkStream.h @@ -138,6 +138,8 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSinkStream NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) ; + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode); NS_IMETHOD DoFragment(PRBool aFlag); NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); diff --git a/htmlparser/src/nsHTMLNullSink.cpp b/htmlparser/src/nsHTMLNullSink.cpp index 6b4ad449e55..17c0c3d9984 100644 --- a/htmlparser/src/nsHTMLNullSink.cpp +++ b/htmlparser/src/nsHTMLNullSink.cpp @@ -69,6 +69,8 @@ public: NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) { return NS_OK; } + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode){ return NS_OK; } NS_IMETHOD DoFragment(PRBool aFlag); NS_IMETHOD BeginContext(PRInt32 aPosition); diff --git a/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/htmlparser/src/nsHTMLToTXTSinkStream.cpp index 42d4ab664f9..c04596487f9 100644 --- a/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -363,6 +363,8 @@ USE_GENERAL_OPEN_METHOD(OpenMap) USE_GENERAL_CLOSE_METHOD(CloseMap) USE_GENERAL_OPEN_METHOD(OpenFrameset) USE_GENERAL_CLOSE_METHOD(CloseFrameset) +USE_GENERAL_OPEN_METHOD(OpenNoscript) +USE_GENERAL_CLOSE_METHOD(CloseNoscript) NS_IMETHODIMP nsHTMLToTXTSinkStream::DoFragment(PRBool aFlag) diff --git a/htmlparser/src/nsHTMLToTXTSinkStream.h b/htmlparser/src/nsHTMLToTXTSinkStream.h index 413934c40c0..e69de29bb2d 100644 --- a/htmlparser/src/nsHTMLToTXTSinkStream.h +++ b/htmlparser/src/nsHTMLToTXTSinkStream.h @@ -1,288 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -/** - * MODULE NOTES: - * - * If you've been paying attention to our many content sink classes, you may be - * asking yourself, "why do we need yet another one?" The answer is that this - * implementation, unlike all the others, really sends its output a given stream - * rather than to an actual content sink (as defined in our HTML document system). - * - * We use this class for a number of purposes: - * 1) For actual document i/o using XIF (xml interchange format) - * 2) For document conversions - * 3) For debug purposes (to cause output to go to cout or a file) - * - * If no stream is declared in the constructor then all output goes to cout. - * The file is pretty printed according to the pretty printing interface. subclasses - * may choose to override this behavior or set runtime flags for desired results. - */ - -#ifndef NS_HTMLTOTEXTSINK_STREAM -#define NS_HTMLTOTEXTSINK_STREAM - -#include "nsIHTMLContentSink.h" - -#include "nsHTMLTags.h" -#include "nsParserCIID.h" -#include "nsCOMPtr.h" - -class nsIDTD; - -#define NS_IHTMLTOTEXTSINKSTREAM_IID \ - {0xa39c6bff, 0x15f0, 0x11d2, \ - {0x80, 0x41, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4}} - - -class nsIUnicodeEncoder; -class nsILineBreaker; -class nsIOutputStream; - -class nsIHTMLToTXTSinkStream : public nsIHTMLContentSink { - public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLTOTEXTSINKSTREAM_IID) - NS_DEFINE_STATIC_CID_ACCESSOR(NS_HTMLTOTXTSINKSTREAM_CID) - - NS_IMETHOD Initialize(nsIOutputStream* aOutStream, - nsAWritableString* aOutString, - PRUint32 aFlags) = 0; - NS_IMETHOD SetCharsetOverride(const nsAReadableString* aCharset) = 0; - NS_IMETHOD SetWrapColumn(PRUint32 aWrapCol) = 0; -}; - -class nsHTMLToTXTSinkStream : public nsIHTMLToTXTSinkStream -{ - public: - - /** - * Standard constructor - * @update gpk02/03/99 - */ - nsHTMLToTXTSinkStream(); - - /** - * virtual destructor - * @update gpk02/03/99 - */ - virtual ~nsHTMLToTXTSinkStream(); - - NS_IMETHOD Initialize(nsIOutputStream* aOutStream, - nsAWritableString* aOutString, - PRUint32 aFlags); - - NS_IMETHOD SetCharsetOverride(const nsAReadableString* aCharset); - - // nsISupports - NS_DECL_ISUPPORTS - - /******************************************************************* - * The following methods are inherited from nsIContentSink. - * Please see that file for details. - *******************************************************************/ - NS_IMETHOD WillBuildModel(void); - NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel); - NS_IMETHOD WillInterrupt(void); - NS_IMETHOD WillResume(void); - NS_IMETHOD SetParser(nsIParser* aParser); - NS_IMETHOD OpenContainer(const nsIParserNode& aNode); - NS_IMETHOD CloseContainer(const nsIParserNode& aNode); - NS_IMETHOD AddLeaf(const nsIParserNode& aNode); - NS_IMETHOD NotifyError(const nsParserError* aError); - NS_IMETHOD AddComment(const nsIParserNode& aNode); - NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode); - NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0); - NS_IMETHOD FlushPendingNotifications() { return NS_OK; } - - /******************************************************************* - * The following methods are inherited from nsIHTMLContentSink. - * Please see that file for details. - *******************************************************************/ - NS_IMETHOD SetTitle(const nsString& aValue); - NS_IMETHOD OpenHTML(const nsIParserNode& aNode); - NS_IMETHOD CloseHTML(const nsIParserNode& aNode); - NS_IMETHOD OpenHead(const nsIParserNode& aNode); - NS_IMETHOD CloseHead(const nsIParserNode& aNode); - NS_IMETHOD OpenBody(const nsIParserNode& aNode); - NS_IMETHOD CloseBody(const nsIParserNode& aNode); - NS_IMETHOD OpenForm(const nsIParserNode& aNode); - NS_IMETHOD CloseForm(const nsIParserNode& aNode); - NS_IMETHOD OpenMap(const nsIParserNode& aNode); - NS_IMETHOD CloseMap(const nsIParserNode& aNode); - NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); - NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); - NS_IMETHOD DoFragment(PRBool aFlag); - NS_IMETHOD BeginContext(PRInt32 aPosition); - NS_IMETHOD EndContext(PRInt32 aPosition); - - /******************************************************************* - * The following methods are specific to this class. - *******************************************************************/ - NS_IMETHOD SetWrapColumn(PRUint32 aWrapCol) { mWrapColumn = aWrapCol; return NS_OK; }; - -protected: - void EnsureBufferSize(PRInt32 aNewSize); - - nsresult InitEncoder(const nsString& aCharset); - - void AddToLine(const PRUnichar * aStringToAdd, PRInt32 aLength); - void EndLine(PRBool softlinebreak); - void EnsureVerticalSpace(PRInt32 noOfRows); - void FlushLine(); - void WriteQuotesAndIndent(); - void WriteSimple(nsString& aString); - void Write(const nsString& aString); - void EncodeToBuffer(nsString& aString); - NS_IMETHOD GetValueOfAttribute(const nsIParserNode& aNode, - char* aMatchKey, - nsString& aValueRet); - PRBool IsConverted(const nsIParserNode& aNode); - PRBool DoOutput(); - PRBool MayWrap(); - - PRBool IsBlockLevel(eHTMLTags aTag); - -protected: - nsIOutputStream* mStream; - // XXX This is wrong. It violates XPCOM string ownership rules. - // We're only getting away with this because instances of this - // class are restricted to single function scope. - nsAWritableString* mString; - nsString mCurrentLine; - - nsIDTD* mDTD; - - PRInt32 mIndent; - // mInIndentString keeps a header that has to be written in the indent. - // That could be, for instance, the bullet in a bulleted list. - nsString mInIndentString; - PRInt32 mCiteQuoteLevel; - PRInt32 mColPos; - PRInt32 mFlags; - - // The wrap column is how many standard sized chars (western languages) - // should be allowed on a line. There could be less chars if the chars - // are wider than latin chars of more if the chars are more narrow. - PRUint32 mWrapColumn; - - // The width of the line as it will appear on the screen (approx.) - PRUint32 mCurrentLineWidth; - - PRBool mDoFragment; - PRInt32 mEmptyLines; // Will be the number of empty lines before - // the current. 0 if we are starting a new - // line and -1 if we are in a line. - PRBool mInWhitespace; - PRBool mPreFormatted; - PRBool mCacheLine; // If the line should be cached before output. This makes it possible to do smarter wrapping. - PRBool mStartedOutput; // we've produced at least a character - - nsString mURL; - PRBool mStructs; // Output structs (pref) - PRInt32 mHeaderStrategy; /* Header strategy (pref) - 0 = no indention - 1 = indention, increased with - header level (default) - 2 = numbering and slight indention */ - PRInt32 mHeaderCounter[7]; /* For header-numbering: - Number of previous headers of - the same depth and in the same - section. - mHeaderCounter[1] for

etc. */ - - // The tag stack: the stack of tags we're operating on, so we can nest: - nsHTMLTag *mTagStack; - PRUint32 mTagStackIndex; - - // The stack for ordered lists: - PRInt32 *mOLStack; - PRUint32 mOLStackIndex; - - char* mBuffer; - PRInt32 mBufferLength; // The length of the data in the buffer - PRInt32 mBufferSize; // The actual size of the buffer, regardless of the data - - nsIUnicodeEncoder* mUnicodeEncoder; - nsString mCharsetOverride; - nsString mLineBreak; - nsILineBreaker* mLineBreaker; -}; - -inline nsresult -NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult, - nsIOutputStream* aOutStream, - const nsAReadableString* aCharsetOverride=nsnull, - PRUint32 aWrapColumn=0, PRUint32 aFlags=0) -{ - nsCOMPtr it; - nsresult rv; - - rv = nsComponentManager::CreateInstance(nsIHTMLToTXTSinkStream::GetCID(), - nsnull, - NS_GET_IID(nsIHTMLToTXTSinkStream), - getter_AddRefs(it)); - if (NS_SUCCEEDED(rv)) { - rv = it->Initialize(aOutStream, nsnull, aFlags); - - if (NS_SUCCEEDED(rv)) { - it->SetWrapColumn(aWrapColumn); - if (aCharsetOverride != nsnull) { - it->SetCharsetOverride(aCharsetOverride); - } - rv = it->QueryInterface(NS_GET_IID(nsIHTMLContentSink), - (void**)aInstancePtrResult); - } - } - - return rv; -} - -inline nsresult -NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult, - nsAWritableString* aOutString, - PRUint32 aWrapColumn=0, PRUint32 aFlags=0) -{ - nsCOMPtr it; - nsresult rv; - - rv = nsComponentManager::CreateInstance(nsIHTMLToTXTSinkStream::GetCID(), - nsnull, - NS_GET_IID(nsIHTMLToTXTSinkStream), - getter_AddRefs(it)); - if (NS_SUCCEEDED(rv)) { - rv = it->Initialize(nsnull, aOutString, aFlags); - - if (NS_SUCCEEDED(rv)) { - it->SetWrapColumn(aWrapColumn); - nsAutoString ucs2; ucs2.AssignWithConversion("ucs2"); - it->SetCharsetOverride(&ucs2); - rv = it->QueryInterface(NS_GET_IID(nsIHTMLContentSink), - (void**)aInstancePtrResult); - } - } - - return rv; -} - - -#endif - diff --git a/htmlparser/src/nsIHTMLContentSink.h b/htmlparser/src/nsIHTMLContentSink.h index b569d52846b..2ffc6ddcfc2 100644 --- a/htmlparser/src/nsIHTMLContentSink.h +++ b/htmlparser/src/nsIHTMLContentSink.h @@ -182,6 +182,22 @@ public: */ NS_IMETHOD CloseFrameset(const nsIParserNode& aNode)=0; + /** + * This method is used in opening a NOSCRIPT container. + * + * @update harishd 08/25/00 + * @param nsIParserNode reference to parser node interface + */ + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode)=0; + + + /** + * This method is used in closing a NOSCRIPT container. + * + * @update harishd 08/25/00 + * @param nsIParserNode reference to parser node interface + */ + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode)=0; /** * This method tells the sink whether or not it is diff --git a/htmlparser/src/nsIParser.h b/htmlparser/src/nsIParser.h index d6a8ebd79ba..89a1c2d47de 100644 --- a/htmlparser/src/nsIParser.h +++ b/htmlparser/src/nsIParser.h @@ -292,6 +292,8 @@ class nsIParser : public nsISupports { #define NS_ERROR_HTMLPARSER_STOPPARSING NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1015) #define NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1016) +#define NS_HTMLPARSER_ALTERNATECONTENT NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_HTMLPARSER,1) + #define NS_ERROR_HTMLPARSER_CONTINUE NS_OK diff --git a/htmlparser/src/nsLoggingSink.h b/htmlparser/src/nsLoggingSink.h index 7172812103a..84bdb74bd56 100644 --- a/htmlparser/src/nsLoggingSink.h +++ b/htmlparser/src/nsLoggingSink.h @@ -62,6 +62,8 @@ public: NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) { return NS_OK; } + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode) { return NS_OK; } NS_IMETHOD DoFragment(PRBool aFlag); NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); diff --git a/htmlparser/src/nsToken.cpp b/htmlparser/src/nsToken.cpp index 44f3cbeb653..afa33922a92 100644 --- a/htmlparser/src/nsToken.cpp +++ b/htmlparser/src/nsToken.cpp @@ -139,6 +139,7 @@ CToken::~CToken() { mUseCount=0; } + /** * This method gets called when a token is about to be reused * for some other purpose. The token should initialize itself diff --git a/htmlparser/src/nsWellFormedDTD.cpp b/htmlparser/src/nsWellFormedDTD.cpp index 024cb307a61..bd0f9e6cbea 100644 --- a/htmlparser/src/nsWellFormedDTD.cpp +++ b/htmlparser/src/nsWellFormedDTD.cpp @@ -636,7 +636,7 @@ nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) { // Pass the ID Attribute atom from the start token to the parser node CStartToken* startToken = NS_STATIC_CAST(CStartToken *, aToken); - nsCOMPtr IDAttr; + nsCOMPtr IDAttr=nsnull; result = startToken->GetIDAttributeAtom(getter_AddRefs(IDAttr)); if (IDAttr && NS_SUCCEEDED(result)) result = theNode.SetIDAttributeAtom(IDAttr); diff --git a/parser/htmlparser/robot/nsRobotSink.cpp b/parser/htmlparser/robot/nsRobotSink.cpp index 0f36da569bb..0ebf4280ef1 100644 --- a/parser/htmlparser/robot/nsRobotSink.cpp +++ b/parser/htmlparser/robot/nsRobotSink.cpp @@ -70,6 +70,8 @@ public: NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) { return NS_OK; } + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode){ return NS_OK; } NS_IMETHOD OpenContainer(const nsIParserNode& aNode); NS_IMETHOD CloseContainer(const nsIParserNode& aNode); NS_IMETHOD NotifyError(const nsParserError* aError); diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 67b1f3efb67..cc2abd61e0a 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -686,10 +686,11 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ deque until we can deal with it. --------------------------------------------------------------------------------- */ - if(!execSkipContent) { + if(!execSkipContent && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) { switch(theTag) { case eHTMLTag_html: + case eHTMLTag_noscript: case eHTMLTag_script: case eHTMLTag_markupDecl: break; // simply pass these through to token handler without further ado... @@ -1174,7 +1175,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) { + if(mParser && mDTDState!=NS_HTMLPARSER_ALTERNATECONTENT) { CObserverService* theService=mParser->GetObserverService(); if(theService) { @@ -1513,11 +1514,6 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) { mHasOpenNoXXX++; break; - case eHTMLTag_noscript: - //mHasOpenNoXXX++; // Fix for 33397 - Enable this when we handle NOSCRIPTS. - isTokenHandled=PR_TRUE; // XXX - Throwing NOSCRIPT to the floor...yet another time.. - break; - case eHTMLTag_script: theHeadIsParent=((!mHasOpenBody) || mRequestedHead); mHasOpenScript=PR_TRUE; @@ -3084,7 +3080,76 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode *aNode){ return result; } +/** + * This method would determine how the noscript content + * should be handled. + * + * harishd 08/24/00 + * @param aNode - The noscript node + * return NS_OK if succeeded else ERROR + */ +nsresult CNavDTD::OpenNoscript(const nsIParserNode *aNode,nsEntryStack* aStyleStack) { + nsresult result=NS_OK; + if(mSink) { + STOP_TIMER(); + MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::OpenNoscript(), this=%p\n", this)); + + result=mSink->OpenNoscript(*aNode); + + MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::OpenNoscript(), this=%p\n", this)); + START_TIMER(); + + if(NS_SUCCEEDED(result)) { + 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; + } + mHasOpenNoXXX++; + mBodyContext->Push(aNode,aStyleStack); + } + } + + return result; +} + +/** + * Call this method to stop handling noscript content + * + * harishd 08/24/00 + * @param aNode - The noscript node + * return NS_OK if succeeded else ERROR + */ +nsresult CNavDTD::CloseNoscript(const nsIParserNode *aNode) { + nsresult result=NS_OK; + + if(mSink) { + STOP_TIMER(); + MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::CloseNoscript(), this=%p\n", this)); + + result=mSink->CloseNoscript(*aNode); + + MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::CloseNoscript(), this=%p\n", this)); + START_TIMER(); + + if(NS_SUCCEEDED(result)) { + if(mHasOpenNoXXX > 0) { + mHasOpenNoXXX--; + } + mDTDState=NS_OK; // switch from alternate content state to regular state + } + } + + return result; +} /** * This method does two things: 1st, help construct @@ -3177,6 +3242,10 @@ CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedB CloseHead(aNode); //do this just in case someone left it open... result=HandleScriptToken(aNode); break; + + case eHTMLTag_noscript: + result=OpenNoscript(aNode,aStyleStack); + break; default: isDefaultNode=PR_TRUE; @@ -3246,6 +3315,10 @@ CNavDTD::CloseContainer(const nsIParserNode *aNode,eHTMLTags aTarget,PRBool aClo case eHTMLTag_frameset: result=CloseFrameset(aNode); break; + + case eHTMLTag_noscript: + result=CloseNoscript(aNode); + break; case eHTMLTag_title: default: @@ -3583,7 +3656,7 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode *aNode){ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){ nsresult result=NS_OK; - static eHTMLTags gNoXTags[]={eHTMLTag_noembed,eHTMLTag_noframes,eHTMLTag_noscript}; + static eHTMLTags gNoXTags[]={eHTMLTag_noembed,eHTMLTag_noframes}; eHTMLTags theTag=(eHTMLTags)aNode->GetNodeType(); @@ -3597,42 +3670,50 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){ } if(mSink) { - result=OpenHead(aNode); - if(NS_OK==result) { - if(eHTMLTag_title==theTag) { + // Alternate content => Content that shouldn't get processed + // as a regular content. That is, probably the content is + // 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) { - 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); - // XXX If the return value tells us to block, go - // ahead and close the tag out anyway, since its - // contents will be consumed. - - // Fix for Bug 31392 - // Do not leave a head context open no matter what the result is. - if(mHasOpenHead) { - nsresult rv=CloseHead(aNode); - // XXX Only send along a failure. If the close - // succeeded we still may need to indicate that the - // parser has blocked (i.e. return the result of - // the AddLeaf. - if (rv != NS_OK) { - result = rv; } - } - } + 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. + + // Fix for Bug 31392 + // Do not leave a head context open no matter what the result is. + if(mHasOpenHead) { + nsresult rv=CloseHead(aNode); + // XXX Only send along a failure. If the close + // succeeded we still may need to indicate that the + // parser has blocked (i.e. return the result of + // the AddLeaf. + if (rv != NS_OK) { + result = rv; + } + } + } + } + else result=AddLeaf(aNode); } return result; } diff --git a/parser/htmlparser/src/CNavDTD.h b/parser/htmlparser/src/CNavDTD.h index 10cd47e6a91..d525ca2b314 100644 --- a/parser/htmlparser/src/CNavDTD.h +++ b/parser/htmlparser/src/CNavDTD.h @@ -429,6 +429,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult OpenForm(const nsIParserNode *aNode); nsresult OpenMap(const nsIParserNode *aNode); nsresult OpenFrameset(const nsIParserNode *aNode); + nsresult OpenNoscript(const nsIParserNode *aNode,nsEntryStack* aStyleStack=0); nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,nsEntryStack* aStyleStack=0); /** @@ -444,6 +445,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult CloseForm(const nsIParserNode *aNode); nsresult CloseMap(const nsIParserNode *aNode); nsresult CloseFrameset(const nsIParserNode *aNode); + nsresult CloseNoscript(const nsIParserNode *aNode); /** * The special purpose methods automatically close diff --git a/parser/htmlparser/src/nsElementTable.cpp b/parser/htmlparser/src/nsElementTable.cpp index 30b62653b2c..cbf2d17e57a 100644 --- a/parser/htmlparser/src/nsElementTable.cpp +++ b/parser/htmlparser/src/nsElementTable.cpp @@ -81,7 +81,7 @@ TagList gFormKids={1,{eHTMLTag_keygen}}; TagList gFramesetKids={3,{eHTMLTag_frame,eHTMLTag_frameset,eHTMLTag_noframes}}; TagList gHtmlKids={9,{eHTMLTag_body,eHTMLTag_frameset,eHTMLTag_head,eHTMLTag_map,eHTMLTag_noscript,eHTMLTag_noframes,eHTMLTag_script,eHTMLTag_newline,eHTMLTag_whitespace}}; -TagList gHeadKids={9,{eHTMLTag_base,eHTMLTag_bgsound,eHTMLTag_link,eHTMLTag_meta,eHTMLTag_script,eHTMLTag_style,eHTMLTag_title,eHTMLTag_noembed,eHTMLTag_noscript}}; +TagList gHeadKids={8,{eHTMLTag_base,eHTMLTag_bgsound,eHTMLTag_link,eHTMLTag_meta,eHTMLTag_script,eHTMLTag_style,eHTMLTag_title,eHTMLTag_noembed}}; TagList gLabelKids={1,{eHTMLTag_span}}; TagList gLIKids={2,{eHTMLTag_ol,eHTMLTag_ul}}; @@ -435,7 +435,7 @@ void InitializeElementTable(void) { /*rootnodes,endrootnodes*/ &gRootTags, &gRootTags, /*autoclose starttags and endtags*/ &gDTCloseTags,0,0,0, /*parent,incl,exclgroups*/ kDLChild, kFlowEntity, kNone, - /*special props, prop-range*/ kNoPropagate|kMustCloseSelf,kDefaultPropRange, + /*special props, prop-range*/ kNoPropagate|kMustCloseSelf|kVerifyHierarchy,kDefaultPropRange, /*special parents,kids,skip*/ &gInDL,0,eHTMLTag_unknown); Initialize( @@ -869,7 +869,7 @@ void InitializeElementTable(void) { /*autoclose starttags and endtags*/ 0,0,0,0, /*parent,incl,exclgroups*/ kBlock, kFlowEntity|kSelf, kNone, /*special props, prop-range*/ 0, kNoPropRange, - /*special parents,kids,skip*/ 0,0,eHTMLTag_noscript); + /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); Initialize( /*tag*/ eHTMLTag_object, diff --git a/parser/htmlparser/src/nsHTMLContentSinkStream.cpp b/parser/htmlparser/src/nsHTMLContentSinkStream.cpp index 9f0b5ece5eb..6fae533856a 100644 --- a/parser/htmlparser/src/nsHTMLContentSinkStream.cpp +++ b/parser/htmlparser/src/nsHTMLContentSinkStream.cpp @@ -578,6 +578,8 @@ USE_GENERAL_OPEN_METHOD(OpenMap, eHTMLTag_map) USE_GENERAL_CLOSE_METHOD(CloseMap, eHTMLTag_map) USE_GENERAL_OPEN_METHOD(OpenFrameset, eHTMLTag_frameset) USE_GENERAL_CLOSE_METHOD(CloseFrameset, eHTMLTag_frameset) +USE_GENERAL_OPEN_METHOD(OpenNoscript, eHTMLTag_noscript) +USE_GENERAL_CLOSE_METHOD(CloseNoscript, eHTMLTag_noscript) /** * diff --git a/parser/htmlparser/src/nsHTMLContentSinkStream.h b/parser/htmlparser/src/nsHTMLContentSinkStream.h index 9cca0caa7a3..f39cecc8f5a 100644 --- a/parser/htmlparser/src/nsHTMLContentSinkStream.h +++ b/parser/htmlparser/src/nsHTMLContentSinkStream.h @@ -138,6 +138,8 @@ class nsHTMLContentSinkStream : public nsIHTMLContentSinkStream NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) ; + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode); NS_IMETHOD DoFragment(PRBool aFlag); NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); diff --git a/parser/htmlparser/src/nsHTMLNullSink.cpp b/parser/htmlparser/src/nsHTMLNullSink.cpp index 6b4ad449e55..17c0c3d9984 100644 --- a/parser/htmlparser/src/nsHTMLNullSink.cpp +++ b/parser/htmlparser/src/nsHTMLNullSink.cpp @@ -69,6 +69,8 @@ public: NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) { return NS_OK; } + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode){ return NS_OK; } NS_IMETHOD DoFragment(PRBool aFlag); NS_IMETHOD BeginContext(PRInt32 aPosition); diff --git a/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp b/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp index 42d4ab664f9..c04596487f9 100644 --- a/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp +++ b/parser/htmlparser/src/nsHTMLToTXTSinkStream.cpp @@ -363,6 +363,8 @@ USE_GENERAL_OPEN_METHOD(OpenMap) USE_GENERAL_CLOSE_METHOD(CloseMap) USE_GENERAL_OPEN_METHOD(OpenFrameset) USE_GENERAL_CLOSE_METHOD(CloseFrameset) +USE_GENERAL_OPEN_METHOD(OpenNoscript) +USE_GENERAL_CLOSE_METHOD(CloseNoscript) NS_IMETHODIMP nsHTMLToTXTSinkStream::DoFragment(PRBool aFlag) diff --git a/parser/htmlparser/src/nsHTMLToTXTSinkStream.h b/parser/htmlparser/src/nsHTMLToTXTSinkStream.h index 413934c40c0..e69de29bb2d 100644 --- a/parser/htmlparser/src/nsHTMLToTXTSinkStream.h +++ b/parser/htmlparser/src/nsHTMLToTXTSinkStream.h @@ -1,288 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -/** - * MODULE NOTES: - * - * If you've been paying attention to our many content sink classes, you may be - * asking yourself, "why do we need yet another one?" The answer is that this - * implementation, unlike all the others, really sends its output a given stream - * rather than to an actual content sink (as defined in our HTML document system). - * - * We use this class for a number of purposes: - * 1) For actual document i/o using XIF (xml interchange format) - * 2) For document conversions - * 3) For debug purposes (to cause output to go to cout or a file) - * - * If no stream is declared in the constructor then all output goes to cout. - * The file is pretty printed according to the pretty printing interface. subclasses - * may choose to override this behavior or set runtime flags for desired results. - */ - -#ifndef NS_HTMLTOTEXTSINK_STREAM -#define NS_HTMLTOTEXTSINK_STREAM - -#include "nsIHTMLContentSink.h" - -#include "nsHTMLTags.h" -#include "nsParserCIID.h" -#include "nsCOMPtr.h" - -class nsIDTD; - -#define NS_IHTMLTOTEXTSINKSTREAM_IID \ - {0xa39c6bff, 0x15f0, 0x11d2, \ - {0x80, 0x41, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4}} - - -class nsIUnicodeEncoder; -class nsILineBreaker; -class nsIOutputStream; - -class nsIHTMLToTXTSinkStream : public nsIHTMLContentSink { - public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLTOTEXTSINKSTREAM_IID) - NS_DEFINE_STATIC_CID_ACCESSOR(NS_HTMLTOTXTSINKSTREAM_CID) - - NS_IMETHOD Initialize(nsIOutputStream* aOutStream, - nsAWritableString* aOutString, - PRUint32 aFlags) = 0; - NS_IMETHOD SetCharsetOverride(const nsAReadableString* aCharset) = 0; - NS_IMETHOD SetWrapColumn(PRUint32 aWrapCol) = 0; -}; - -class nsHTMLToTXTSinkStream : public nsIHTMLToTXTSinkStream -{ - public: - - /** - * Standard constructor - * @update gpk02/03/99 - */ - nsHTMLToTXTSinkStream(); - - /** - * virtual destructor - * @update gpk02/03/99 - */ - virtual ~nsHTMLToTXTSinkStream(); - - NS_IMETHOD Initialize(nsIOutputStream* aOutStream, - nsAWritableString* aOutString, - PRUint32 aFlags); - - NS_IMETHOD SetCharsetOverride(const nsAReadableString* aCharset); - - // nsISupports - NS_DECL_ISUPPORTS - - /******************************************************************* - * The following methods are inherited from nsIContentSink. - * Please see that file for details. - *******************************************************************/ - NS_IMETHOD WillBuildModel(void); - NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel); - NS_IMETHOD WillInterrupt(void); - NS_IMETHOD WillResume(void); - NS_IMETHOD SetParser(nsIParser* aParser); - NS_IMETHOD OpenContainer(const nsIParserNode& aNode); - NS_IMETHOD CloseContainer(const nsIParserNode& aNode); - NS_IMETHOD AddLeaf(const nsIParserNode& aNode); - NS_IMETHOD NotifyError(const nsParserError* aError); - NS_IMETHOD AddComment(const nsIParserNode& aNode); - NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode); - NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0); - NS_IMETHOD FlushPendingNotifications() { return NS_OK; } - - /******************************************************************* - * The following methods are inherited from nsIHTMLContentSink. - * Please see that file for details. - *******************************************************************/ - NS_IMETHOD SetTitle(const nsString& aValue); - NS_IMETHOD OpenHTML(const nsIParserNode& aNode); - NS_IMETHOD CloseHTML(const nsIParserNode& aNode); - NS_IMETHOD OpenHead(const nsIParserNode& aNode); - NS_IMETHOD CloseHead(const nsIParserNode& aNode); - NS_IMETHOD OpenBody(const nsIParserNode& aNode); - NS_IMETHOD CloseBody(const nsIParserNode& aNode); - NS_IMETHOD OpenForm(const nsIParserNode& aNode); - NS_IMETHOD CloseForm(const nsIParserNode& aNode); - NS_IMETHOD OpenMap(const nsIParserNode& aNode); - NS_IMETHOD CloseMap(const nsIParserNode& aNode); - NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); - NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); - NS_IMETHOD DoFragment(PRBool aFlag); - NS_IMETHOD BeginContext(PRInt32 aPosition); - NS_IMETHOD EndContext(PRInt32 aPosition); - - /******************************************************************* - * The following methods are specific to this class. - *******************************************************************/ - NS_IMETHOD SetWrapColumn(PRUint32 aWrapCol) { mWrapColumn = aWrapCol; return NS_OK; }; - -protected: - void EnsureBufferSize(PRInt32 aNewSize); - - nsresult InitEncoder(const nsString& aCharset); - - void AddToLine(const PRUnichar * aStringToAdd, PRInt32 aLength); - void EndLine(PRBool softlinebreak); - void EnsureVerticalSpace(PRInt32 noOfRows); - void FlushLine(); - void WriteQuotesAndIndent(); - void WriteSimple(nsString& aString); - void Write(const nsString& aString); - void EncodeToBuffer(nsString& aString); - NS_IMETHOD GetValueOfAttribute(const nsIParserNode& aNode, - char* aMatchKey, - nsString& aValueRet); - PRBool IsConverted(const nsIParserNode& aNode); - PRBool DoOutput(); - PRBool MayWrap(); - - PRBool IsBlockLevel(eHTMLTags aTag); - -protected: - nsIOutputStream* mStream; - // XXX This is wrong. It violates XPCOM string ownership rules. - // We're only getting away with this because instances of this - // class are restricted to single function scope. - nsAWritableString* mString; - nsString mCurrentLine; - - nsIDTD* mDTD; - - PRInt32 mIndent; - // mInIndentString keeps a header that has to be written in the indent. - // That could be, for instance, the bullet in a bulleted list. - nsString mInIndentString; - PRInt32 mCiteQuoteLevel; - PRInt32 mColPos; - PRInt32 mFlags; - - // The wrap column is how many standard sized chars (western languages) - // should be allowed on a line. There could be less chars if the chars - // are wider than latin chars of more if the chars are more narrow. - PRUint32 mWrapColumn; - - // The width of the line as it will appear on the screen (approx.) - PRUint32 mCurrentLineWidth; - - PRBool mDoFragment; - PRInt32 mEmptyLines; // Will be the number of empty lines before - // the current. 0 if we are starting a new - // line and -1 if we are in a line. - PRBool mInWhitespace; - PRBool mPreFormatted; - PRBool mCacheLine; // If the line should be cached before output. This makes it possible to do smarter wrapping. - PRBool mStartedOutput; // we've produced at least a character - - nsString mURL; - PRBool mStructs; // Output structs (pref) - PRInt32 mHeaderStrategy; /* Header strategy (pref) - 0 = no indention - 1 = indention, increased with - header level (default) - 2 = numbering and slight indention */ - PRInt32 mHeaderCounter[7]; /* For header-numbering: - Number of previous headers of - the same depth and in the same - section. - mHeaderCounter[1] for

etc. */ - - // The tag stack: the stack of tags we're operating on, so we can nest: - nsHTMLTag *mTagStack; - PRUint32 mTagStackIndex; - - // The stack for ordered lists: - PRInt32 *mOLStack; - PRUint32 mOLStackIndex; - - char* mBuffer; - PRInt32 mBufferLength; // The length of the data in the buffer - PRInt32 mBufferSize; // The actual size of the buffer, regardless of the data - - nsIUnicodeEncoder* mUnicodeEncoder; - nsString mCharsetOverride; - nsString mLineBreak; - nsILineBreaker* mLineBreaker; -}; - -inline nsresult -NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult, - nsIOutputStream* aOutStream, - const nsAReadableString* aCharsetOverride=nsnull, - PRUint32 aWrapColumn=0, PRUint32 aFlags=0) -{ - nsCOMPtr it; - nsresult rv; - - rv = nsComponentManager::CreateInstance(nsIHTMLToTXTSinkStream::GetCID(), - nsnull, - NS_GET_IID(nsIHTMLToTXTSinkStream), - getter_AddRefs(it)); - if (NS_SUCCEEDED(rv)) { - rv = it->Initialize(aOutStream, nsnull, aFlags); - - if (NS_SUCCEEDED(rv)) { - it->SetWrapColumn(aWrapColumn); - if (aCharsetOverride != nsnull) { - it->SetCharsetOverride(aCharsetOverride); - } - rv = it->QueryInterface(NS_GET_IID(nsIHTMLContentSink), - (void**)aInstancePtrResult); - } - } - - return rv; -} - -inline nsresult -NS_New_HTMLToTXT_SinkStream(nsIHTMLContentSink** aInstancePtrResult, - nsAWritableString* aOutString, - PRUint32 aWrapColumn=0, PRUint32 aFlags=0) -{ - nsCOMPtr it; - nsresult rv; - - rv = nsComponentManager::CreateInstance(nsIHTMLToTXTSinkStream::GetCID(), - nsnull, - NS_GET_IID(nsIHTMLToTXTSinkStream), - getter_AddRefs(it)); - if (NS_SUCCEEDED(rv)) { - rv = it->Initialize(nsnull, aOutString, aFlags); - - if (NS_SUCCEEDED(rv)) { - it->SetWrapColumn(aWrapColumn); - nsAutoString ucs2; ucs2.AssignWithConversion("ucs2"); - it->SetCharsetOverride(&ucs2); - rv = it->QueryInterface(NS_GET_IID(nsIHTMLContentSink), - (void**)aInstancePtrResult); - } - } - - return rv; -} - - -#endif - diff --git a/parser/htmlparser/src/nsIHTMLContentSink.h b/parser/htmlparser/src/nsIHTMLContentSink.h index b569d52846b..2ffc6ddcfc2 100644 --- a/parser/htmlparser/src/nsIHTMLContentSink.h +++ b/parser/htmlparser/src/nsIHTMLContentSink.h @@ -182,6 +182,22 @@ public: */ NS_IMETHOD CloseFrameset(const nsIParserNode& aNode)=0; + /** + * This method is used in opening a NOSCRIPT container. + * + * @update harishd 08/25/00 + * @param nsIParserNode reference to parser node interface + */ + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode)=0; + + + /** + * This method is used in closing a NOSCRIPT container. + * + * @update harishd 08/25/00 + * @param nsIParserNode reference to parser node interface + */ + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode)=0; /** * This method tells the sink whether or not it is diff --git a/parser/htmlparser/src/nsIParser.h b/parser/htmlparser/src/nsIParser.h index d6a8ebd79ba..89a1c2d47de 100644 --- a/parser/htmlparser/src/nsIParser.h +++ b/parser/htmlparser/src/nsIParser.h @@ -292,6 +292,8 @@ class nsIParser : public nsISupports { #define NS_ERROR_HTMLPARSER_STOPPARSING NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1015) #define NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_HTMLPARSER,1016) +#define NS_HTMLPARSER_ALTERNATECONTENT NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_HTMLPARSER,1) + #define NS_ERROR_HTMLPARSER_CONTINUE NS_OK diff --git a/parser/htmlparser/src/nsLoggingSink.h b/parser/htmlparser/src/nsLoggingSink.h index 7172812103a..84bdb74bd56 100644 --- a/parser/htmlparser/src/nsLoggingSink.h +++ b/parser/htmlparser/src/nsLoggingSink.h @@ -62,6 +62,8 @@ public: NS_IMETHOD CloseMap(const nsIParserNode& aNode); NS_IMETHOD OpenFrameset(const nsIParserNode& aNode); NS_IMETHOD CloseFrameset(const nsIParserNode& aNode); + NS_IMETHOD OpenNoscript(const nsIParserNode& aNode) { return NS_OK; } + NS_IMETHOD CloseNoscript(const nsIParserNode& aNode) { return NS_OK; } NS_IMETHOD DoFragment(PRBool aFlag); NS_IMETHOD BeginContext(PRInt32 aPosition); NS_IMETHOD EndContext(PRInt32 aPosition); diff --git a/parser/htmlparser/src/nsToken.cpp b/parser/htmlparser/src/nsToken.cpp index 44f3cbeb653..afa33922a92 100644 --- a/parser/htmlparser/src/nsToken.cpp +++ b/parser/htmlparser/src/nsToken.cpp @@ -139,6 +139,7 @@ CToken::~CToken() { mUseCount=0; } + /** * This method gets called when a token is about to be reused * for some other purpose. The token should initialize itself diff --git a/parser/htmlparser/src/nsWellFormedDTD.cpp b/parser/htmlparser/src/nsWellFormedDTD.cpp index 024cb307a61..bd0f9e6cbea 100644 --- a/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -636,7 +636,7 @@ nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) { // Pass the ID Attribute atom from the start token to the parser node CStartToken* startToken = NS_STATIC_CAST(CStartToken *, aToken); - nsCOMPtr IDAttr; + nsCOMPtr IDAttr=nsnull; result = startToken->GetIDAttributeAtom(getter_AddRefs(IDAttr)); if (IDAttr && NS_SUCCEEDED(result)) result = theNode.SetIDAttributeAtom(IDAttr);