parser/html/nsHtml5TreeOpExecutor.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5TreeOpExecutor.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,270 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef nsHtml5TreeOpExecutor_h
     1.9 +#define nsHtml5TreeOpExecutor_h
    1.10 +
    1.11 +#include "nsIAtom.h"
    1.12 +#include "nsIContent.h"
    1.13 +#include "nsIDocument.h"
    1.14 +#include "nsTraceRefcnt.h"
    1.15 +#include "nsHtml5TreeOperation.h"
    1.16 +#include "nsHtml5SpeculativeLoad.h"
    1.17 +#include "nsTArray.h"
    1.18 +#include "nsContentSink.h"
    1.19 +#include "nsNodeInfoManager.h"
    1.20 +#include "nsHtml5DocumentMode.h"
    1.21 +#include "nsIScriptElement.h"
    1.22 +#include "nsIParser.h"
    1.23 +#include "nsAHtml5TreeOpSink.h"
    1.24 +#include "nsHtml5TreeOpStage.h"
    1.25 +#include "nsIURI.h"
    1.26 +#include "nsTHashtable.h"
    1.27 +#include "nsHashKeys.h"
    1.28 +#include "mozilla/LinkedList.h"
    1.29 +#include "nsHtml5DocumentBuilder.h"
    1.30 +
    1.31 +class nsHtml5Parser;
    1.32 +class nsHtml5TreeBuilder;
    1.33 +class nsHtml5Tokenizer;
    1.34 +class nsHtml5StreamParser;
    1.35 +
    1.36 +class nsHtml5TreeOpExecutor : public nsHtml5DocumentBuilder,
    1.37 +                              public nsIContentSink,
    1.38 +                              public nsAHtml5TreeOpSink,
    1.39 +                              public mozilla::LinkedListElement<nsHtml5TreeOpExecutor>
    1.40 +{
    1.41 +  friend class nsHtml5FlushLoopGuard;
    1.42 +
    1.43 +  public:
    1.44 +    NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
    1.45 +    NS_DECL_ISUPPORTS_INHERITED
    1.46 +
    1.47 +  private:
    1.48 +    static bool        sExternalViewSource;
    1.49 +#ifdef DEBUG_NS_HTML5_TREE_OP_EXECUTOR_FLUSH
    1.50 +    static uint32_t    sAppendBatchMaxSize;
    1.51 +    static uint32_t    sAppendBatchSlotsExamined;
    1.52 +    static uint32_t    sAppendBatchExaminations;
    1.53 +    static uint32_t    sLongestTimeOffTheEventLoop;
    1.54 +    static uint32_t    sTimesFlushLoopInterrupted;
    1.55 +#endif
    1.56 +
    1.57 +    /**
    1.58 +     * Whether EOF needs to be suppressed
    1.59 +     */
    1.60 +    bool                                 mSuppressEOF;
    1.61 +    
    1.62 +    bool                                 mReadingFromStage;
    1.63 +    nsTArray<nsHtml5TreeOperation>       mOpQueue;
    1.64 +    nsHtml5StreamParser*                 mStreamParser;
    1.65 +    
    1.66 +    /**
    1.67 +     * URLs already preloaded/preloading.
    1.68 +     */
    1.69 +    nsTHashtable<nsCStringHashKey> mPreloadedURLs;
    1.70 +
    1.71 +    nsCOMPtr<nsIURI> mSpeculationBaseURI;
    1.72 +
    1.73 +    nsCOMPtr<nsIURI> mViewSourceBaseURI;
    1.74 +
    1.75 +    /**
    1.76 +     * Whether the parser has started
    1.77 +     */
    1.78 +    bool                          mStarted;
    1.79 +
    1.80 +    nsHtml5TreeOpStage            mStage;
    1.81 +
    1.82 +    bool                          mRunFlushLoopOnStack;
    1.83 +
    1.84 +    bool                          mCallContinueInterruptedParsingIfEnabled;
    1.85 +
    1.86 +    /**
    1.87 +     * Whether this executor has already complained about matters related
    1.88 +     * to character encoding declarations.
    1.89 +     */
    1.90 +    bool                          mAlreadyComplainedAboutCharset;
    1.91 +
    1.92 +  public:
    1.93 +  
    1.94 +    nsHtml5TreeOpExecutor();
    1.95 +    virtual ~nsHtml5TreeOpExecutor();
    1.96 +  
    1.97 +    // nsIContentSink
    1.98 +
    1.99 +    /**
   1.100 +     * Unimplemented. For interface compat only.
   1.101 +     */
   1.102 +    NS_IMETHOD WillParse();
   1.103 +
   1.104 +    /**
   1.105 +     * 
   1.106 +     */
   1.107 +    NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
   1.108 +
   1.109 +    /**
   1.110 +     * Emits EOF.
   1.111 +     */
   1.112 +    NS_IMETHOD DidBuildModel(bool aTerminated);
   1.113 +
   1.114 +    /**
   1.115 +     * Forwards to nsContentSink
   1.116 +     */
   1.117 +    NS_IMETHOD WillInterrupt();
   1.118 +
   1.119 +    /**
   1.120 +     * Unimplemented. For interface compat only.
   1.121 +     */
   1.122 +    NS_IMETHOD WillResume();
   1.123 +
   1.124 +    /**
   1.125 +     * Sets the parser.
   1.126 +     */
   1.127 +    NS_IMETHOD SetParser(nsParserBase* aParser);
   1.128 +
   1.129 +    /**
   1.130 +     * No-op for backwards compat.
   1.131 +     */
   1.132 +    virtual void FlushPendingNotifications(mozFlushType aType);
   1.133 +
   1.134 +    /**
   1.135 +     * Don't call. For interface compat only.
   1.136 +     */
   1.137 +    NS_IMETHOD SetDocumentCharset(nsACString& aCharset) {
   1.138 +    	NS_NOTREACHED("No one should call this.");
   1.139 +    	return NS_ERROR_NOT_IMPLEMENTED;
   1.140 +    }
   1.141 +
   1.142 +    /**
   1.143 +     * Returns the document.
   1.144 +     */
   1.145 +    virtual nsISupports *GetTarget();
   1.146 +  
   1.147 +    virtual void ContinueInterruptedParsingAsync();
   1.148 + 
   1.149 +    // XXX Does anyone need this?
   1.150 +    nsIDocShell* GetDocShell()
   1.151 +    {
   1.152 +      return mDocShell;
   1.153 +    }
   1.154 +
   1.155 +    bool IsScriptExecuting()
   1.156 +    {
   1.157 +      return IsScriptExecutingImpl();
   1.158 +    }
   1.159 +
   1.160 +    // Not from interface
   1.161 +
   1.162 +    void SetStreamParser(nsHtml5StreamParser* aStreamParser)
   1.163 +    {
   1.164 +      mStreamParser = aStreamParser;
   1.165 +    }
   1.166 +    
   1.167 +    void InitializeDocWriteParserState(nsAHtml5TreeBuilderState* aState, int32_t aLine);
   1.168 +
   1.169 +    bool IsScriptEnabled();
   1.170 +
   1.171 +    virtual nsresult MarkAsBroken(nsresult aReason);
   1.172 +
   1.173 +    void StartLayout();
   1.174 +    
   1.175 +    void FlushSpeculativeLoads();
   1.176 +                  
   1.177 +    void RunFlushLoop();
   1.178 +
   1.179 +    nsresult FlushDocumentWrite();
   1.180 +
   1.181 +    void MaybeSuspend();
   1.182 +
   1.183 +    void Start();
   1.184 +
   1.185 +    void NeedsCharsetSwitchTo(const char* aEncoding,
   1.186 +                              int32_t aSource,
   1.187 +                              uint32_t aLineNumber);
   1.188 +
   1.189 +    void MaybeComplainAboutCharset(const char* aMsgId,
   1.190 +                                   bool aError,
   1.191 +                                   uint32_t aLineNumber);
   1.192 +
   1.193 +    void ComplainAboutBogusProtocolCharset(nsIDocument* aDoc);
   1.194 +
   1.195 +    bool IsComplete()
   1.196 +    {
   1.197 +      return !mParser;
   1.198 +    }
   1.199 +    
   1.200 +    bool HasStarted()
   1.201 +    {
   1.202 +      return mStarted;
   1.203 +    }
   1.204 +    
   1.205 +    bool IsFlushing()
   1.206 +    {
   1.207 +      return mFlushState >= eInFlush;
   1.208 +    }
   1.209 +
   1.210 +#ifdef DEBUG
   1.211 +    bool IsInFlushLoop()
   1.212 +    {
   1.213 +      return mRunFlushLoopOnStack;
   1.214 +    }
   1.215 +#endif
   1.216 +    
   1.217 +    void RunScript(nsIContent* aScriptElement);
   1.218 +    
   1.219 +    /**
   1.220 +     * Flush the operations from the tree operations from the argument
   1.221 +     * queue unconditionally. (This is for the main thread case.)
   1.222 +     */
   1.223 +    virtual void MoveOpsFrom(nsTArray<nsHtml5TreeOperation>& aOpQueue);
   1.224 +    
   1.225 +    nsHtml5TreeOpStage* GetStage()
   1.226 +    {
   1.227 +      return &mStage;
   1.228 +    }
   1.229 +    
   1.230 +    void StartReadingFromStage()
   1.231 +    {
   1.232 +      mReadingFromStage = true;
   1.233 +    }
   1.234 +
   1.235 +    void StreamEnded();
   1.236 +    
   1.237 +#ifdef DEBUG
   1.238 +    void AssertStageEmpty()
   1.239 +    {
   1.240 +      mStage.AssertEmpty();
   1.241 +    }
   1.242 +#endif
   1.243 +
   1.244 +    nsIURI* GetViewSourceBaseURI();
   1.245 +
   1.246 +    void PreloadScript(const nsAString& aURL,
   1.247 +                       const nsAString& aCharset,
   1.248 +                       const nsAString& aType,
   1.249 +                       const nsAString& aCrossOrigin,
   1.250 +                       bool aScriptFromHead);
   1.251 +
   1.252 +    void PreloadStyle(const nsAString& aURL, const nsAString& aCharset,
   1.253 +		      const nsAString& aCrossOrigin);
   1.254 +
   1.255 +    void PreloadImage(const nsAString& aURL, const nsAString& aCrossOrigin);
   1.256 +
   1.257 +    void SetSpeculationBase(const nsAString& aURL);
   1.258 +
   1.259 +    static void InitializeStatics();
   1.260 +
   1.261 +  private:
   1.262 +    nsHtml5Parser* GetParser();
   1.263 +
   1.264 +    bool IsExternalViewSource();
   1.265 +
   1.266 +    /**
   1.267 +     * Get a nsIURI for an nsString if the URL hasn't been preloaded yet.
   1.268 +     */
   1.269 +    already_AddRefed<nsIURI> ConvertIfNotPreloadedYet(const nsAString& aURL);
   1.270 +
   1.271 +};
   1.272 +
   1.273 +#endif // nsHtml5TreeOpExecutor_h

mercurial