2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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-11-12 01:06:16 +03:00
|
|
|
|
|
|
|
#ifndef nsXMLContentSink_h__
|
|
|
|
#define nsXMLContentSink_h__
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2003-10-05 11:29:50 +04:00
|
|
|
#include "nsContentSink.h"
|
1998-11-12 01:06:16 +03:00
|
|
|
#include "nsIXMLContentSink.h"
|
2002-01-09 04:37:50 +03:00
|
|
|
#include "nsIExpatSink.h"
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
#include "nsIDocumentTransformer.h"
|
2007-01-31 00:21:06 +03:00
|
|
|
#include "nsTArray.h"
|
2003-07-03 09:34:26 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2007-02-02 05:12:48 +03:00
|
|
|
#include "nsCRT.h"
|
2008-02-09 01:07:51 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2009-06-24 01:22:16 +04:00
|
|
|
#include "nsIDTD.h"
|
2010-10-25 16:17:38 +04:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2003-10-05 15:28:06 +04:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
class nsIDocument;
|
1999-06-23 07:29:44 +04:00
|
|
|
class nsIURI;
|
1998-11-12 01:06:16 +03:00
|
|
|
class nsIContent;
|
1998-12-11 20:02:37 +03:00
|
|
|
class nsIParser;
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class NodeInfo;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-06-20 06:01:40 +04:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
typedef enum {
|
|
|
|
eXMLContentSinkState_InProlog,
|
|
|
|
eXMLContentSinkState_InDocumentElement,
|
|
|
|
eXMLContentSinkState_InEpilog
|
|
|
|
} XMLContentSinkState;
|
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
struct StackNode {
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mNumFlushed;
|
2007-01-31 00:21:06 +03:00
|
|
|
};
|
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
class nsXMLContentSink : public nsContentSink,
|
|
|
|
public nsIXMLContentSink,
|
2002-06-20 16:04:22 +04:00
|
|
|
public nsITransformObserver,
|
2003-10-05 15:28:06 +04:00
|
|
|
public nsIExpatSink
|
1999-06-28 18:17:30 +04:00
|
|
|
{
|
1998-11-12 01:06:16 +03:00
|
|
|
public:
|
|
|
|
nsXMLContentSink();
|
|
|
|
|
|
|
|
nsresult Init(nsIDocument* aDoc,
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* aURL,
|
2003-04-03 22:57:33 +04:00
|
|
|
nsISupports* aContainer,
|
2002-03-27 09:19:14 +03:00
|
|
|
nsIChannel* aChannel);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
|
|
|
// nsISupports
|
2003-10-05 11:29:50 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2008-02-09 01:07:51 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
|
|
|
|
nsContentSink)
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_DECL_NSIEXPATSINK
|
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
// nsIContentSink
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD WillParse(void) override;
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
|
|
|
NS_IMETHOD WillInterrupt(void) override;
|
|
|
|
NS_IMETHOD WillResume(void) override;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
2017-01-05 10:31:56 +03:00
|
|
|
virtual void FlushPendingNotifications(mozilla::FlushType aType) override;
|
2017-06-18 14:37:50 +03:00
|
|
|
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsISupports *GetTarget() override;
|
|
|
|
virtual bool IsScriptExecuting() override;
|
|
|
|
virtual void ContinueInterruptedParsingAsync() override;
|
1998-11-12 01:06:16 +03:00
|
|
|
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
// nsITransformObserver
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument) override;
|
|
|
|
NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) override;
|
Landing XSLT branch. Tracking bug is 155578, fixes bugs 46633, 54659, 73492, 70369, 85408, 90157, 130161, 109918, 150916 and 170097
* New scriptable interfaces to XSLT
* Make HTML-output create real html
* cleanup the XSLTProcessor class
Patch by sicking, pike and peterv
r=sicking/pike, sr=peterv, a=asa
2002-10-22 01:35:23 +04:00
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
// nsICSSLoaderObserver
|
2016-09-26 15:03:25 +03:00
|
|
|
NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheet* aSheet,
|
2014-06-20 14:32:49 +04:00
|
|
|
bool aWasAlternate,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult aStatus) override;
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ParsePIData(const nsString &aData, nsString &aHref,
|
2006-03-17 17:38:57 +03:00
|
|
|
nsString &aTitle, nsString &aMedia,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool &aIsAlternate);
|
2006-03-17 17:38:57 +03:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~nsXMLContentSink();
|
2012-01-20 15:16:27 +04:00
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
nsIParser* GetParser();
|
|
|
|
|
2012-01-20 15:16:27 +04:00
|
|
|
void ContinueInterruptedParsingIfEnabled();
|
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
// Start layout. If aIgnorePendingSheets is true, this will happen even if
|
|
|
|
// we still have stylesheet loads pending. Otherwise, we'll wait until the
|
|
|
|
// stylesheets are all done loading.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual void MaybeStartLayout(bool aIgnorePendingSheets);
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2017-12-05 20:05:51 +03:00
|
|
|
virtual nsresult AddAttributes(const char16_t** aNode, Element* aElement);
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult AddText(const char16_t* aString, int32_t aLength);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
virtual bool OnOpenContainer(const char16_t **aAtts,
|
|
|
|
uint32_t aAttsCount,
|
|
|
|
int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aTagName,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber) { return true; }
|
2004-10-01 02:27:45 +04:00
|
|
|
// Set the given content as the root element for the created document
|
|
|
|
// don't set if root element was already set.
|
|
|
|
// return TRUE if this call set the root element
|
2017-07-06 15:00:35 +03:00
|
|
|
virtual bool SetDocElement(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom *aTagName,
|
2004-10-01 02:27:45 +04:00
|
|
|
nsIContent *aContent);
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool NotifyForDocElement() { return true; }
|
2014-01-04 19:02:17 +04:00
|
|
|
virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
|
2014-06-20 06:01:40 +04:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 16:17:38 +04:00
|
|
|
mozilla::dom::FromParser aFromParser);
|
2002-12-03 02:24:57 +03:00
|
|
|
|
2005-06-02 06:38:20 +04:00
|
|
|
// aParent is allowed to be null here if this is the root content
|
|
|
|
// being closed
|
2006-11-04 08:45:02 +03:00
|
|
|
virtual nsresult CloseElement(nsIContent* aContent);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual nsresult FlushText(bool aReleaseTextNode = true);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
nsresult AddContentAsLeaf(nsIContent *aContent);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
1998-11-12 01:06:16 +03:00
|
|
|
nsIContent* GetCurrentContent();
|
2010-10-05 05:25:44 +04:00
|
|
|
StackNode* GetCurrentStackNode();
|
2007-01-31 00:21:06 +03:00
|
|
|
nsresult PushContent(nsIContent *aContent);
|
|
|
|
void PopContent();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HaveNotifiedForCurrentContent() const;
|
1998-11-12 01:06:16 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult FlushTags() override;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void UpdateChildCounts() override;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
|
|
|
void DidAddContent()
|
|
|
|
{
|
2017-11-03 18:58:59 +03:00
|
|
|
if (!mXSLTProcessor && IsTimeToNotify()) {
|
2017-07-06 15:00:35 +03:00
|
|
|
FlushTags();
|
2007-01-31 00:21:06 +03:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2003-10-05 11:29:50 +04:00
|
|
|
// nsContentSink override
|
|
|
|
virtual nsresult ProcessStyleLink(nsIContent* aElement,
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& aHref,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aAlternate,
|
2017-06-20 12:19:52 +03:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aType,
|
2017-08-15 07:05:00 +03:00
|
|
|
const nsAString& aMedia,
|
|
|
|
const nsAString& aReferrerPolicy) override;
|
1999-06-28 18:17:30 +04:00
|
|
|
|
2001-11-02 13:13:05 +03:00
|
|
|
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CanStillPrettyPrint();
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2002-10-09 11:03:15 +04:00
|
|
|
nsresult MaybePrettyPrint();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
bool IsMonolithicContainer(mozilla::dom::NodeInfo* aNodeInfo);
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts,
|
2014-05-30 11:36:53 +04:00
|
|
|
uint32_t aAttsCount, uint32_t aLineNumber,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInterruptable);
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult HandleEndElement(const char16_t *aName, bool aInterruptable);
|
|
|
|
nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aInterruptable);
|
2007-06-11 14:15:17 +04:00
|
|
|
|
2012-11-12 21:43:02 +04:00
|
|
|
nsCOMPtr<nsIContent> mDocElement;
|
2007-07-11 07:42:11 +04:00
|
|
|
nsCOMPtr<nsIContent> mCurrentHead; // When set, we're in an XHTML <haed>
|
1998-11-12 01:06:16 +03:00
|
|
|
|
|
|
|
XMLContentSinkState mState;
|
|
|
|
|
2015-10-12 20:07:51 +03:00
|
|
|
// The length of the valid data in mText.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mTextLength;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mNotifyLevel;
|
2008-10-16 01:29:35 +04:00
|
|
|
nsCOMPtr<nsIContent> mLastTextNode;
|
2007-01-31 00:21:06 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mPrettyPrintXML : 1;
|
|
|
|
uint8_t mPrettyPrintHasSpecialRoot : 1;
|
|
|
|
uint8_t mPrettyPrintHasFactoredElements : 1;
|
|
|
|
uint8_t mPrettyPrinting : 1; // True if we called PrettyPrint() and it
|
2007-05-31 05:42:48 +04:00
|
|
|
// decided we should in fact prettyprint.
|
2012-06-20 11:05:39 +04:00
|
|
|
// True to call prevent script execution in the fragment mode.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mPreventScriptExecution : 1;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
nsTArray<StackNode> mContentStack;
|
|
|
|
|
2003-07-03 09:34:26 +04:00
|
|
|
nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;
|
2015-10-12 20:07:51 +03:00
|
|
|
|
2017-11-03 18:58:59 +03:00
|
|
|
// Holds the children in the prolog until the root element is added, after which they're
|
|
|
|
// inserted in the document. However, if we're doing an XSLT transform this will
|
|
|
|
// actually hold all the children of the source document, until the transform is
|
|
|
|
// finished. After the transform is finished we'll just discard the children.
|
|
|
|
nsTArray<nsCOMPtr<nsIContent>> mDocumentChildren;
|
|
|
|
|
2015-10-12 20:07:51 +03:00
|
|
|
static const int NS_ACCUMULATION_BUFFER_SIZE = 4096;
|
|
|
|
// Our currently accumulated text that we have not flushed to a textnode yet.
|
|
|
|
char16_t mText[NS_ACCUMULATION_BUFFER_SIZE];
|
1998-11-12 01:06:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXMLContentSink_h__
|