Bug 1687263: part 4) Defer and in some cases avoid removing spellchecking-ranges...
[gecko.git] / parser / html / nsHtml5SpeculativeLoad.cpp
blobceec89078769a64b8d9a23ccde17482657dcea39
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/. */
5 #include "nsHtml5SpeculativeLoad.h"
6 #include "mozilla/Encoding.h"
7 #include "nsHtml5TreeOpExecutor.h"
9 using namespace mozilla;
11 nsHtml5SpeculativeLoad::nsHtml5SpeculativeLoad()
12 : mOpCode(eSpeculativeLoadUninitialized),
13 mIsAsync(false),
14 mIsDefer(false),
15 mIsLinkPreload(false),
16 mEncoding(nullptr) {
17 MOZ_COUNT_CTOR(nsHtml5SpeculativeLoad);
18 new (&mCharsetOrSrcset) nsString;
21 nsHtml5SpeculativeLoad::~nsHtml5SpeculativeLoad() {
22 MOZ_COUNT_DTOR(nsHtml5SpeculativeLoad);
23 NS_ASSERTION(mOpCode != eSpeculativeLoadUninitialized,
24 "Uninitialized speculative load.");
25 if (mOpCode != eSpeculativeLoadSetDocumentCharset) {
26 mCharsetOrSrcset.~nsString();
30 void nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor) {
31 switch (mOpCode) {
32 case eSpeculativeLoadBase:
33 aExecutor->SetSpeculationBase(mUrlOrSizes);
34 break;
35 case eSpeculativeLoadCSP:
36 aExecutor->AddSpeculationCSP(
37 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
38 break;
39 case eSpeculativeLoadMetaReferrer:
40 aExecutor->UpdateReferrerInfoFromMeta(mReferrerPolicyOrIntegrity);
41 break;
42 case eSpeculativeLoadImage:
43 aExecutor->PreloadImage(
44 mUrlOrSizes, mCrossOrigin, mMedia, mCharsetOrSrcset,
45 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
46 mReferrerPolicyOrIntegrity, mIsLinkPreload);
47 break;
48 case eSpeculativeLoadOpenPicture:
49 aExecutor->PreloadOpenPicture();
50 break;
51 case eSpeculativeLoadEndPicture:
52 aExecutor->PreloadEndPicture();
53 break;
54 case eSpeculativeLoadPictureSource:
55 aExecutor->PreloadPictureSource(
56 mCharsetOrSrcset, mUrlOrSizes,
57 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
58 mMedia);
59 break;
60 case eSpeculativeLoadScript:
61 aExecutor->PreloadScript(
62 mUrlOrSizes, mCharsetOrSrcset,
63 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
64 mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
65 mScriptReferrerPolicy, false, mIsAsync, mIsDefer, false,
66 mIsLinkPreload);
67 break;
68 case eSpeculativeLoadScriptFromHead:
69 aExecutor->PreloadScript(
70 mUrlOrSizes, mCharsetOrSrcset,
71 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
72 mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
73 mScriptReferrerPolicy, true, mIsAsync, mIsDefer, false,
74 mIsLinkPreload);
75 break;
76 case eSpeculativeLoadNoModuleScript:
77 aExecutor->PreloadScript(
78 mUrlOrSizes, mCharsetOrSrcset,
79 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
80 mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
81 mScriptReferrerPolicy, false, mIsAsync, mIsDefer, true,
82 mIsLinkPreload);
83 break;
84 case eSpeculativeLoadNoModuleScriptFromHead:
85 aExecutor->PreloadScript(
86 mUrlOrSizes, mCharsetOrSrcset,
87 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
88 mCrossOrigin, mMedia, mReferrerPolicyOrIntegrity,
89 mScriptReferrerPolicy, true, mIsAsync, mIsDefer, true,
90 mIsLinkPreload);
91 break;
92 case eSpeculativeLoadStyle:
93 aExecutor->PreloadStyle(
94 mUrlOrSizes, mCharsetOrSrcset, mCrossOrigin, mMedia,
95 mReferrerPolicyOrIntegrity,
96 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
97 mIsLinkPreload);
98 break;
99 case eSpeculativeLoadManifest:
100 // TODO: remove this
101 break;
102 case eSpeculativeLoadSetDocumentCharset: {
103 NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
104 .Length() == 1,
105 "Unexpected charset source string");
106 int32_t intSource =
107 (int32_t)mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
108 .First();
109 aExecutor->SetDocumentCharsetAndSource(WrapNotNull(mEncoding), intSource);
110 } break;
111 case eSpeculativeLoadSetDocumentMode: {
112 NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
113 .Length() == 1,
114 "Unexpected document mode string");
115 nsHtml5DocumentMode mode =
116 (nsHtml5DocumentMode)
117 mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
118 .First();
119 aExecutor->SetDocumentMode(mode);
120 } break;
121 case eSpeculativeLoadPreconnect:
122 aExecutor->Preconnect(mUrlOrSizes, mCrossOrigin);
123 break;
124 case eSpeculativeLoadFont:
125 aExecutor->PreloadFont(mUrlOrSizes, mCrossOrigin, mMedia,
126 mReferrerPolicyOrIntegrity);
127 break;
128 case eSpeculativeLoadFetch:
129 aExecutor->PreloadFetch(mUrlOrSizes, mCrossOrigin, mMedia,
130 mReferrerPolicyOrIntegrity);
131 break;
132 default:
133 MOZ_ASSERT_UNREACHABLE("Bogus speculative load.");
134 break;