Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends
nsParser Class Reference

#include <nsParser.h>

Inheritance diagram for nsParser:
Inheritance graph
[legend]
Collaboration diagram for nsParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsParser ()
 default constructor gess5/11/98
virtual ~nsParser ()
 Destructor gess5/11/98.
 NS_IMETHOD_ (void) SetContentSink(nsIContentSink *aSink)
 Select given content sink into parser for parser output gess5/11/98.
 NS_IMETHOD_ (nsIContentSink *) GetContentSink(void)
 retrive the sink set into the parser gess5/11/98
 NS_IMETHOD_ (void) GetCommand(nsCString &aCommand)
 Call this method once you've created a parser, and want to instruct it about the command which caused the parser to be constructed.
 NS_IMETHOD_ (void) SetCommand(const char *aCommand)
 NS_IMETHOD_ (void) SetCommand(eParserCommands aParserCommand)
 Select given content sink into parser for parser output gess5/11/98.
 NS_IMETHOD_ (void) SetDocumentCharset(const nsACString &aCharset
 Call this method once you've created a parser, and want to instruct it about what charset to load.
 NS_IMETHOD_ (void) GetDocumentCharset(nsACString &aCharset
 Select given content sink into parser for parser output gess5/11/98.
NS_IMETHOD RegisterDTD (nsIDTD *aDTD)
 Call this method when you want to register your dynamic DTD's with the parser.
 NS_IMETHOD_ (nsDTDMode) GetParseMode(void)
 Retrieve the scanner from the topmost parser context.
NS_IMETHOD Parse (nsIURI *aURL, nsIRequestObserver *aListener=nsnull, PRBool aEnableVerify=PR_FALSE, void *aKey=0, nsDTDMode aMode=eDTDMode_autodetect)
 Cause parser to parse input from given URL gess5/11/98.
NS_IMETHOD Parse (nsIInputStream *aStream, const nsACString &aMimeType, PRBool aEnableVerify=PR_FALSE, void *aKey=0, nsDTDMode aMode=eDTDMode_autodetect)
 Cause parser to parse input from given stream gess5/11/98.
NS_IMETHOD Parse (const nsAString &aSourceBuffer, void *aKey, const nsACString &aContentType, PRBool aEnableVerify, PRBool aLastCall, nsDTDMode aMode=eDTDMode_autodetect)
 gess5/11/98
NS_IMETHOD ParseFragment (const nsAString &aSourceBuffer, void *aKey, nsVoidArray &aTagStack, PRBool aXMLMode, const nsACString &aContentType, nsDTDMode aMode=eDTDMode_autodetect)
 This method needs documentation.
NS_IMETHOD BuildModel (void)
 This method gets called when the tokens have been consumed, and it's time to build the model via the content sink.
NS_IMETHOD ContinueParsing ()
 Call this when you want control whether or not the parser will parse and tokenize input (TRUE), or whether it just caches input to be parsed later (FALSE).
NS_IMETHOD ContinueInterruptedParsing ()
 NS_IMETHOD_ (void) BlockParser()
 Select given content sink into parser for parser output gess5/11/98.
 NS_IMETHOD_ (void) UnblockParser()
 Select given content sink into parser for parser output gess5/11/98.
NS_IMETHOD Terminate (void)
 Call this when you want to force the parser to terminate the parsing process altogether.
 NS_IMETHOD_ (PRBool) IsParserEnabled()
 Call this to query whether the parser is enabled or not.
 NS_IMETHOD_ (PRBool) IsComplete()
 Call this to query whether the parser thinks it's done with parsing.
void SetUnusedInput (nsString &aBuffer)
 This rather arcane method (hack) is used as a signal between the DTD and the parser.
virtual nsresult ResumeParse (PRBool allowIteration=PR_TRUE, PRBool aIsFinalChunk=PR_FALSE, PRBool aCanInterrupt=PR_TRUE)
 This method gets called (automatically) during incremental parsing gess5/11/98.
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER void 
PushContext (CParserContext &aContext)
 This method adds a new parser context to the list, pushing the current one to the next position.
CParserContextPopContext ()
 This method pops the topmost context off the stack, returning it to the user.
CParserContextPeekContext ()
nsresult GetTokenizer (nsITokenizer *&aTokenizer)
 gess 1/22/99
NS_IMETHOD GetChannel (nsIChannel **aChannel)
 Get the channel associated with this parser harishd,gagan 07/17/01.
NS_IMETHOD GetDTD (nsIDTD **aDTD)
 Get the DTD associated with this parser vidur 9/29/99.
PRBool DetectMetaTag (const char *aBytes, PRInt32 aLen, nsCString &oCharset, PRInt32 &oCharsetSource)
 Detects the existence of a META tag with charset information in the given buffer.
void SetSinkCharset (nsACString &aCharset)
NS_IMETHODIMP CancelParsingEvents ()
 Removes continue parsing events kmcclusk 5/18/98.
PRBool CanInterrupt (void)
 Indicates whether the parser is in a state where it can be interrupted.
void SetCanInterrupt (PRBool aCanInterrupt)
 Set to parser state to indicate whether parsing tokens can be interrupted.
nsresult PostContinueEvent ()
 This is called when the final chunk has been passed to the parser and the content sink has interrupted token processing.
void HandleParserContinueEvent (void)
 Fired when the continue parse event is triggered.
nsresult DataAdded (const nsSubstring &aData, nsIRequest *aRequest)
 Called by top-level scanners when data from necko is added to the scanner.
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Static Public Member Functions

static nsresult Init ()
 Called on module init.
static void Shutdown ()
 Called on module shutdown.

Public Attributes

PRInt32 aSource
PRInt32oSource = 0

Static Public Attributes

static nsCOMArray
< nsIUnicharStreamListener > * 
sParserDataListeners

Protected Member Functions

nsresult WillBuildModel (nsString &aFilename)
 gess5/18/98
nsresult DidBuildModel (nsresult anErrorCode)
 gess5/18/98

Protected Attributes

nsCOMPtr< nsIEventQueuemEventQueue
CParserContextmParserContext
nsCOMPtr< nsIRequestObservermObserver
nsCOMPtr< nsIContentSinkmSink
nsCOMPtr< nsIParserFiltermParserFilter
nsTokenAllocator mTokenAllocator
eParserCommands mCommand
nsresult mInternalState
PRInt32 mStreamStatus
PRInt32 mCharsetSource
PRUint16 mFlags
nsString mUnusedInput
nsCString mCharset
nsCString mCommandStr

Private Member Functions

PRBool WillTokenize (PRBool aIsFinalChunk=PR_FALSE)
 Part of the code sandwich, this gets called right before the tokenization process begins.
nsresult Tokenize (PRBool aIsFinalChunk=PR_FALSE)
 This is the primary control routine.
PRBool DidTokenize (PRBool aIsFinalChunk=PR_FALSE)
 This is the tail-end of the code sandwich for the tokenization process.

Friends

class CTokenHandler

Detailed Description

Definition at line 102 of file nsParser.h.


Constructor & Destructor Documentation

default constructor gess5/11/98

default constructor

gess 01/04/99

Parameters:
@return

Definition at line 356 of file nsParser.cpp.

                   {
#ifdef NS_DEBUG
  if(!gDumpContent) {
    gDumpContent=(PR_GetEnv("PARSER_DUMP_CONTENT"))? PR_TRUE:PR_FALSE;
  }
#endif

  mCharset.AssignLiteral("ISO-8859-1");
  mParserContext=0;
  mStreamStatus=0;
  mCharsetSource=kCharsetUninitialized;
  mInternalState=NS_OK;;
  mCommand=eViewNormal;
  mFlags = NS_PARSER_FLAG_OBSERVERS_ENABLED | NS_PARSER_FLAG_PARSER_ENABLED | NS_PARSER_FLAG_CAN_TOKENIZE;
 
  MOZ_TIMER_DEBUGLOG(("Reset: Parse Time: nsParser::nsParser(), this=%p\n", this));
  MOZ_TIMER_RESET(mParseTime);  
  MOZ_TIMER_RESET(mDTDTime);  
  MOZ_TIMER_RESET(mTokenizeTime);

  nsresult rv = NS_OK;
  if (mEventQueue == nsnull) {
    // Cache the event queue of the current UI thread
    nsCOMPtr<nsIEventQueueService> eventService = 
             do_GetService(kEventQueueServiceCID, &rv);
    if (NS_SUCCEEDED(rv) && (eventService)) {                  // XXX this implies that the UI is the current thread.
      rv = eventService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(mEventQueue));
    }

   // NS_ASSERTION(mEventQueue, "event queue is null");
  }
}

Here is the call graph for this function:

nsParser::~nsParser ( ) [virtual]

Destructor gess5/11/98.

Default destructor.

gess 01/04/99

Parameters:
@return

Definition at line 396 of file nsParser.cpp.

                    {

#ifdef NS_DEBUG
  if(gDumpContent) {
    if(mSink) {
      // Sink ( HTMLContentSink at this time) supports nsIDebugDumpContent
      // interface. We can get to the content model through the sink.
      nsresult result=NS_OK;
      nsCOMPtr<nsIDebugDumpContent> trigger=do_QueryInterface(mSink,&result);
      if(NS_SUCCEEDED(result)) {
        trigger->DumpContentModel();
      }
    }
  }
#endif

#ifdef DEBUG
  if (mParserContext && mParserContext->mPrevContext) {
    NS_WARNING("Extra parser contexts still on the parser stack");
  }
#endif

  while (mParserContext) {
    CParserContext *pc = mParserContext->mPrevContext;
    delete mParserContext;
    mParserContext = pc;
  }

  if (mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT) {
    NS_ASSERTION(mEventQueue != nsnull,"Event queue is null"); 
    mEventQueue->RevokeEvents(this);
  }
}

Here is the call graph for this function:


Member Function Documentation

This method gets called when the tokens have been consumed, and it's time to build the model via the content sink.

This is where we loop over the tokens created in the tokenization phase, and try to make sense out of them.

gess5/11/98

Returns:
YES if model building went well -- NO otherwise.

gess 01/04/99

Parameters:
@returnerror code -- 0 if ok, non-zero if error.

Implements nsIParser.

Definition at line 2143 of file nsParser.cpp.

                              {
  CParserContext* theRootContext = mParserContext;
  nsITokenizer*   theTokenizer = 0;

  nsresult result = NS_OK;
  if (mParserContext) {
    PRInt32 type = mParserContext->mDTD ? mParserContext->mDTD->GetType() : NS_IPARSER_FLAG_HTML;
    mParserContext->GetTokenizer(type, mSink, theTokenizer);
  }

  if (theTokenizer) {

    //Get the root DTD for use in model building...
    while (theRootContext->mPrevContext) {
      theRootContext = theRootContext->mPrevContext;
    }

    nsIDTD* theRootDTD = theRootContext->mDTD;
    if (theRootDTD) {      
      MOZ_TIMER_START(mDTDTime);
      
      result = theRootDTD->BuildModel(this, theTokenizer, nsnull, mSink);  
      
      MOZ_TIMER_STOP(mDTDTime);
    }
  }
  else{
    mInternalState = result = NS_ERROR_HTMLPARSER_BADTOKENIZER;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Removes continue parsing events kmcclusk 5/18/98.

Implements nsIParser.

Definition at line 1254 of file nsParser.cpp.

{
  if (mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT) {
    NS_ASSERTION(mEventQueue,"Event queue is null");
    // Revoke all pending continue parsing events 
    if (mEventQueue != nsnull) {
      mEventQueue->RevokeEvents(this);
    } 

    mFlags &= ~NS_PARSER_FLAG_PENDING_CONTINUE_EVENT;
  }
  return NS_OK;
}

Here is the caller graph for this function:

Indicates whether the parser is in a state where it can be interrupted.

Returns:
PR_TRUE if parser can be interrupted, PR_FALSE if it can not be interrupted. kmcclusk 5/18/98

Definition at line 1579 of file nsParser.cpp.

Implements nsIParser.

Definition at line 1461 of file nsParser.cpp.

{
  // If the stream has already finished, there's a good chance
  // that we might start closing things down when the parser
  // is reenabled. To make sure that we're not deleted across
  // the reenabling process, hold a reference to ourselves.
  nsresult result=NS_OK;
  nsCOMPtr<nsIParser> kungFuDeathGrip(this);

#ifdef DEBUG
  if (!(mFlags & NS_PARSER_FLAG_PARSER_ENABLED)) {
    NS_WARNING("Don't call ContinueInterruptedParsing on a blocked parser.");
  }
#endif

  PRBool isFinalChunk = (mParserContext &&
                          mParserContext->mStreamListenerState==eOnStop) ?
                          PR_TRUE : PR_FALSE;
  
  result=ResumeParse(PR_TRUE,isFinalChunk); // Ref. bug 57999
  
  if(result!=NS_OK) 
    result=mInternalState;
  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Call this when you want control whether or not the parser will parse and tokenize input (TRUE), or whether it just caches input to be parsed later (FALSE).

gess 1/29/99

gess 9/1/98

Parameters:
aStatedetermines whether we parse/tokenize or just cache.
Returns:
current state
Parameters:
aStatedetermines whether we parse/tokenize or just cache.
Returns:
current state

Implements nsIParser.

Definition at line 1449 of file nsParser.cpp.

{    
  if (mFlags & NS_PARSER_FLAG_PARSER_ENABLED) {
    NS_WARNING("Trying to continue parsing on a unblocked parser.");
    return NS_OK;
  }

  mFlags |= NS_PARSER_FLAG_PARSER_ENABLED;

  return ContinueInterruptedParsing();
}

Here is the call graph for this function:

nsresult nsParser::DataAdded ( const nsSubstring aData,
nsIRequest aRequest 
)

Called by top-level scanners when data from necko is added to the scanner.

Definition at line 1551 of file nsParser.cpp.

{
  NS_ASSERTION(sParserDataListeners,
               "Don't call this with no parser data listeners!");

  if (!mSink || !aRequest) {
    return NS_OK;
  }

  nsISupports *ctx = mSink->GetTarget();
  PRInt32 count = sParserDataListeners->Count();
  nsresult rv = NS_OK;
  PRBool canceled = PR_FALSE;

  while (count--) {
    rv |= sParserDataListeners->ObjectAt(count)->
      OnUnicharDataAvailable(aRequest, ctx, aData);

    if (NS_FAILED(rv) && !canceled) {
      aRequest->Cancel(rv);

      canceled = PR_TRUE;
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsParser::DetectMetaTag ( const char *  aBytes,
PRInt32  aLen,
nsCString oCharset,
PRInt32 oCharsetSource 
)

Detects the existence of a META tag with charset information in the given buffer.

Definition at line 2454 of file nsParser.cpp.

{
  aCharsetSource= kCharsetFromMetaTag;
  aCharset.SetLength(0);

  // XXX Only look inside HTML documents for now. For XML
  // documents we should be looking inside the XMLDecl.
  if (!mParserContext->mMimeType.EqualsLiteral(kHTMLTextContentType)) {
    return PR_FALSE;
  }

  // Fast and loose parsing to determine if we have a complete
  // META tag in this block, looking upto 2k into it.
  const nsASingleFragmentCString& str =
      Substring(aBytes, aBytes + PR_MIN(aLen, 2048));
  // XXXldb Should be const_char_iterator when FindInReadable supports it.
  nsACString::const_iterator begin, end;
  
  str.BeginReading(begin);
  str.EndReading(end);
  nsACString::const_iterator currPos(begin);
  nsACString::const_iterator tokEnd;
  nsACString::const_iterator tagEnd(begin);
  
  while (currPos != end) {
    if (!FindCharInReadable('<', currPos, end)) 
      break; // no tag found in this buffer

    if (GetNextChar(currPos, end) == '!' && 
        GetNextChar(currPos, end) == '-' &&
        GetNextChar(currPos, end) == '-') {
      // Found MDO ( <!-- ). Now search for MDC ( --[*s]> )
      PRBool foundMDC = PR_FALSE;
      PRBool foundMatch = PR_FALSE; 
      while (!foundMDC) {
        if (GetNextChar(currPos, end) == '-' && 
            GetNextChar(currPos, end) == '-') {
          foundMatch = !foundMatch; // toggle until we've matching "--"
        }
        else if (currPos == end) {
          return PR_FALSE; // Couldn't find --[*s]> in this buffer
        }
        else if (foundMatch && *currPos == '>') {
          foundMDC = PR_TRUE; // found comment end delimiter.
          ++currPos;
        }
      }
      continue; // continue searching for META tag.
    }

    // Find the end of the tag, break if incomplete
    tagEnd = currPos;
    if (!FindCharInReadable('>', tagEnd, end))
      break;

    // If this is not a META tag, continue to next loop
    if ( (*currPos != 'm' && *currPos != 'M') ||
         (*(++currPos) != 'e' && *currPos != 'E') ||
         (*(++currPos) != 't' && *currPos != 'T') ||
         (*(++currPos) != 'a' && *currPos != 'A') ) {
      currPos = tagEnd;
      continue;
    }

    // If could not find "charset" in this tag, skip this tag and try next
    tokEnd = tagEnd;
    if (!CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("CHARSET"), currPos, tokEnd)) {
      currPos = tagEnd;
      continue;
    }
    currPos = tokEnd;

    // skip spaces before '='
    while (*currPos == kSpace || *currPos == kNewLine ||
           *currPos == kCR || *currPos == kTab)  
      ++currPos;
    // skip '='
    if (*currPos != '=') {
      currPos = tagEnd;
      continue;
    }
    ++currPos;
    // skip spaces after '='
    while (*currPos == kSpace || *currPos == kNewLine ||
           *currPos == kCR || *currPos == kTab)  
      ++currPos;
          
    // skip open quote
    if ((*currPos == '\'' || *currPos == '\"'))
      ++currPos;

    // find the end of charset string
    tokEnd = currPos;
    while (*tokEnd != '\'' && *tokEnd != '\"' && tokEnd != tagEnd) 
      ++tokEnd;

    // return true if we successfully got something for charset
    if (currPos != tokEnd) {
      aCharset.Assign(currPos.get(), tokEnd.get() - currPos.get());
      return PR_TRUE;
    } 
    
    //nothing specified as charset, continue next loop
    currPos = tagEnd;
  } 
  
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsParser::DidBuildModel ( nsresult  anErrorCode) [protected]

gess5/18/98

This gets called when the parser is done with its input.

Parameters:
@returnNote that the parser may have been called recursively, so we have to check for a prev. context before closing out the DTD/sink. gess5/18/98
@returnerror code -- 0 if ok, non-zero if error.

Definition at line 1319 of file nsParser.cpp.

                                                     {
  //One last thing...close any open containers.
  nsresult result=anErrorCode;

  if (IsComplete()) {
    if (mParserContext && !mParserContext->mPrevContext) {
      if (mParserContext->mDTD) {
        result = mParserContext->mDTD->DidBuildModel(anErrorCode,PR_TRUE,this,mSink);
      }
      //Ref. to bug 61462.
      mParserContext->mRequest = 0;
    }//if
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsParser::DidTokenize ( PRBool  aIsFinalChunk = PR_FALSE) [private]

This is the tail-end of the code sandwich for the tokenization process.

It gets called once tokenziation has completed.

gess 3/25/98

Parameters:
@returnTRUE if all went well

It gets called once tokenziation has completed for each phase.

gess 01/04/99

Parameters:
@returnTRUE if all went well

Definition at line 2903 of file nsParser.cpp.

                                                {
  PRBool result=PR_TRUE;

  nsITokenizer* theTokenizer=0;
  nsresult rv = NS_OK;
  if (mParserContext) {
    PRInt32 type = mParserContext->mDTD ? mParserContext->mDTD->GetType() : NS_IPARSER_FLAG_HTML;
    mParserContext->GetTokenizer(type, mSink, theTokenizer);
  }

  if (NS_SUCCEEDED(rv) && theTokenizer) {
    result = theTokenizer->DidTokenize(aIsFinalChunk);
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsParser::GetChannel ( nsIChannel **  aChannel) [virtual]

Get the channel associated with this parser harishd,gagan 07/17/01.

Parameters:
aChannelout param that will contain the result
Returns:
NS_OK if successful

Implements nsIParser.

Definition at line 2926 of file nsParser.cpp.

Here is the call graph for this function:

NS_IMETHODIMP nsParser::GetDTD ( nsIDTD **  aDTD) [virtual]

Get the DTD associated with this parser vidur 9/29/99.

Parameters:
aDTDout param that will contain the result
Returns:
NS_OK if successful, NS_ERROR_FAILURE for runtime error

Implements nsIParser.

Definition at line 2941 of file nsParser.cpp.

gess 1/22/99

gess1/22/99

Parameters:
@return

Definition at line 2182 of file nsParser.cpp.

                                                         {
  nsresult result = NS_OK;
  aTokenizer = nsnull;
  if(mParserContext) {
    PRInt32 type = mParserContext->mDTD ? mParserContext->mDTD->GetType() : NS_IPARSER_FLAG_HTML;
    result = mParserContext->GetTokenizer(type, mSink, aTokenizer);
  }
  return result;
}

Here is the call graph for this function:

Fired when the continue parse event is triggered.

kmcclusk 5/18/98

Definition at line 1546 of file nsParser.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsParser::Init ( void  ) [static]

Called on module init.

This gets called when the htmlparser module is initialized.

Definition at line 280 of file nsParser.cpp.

{
  nsresult rv;
  nsCOMPtr<nsICategoryManager> cm =
    do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISimpleEnumerator> e;
  rv = cm->EnumerateCategory("Parser data listener", getter_AddRefs(e));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString categoryEntry;
  nsXPIDLCString contractId;
  nsCOMPtr<nsISupports> entry;

  while (NS_SUCCEEDED(e->GetNext(getter_AddRefs(entry)))) {
    nsCOMPtr<nsISupportsCString> category(do_QueryInterface(entry));

    if (!category) {
      NS_WARNING("Category entry not an nsISupportsCString!");

      continue;
    }

    rv = category->GetData(categoryEntry);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = cm->GetCategoryEntry("Parser data listener", categoryEntry.get(),
                              getter_Copies(contractId));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIUnicharStreamListener> listener =
      do_CreateInstance(contractId.get());

    if (listener) {
      if (!sParserDataListeners) {
        sParserDataListeners = new nsCOMArray<nsIUnicharStreamListener>();

        if (!sParserDataListeners)
          return NS_ERROR_OUT_OF_MEMORY;
      }

      sParserDataListeners->AppendObject(listener);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsParser::NS_IMETHOD_ ( void  ) [virtual]

Select given content sink into parser for parser output gess5/11/98.

Parameters:
aSinkis the new sink to be used by parser
Returns:
old sink, or NULL

Implements nsIParser.

retrive the sink set into the parser gess5/11/98

Parameters:
aSinkis the new sink to be used by parser
Returns:
old sink, or NULL

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) [virtual]

Call this method once you've created a parser, and want to instruct it about the command which caused the parser to be constructed.

For example, this allows us to select a DTD which can do, say, view-source.

gess 3/25/98

Parameters:
aCommand-- ptrs to string that contains command
Returns:
nada

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) const [virtual]

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) [virtual]

Select given content sink into parser for parser output gess5/11/98.

Parameters:
aSinkis the new sink to be used by parser
Returns:

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) const [virtual]

Call this method once you've created a parser, and want to instruct it about what charset to load.

ftang 4/23/99

Parameters:
aCharset-the charset of a document
aCharsetSource-the source of the charset
Returns:
nada

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) [virtual]

Select given content sink into parser for parser output gess5/11/98.

Parameters:
aSinkis the new sink to be used by parser
Returns:

Implements nsIParser.

Retrieve the scanner from the topmost parser context.

gess 6/9/98

Returns:
ptr to scanner

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) [virtual]

Select given content sink into parser for parser output gess5/11/98.

Parameters:
aSinkis the new sink to be used by parser
Returns:

Implements nsIParser.

nsParser::NS_IMETHOD_ ( void  ) [virtual]

Select given content sink into parser for parser output gess5/11/98.

Parameters:
aSinkis the new sink to be used by parser
Returns:

Implements nsIParser.

nsParser::NS_IMETHOD_ ( PRBool  ) [virtual]

Call this to query whether the parser is enabled or not.

vidur 4/12/99

Returns:
current state

Implements nsIParser.

nsParser::NS_IMETHOD_ ( PRBool  ) [virtual]

Call this to query whether the parser thinks it's done with parsing.

rickg 5/12/01

Returns:
complete state

Implements nsIParser.

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

NS_IMETHODIMP nsParser::Parse ( nsIURI aURL,
nsIRequestObserver aListener = nsnull,
PRBool  aVerifyEnabled = PR_FALSE,
void aKey = 0,
nsDTDMode  aMode = eDTDMode_autodetect 
) [virtual]

Cause parser to parse input from given URL gess5/11/98.

This is the main controlling routine in the parsing process.

Parameters:
aURLis a descriptor for source document
aListeneris a listener to forward notifications to
Returns:
TRUE if all went well -- FALSE otherwise

Note that it may get called multiple times for the same scanner, since this is a pushed based system, and all the tokens may not have been consumed by the scanner during a given invocation of this method.

gess 01/04/99

Parameters:
aFilename-- const char* containing file to be parsed.
Returns:
error code -- 0 if ok, non-zero if error.

Implements nsIParser.

Definition at line 1604 of file nsParser.cpp.

{  

  NS_PRECONDITION(aURL, "Error: Null URL given");

  nsresult result=kBadURL;
  mObserver = aListener;
 
  if (aVerifyEnabled) {
    mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION;
  }
  else {
    mFlags &= ~NS_PARSER_FLAG_DTD_VERIFICATION;
  }

  if(aURL) {
    nsCAutoString spec;
    nsresult rv = aURL->GetSpec(spec);
    if (rv != NS_OK) {      
      return rv;
    }
    NS_ConvertUTF8toUCS2 theName(spec);

    nsScanner* theScanner=new nsScanner(theName,PR_FALSE,mCharset,mCharsetSource);
    CParserContext* pc=new CParserContext(theScanner,aKey,mCommand,aListener);
    if(pc && theScanner) {
      pc->mMultipart=PR_TRUE;
      pc->mContextType=CParserContext::eCTURL;
      pc->mDTDMode=aMode;
      PushContext(*pc);

      // Here, and only here, hand this parser off to the scanner. We
      // only want to do that here since the only reason the scanner
      // needs the parser is to call DataAdded() on it, and that's
      // only ever wanted when parsing from an URI.
      theScanner->SetParser(this);

      result=NS_OK;
    }
    else{
      result=mInternalState=NS_ERROR_HTMLPARSER_BADCONTEXT;
    }
  }  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsParser::Parse ( nsIInputStream aStream,
const nsACString &  aMimeType,
PRBool  aVerifyEnabled = PR_FALSE,
void aKey = 0,
nsDTDMode  aMode = eDTDMode_autodetect 
) [virtual]

Cause parser to parse input from given stream gess5/11/98.

Cause parser to parse input from given stream vidur 12/11/98.

Parameters:
aStreamis the i/o source
Returns:
TRUE if all went well -- FALSE otherwise
Parameters:
aStreamis the i/o source
Returns:
error code -- 0 if ok, non-zero if error.

Implements nsIParser.

Definition at line 1662 of file nsParser.cpp.

{
  if (aVerifyEnabled) {
    mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION;
  }
  else {
    mFlags &= ~NS_PARSER_FLAG_DTD_VERIFICATION;
  }
  
  nsresult  result=NS_ERROR_OUT_OF_MEMORY;

  //ok, time to create our tokenizer and begin the process
  nsAutoString theUnknownFilename(NS_LITERAL_STRING("unknown"));

  // references 
  nsScanner* theScanner=new nsScanner(theUnknownFilename,aStream,mCharset,mCharsetSource);

  CParserContext* pc=new CParserContext(theScanner,aKey,mCommand,0);
  if(pc && theScanner) {
    PushContext(*pc);
    pc->SetMimeType(aMimeType);
    pc->mStreamListenerState=eOnStart;  
    pc->mMultipart=PR_FALSE;
    pc->mContextType=CParserContext::eCTStream;
    pc->mDTDMode=aMode;
    mParserContext->mScanner->FillBuffer();
    result=ResumeParse();
    pc=PopContext();
    delete pc;
  }
  else{
    result=mInternalState=NS_ERROR_HTMLPARSER_BADCONTEXT;
  }  
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsParser::Parse ( const nsAString &  aSourceBuffer,
void aKey,
const nsACString &  aMimeType,
PRBool  aVerifyEnabled,
PRBool  aLastCall,
nsDTDMode  aMode = eDTDMode_autodetect 
) [virtual]

gess5/11/98

Call this method if all you want to do is parse 1 string full of HTML text.

Parameters:
anHTMLStringcontains a string-full of real HTML
appendTokenstells us whether we should insert tokens inline, or append them.
Returns:
TRUE if all went well -- FALSE otherwise

In particular, this method should be called by the DOM when it has an HTML string to feed to the parser in real-time.

gess5/11/98

Parameters:
aSourceBuffercontains a string-full of real content
aMimeTypetells us what type of content to expect in the given string
Returns:
error code -- 0 if ok, non-zero if error.

Implements nsIParser.

Definition at line 1713 of file nsParser.cpp.

{ 

  //NOTE: Make sure that updates to this method don't cause 
  //      bug #2361 to break again! 

  nsresult result=NS_OK;

  // Don't bother if we're never going to parse this.
  if (mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING) {
    return result;
  }

  if(!aLastCall && aSourceBuffer.IsEmpty()) {
    // Nothing is being passed to the parser so return
    // immediately. mUnusedInput will get processed when
    // some data is actually passed in.
    // But if this is the last call, make sure to finish up
    // stuff correctly.
    return result;
  }

  // hack to pass on to the dtd the caller's desire to 
  // parse a fragment without worrying about containment rules
  if (aMode == eDTDMode_fragment)
    mCommand = eViewFragment;
  
  // Maintain a reference to ourselves so we don't go away 
  // till we're completely done. 
  nsCOMPtr<nsIParser> kungFuDeathGrip(this);

  if(aLastCall || !aSourceBuffer.IsEmpty() || !mUnusedInput.IsEmpty()) {
    
    if (aVerifyEnabled) {
      mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION;
    }
    else {
      mFlags &= ~NS_PARSER_FLAG_DTD_VERIFICATION;
    }
    
    CParserContext* pc=0;

    if((!mParserContext) || (mParserContext->mKey!=aKey))  { 
      //only make a new context if we dont have one, OR if we do, but has a different context key... 
  
      nsScanner* theScanner = new nsScanner(mUnusedInput,mCharset,mCharsetSource);
      NS_ENSURE_TRUE(theScanner, NS_ERROR_OUT_OF_MEMORY);
      
      nsIDTD *theDTD = 0; 
      eAutoDetectResult theStatus = eUnknownDetect; 

      if (mParserContext && mParserContext->mMimeType==aMimeType) {
        NS_ASSERTION(mParserContext->mDTD,"How come the DTD is null?"); // Ref. Bug 90379
        
        if (mParserContext) {
          // To fix bug 32263 we used create a new instance of the DTD!.
          // All we need is a new tokenizer which now gets created with
          // a parser context.
          theDTD = mParserContext->mDTD; 
          theStatus=mParserContext->mAutoDetectStatus; 
          //added this to fix bug 32022.
        }
      } 

      pc = new CParserContext(theScanner, aKey, mCommand,
                              0, theDTD, theStatus, aLastCall);
      NS_ENSURE_TRUE(pc, NS_ERROR_OUT_OF_MEMORY);

      PushContext(*pc); 

      pc->mMultipart=!aLastCall; //by default 
      if (pc->mPrevContext) { 
        pc->mMultipart |= pc->mPrevContext->mMultipart;  //if available 
      } 

      // start fix bug 40143
      if(pc->mMultipart) {
        pc->mStreamListenerState=eOnDataAvail;
        if(pc->mScanner) pc->mScanner->SetIncremental(PR_TRUE);
      }
      else {
        pc->mStreamListenerState=eOnStop;
        if(pc->mScanner) pc->mScanner->SetIncremental(PR_FALSE);
      }
      // end fix for 40143

      pc->mContextType=CParserContext::eCTString; 
      pc->SetMimeType(aMimeType);
      if (pc->mPrevContext && aMode == eDTDMode_autodetect) {
        // Preserve the DTD mode from the last context, bug 265814.
        pc->mDTDMode = pc->mPrevContext->mDTDMode;
      }
      else {
        pc->mDTDMode = aMode;
      }

      mUnusedInput.Truncate(); 

      //printf("Parse(string) iterate: %i",PR_FALSE); 
      pc->mScanner->Append(aSourceBuffer); 
      // Do not interrupt document.write() - bug 95487
      result = ResumeParse(PR_FALSE, PR_FALSE, PR_FALSE);
    } 
    else { 
      mParserContext->mScanner->Append(aSourceBuffer); 
      if(!mParserContext->mPrevContext) {
        // Set stream listener state to eOnStop, on the final context - Fix 68160,
        // to guarantee DidBuildModel() call - Fix 36148
        if(aLastCall) {
          mParserContext->mStreamListenerState=eOnStop;
          mParserContext->mScanner->SetIncremental(PR_FALSE);
        }
        ResumeParse(PR_FALSE, PR_FALSE, PR_FALSE);
      }
    } 
  }//if 

  return result; 
}  

Here is the call graph for this function:

NS_IMETHODIMP nsParser::ParseFragment ( const nsAString &  aSourceBuffer,
void aKey,
nsVoidArray aTagStack,
PRBool  aXMLMode,
const nsACString &  aMimeType,
nsDTDMode  aMode = eDTDMode_autodetect 
) [virtual]

This method needs documentation.

gess 04/01/99

Parameters:
@return

Implements nsIParser.

Definition at line 1845 of file nsParser.cpp.

{
  nsresult result = NS_OK;
  nsAutoString  theContext;
  PRUint32 theCount = aTagStack.Count();
  PRUint32 theIndex = 0;

  // Disable observers for fragments
  mFlags &= ~NS_PARSER_FLAG_OBSERVERS_ENABLED;

  for (theIndex = 0; theIndex < theCount; theIndex++) {
    theContext.AppendLiteral("<");
    theContext.Append((PRUnichar*)aTagStack.ElementAt(theCount - theIndex - 1));
    theContext.AppendLiteral(">");
  }

  // First, parse the context to build up the DTD's tag stack. Note that we
  // pass PR_FALSE for the aLastCall parameter.
  result = Parse(theContext, (void*)&theContext, aMimeType, 
                 PR_FALSE, PR_FALSE, aMode);
  if (NS_FAILED(result)) {
    mFlags |= NS_PARSER_FLAG_OBSERVERS_ENABLED;
    return result;
  }

  nsCOMPtr<nsIFragmentContentSink> fragSink = do_QueryInterface(mSink);
  if (!fragSink) {
    NS_ERROR("ParseFragment requires a fragment content sink");
    mFlags |= NS_PARSER_FLAG_OBSERVERS_ENABLED;
    return NS_ERROR_HTMLPARSER_UNKNOWN;
  }

  if (!aXMLMode) {
    // First, we have to flush any tags that don't belong in the head if there
    // was no <body> in the context.
    // XXX This is extremely ugly. Maybe CNavDTD should have FlushMisplaced()?
    if (!mParserContext) {
      NS_ERROR("Parsing didn't create a parser context?");
      mFlags |= NS_PARSER_FLAG_OBSERVERS_ENABLED;
      return NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
    }
    nsCOMPtr<CNavDTD> dtd = do_QueryInterface(mParserContext->mDTD);

    if (dtd) {
      CStartToken bodyToken(NS_LITERAL_STRING("BODY"), eHTMLTag_body);
      nsCParserNode bodyNode(&bodyToken, 0);

      dtd->OpenBody(&bodyNode);

      // Now parse the flushed out tags.
      result = BuildModel();
      if (NS_FAILED(result)) {
        mFlags |= NS_PARSER_FLAG_OBSERVERS_ENABLED;
        return result;
      }
    }

    // Now that we've flushed all of the tags out of the body, we have to make
    // sure that there aren't any context tags left in the scanner.
    NS_ASSERTION(mParserContext->mScanner, "Where'd the scanner go?");

    PRUnichar next;
    if (NS_SUCCEEDED(mParserContext->mScanner->Peek(next))) {
      // Uh, oh. This must mean that the context stack has a special tag on
      // it, such as <textarea> or <title> that requires its end tag before it
      // will be consumed. Tell the content sink that it will be coming.
      // Note: For now, we can assume that there is only one such tag.
      NS_ASSERTION(next == '<', "The tokenizer failed to consume a token");
      fragSink->IgnoreFirstContainer();
    }
  }

  fragSink->WillBuildContent();
  // Now, parse the actual content. Note that this is the last call
  // for HTML content, but for XML, we will want to build and parse
  // the end tags.  However, if tagStack is empty, it's the last call
  // for XML as well.
  if (!aXMLMode || (theCount == 0)) {
    result = Parse(aSourceBuffer, (void*)&theContext, aMimeType,
                   PR_FALSE, PR_TRUE, aMode);
    fragSink->DidBuildContent();
  } else {
    // Add an end tag chunk, so expat will read the whole source buffer,
    // and not worry about ']]' etc.
    result = Parse(aSourceBuffer + NS_LITERAL_STRING("</"),
                   (void*)&theContext, aMimeType, PR_FALSE, PR_FALSE, aMode);
    fragSink->DidBuildContent();
 
    if (NS_SUCCEEDED(result)) {
      nsAutoString endContext;       
      for (theIndex = 0; theIndex < theCount; theIndex++) {
         // we already added an end tag chunk above
        if (theIndex > 0) {
          endContext.AppendLiteral("</");
        }

        nsAutoString thisTag( (PRUnichar*)aTagStack.ElementAt(theIndex) );
        // was there an xmlns=?
        PRInt32 endOfTag = thisTag.FindChar(PRUnichar(' '));
        if (endOfTag == -1) {
          endContext.Append(thisTag);
        } else {
          endContext.Append(Substring(thisTag,0,endOfTag));
        }

        endContext.AppendLiteral(">");
      }
       
      result = Parse(endContext, (void*)&theContext, aMimeType,
                     PR_FALSE, PR_TRUE, aMode);
    }
  }
    
  mFlags |= NS_PARSER_FLAG_OBSERVERS_ENABLED; //now reenable.

  return result;
}

Here is the call graph for this function:

Definition at line 314 of file nsParser.h.

{return mParserContext;}

This method pops the topmost context off the stack, returning it to the user.

The next context (if any) becomes the current context. gess7/22/98

Returns:
prev. context

Definition at line 1356 of file nsParser.cpp.

{
  CParserContext* oldContext = mParserContext;
  if (oldContext) {
    mParserContext = oldContext->mPrevContext;
    if (mParserContext) {
      // If the old context was blocked, propagate the blocked state
      // back to the new one. Also, propagate the stream listener state
      // but don't override onStop state to guarantee the call to DidBuildModel().
      if (mParserContext->mStreamListenerState != eOnStop) {
        mParserContext->mStreamListenerState = oldContext->mStreamListenerState;
      }
      // Update the current context's tokenizer to any information gleaned
      // while parsing document.write() calls (such as "a plaintext tag was
      // found")
      if (mParserContext->mTokenizer) {
        mParserContext->mTokenizer->CopyState(oldContext->mTokenizer);
      }
    }
  }
  return oldContext;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This is called when the final chunk has been passed to the parser and the content sink has interrupted token processing.

It schedules a ParserContinue PL_Event which will ask the parser to HandleParserContinueEvent when it is handled. kmcclusk6/1/2001

Definition at line 480 of file nsParser.cpp.

{
  if (!(mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT) && mEventQueue) {
    nsParserContinueEvent* ev = new nsParserContinueEvent(this);
    NS_ENSURE_TRUE(ev, NS_ERROR_OUT_OF_MEMORY);
    if (NS_FAILED(mEventQueue->PostEvent(ev))) {
        NS_ERROR("failed to post parser continuation event");
        PL_DestroyEvent(ev);
    }
    else {
        mFlags |= NS_PARSER_FLAG_PENDING_CONTINUE_EVENT;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This method adds a new parser context to the list, pushing the current one to the next position.

gess7/22/98

Parameters:
ptrto new context
Returns:
nada

Definition at line 1344 of file nsParser.cpp.

Here is the caller graph for this function:

Call this method when you want to register your dynamic DTD's with the parser.

gess 01/04/99

Parameters:
aDTDis the object to be registered.
Returns:
nothing.

Implements nsIParser.

Definition at line 609 of file nsParser.cpp.

{
  CSharedParserObjects* sharedObjects;
  nsresult rv = GetSharedObjects(&sharedObjects);
  NS_ENSURE_SUCCESS(rv, rv);
  return sharedObjects->RegisterDTD(aDTD);
}

Here is the call graph for this function:

nsresult nsParser::ResumeParse ( PRBool  allowIteration = PR_TRUE,
PRBool  aIsFinalChunk = PR_FALSE,
PRBool  aCanInterrupt = PR_TRUE 
) [virtual]

This method gets called (automatically) during incremental parsing gess5/11/98.

This routine is called to cause the parser to continue parsing it's underlying stream.

Returns:
TRUE if all went well, otherwise FALSE

This call allows the parse process to happen in chunks, such as when the content is push based, and we need to parse in pieces.

An interesting change in how the parser gets used has led us to add extra processing to this method. The case occurs when the parser is blocked in one context, and gets a parse(string) call in another context. In this case, the parserContexts are linked. No problem.

The problem is that Parse(string) assumes that it can proceed unabated, but if the parser is already blocked that assumption is false. So we needed to add a mechanism here to allow the parser to continue to process (the pop and free) contexts until 1) it get's blocked again; 2) it runs out of contexts.

rickg 03.10.2000

Parameters:
allowItertion: set to true if non-script resumption is requested
aIsFinalChunk: tells us when the last chunk of data is provided.
Returns:
error code -- 0 if ok, non-zero if error.

Definition at line 1988 of file nsParser.cpp.

                                                                                                {

  //printf("  Resume %i, prev-context: %p\n",allowIteration,mParserContext->mPrevContext);
  

  nsresult result=NS_OK;

  if((mFlags & NS_PARSER_FLAG_PARSER_ENABLED) && 
     mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) {


    MOZ_TIMER_DEBUGLOG(("Start: Parse Time: nsParser::ResumeParse(), this=%p\n", this));
    MOZ_TIMER_START(mParseTime);

    result = WillBuildModel(mParserContext->mScanner->GetFilename());
    if (NS_FAILED(result)) {
      mFlags &= ~NS_PARSER_FLAG_CAN_TOKENIZE;
      return result;
    }

    if(mParserContext->mDTD) {

      mParserContext->mDTD->WillResumeParse(mSink);
      PRBool theFirstTime=PR_TRUE;
      PRBool theIterationIsOk=(theFirstTime || allowIteration||(!mParserContext->mPrevContext));
       
      while((result==NS_OK) && (theIterationIsOk)) {
        theFirstTime=PR_FALSE;
        if(!mUnusedInput.IsEmpty()) {
          if(mParserContext->mScanner) {
            // -- Ref: Bug# 22485 --
            // Insert the unused input into the source buffer 
            // as if it was read from the input stream. 
            // Adding UngetReadable() per vidur!!
            mParserContext->mScanner->UngetReadable(mUnusedInput);
           mUnusedInput.Truncate(0);
          }
        }

        //Only allow parsing to be interrupted in the subsequent call
        //to build model.
        SetCanInterrupt(aCanInterrupt); 
        nsresult theTokenizerResult = mFlags & NS_PARSER_FLAG_CAN_TOKENIZE ? Tokenize(aIsFinalChunk) : NS_OK;   // kEOF==2152596456
        result=BuildModel(); 

        if(result==NS_ERROR_HTMLPARSER_INTERRUPTED) {
          if(aIsFinalChunk)
            PostContinueEvent();
        }
        SetCanInterrupt(PR_FALSE); 

        theIterationIsOk=PRBool((kEOF!=theTokenizerResult) && (result!=NS_ERROR_HTMLPARSER_INTERRUPTED));

       // Make sure not to stop parsing too early. Therefore, before shutting down the 
        // parser, it's important to check whether the input buffer has been scanned to 
        // completion ( theTokenizerResult should be kEOF ). kEOF -> End of buffer.

        // If we're told to block the parser, we disable all further parsing 
        // (and cache any data coming in) until the parser is re-enabled.

        if(NS_ERROR_HTMLPARSER_BLOCK==result) {
          //BLOCK == 2152596464
          if (mParserContext->mDTD) {
            mParserContext->mDTD->WillInterruptParse(mSink);
          }
          
          BlockParser();
          return NS_OK;
        }
        
        else if (NS_ERROR_HTMLPARSER_STOPPARSING==result) {
          // Note: Parser Terminate() calls DidBuildModel.
          if(mInternalState!=NS_ERROR_HTMLPARSER_STOPPARSING) {
            DidBuildModel(mStreamStatus);
            mInternalState = result;
          }
          return NS_OK;
        }
                  
        else if(((NS_OK==result) && (theTokenizerResult==kEOF)) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)){

          PRBool theContextIsStringBased=PRBool(CParserContext::eCTString==mParserContext->mContextType);
          if( (eOnStop==mParserContext->mStreamListenerState) || 
              (!mParserContext->mMultipart) || theContextIsStringBased) {

            if(!mParserContext->mPrevContext) {
              if(eOnStop==mParserContext->mStreamListenerState) {

                DidBuildModel(mStreamStatus);          

                MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: nsParser::ResumeParse(), this=%p\n", this));
                MOZ_TIMER_STOP(mParseTime);

                MOZ_TIMER_LOG(("Parse Time (this=%p): ", this));
                MOZ_TIMER_PRINT(mParseTime);

                MOZ_TIMER_LOG(("DTD Time: "));
                MOZ_TIMER_PRINT(mDTDTime);

                MOZ_TIMER_LOG(("Tokenize Time: "));
                MOZ_TIMER_PRINT(mTokenizeTime);

                return NS_OK;
              }

            }
            else { 

              CParserContext* theContext=PopContext();
              if(theContext) {
                theIterationIsOk=PRBool(allowIteration && theContextIsStringBased);
                if(theContext->mCopyUnused) {
                  theContext->mScanner->CopyUnusedData(mUnusedInput);
                }
                delete theContext;
              }
              result = mInternalState;  
              aIsFinalChunk=(mParserContext && mParserContext->mStreamListenerState==eOnStop)? PR_TRUE:PR_FALSE;
              
                //...then intentionally fall through to WillInterruptParse()...
            }

          }             

        }

        if((kEOF==theTokenizerResult) || (result==NS_ERROR_HTMLPARSER_INTERRUPTED)) {
          result = (result == NS_ERROR_HTMLPARSER_INTERRUPTED) ? NS_OK : result;
          if (mParserContext->mDTD) {
            mParserContext->mDTD->WillInterruptParse(mSink);
          }
        }


      }//while
    }//if
    else {
      mInternalState=result=NS_ERROR_HTMLPARSER_UNRESOLVEDDTD;
    }
  }//if

  MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: nsParser::ResumeParse(), this=%p\n", this));
  MOZ_TIMER_STOP(mParseTime);

  return (result==NS_ERROR_HTMLPARSER_INTERRUPTED) ? NS_OK : result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Set to parser state to indicate whether parsing tokens can be interrupted.

Parameters:
aCanInterruptPR_TRUE if parser can be interrupted, PR_FALSE if it can not be interrupted. kmcclusk 5/18/98

Definition at line 1583 of file nsParser.cpp.

                                                   {
  if (aCanInterrupt) {
    mFlags |= NS_PARSER_FLAG_CAN_INTERRUPT;
  }
  else {
    mFlags &= ~NS_PARSER_FLAG_CAN_INTERRUPT;
  }
}

Here is the caller graph for this function:

void nsParser::SetSinkCharset ( nsACString &  aCharset)

Definition at line 565 of file nsParser.cpp.

{
  if (mSink) {
    mSink->SetDocumentCharset(aCharset);
  }
}

Here is the caller graph for this function:

This rather arcane method (hack) is used as a signal between the DTD and the parser.

Call this when you want control whether or not the parser will parse and tokenize input (TRUE), or whether it just caches input to be parsed later (FALSE).

It allows the DTD to tell the parser that content that comes through (parser::parser(string)) but not consumed should propagate into the next string based parse call.

gess 9/1/98

Parameters:
aStatedetermines whether we propagate unused string content.
Returns:
current state

gess 1/29/99

Parameters:
aStatedetermines whether we parse/tokenize or just cache.
Returns:
current state

Definition at line 1388 of file nsParser.cpp.

{
  mUnusedInput=aBuffer;
}
void nsParser::Shutdown ( void  ) [static]

Called on module shutdown.

This gets called when the htmlparser module is shutdown.

gess 01/04/99

Definition at line 336 of file nsParser.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Call this when you want to force the parser to terminate the parsing process altogether.

This is binary -- so once you terminate you can't resume without restarting altogether.

gess 7/4/99

Returns:
should return NS_OK once implemented

Implements nsIParser.

Definition at line 1401 of file nsParser.cpp.

{
  nsresult result = NS_OK;
  // XXX - [ until we figure out a way to break parser-sink circularity ]
  // Hack - Hold a reference until we are completely done...
  nsCOMPtr<nsIParser> kungFuDeathGrip(this); 
  mInternalState = result = NS_ERROR_HTMLPARSER_STOPPARSING;

  // CancelParsingEvents must be called to avoid leaking the nsParser object
  // @see bug 108049
  // If NS_PARSER_FLAG_PENDING_CONTINUE_EVENT is set then CancelParsingEvents 
  // will reset it so DidBuildModel will call DidBuildModel on the DTD. Note: 
  // The IsComplete() call inside of DidBuildModel looks at the pendingContinueEvents flag.
  CancelParsingEvents();

  // If we got interrupted in the middle of a document.write, then we might
  // have more than one parser context on our parsercontext stack. This has
  // the effect of making DidBuildModel a no-op, meaning that we never call
  // our sink's DidBuildModel and break the reference cycle, causing a leak.
  // Since we're getting terminated, we manually clean up our context stack.
  while (mParserContext && mParserContext->mPrevContext) {
    CParserContext *prev = mParserContext->mPrevContext;
    NS_ASSERTION(prev->mPrevContext || prev->mDTD, "How is there no root DTD?");

    delete mParserContext;
    mParserContext = prev;
  }

  if (mParserContext && mParserContext->mDTD) {
    mParserContext->mDTD->Terminate();
    DidBuildModel(result);
  }
  else if (mSink) {
    // We have no parser context or no DTD yet (so we got terminated before we
    // got any data).  Manually break the reference cycle with the sink.
    result = mSink->DidBuildModel();
    NS_ENSURE_SUCCESS(result, result);
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsParser::Tokenize ( PRBool  aIsFinalChunk = PR_FALSE) [private]

This is the primary control routine.

This is the primary control routine to consume tokens.

It iteratively consumes tokens until an error occurs or you run out of data.

gess 3/25/98

Returns:
error code
 It iteratively consumes tokens until an error occurs or 
 you run out of data.

gess 01/04/99

Returns:
error code -- 0 if ok, non-zero if error.

Definition at line 2831 of file nsParser.cpp.

                                               {
  
  nsITokenizer* theTokenizer = 0;
    
  nsresult result = NS_OK;

  if (mParserContext) {
    PRInt32 type = mParserContext->mDTD ? mParserContext->mDTD->GetType() : NS_IPARSER_FLAG_HTML;
    mParserContext->GetTokenizer(type, mSink, theTokenizer);
  }

  if (theTokenizer) { 
    if (mFlags & NS_PARSER_FLAG_FLUSH_TOKENS) {
      // For some reason tokens didn't get flushed ( probably
      // the parser got blocked before all the tokens in the
      // stack got handled ). Flush 'em now. Ref. bug 104856
      if (theTokenizer->GetCount() == 0) {
        mFlags &= ~NS_PARSER_FLAG_FLUSH_TOKENS; // reset since the tokens have been flushed.
        // Resume tokenization for the rest of the document 
        // since all the tokens in the tokenizer got flushed.
        result = Tokenize(aIsFinalChunk); 
      }
    }
    else {
      PRBool flushTokens=PR_FALSE;

      MOZ_TIMER_START(mTokenizeTime);

      WillTokenize(aIsFinalChunk);
      while (NS_SUCCEEDED(result)) {
        mParserContext->mScanner->Mark();
        result=theTokenizer->ConsumeToken(*mParserContext->mScanner, flushTokens);
        if (NS_FAILED(result)) {
          mParserContext->mScanner->RewindToMark();
          if (kEOF == result){
            break;
          }
          else if(NS_ERROR_HTMLPARSER_STOPPARSING==result) {
            result = Terminate();
            break;
          }
        }
        else if (flushTokens && (mFlags & NS_PARSER_FLAG_OBSERVERS_ENABLED)) {
          // I added the extra test of NS_PARSER_FLAG_OBSERVERS_ENABLED to fix Bug# 23931.
          // Flush tokens on seeing </SCRIPT> -- Ref: Bug# 22485 --
          // Also remember to update the marked position.
          mFlags |= NS_PARSER_FLAG_FLUSH_TOKENS;
          mParserContext->mScanner->Mark();
          break;
        }
      } 
      DidTokenize(aIsFinalChunk);

      MOZ_TIMER_STOP(mTokenizeTime);
    }  
  }
  else{
    result = mInternalState = NS_ERROR_HTMLPARSER_BADTOKENIZER;
  }
  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsParser::WillBuildModel ( nsString aFilename) [protected]

gess5/18/98

This gets called just prior to the model actually being constructed.

Parameters:
@returnIt's important to make this the last thing that happens right before parsing, so we can delay until the last moment the resolution of which DTD to use (unless of course we're assigned one).

Definition at line 1279 of file nsParser.cpp.

{
  if (!mParserContext)
    return kInvalidParserContext;

  if (eUnknownDetect != mParserContext->mAutoDetectStatus)
    return NS_OK;

  if (eDTDMode_unknown == mParserContext->mDTDMode ||
      eDTDMode_autodetect == mParserContext->mDTDMode) {
    PRUnichar buf[1025];
    nsFixedString theBuffer(buf, 1024, 0);

    // Grab 1024 characters, starting at the first non-whitespace
    // character, to look for the doctype in.
    mParserContext->mScanner->Peek(theBuffer, 1024, mParserContext->mScanner->FirstNonWhitespacePosition());    
    DetermineParseMode(theBuffer, mParserContext->mDTDMode,
                       mParserContext->mDocType, mParserContext->mMimeType);
  }
  
  PRBool found;
  nsresult rv = FindSuitableDTD(*mParserContext, &found);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!found)
    return rv;

  nsITokenizer* tokenizer;
  mParserContext->GetTokenizer(mParserContext->mDTD->GetType(), mSink, tokenizer);
  return mParserContext->mDTD->WillBuildModel(*mParserContext, tokenizer, mSink);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsParser::WillTokenize ( PRBool  aIsFinalChunk = PR_FALSE) [private]

Part of the code sandwich, this gets called right before the tokenization process begins.

The main reason for this call is to allow the delegate to do initialization.

gess 3/25/98

Parameters:
@returnTRUE if it's ok to proceed

The main reason for this call is to allow the delegate to do initialization.

gess 01/04/99

Parameters:
@returnTRUE if it's ok to proceed

Definition at line 2808 of file nsParser.cpp.

                                                 {
  nsITokenizer* theTokenizer=0;
  nsresult result = NS_OK;
  if (mParserContext) {
    PRInt32 type = mParserContext->mDTD ? mParserContext->mDTD->GetType() : NS_IPARSER_FLAG_HTML;
    mParserContext->GetTokenizer(type, mSink, theTokenizer);
  }

  if (theTokenizer) {
    result = theTokenizer->WillTokenize(aIsFinalChunk,&mTokenAllocator);
  }  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class CTokenHandler [friend]

Definition at line 107 of file nsParser.h.


Member Data Documentation

Reimplemented from nsIParser.

Definition at line 172 of file nsParser.h.

Definition at line 477 of file nsParser.h.

Definition at line 472 of file nsParser.h.

Definition at line 469 of file nsParser.h.

Definition at line 478 of file nsParser.h.

Definition at line 461 of file nsParser.h.

Definition at line 474 of file nsParser.h.

Definition at line 470 of file nsParser.h.

Definition at line 463 of file nsParser.h.

Definition at line 462 of file nsParser.h.

Definition at line 466 of file nsParser.h.

Definition at line 464 of file nsParser.h.

Definition at line 471 of file nsParser.h.

Definition at line 467 of file nsParser.h.

Definition at line 476 of file nsParser.h.

PRInt32& nsIParser::oSource = 0 [inherited]

Definition at line 194 of file nsIParser.h.

Definition at line 395 of file nsParser.h.


The documentation for this class was generated from the following files: