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