parser/html/nsHtml5SpeculativeLoad.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5SpeculativeLoad.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     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 nsHtml5SpeculativeLoad_h
     1.9 +#define nsHtml5SpeculativeLoad_h
    1.10 +
    1.11 +#include "nsString.h"
    1.12 +
    1.13 +class nsHtml5TreeOpExecutor;
    1.14 +
    1.15 +enum eHtml5SpeculativeLoad {
    1.16 +#ifdef DEBUG
    1.17 +  eSpeculativeLoadUninitialized,
    1.18 +#endif
    1.19 +  eSpeculativeLoadBase,
    1.20 +  eSpeculativeLoadImage,
    1.21 +  eSpeculativeLoadScript,
    1.22 +  eSpeculativeLoadScriptFromHead,
    1.23 +  eSpeculativeLoadStyle,
    1.24 +  eSpeculativeLoadManifest,
    1.25 +  eSpeculativeLoadSetDocumentCharset
    1.26 +};
    1.27 +
    1.28 +class nsHtml5SpeculativeLoad {
    1.29 +  public:
    1.30 +    nsHtml5SpeculativeLoad();
    1.31 +    ~nsHtml5SpeculativeLoad();
    1.32 +    
    1.33 +    inline void InitBase(const nsAString& aUrl)
    1.34 +    {
    1.35 +      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
    1.36 +                      "Trying to reinitialize a speculative load!");
    1.37 +      mOpCode = eSpeculativeLoadBase;
    1.38 +      mUrl.Assign(aUrl);
    1.39 +    }
    1.40 +
    1.41 +    inline void InitImage(const nsAString& aUrl,
    1.42 +                          const nsAString& aCrossOrigin)
    1.43 +    {
    1.44 +      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
    1.45 +                      "Trying to reinitialize a speculative load!");
    1.46 +      mOpCode = eSpeculativeLoadImage;
    1.47 +      mUrl.Assign(aUrl);
    1.48 +      mCrossOrigin.Assign(aCrossOrigin);
    1.49 +    }
    1.50 +
    1.51 +    inline void InitScript(const nsAString& aUrl,
    1.52 +                           const nsAString& aCharset,
    1.53 +                           const nsAString& aType,
    1.54 +                           const nsAString& aCrossOrigin,
    1.55 +                           bool aParserInHead)
    1.56 +    {
    1.57 +      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
    1.58 +                      "Trying to reinitialize a speculative load!");
    1.59 +      mOpCode = aParserInHead ?
    1.60 +          eSpeculativeLoadScriptFromHead : eSpeculativeLoadScript;
    1.61 +      mUrl.Assign(aUrl);
    1.62 +      mCharset.Assign(aCharset);
    1.63 +      mTypeOrCharsetSource.Assign(aType);
    1.64 +      mCrossOrigin.Assign(aCrossOrigin);
    1.65 +    }
    1.66 +    
    1.67 +    inline void InitStyle(const nsAString& aUrl, const nsAString& aCharset,
    1.68 +			  const nsAString& aCrossOrigin)
    1.69 +    {
    1.70 +      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
    1.71 +                      "Trying to reinitialize a speculative load!");
    1.72 +      mOpCode = eSpeculativeLoadStyle;
    1.73 +      mUrl.Assign(aUrl);
    1.74 +      mCharset.Assign(aCharset);
    1.75 +      mCrossOrigin.Assign(aCrossOrigin);
    1.76 +    }
    1.77 +
    1.78 +    /**
    1.79 +     * "Speculative" manifest loads aren't truly speculative--if a manifest
    1.80 +     * gets loaded, we are committed to it. There can never be a <script>
    1.81 +     * before the manifest, so the situation of having to undo a manifest due
    1.82 +     * to document.write() never arises. The reason why a parser
    1.83 +     * thread-discovered manifest gets loaded via the speculative load queue
    1.84 +     * as opposed to tree operation queue is that the manifest must get
    1.85 +     * processed before any actual speculative loads such as scripts. Thus,
    1.86 +     * manifests seen by the parser thread have to maintain the queue order
    1.87 +     * relative to true speculative loads. See bug 541079.
    1.88 +     */
    1.89 +    inline void InitManifest(const nsAString& aUrl)
    1.90 +    {
    1.91 +      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
    1.92 +                      "Trying to reinitialize a speculative load!");
    1.93 +      mOpCode = eSpeculativeLoadManifest;
    1.94 +      mUrl.Assign(aUrl);
    1.95 +    }
    1.96 +
    1.97 +    /**
    1.98 +     * "Speculative" charset setting isn't truly speculative. If the charset
    1.99 +     * is set via this operation, we are committed to it unless chardet or
   1.100 +     * a late meta cause a reload. The reason why a parser
   1.101 +     * thread-discovered charset gets communicated via the speculative load
   1.102 +     * queue as opposed to tree operation queue is that the charset change
   1.103 +     * must get processed before any actual speculative loads such as style
   1.104 +     * sheets. Thus, encoding decisions by the parser thread have to maintain
   1.105 +     * the queue order relative to true speculative loads. See bug 675499.
   1.106 +     */
   1.107 +    inline void InitSetDocumentCharset(nsACString& aCharset,
   1.108 +                                       int32_t aCharsetSource)
   1.109 +    {
   1.110 +      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
   1.111 +                      "Trying to reinitialize a speculative load!");
   1.112 +      mOpCode = eSpeculativeLoadSetDocumentCharset;
   1.113 +      CopyUTF8toUTF16(aCharset, mCharset);
   1.114 +      mTypeOrCharsetSource.Assign((char16_t)aCharsetSource);
   1.115 +    }
   1.116 +
   1.117 +    void Perform(nsHtml5TreeOpExecutor* aExecutor);
   1.118 +    
   1.119 +  private:
   1.120 +    eHtml5SpeculativeLoad mOpCode;
   1.121 +    nsString mUrl;
   1.122 +    /**
   1.123 +     * If mOpCode is eSpeculativeLoadStyle or eSpeculativeLoadScript[FromHead]
   1.124 +     * then this is the value of the "charset" attribute. For
   1.125 +     * eSpeculativeLoadSetDocumentCharset it is the charset that the
   1.126 +     * document's charset is being set to. Otherwise it's empty.
   1.127 +     */
   1.128 +    nsString mCharset;
   1.129 +    /**
   1.130 +     * If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
   1.131 +     * one-character string whose single character's code point is to be
   1.132 +     * interpreted as a charset source integer. Otherwise, it is empty or
   1.133 +     * the value of the type attribute.
   1.134 +     */
   1.135 +    nsString mTypeOrCharsetSource;
   1.136 +    /**
   1.137 +     * If mOpCode is eSpeculativeLoadImage or eSpeculativeLoadScript[FromHead],
   1.138 +     * this is the value of the "crossorigin" attribute.  If the
   1.139 +     * attribute is not set, this will be a void string.
   1.140 +     */
   1.141 +    nsString mCrossOrigin;
   1.142 +};
   1.143 +
   1.144 +#endif // nsHtml5SpeculativeLoad_h

mercurial