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