2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsXMLContentSink_h__
|
|
|
|
#define nsXMLContentSink_h__
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsContentSink.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsIExpatSink.h"
|
|
|
|
#include "nsIDocumentTransformer.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCRT.h"
|
2008-02-08 14:07:51 -08:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2009-06-23 14:22:16 -07:00
|
|
|
#include "nsIDTD.h"
|
2010-10-25 05:17:38 -07:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIDocument;
|
|
|
|
class nsIURI;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIParser;
|
2013-01-04 19:12:24 -08:00
|
|
|
class nsViewManager;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class NodeInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef enum {
|
|
|
|
eXMLContentSinkState_InProlog,
|
|
|
|
eXMLContentSinkState_InDocumentElement,
|
|
|
|
eXMLContentSinkState_InEpilog
|
|
|
|
} XMLContentSinkState;
|
|
|
|
|
|
|
|
struct StackNode {
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mNumFlushed;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsXMLContentSink : public nsContentSink,
|
|
|
|
public nsIXMLContentSink,
|
|
|
|
public nsITransformObserver,
|
|
|
|
public nsIExpatSink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsXMLContentSink();
|
|
|
|
|
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
|
|
|
nsresult Init(nsIDocument* aDoc,
|
|
|
|
nsIURI* aURL,
|
|
|
|
nsISupports* aContainer,
|
|
|
|
nsIChannel* aChannel);
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2008-02-08 14:07:51 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
|
|
|
|
nsContentSink)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIEXPATSINK
|
|
|
|
|
|
|
|
// nsIContentSink
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD WillParse(void) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD WillResume(void) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE;
|
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE;
|
|
|
|
virtual nsISupports *GetTarget() MOZ_OVERRIDE;
|
|
|
|
virtual bool IsScriptExecuting() MOZ_OVERRIDE;
|
|
|
|
virtual void ContinueInterruptedParsingAsync() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsITransformObserver
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-30 18:42:48 -07:00
|
|
|
// nsICSSLoaderObserver
|
2014-06-20 03:32:49 -07:00
|
|
|
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet,
|
|
|
|
bool aWasAlternate,
|
2013-05-29 13:43:41 -07:00
|
|
|
nsresult aStatus) MOZ_OVERRIDE;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ParsePIData(const nsString &aData, nsString &aHref,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsString &aTitle, nsString &aMedia,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool &aIsAlternate);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2014-07-08 14:23:16 -07:00
|
|
|
virtual ~nsXMLContentSink();
|
2012-01-20 03:16:27 -08:00
|
|
|
|
2012-01-20 03:16:27 -08:00
|
|
|
nsIParser* GetParser();
|
|
|
|
|
2012-01-20 03:16:27 -08:00
|
|
|
void ContinueInterruptedParsingIfEnabled();
|
|
|
|
|
2007-04-20 15:59:18 -07: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-28 23:19:26 -07:00
|
|
|
virtual void MaybeStartLayout(bool aIgnorePendingSheets);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
virtual nsresult AddAttributes(const char16_t** aNode, nsIContent* aContent);
|
|
|
|
nsresult AddText(const char16_t* aString, int32_t aLength);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
virtual bool OnOpenContainer(const char16_t **aAtts,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aTagName,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber) { return true; }
|
2007-03-22 10:30:00 -07: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
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool SetDocElement(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *aTagName,
|
|
|
|
nsIContent *aContent);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool NotifyForDocElement() { return true; }
|
2014-01-04 07:02:17 -08:00
|
|
|
virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
|
2014-06-19 19:01:40 -07:00
|
|
|
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIContent** aResult, bool* aAppendContent,
|
2010-10-25 05:17:38 -07:00
|
|
|
mozilla::dom::FromParser aFromParser);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// aParent is allowed to be null here if this is the root content
|
|
|
|
// being closed
|
|
|
|
virtual nsresult CloseElement(nsIContent* aContent);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual nsresult FlushText(bool aReleaseTextNode = true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult AddContentAsLeaf(nsIContent *aContent);
|
|
|
|
|
|
|
|
nsIContent* GetCurrentContent();
|
2010-10-04 18:25:44 -07:00
|
|
|
StackNode* GetCurrentStackNode();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult PushContent(nsIContent *aContent);
|
|
|
|
void PopContent();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HaveNotifiedForCurrentContent() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
nsresult FlushTags() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
void UpdateChildCounts() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void DidAddContent()
|
|
|
|
{
|
|
|
|
if (IsTimeToNotify()) {
|
|
|
|
FlushTags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsContentSink override
|
|
|
|
virtual nsresult ProcessStyleLink(nsIContent* aElement,
|
|
|
|
const nsSubstring& aHref,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAlternate,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aType,
|
2013-05-29 13:43:41 -07:00
|
|
|
const nsSubstring& aMedia) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult LoadXSLStyleSheet(nsIURI* aUrl);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CanStillPrettyPrint();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult MaybePrettyPrint();
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
bool IsMonolithicContainer(mozilla::dom::NodeInfo* aNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts,
|
2014-05-30 00:36:53 -07:00
|
|
|
uint32_t aAttsCount, uint32_t aLineNumber,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aInterruptable);
|
2014-01-04 07:02:17 -08:00
|
|
|
nsresult HandleEndElement(const char16_t *aName, bool aInterruptable);
|
|
|
|
nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aInterruptable);
|
2007-06-11 03:15:17 -07:00
|
|
|
|
2012-11-12 09:43:02 -08:00
|
|
|
nsCOMPtr<nsIContent> mDocElement;
|
2007-07-10 20:42:11 -07:00
|
|
|
nsCOMPtr<nsIContent> mCurrentHead; // When set, we're in an XHTML <haed>
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t* mText;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
XMLContentSinkState mState;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mTextLength;
|
|
|
|
int32_t mTextSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mNotifyLevel;
|
2008-10-15 14:29:35 -07:00
|
|
|
nsCOMPtr<nsIContent> mLastTextNode;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mLastTextNodeSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mConstrainSize : 1;
|
|
|
|
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-30 18:42:48 -07:00
|
|
|
// decided we should in fact prettyprint.
|
2012-06-20 00:05:39 -07:00
|
|
|
// True to call prevent script execution in the fragment mode.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mPreventScriptExecution : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTArray<StackNode> mContentStack;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXMLContentSink_h__
|