content/xml/document/src/nsXMLContentSink.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsXMLContentSink_h__
     7 #define nsXMLContentSink_h__
     9 #include "mozilla/Attributes.h"
    10 #include "nsContentSink.h"
    11 #include "nsIXMLContentSink.h"
    12 #include "nsIExpatSink.h"
    13 #include "nsIDocumentTransformer.h"
    14 #include "nsTArray.h"
    15 #include "nsCOMPtr.h"
    16 #include "nsCRT.h"
    17 #include "nsCycleCollectionParticipant.h"
    18 #include "nsIDTD.h"
    19 #include "mozilla/dom/FromParser.h"
    21 class nsIDocument;
    22 class nsIURI;
    23 class nsIContent;
    24 class nsINodeInfo;
    25 class nsIParser;
    26 class nsViewManager;
    28 typedef enum {
    29   eXMLContentSinkState_InProlog,
    30   eXMLContentSinkState_InDocumentElement,
    31   eXMLContentSinkState_InEpilog
    32 } XMLContentSinkState;
    34 struct StackNode {
    35   nsCOMPtr<nsIContent> mContent;
    36   uint32_t mNumFlushed;
    37 };
    39 class nsXMLContentSink : public nsContentSink,
    40                          public nsIXMLContentSink,
    41                          public nsITransformObserver,
    42                          public nsIExpatSink
    43 {
    44 public:
    45   nsXMLContentSink();
    46   virtual ~nsXMLContentSink();
    48   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
    50   nsresult Init(nsIDocument* aDoc,
    51                 nsIURI* aURL,
    52                 nsISupports* aContainer,
    53                 nsIChannel* aChannel);
    55   // nsISupports
    56   NS_DECL_ISUPPORTS_INHERITED
    58   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLContentSink,
    59                                                      nsContentSink)
    61   NS_DECL_NSIEXPATSINK
    63   // nsIContentSink
    64   NS_IMETHOD WillParse(void) MOZ_OVERRIDE;
    65   NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) MOZ_OVERRIDE;
    66   NS_IMETHOD DidBuildModel(bool aTerminated) MOZ_OVERRIDE;
    67   NS_IMETHOD WillInterrupt(void) MOZ_OVERRIDE;
    68   NS_IMETHOD WillResume(void) MOZ_OVERRIDE;
    69   NS_IMETHOD SetParser(nsParserBase* aParser) MOZ_OVERRIDE;
    70   virtual void FlushPendingNotifications(mozFlushType aType) MOZ_OVERRIDE;
    71   NS_IMETHOD SetDocumentCharset(nsACString& aCharset) MOZ_OVERRIDE;
    72   virtual nsISupports *GetTarget() MOZ_OVERRIDE;
    73   virtual bool IsScriptExecuting() MOZ_OVERRIDE;
    74   virtual void ContinueInterruptedParsingAsync() MOZ_OVERRIDE;
    76   // nsITransformObserver
    77   NS_IMETHOD OnDocumentCreated(nsIDocument *aResultDocument) MOZ_OVERRIDE;
    78   NS_IMETHOD OnTransformDone(nsresult aResult, nsIDocument *aResultDocument) MOZ_OVERRIDE;
    80   // nsICSSLoaderObserver
    81   NS_IMETHOD StyleSheetLoaded(nsCSSStyleSheet* aSheet, bool aWasAlternate,
    82                               nsresult aStatus) MOZ_OVERRIDE;
    83   static bool ParsePIData(const nsString &aData, nsString &aHref,
    84                           nsString &aTitle, nsString &aMedia,
    85                           bool &aIsAlternate);
    87 protected:
    89   nsIParser* GetParser();
    91   void ContinueInterruptedParsingIfEnabled();
    93   // Start layout.  If aIgnorePendingSheets is true, this will happen even if
    94   // we still have stylesheet loads pending.  Otherwise, we'll wait until the
    95   // stylesheets are all done loading.
    96   virtual void MaybeStartLayout(bool aIgnorePendingSheets);
    98   virtual nsresult AddAttributes(const char16_t** aNode, nsIContent* aContent);
    99   nsresult AddText(const char16_t* aString, int32_t aLength);
   101   virtual bool OnOpenContainer(const char16_t **aAtts, 
   102                                  uint32_t aAttsCount, 
   103                                  int32_t aNameSpaceID, 
   104                                  nsIAtom* aTagName,
   105                                  uint32_t aLineNumber) { return true; }
   106   // Set the given content as the root element for the created document
   107   //  don't set if root element was already set.
   108   //  return TRUE if this call set the root element
   109   virtual bool SetDocElement(int32_t aNameSpaceID, 
   110                                nsIAtom *aTagName,
   111                                nsIContent *aContent);
   112   virtual bool NotifyForDocElement() { return true; }
   113   virtual nsresult CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
   114                                  nsINodeInfo* aNodeInfo, uint32_t aLineNumber,
   115                                  nsIContent** aResult, bool* aAppendContent,
   116                                  mozilla::dom::FromParser aFromParser);
   118   // aParent is allowed to be null here if this is the root content
   119   // being closed
   120   virtual nsresult CloseElement(nsIContent* aContent);
   122   virtual nsresult FlushText(bool aReleaseTextNode = true);
   124   nsresult AddContentAsLeaf(nsIContent *aContent);
   126   nsIContent* GetCurrentContent();
   127   StackNode* GetCurrentStackNode();
   128   nsresult PushContent(nsIContent *aContent);
   129   void PopContent();
   130   bool HaveNotifiedForCurrentContent() const;
   132   nsresult FlushTags() MOZ_OVERRIDE;
   134   void UpdateChildCounts() MOZ_OVERRIDE;
   136   void DidAddContent()
   137   {
   138     if (IsTimeToNotify()) {
   139       FlushTags();	
   140     }
   141   }
   143   // nsContentSink override
   144   virtual nsresult ProcessStyleLink(nsIContent* aElement,
   145                                     const nsSubstring& aHref,
   146                                     bool aAlternate,
   147                                     const nsSubstring& aTitle,
   148                                     const nsSubstring& aType,
   149                                     const nsSubstring& aMedia) MOZ_OVERRIDE;
   151   nsresult LoadXSLStyleSheet(nsIURI* aUrl);
   153   bool CanStillPrettyPrint();
   155   nsresult MaybePrettyPrint();
   157   bool IsMonolithicContainer(nsINodeInfo* aNodeInfo);
   159   nsresult HandleStartElement(const char16_t *aName, const char16_t **aAtts, 
   160                               uint32_t aAttsCount, int32_t aIndex, 
   161                               uint32_t aLineNumber,
   162                               bool aInterruptable);
   163   nsresult HandleEndElement(const char16_t *aName, bool aInterruptable);
   164   nsresult HandleCharacterData(const char16_t *aData, uint32_t aLength,
   165                                bool aInterruptable);
   167   nsCOMPtr<nsIContent> mDocElement;
   168   nsCOMPtr<nsIContent> mCurrentHead;  // When set, we're in an XHTML <haed>
   169   char16_t*       mText;
   171   XMLContentSinkState mState;
   173   int32_t mTextLength;
   174   int32_t mTextSize;
   176   int32_t mNotifyLevel;
   177   nsCOMPtr<nsIContent> mLastTextNode;
   178   int32_t mLastTextNodeSize;
   180   uint8_t mConstrainSize : 1;
   181   uint8_t mPrettyPrintXML : 1;
   182   uint8_t mPrettyPrintHasSpecialRoot : 1;
   183   uint8_t mPrettyPrintHasFactoredElements : 1;
   184   uint8_t mPrettyPrinting : 1;  // True if we called PrettyPrint() and it
   185                                 // decided we should in fact prettyprint.
   186   // True to call prevent script execution in the fragment mode.
   187   uint8_t mPreventScriptExecution : 1;
   189   nsTArray<StackNode>              mContentStack;
   191   nsCOMPtr<nsIDocumentTransformer> mXSLTProcessor;
   192 };
   194 #endif // nsXMLContentSink_h__

mercurial