2009-05-19 19:54:42 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2006-01-24 04:25:14 +03:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifndef NS_IPARSER___
|
|
|
|
#define NS_IPARSER___
|
|
|
|
|
|
|
|
|
2012-03-22 18:42:42 +04:00
|
|
|
/**
|
|
|
|
* This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
|
|
|
|
* to the point of being near-unrecognizable).
|
1998-07-23 12:21:02 +04:00
|
|
|
*
|
2012-03-22 18:42:42 +04:00
|
|
|
* Please DO NOT #include this file in comm-central code, in your XULRunner
|
|
|
|
* app or binary extensions.
|
|
|
|
*
|
|
|
|
* Please DO NOT #include this into new files even inside Gecko. It is more
|
|
|
|
* likely than not that #including this header is the wrong thing to do.
|
|
|
|
*/
|
1998-07-23 12:21:02 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsISupports.h"
|
1998-07-02 12:14:22 +04:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIDTD.h"
|
2013-09-23 21:25:00 +04:00
|
|
|
#include "nsString.h"
|
2007-11-13 04:41:40 +03:00
|
|
|
#include "nsTArray.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2012-01-20 15:16:27 +04:00
|
|
|
#include "nsParserBase.h"
|
2017-06-18 14:37:50 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
1999-01-09 04:09:02 +03:00
|
|
|
|
2006-01-24 04:25:14 +03:00
|
|
|
#define NS_IPARSER_IID \
|
2012-03-27 10:27:45 +04:00
|
|
|
{ 0x2c4ad90a, 0x740e, 0x4212, \
|
|
|
|
{ 0xba, 0x3f, 0xfe, 0xac, 0xda, 0x4b, 0x92, 0x9e } }
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
class nsIContentSink;
|
2001-04-10 10:01:08 +04:00
|
|
|
class nsIRequestObserver;
|
1999-06-23 07:29:44 +04:00
|
|
|
class nsIURI;
|
2001-08-22 04:38:46 +04:00
|
|
|
class nsIChannel;
|
2017-06-18 14:37:50 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class Encoding;
|
|
|
|
}
|
1998-08-12 12:53:55 +04:00
|
|
|
|
2000-03-25 06:35:50 +03:00
|
|
|
enum eParserCommands {
|
|
|
|
eViewNormal,
|
|
|
|
eViewSource,
|
2002-08-29 12:17:41 +04:00
|
|
|
eViewFragment,
|
2000-03-25 08:38:11 +03:00
|
|
|
eViewErrors
|
2000-03-25 06:35:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum eParserDocType {
|
|
|
|
ePlainText = 0,
|
2001-09-08 22:37:19 +04:00
|
|
|
eXML,
|
|
|
|
eHTML_Quirks,
|
|
|
|
eHTML_Strict
|
2000-03-25 06:35:50 +03:00
|
|
|
};
|
|
|
|
|
1999-01-12 03:19:17 +03:00
|
|
|
enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
|
|
|
|
|
1998-05-01 00:23:07 +04:00
|
|
|
/**
|
2012-03-22 18:42:42 +04:00
|
|
|
* This GECKO-INTERNAL interface is on track to being REMOVED (or refactored
|
|
|
|
* to the point of being near-unrecognizable).
|
|
|
|
*
|
|
|
|
* Please DO NOT #include this file in comm-central code, in your XULRunner
|
|
|
|
* app or binary extensions.
|
|
|
|
*
|
|
|
|
* Please DO NOT #include this into new files even inside Gecko. It is more
|
|
|
|
* likely than not that #including this header is the wrong thing to do.
|
1998-05-01 00:23:07 +04:00
|
|
|
*/
|
2012-01-20 15:16:27 +04:00
|
|
|
class nsIParser : public nsParserBase {
|
2017-06-18 14:37:50 +03:00
|
|
|
protected:
|
|
|
|
using Encoding = mozilla::Encoding;
|
|
|
|
template <typename T> using NotNull = mozilla::NotNull<T>;
|
1998-04-25 23:45:14 +04:00
|
|
|
public:
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
|
1999-06-30 23:12:21 +04:00
|
|
|
|
1998-07-23 12:21:02 +04:00
|
|
|
/**
|
1998-11-26 05:55:59 +03:00
|
|
|
* Select given content sink into parser for parser output
|
|
|
|
* @update gess5/11/98
|
|
|
|
* @param aSink is the new sink to be used by parser
|
2003-04-09 01:23:34 +04:00
|
|
|
* @return
|
1998-11-26 05:55:59 +03:00
|
|
|
*/
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0;
|
1998-11-26 05:55:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-04-09 01:23:34 +04:00
|
|
|
* retrieve the sink set into the parser
|
1998-11-26 05:55:59 +03:00
|
|
|
* @update gess5/11/98
|
2003-04-09 01:23:34 +04:00
|
|
|
* @return current sink
|
1998-07-23 12:21:02 +04:00
|
|
|
*/
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0;
|
1998-06-25 05:42:50 +04:00
|
|
|
|
1998-11-11 14:55:32 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @update gess 3/25/98
|
1998-11-13 07:36:46 +03:00
|
|
|
* @param aCommand -- ptrs to string that contains command
|
|
|
|
* @return nada
|
1998-11-11 14:55:32 +03:00
|
|
|
*/
|
2004-07-18 01:45:37 +04:00
|
|
|
NS_IMETHOD_(void) GetCommand(nsCString& aCommand)=0;
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD_(void) SetCommand(const char* aCommand)=0;
|
|
|
|
NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0;
|
1998-11-11 14:55:32 +03:00
|
|
|
|
1999-04-26 21:49:45 +04:00
|
|
|
/**
|
|
|
|
* Call this method once you've created a parser, and want to instruct it
|
|
|
|
* about what charset to load
|
|
|
|
*
|
|
|
|
* @update ftang 4/23/99
|
|
|
|
* @param aCharset- the charest of a document
|
|
|
|
* @param aCharsetSource- the soure of the chares
|
|
|
|
* @return nada
|
|
|
|
*/
|
2017-06-18 14:37:50 +03:00
|
|
|
virtual void SetDocumentCharset(NotNull<const Encoding*> aCharset,
|
|
|
|
int32_t aSource) = 0;
|
1999-04-26 21:49:45 +04:00
|
|
|
|
2001-08-22 04:38:46 +04:00
|
|
|
/**
|
|
|
|
* Get the channel associated with this parser
|
|
|
|
* @update harishd,gagan 07/17/01
|
|
|
|
* @param aChannel out param that will contain the result
|
|
|
|
* @return NS_OK if successful
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetChannel(nsIChannel** aChannel) override = 0;
|
1998-07-23 12:21:02 +04:00
|
|
|
|
1999-10-01 02:01:48 +04:00
|
|
|
/**
|
|
|
|
* Get the DTD associated with this parser
|
|
|
|
* @update vidur 9/29/99
|
|
|
|
* @param aDTD out param that will contain the result
|
|
|
|
* @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
|
|
|
|
*/
|
|
|
|
NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;
|
2009-09-18 13:21:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the nsIStreamListener for this parser
|
|
|
|
*/
|
2011-11-16 11:50:19 +04:00
|
|
|
virtual nsIStreamListener* GetStreamListener() = 0;
|
1999-10-01 02:01:48 +04:00
|
|
|
|
2006-01-24 04:25:14 +03:00
|
|
|
/**************************************************************************
|
|
|
|
* Parse methods always begin with an input source, and perform
|
|
|
|
* conversions until you wind up being emitted to the given contentsink
|
|
|
|
* (which may or may not be a proxy for the NGLayout content model).
|
|
|
|
************************************************************************/
|
2001-02-07 02:35:29 +03:00
|
|
|
|
2005-01-27 22:28:22 +03:00
|
|
|
// Call this method to resume the parser from an unblocked state.
|
|
|
|
// This can happen, for example, if parsing was interrupted and then the
|
|
|
|
// consumer needed to restart the parser without waiting for more data.
|
|
|
|
// This also happens after loading scripts, which unblock the parser in
|
|
|
|
// order to process the output of document.write() and then need to
|
|
|
|
// continue on with the page load on an enabled parser.
|
|
|
|
NS_IMETHOD ContinueInterruptedParsing() = 0;
|
2001-02-07 02:35:29 +03:00
|
|
|
|
|
|
|
// Stops parsing temporarily.
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD_(void) BlockParser() = 0;
|
2001-02-07 02:35:29 +03:00
|
|
|
|
|
|
|
// Open up the parser for tokenization, building up content
|
|
|
|
// model..etc. However, this method does not resume parsing
|
|
|
|
// automatically. It's the callers' responsibility to restart
|
|
|
|
// the parsing engine.
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD_(void) UnblockParser() = 0;
|
2001-02-07 02:35:29 +03:00
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
/**
|
|
|
|
* Asynchronously continues parsing.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD_(void) ContinueInterruptedParsingAsync() = 0;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD_(bool) IsParserEnabled() override = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHOD_(bool) IsComplete() = 0;
|
2000-03-25 06:35:50 +03:00
|
|
|
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD Parse(nsIURI* aURL,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIRequestObserver* aListener = nullptr,
|
2003-04-09 01:23:34 +04:00
|
|
|
void* aKey = 0,
|
|
|
|
nsDTDMode aMode = eDTDMode_autodetect) = 0;
|
2006-01-24 04:25:14 +03:00
|
|
|
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD Terminate(void) = 0;
|
1998-05-15 02:19:08 +04:00
|
|
|
|
2005-02-18 22:18:39 +03:00
|
|
|
/**
|
|
|
|
* This method gets called when you want to parse a fragment of HTML or XML
|
|
|
|
* surrounded by the context |aTagStack|. It requires that the parser have
|
|
|
|
* been given a fragment content sink.
|
|
|
|
*
|
|
|
|
* @param aSourceBuffer The XML or HTML that hasn't been parsed yet.
|
|
|
|
* @param aTagStack The context of the source buffer.
|
|
|
|
* @return Success or failure.
|
|
|
|
*/
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer,
|
2011-08-01 11:48:24 +04:00
|
|
|
nsTArray<nsString>& aTagStack) = 0;
|
2009-06-29 02:44:22 +04:00
|
|
|
|
1998-06-18 03:13:28 +04:00
|
|
|
/**
|
|
|
|
* This method gets called when the tokens have been consumed, and it's time
|
|
|
|
* to build the model via the content sink.
|
|
|
|
* @update gess5/11/98
|
1998-07-23 12:21:02 +04:00
|
|
|
* @return error code -- 0 if model building went well .
|
1998-06-18 03:13:28 +04:00
|
|
|
*/
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD BuildModel(void) = 0;
|
1998-06-01 23:51:52 +04:00
|
|
|
|
2001-06-21 06:06:23 +04:00
|
|
|
/**
|
|
|
|
* Call this method to cancel any pending parsing events.
|
|
|
|
* Parsing events may be pending if all of the document's content
|
|
|
|
* has been passed to the parser but the parser has been interrupted
|
|
|
|
* because processing the tokens took too long.
|
|
|
|
*
|
|
|
|
* @update kmcclusk 05/18/01
|
|
|
|
* @return NS_OK if succeeded else ERROR.
|
|
|
|
*/
|
|
|
|
|
2003-04-09 01:23:34 +04:00
|
|
|
NS_IMETHOD CancelParsingEvents() = 0;
|
2008-02-09 01:07:51 +03:00
|
|
|
|
|
|
|
virtual void Reset() = 0;
|
2009-05-19 19:54:42 +04:00
|
|
|
|
2009-10-15 15:29:11 +04:00
|
|
|
/**
|
|
|
|
* True if the insertion point (per HTML5) is defined.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsInsertionPointDefined() = 0;
|
2009-10-15 15:29:11 +04:00
|
|
|
|
|
|
|
/**
|
2016-09-03 00:55:38 +03:00
|
|
|
* Call immediately before starting to evaluate a parser-inserted script or
|
|
|
|
* in general when the spec says to define an insertion point.
|
2009-10-15 15:29:11 +04:00
|
|
|
*/
|
2016-09-03 00:55:38 +03:00
|
|
|
virtual void PushDefinedInsertionPoint() = 0;
|
2009-10-15 15:29:11 +04:00
|
|
|
|
|
|
|
/**
|
2016-09-03 00:55:38 +03:00
|
|
|
* Call immediately after having evaluated a parser-inserted script or
|
|
|
|
* generally want to restore to the state before the last
|
|
|
|
* PushDefinedInsertionPoint call.
|
2009-10-15 15:29:11 +04:00
|
|
|
*/
|
2016-09-03 00:55:38 +03:00
|
|
|
virtual void PopDefinedInsertionPoint() = 0;
|
2009-10-15 15:29:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the HTML5 parser as not a script-created parser.
|
|
|
|
*/
|
2010-07-30 14:15:38 +04:00
|
|
|
virtual void MarkAsNotScriptCreated(const char* aCommand) = 0;
|
2009-10-15 15:29:11 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* True if this is a script-created HTML5 parser.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsScriptCreated() = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2005-11-11 17:36:26 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)
|
|
|
|
|
1999-01-09 04:09:02 +03:00
|
|
|
/* ===========================================================*
|
|
|
|
Some useful constants...
|
|
|
|
* ===========================================================*/
|
|
|
|
|
2004-12-01 07:37:36 +03:00
|
|
|
#define NS_IPARSER_FLAG_XML 0x00000200
|
|
|
|
#define NS_IPARSER_FLAG_HTML 0x00000400
|
2001-05-16 02:32:26 +04:00
|
|
|
|
2016-12-23 05:21:33 +03:00
|
|
|
#endif
|