parser/html/nsHtml5SpeculativeLoad.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.

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 nsHtml5SpeculativeLoad_h
michael@0 6 #define nsHtml5SpeculativeLoad_h
michael@0 7
michael@0 8 #include "nsString.h"
michael@0 9
michael@0 10 class nsHtml5TreeOpExecutor;
michael@0 11
michael@0 12 enum eHtml5SpeculativeLoad {
michael@0 13 #ifdef DEBUG
michael@0 14 eSpeculativeLoadUninitialized,
michael@0 15 #endif
michael@0 16 eSpeculativeLoadBase,
michael@0 17 eSpeculativeLoadImage,
michael@0 18 eSpeculativeLoadScript,
michael@0 19 eSpeculativeLoadScriptFromHead,
michael@0 20 eSpeculativeLoadStyle,
michael@0 21 eSpeculativeLoadManifest,
michael@0 22 eSpeculativeLoadSetDocumentCharset
michael@0 23 };
michael@0 24
michael@0 25 class nsHtml5SpeculativeLoad {
michael@0 26 public:
michael@0 27 nsHtml5SpeculativeLoad();
michael@0 28 ~nsHtml5SpeculativeLoad();
michael@0 29
michael@0 30 inline void InitBase(const nsAString& aUrl)
michael@0 31 {
michael@0 32 NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
michael@0 33 "Trying to reinitialize a speculative load!");
michael@0 34 mOpCode = eSpeculativeLoadBase;
michael@0 35 mUrl.Assign(aUrl);
michael@0 36 }
michael@0 37
michael@0 38 inline void InitImage(const nsAString& aUrl,
michael@0 39 const nsAString& aCrossOrigin)
michael@0 40 {
michael@0 41 NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
michael@0 42 "Trying to reinitialize a speculative load!");
michael@0 43 mOpCode = eSpeculativeLoadImage;
michael@0 44 mUrl.Assign(aUrl);
michael@0 45 mCrossOrigin.Assign(aCrossOrigin);
michael@0 46 }
michael@0 47
michael@0 48 inline void InitScript(const nsAString& aUrl,
michael@0 49 const nsAString& aCharset,
michael@0 50 const nsAString& aType,
michael@0 51 const nsAString& aCrossOrigin,
michael@0 52 bool aParserInHead)
michael@0 53 {
michael@0 54 NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
michael@0 55 "Trying to reinitialize a speculative load!");
michael@0 56 mOpCode = aParserInHead ?
michael@0 57 eSpeculativeLoadScriptFromHead : eSpeculativeLoadScript;
michael@0 58 mUrl.Assign(aUrl);
michael@0 59 mCharset.Assign(aCharset);
michael@0 60 mTypeOrCharsetSource.Assign(aType);
michael@0 61 mCrossOrigin.Assign(aCrossOrigin);
michael@0 62 }
michael@0 63
michael@0 64 inline void InitStyle(const nsAString& aUrl, const nsAString& aCharset,
michael@0 65 const nsAString& aCrossOrigin)
michael@0 66 {
michael@0 67 NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
michael@0 68 "Trying to reinitialize a speculative load!");
michael@0 69 mOpCode = eSpeculativeLoadStyle;
michael@0 70 mUrl.Assign(aUrl);
michael@0 71 mCharset.Assign(aCharset);
michael@0 72 mCrossOrigin.Assign(aCrossOrigin);
michael@0 73 }
michael@0 74
michael@0 75 /**
michael@0 76 * "Speculative" manifest loads aren't truly speculative--if a manifest
michael@0 77 * gets loaded, we are committed to it. There can never be a <script>
michael@0 78 * before the manifest, so the situation of having to undo a manifest due
michael@0 79 * to document.write() never arises. The reason why a parser
michael@0 80 * thread-discovered manifest gets loaded via the speculative load queue
michael@0 81 * as opposed to tree operation queue is that the manifest must get
michael@0 82 * processed before any actual speculative loads such as scripts. Thus,
michael@0 83 * manifests seen by the parser thread have to maintain the queue order
michael@0 84 * relative to true speculative loads. See bug 541079.
michael@0 85 */
michael@0 86 inline void InitManifest(const nsAString& aUrl)
michael@0 87 {
michael@0 88 NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
michael@0 89 "Trying to reinitialize a speculative load!");
michael@0 90 mOpCode = eSpeculativeLoadManifest;
michael@0 91 mUrl.Assign(aUrl);
michael@0 92 }
michael@0 93
michael@0 94 /**
michael@0 95 * "Speculative" charset setting isn't truly speculative. If the charset
michael@0 96 * is set via this operation, we are committed to it unless chardet or
michael@0 97 * a late meta cause a reload. The reason why a parser
michael@0 98 * thread-discovered charset gets communicated via the speculative load
michael@0 99 * queue as opposed to tree operation queue is that the charset change
michael@0 100 * must get processed before any actual speculative loads such as style
michael@0 101 * sheets. Thus, encoding decisions by the parser thread have to maintain
michael@0 102 * the queue order relative to true speculative loads. See bug 675499.
michael@0 103 */
michael@0 104 inline void InitSetDocumentCharset(nsACString& aCharset,
michael@0 105 int32_t aCharsetSource)
michael@0 106 {
michael@0 107 NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
michael@0 108 "Trying to reinitialize a speculative load!");
michael@0 109 mOpCode = eSpeculativeLoadSetDocumentCharset;
michael@0 110 CopyUTF8toUTF16(aCharset, mCharset);
michael@0 111 mTypeOrCharsetSource.Assign((char16_t)aCharsetSource);
michael@0 112 }
michael@0 113
michael@0 114 void Perform(nsHtml5TreeOpExecutor* aExecutor);
michael@0 115
michael@0 116 private:
michael@0 117 eHtml5SpeculativeLoad mOpCode;
michael@0 118 nsString mUrl;
michael@0 119 /**
michael@0 120 * If mOpCode is eSpeculativeLoadStyle or eSpeculativeLoadScript[FromHead]
michael@0 121 * then this is the value of the "charset" attribute. For
michael@0 122 * eSpeculativeLoadSetDocumentCharset it is the charset that the
michael@0 123 * document's charset is being set to. Otherwise it's empty.
michael@0 124 */
michael@0 125 nsString mCharset;
michael@0 126 /**
michael@0 127 * If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
michael@0 128 * one-character string whose single character's code point is to be
michael@0 129 * interpreted as a charset source integer. Otherwise, it is empty or
michael@0 130 * the value of the type attribute.
michael@0 131 */
michael@0 132 nsString mTypeOrCharsetSource;
michael@0 133 /**
michael@0 134 * If mOpCode is eSpeculativeLoadImage or eSpeculativeLoadScript[FromHead],
michael@0 135 * this is the value of the "crossorigin" attribute. If the
michael@0 136 * attribute is not set, this will be a void string.
michael@0 137 */
michael@0 138 nsString mCrossOrigin;
michael@0 139 };
michael@0 140
michael@0 141 #endif // nsHtml5SpeculativeLoad_h

mercurial