Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef nsHtml5TreeOpExecutor_h |
michael@0 | 6 | #define nsHtml5TreeOpExecutor_h |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIAtom.h" |
michael@0 | 9 | #include "nsIContent.h" |
michael@0 | 10 | #include "nsIDocument.h" |
michael@0 | 11 | #include "nsTraceRefcnt.h" |
michael@0 | 12 | #include "nsHtml5TreeOperation.h" |
michael@0 | 13 | #include "nsHtml5SpeculativeLoad.h" |
michael@0 | 14 | #include "nsTArray.h" |
michael@0 | 15 | #include "nsContentSink.h" |
michael@0 | 16 | #include "nsNodeInfoManager.h" |
michael@0 | 17 | #include "nsHtml5DocumentMode.h" |
michael@0 | 18 | #include "nsIScriptElement.h" |
michael@0 | 19 | #include "nsIParser.h" |
michael@0 | 20 | #include "nsAHtml5TreeOpSink.h" |
michael@0 | 21 | #include "nsHtml5TreeOpStage.h" |
michael@0 | 22 | #include "nsIURI.h" |
michael@0 | 23 | #include "nsTHashtable.h" |
michael@0 | 24 | #include "nsHashKeys.h" |
michael@0 | 25 | #include "mozilla/LinkedList.h" |
michael@0 | 26 | #include "nsHtml5DocumentBuilder.h" |
michael@0 | 27 | |
michael@0 | 28 | class nsHtml5Parser; |
michael@0 | 29 | class nsHtml5TreeBuilder; |
michael@0 | 30 | class nsHtml5Tokenizer; |
michael@0 | 31 | class nsHtml5StreamParser; |
michael@0 | 32 | |
michael@0 | 33 | class nsHtml5TreeOpExecutor : public nsHtml5DocumentBuilder, |
michael@0 | 34 | public nsIContentSink, |
michael@0 | 35 | public nsAHtml5TreeOpSink, |
michael@0 | 36 | public mozilla::LinkedListElement<nsHtml5TreeOpExecutor> |
michael@0 | 37 | { |
michael@0 | 38 | friend class nsHtml5FlushLoopGuard; |
michael@0 | 39 | |
michael@0 | 40 | public: |
michael@0 | 41 | NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW |
michael@0 | 42 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 43 | |
michael@0 | 44 | private: |
michael@0 | 45 | static bool sExternalViewSource; |
michael@0 | 46 | #ifdef DEBUG_NS_HTML5_TREE_OP_EXECUTOR_FLUSH |
michael@0 | 47 | static uint32_t sAppendBatchMaxSize; |
michael@0 | 48 | static uint32_t sAppendBatchSlotsExamined; |
michael@0 | 49 | static uint32_t sAppendBatchExaminations; |
michael@0 | 50 | static uint32_t sLongestTimeOffTheEventLoop; |
michael@0 | 51 | static uint32_t sTimesFlushLoopInterrupted; |
michael@0 | 52 | #endif |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Whether EOF needs to be suppressed |
michael@0 | 56 | */ |
michael@0 | 57 | bool mSuppressEOF; |
michael@0 | 58 | |
michael@0 | 59 | bool mReadingFromStage; |
michael@0 | 60 | nsTArray<nsHtml5TreeOperation> mOpQueue; |
michael@0 | 61 | nsHtml5StreamParser* mStreamParser; |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * URLs already preloaded/preloading. |
michael@0 | 65 | */ |
michael@0 | 66 | nsTHashtable<nsCStringHashKey> mPreloadedURLs; |
michael@0 | 67 | |
michael@0 | 68 | nsCOMPtr<nsIURI> mSpeculationBaseURI; |
michael@0 | 69 | |
michael@0 | 70 | nsCOMPtr<nsIURI> mViewSourceBaseURI; |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Whether the parser has started |
michael@0 | 74 | */ |
michael@0 | 75 | bool mStarted; |
michael@0 | 76 | |
michael@0 | 77 | nsHtml5TreeOpStage mStage; |
michael@0 | 78 | |
michael@0 | 79 | bool mRunFlushLoopOnStack; |
michael@0 | 80 | |
michael@0 | 81 | bool mCallContinueInterruptedParsingIfEnabled; |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Whether this executor has already complained about matters related |
michael@0 | 85 | * to character encoding declarations. |
michael@0 | 86 | */ |
michael@0 | 87 | bool mAlreadyComplainedAboutCharset; |
michael@0 | 88 | |
michael@0 | 89 | public: |
michael@0 | 90 | |
michael@0 | 91 | nsHtml5TreeOpExecutor(); |
michael@0 | 92 | virtual ~nsHtml5TreeOpExecutor(); |
michael@0 | 93 | |
michael@0 | 94 | // nsIContentSink |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * Unimplemented. For interface compat only. |
michael@0 | 98 | */ |
michael@0 | 99 | NS_IMETHOD WillParse(); |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * |
michael@0 | 103 | */ |
michael@0 | 104 | NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode); |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * Emits EOF. |
michael@0 | 108 | */ |
michael@0 | 109 | NS_IMETHOD DidBuildModel(bool aTerminated); |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Forwards to nsContentSink |
michael@0 | 113 | */ |
michael@0 | 114 | NS_IMETHOD WillInterrupt(); |
michael@0 | 115 | |
michael@0 | 116 | /** |
michael@0 | 117 | * Unimplemented. For interface compat only. |
michael@0 | 118 | */ |
michael@0 | 119 | NS_IMETHOD WillResume(); |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Sets the parser. |
michael@0 | 123 | */ |
michael@0 | 124 | NS_IMETHOD SetParser(nsParserBase* aParser); |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * No-op for backwards compat. |
michael@0 | 128 | */ |
michael@0 | 129 | virtual void FlushPendingNotifications(mozFlushType aType); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Don't call. For interface compat only. |
michael@0 | 133 | */ |
michael@0 | 134 | NS_IMETHOD SetDocumentCharset(nsACString& aCharset) { |
michael@0 | 135 | NS_NOTREACHED("No one should call this."); |
michael@0 | 136 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | /** |
michael@0 | 140 | * Returns the document. |
michael@0 | 141 | */ |
michael@0 | 142 | virtual nsISupports *GetTarget(); |
michael@0 | 143 | |
michael@0 | 144 | virtual void ContinueInterruptedParsingAsync(); |
michael@0 | 145 | |
michael@0 | 146 | // XXX Does anyone need this? |
michael@0 | 147 | nsIDocShell* GetDocShell() |
michael@0 | 148 | { |
michael@0 | 149 | return mDocShell; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | bool IsScriptExecuting() |
michael@0 | 153 | { |
michael@0 | 154 | return IsScriptExecutingImpl(); |
michael@0 | 155 | } |
michael@0 | 156 | |
michael@0 | 157 | // Not from interface |
michael@0 | 158 | |
michael@0 | 159 | void SetStreamParser(nsHtml5StreamParser* aStreamParser) |
michael@0 | 160 | { |
michael@0 | 161 | mStreamParser = aStreamParser; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | void InitializeDocWriteParserState(nsAHtml5TreeBuilderState* aState, int32_t aLine); |
michael@0 | 165 | |
michael@0 | 166 | bool IsScriptEnabled(); |
michael@0 | 167 | |
michael@0 | 168 | virtual nsresult MarkAsBroken(nsresult aReason); |
michael@0 | 169 | |
michael@0 | 170 | void StartLayout(); |
michael@0 | 171 | |
michael@0 | 172 | void FlushSpeculativeLoads(); |
michael@0 | 173 | |
michael@0 | 174 | void RunFlushLoop(); |
michael@0 | 175 | |
michael@0 | 176 | nsresult FlushDocumentWrite(); |
michael@0 | 177 | |
michael@0 | 178 | void MaybeSuspend(); |
michael@0 | 179 | |
michael@0 | 180 | void Start(); |
michael@0 | 181 | |
michael@0 | 182 | void NeedsCharsetSwitchTo(const char* aEncoding, |
michael@0 | 183 | int32_t aSource, |
michael@0 | 184 | uint32_t aLineNumber); |
michael@0 | 185 | |
michael@0 | 186 | void MaybeComplainAboutCharset(const char* aMsgId, |
michael@0 | 187 | bool aError, |
michael@0 | 188 | uint32_t aLineNumber); |
michael@0 | 189 | |
michael@0 | 190 | void ComplainAboutBogusProtocolCharset(nsIDocument* aDoc); |
michael@0 | 191 | |
michael@0 | 192 | bool IsComplete() |
michael@0 | 193 | { |
michael@0 | 194 | return !mParser; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | bool HasStarted() |
michael@0 | 198 | { |
michael@0 | 199 | return mStarted; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | bool IsFlushing() |
michael@0 | 203 | { |
michael@0 | 204 | return mFlushState >= eInFlush; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | #ifdef DEBUG |
michael@0 | 208 | bool IsInFlushLoop() |
michael@0 | 209 | { |
michael@0 | 210 | return mRunFlushLoopOnStack; |
michael@0 | 211 | } |
michael@0 | 212 | #endif |
michael@0 | 213 | |
michael@0 | 214 | void RunScript(nsIContent* aScriptElement); |
michael@0 | 215 | |
michael@0 | 216 | /** |
michael@0 | 217 | * Flush the operations from the tree operations from the argument |
michael@0 | 218 | * queue unconditionally. (This is for the main thread case.) |
michael@0 | 219 | */ |
michael@0 | 220 | virtual void MoveOpsFrom(nsTArray<nsHtml5TreeOperation>& aOpQueue); |
michael@0 | 221 | |
michael@0 | 222 | nsHtml5TreeOpStage* GetStage() |
michael@0 | 223 | { |
michael@0 | 224 | return &mStage; |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | void StartReadingFromStage() |
michael@0 | 228 | { |
michael@0 | 229 | mReadingFromStage = true; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | void StreamEnded(); |
michael@0 | 233 | |
michael@0 | 234 | #ifdef DEBUG |
michael@0 | 235 | void AssertStageEmpty() |
michael@0 | 236 | { |
michael@0 | 237 | mStage.AssertEmpty(); |
michael@0 | 238 | } |
michael@0 | 239 | #endif |
michael@0 | 240 | |
michael@0 | 241 | nsIURI* GetViewSourceBaseURI(); |
michael@0 | 242 | |
michael@0 | 243 | void PreloadScript(const nsAString& aURL, |
michael@0 | 244 | const nsAString& aCharset, |
michael@0 | 245 | const nsAString& aType, |
michael@0 | 246 | const nsAString& aCrossOrigin, |
michael@0 | 247 | bool aScriptFromHead); |
michael@0 | 248 | |
michael@0 | 249 | void PreloadStyle(const nsAString& aURL, const nsAString& aCharset, |
michael@0 | 250 | const nsAString& aCrossOrigin); |
michael@0 | 251 | |
michael@0 | 252 | void PreloadImage(const nsAString& aURL, const nsAString& aCrossOrigin); |
michael@0 | 253 | |
michael@0 | 254 | void SetSpeculationBase(const nsAString& aURL); |
michael@0 | 255 | |
michael@0 | 256 | static void InitializeStatics(); |
michael@0 | 257 | |
michael@0 | 258 | private: |
michael@0 | 259 | nsHtml5Parser* GetParser(); |
michael@0 | 260 | |
michael@0 | 261 | bool IsExternalViewSource(); |
michael@0 | 262 | |
michael@0 | 263 | /** |
michael@0 | 264 | * Get a nsIURI for an nsString if the URL hasn't been preloaded yet. |
michael@0 | 265 | */ |
michael@0 | 266 | already_AddRefed<nsIURI> ConvertIfNotPreloadedYet(const nsAString& aURL); |
michael@0 | 267 | |
michael@0 | 268 | }; |
michael@0 | 269 | |
michael@0 | 270 | #endif // nsHtml5TreeOpExecutor_h |