2012-05-29 19:52:43 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-12 17:08:04 +04:00
|
|
|
|
2010-02-26 12:18:38 +03:00
|
|
|
#include "nsHtml5SpeculativeLoad.h"
|
2017-09-21 07:02:05 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2018-03-16 18:26:06 +03:00
|
|
|
#include "nsHtml5TreeOpExecutor.h"
|
2009-10-12 17:08:04 +04:00
|
|
|
|
2017-12-05 00:09:15 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-02-26 12:18:38 +03:00
|
|
|
nsHtml5SpeculativeLoad::nsHtml5SpeculativeLoad()
|
2018-06-14 11:46:13 +03:00
|
|
|
: mOpCode(eSpeculativeLoadUninitialized),
|
|
|
|
mIsAsync(false),
|
2018-03-16 18:26:06 +03:00
|
|
|
mIsDefer(false),
|
2019-11-28 00:45:12 +03:00
|
|
|
mIsLinkPreload(false),
|
2018-06-14 11:46:13 +03:00
|
|
|
mEncoding(nullptr) {
|
2010-02-26 12:18:38 +03:00
|
|
|
MOZ_COUNT_CTOR(nsHtml5SpeculativeLoad);
|
2018-03-16 18:26:06 +03:00
|
|
|
new (&mCharsetOrSrcset) nsString;
|
2010-02-26 12:18:38 +03:00
|
|
|
}
|
2009-10-12 17:08:04 +04:00
|
|
|
|
2010-02-26 12:18:38 +03:00
|
|
|
nsHtml5SpeculativeLoad::~nsHtml5SpeculativeLoad() {
|
|
|
|
MOZ_COUNT_DTOR(nsHtml5SpeculativeLoad);
|
|
|
|
NS_ASSERTION(mOpCode != eSpeculativeLoadUninitialized,
|
|
|
|
"Uninitialized speculative load.");
|
2017-12-07 17:21:42 +03:00
|
|
|
if (mOpCode != eSpeculativeLoadSetDocumentCharset) {
|
|
|
|
mCharsetOrSrcset.~nsString();
|
|
|
|
}
|
2010-02-26 12:18:38 +03:00
|
|
|
}
|
2010-02-24 03:36:30 +03:00
|
|
|
|
2010-02-26 12:18:38 +03:00
|
|
|
void nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor) {
|
|
|
|
switch (mOpCode) {
|
2010-07-26 15:18:43 +04:00
|
|
|
case eSpeculativeLoadBase:
|
2017-08-17 02:33:00 +03:00
|
|
|
aExecutor->SetSpeculationBase(mUrlOrSizes);
|
2010-07-26 15:18:43 +04:00
|
|
|
break;
|
2015-11-15 06:28:51 +03:00
|
|
|
case eSpeculativeLoadCSP:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->AddSpeculationCSP(
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity);
|
2015-11-15 06:28:51 +03:00
|
|
|
break;
|
2014-11-18 16:46:29 +03:00
|
|
|
case eSpeculativeLoadMetaReferrer:
|
2019-06-06 10:23:37 +03:00
|
|
|
aExecutor->UpdateReferrerInfoFromMeta(mReferrerPolicyOrIntegrity);
|
2014-11-18 16:46:29 +03:00
|
|
|
break;
|
2010-02-26 12:18:38 +03:00
|
|
|
case eSpeculativeLoadImage:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadImage(
|
|
|
|
mUrlOrSizes, mCrossOriginOrMedia, mCharsetOrSrcset,
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mReferrerPolicyOrIntegrity);
|
2014-12-11 02:54:00 +03:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadOpenPicture:
|
|
|
|
aExecutor->PreloadOpenPicture();
|
|
|
|
break;
|
|
|
|
case eSpeculativeLoadEndPicture:
|
|
|
|
aExecutor->PreloadEndPicture();
|
|
|
|
break;
|
|
|
|
case eSpeculativeLoadPictureSource:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadPictureSource(
|
|
|
|
mCharsetOrSrcset, mUrlOrSizes,
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mCrossOriginOrMedia);
|
2010-02-26 12:18:38 +03:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadScript:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadScript(
|
|
|
|
mUrlOrSizes, mCharsetOrSrcset,
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mCrossOriginOrMedia, mReferrerPolicyOrIntegrity,
|
2019-11-28 00:45:12 +03:00
|
|
|
mScriptReferrerPolicy, false, mIsAsync, mIsDefer, false,
|
|
|
|
mIsLinkPreload);
|
2012-12-05 03:06:29 +04:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadScriptFromHead:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadScript(
|
|
|
|
mUrlOrSizes, mCharsetOrSrcset,
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mCrossOriginOrMedia, mReferrerPolicyOrIntegrity,
|
2019-11-28 00:45:12 +03:00
|
|
|
mScriptReferrerPolicy, true, mIsAsync, mIsDefer, false,
|
|
|
|
mIsLinkPreload);
|
2018-01-23 16:07:37 +03:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadNoModuleScript:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadScript(
|
|
|
|
mUrlOrSizes, mCharsetOrSrcset,
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mCrossOriginOrMedia, mReferrerPolicyOrIntegrity,
|
2019-11-28 00:45:12 +03:00
|
|
|
mScriptReferrerPolicy, false, mIsAsync, mIsDefer, true,
|
|
|
|
mIsLinkPreload);
|
2018-01-23 16:07:37 +03:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadNoModuleScriptFromHead:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadScript(
|
|
|
|
mUrlOrSizes, mCharsetOrSrcset,
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mCrossOriginOrMedia, mReferrerPolicyOrIntegrity,
|
2019-11-28 00:45:12 +03:00
|
|
|
mScriptReferrerPolicy, true, mIsAsync, mIsDefer, true,
|
|
|
|
mIsLinkPreload);
|
2010-02-26 12:18:38 +03:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadStyle:
|
2018-03-16 18:26:06 +03:00
|
|
|
aExecutor->PreloadStyle(
|
|
|
|
mUrlOrSizes, mCharsetOrSrcset, mCrossOriginOrMedia,
|
|
|
|
mReferrerPolicyOrIntegrity,
|
2019-11-28 00:45:12 +03:00
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity,
|
|
|
|
mIsLinkPreload);
|
2010-02-26 12:18:38 +03:00
|
|
|
break;
|
2018-01-23 16:07:37 +03:00
|
|
|
case eSpeculativeLoadManifest:
|
2017-08-17 02:33:00 +03:00
|
|
|
aExecutor->ProcessOfflineManifest(mUrlOrSizes);
|
2011-08-02 21:45:38 +04:00
|
|
|
break;
|
|
|
|
case eSpeculativeLoadSetDocumentCharset: {
|
2018-03-16 18:26:06 +03:00
|
|
|
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
|
|
|
|
.Length() == 1,
|
|
|
|
"Unexpected charset source string");
|
|
|
|
int32_t intSource =
|
|
|
|
(int32_t)mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
|
|
|
|
.First();
|
|
|
|
aExecutor->SetDocumentCharsetAndSource(WrapNotNull(mEncoding), intSource);
|
|
|
|
} break;
|
2016-08-25 12:20:58 +03:00
|
|
|
case eSpeculativeLoadSetDocumentMode: {
|
2018-03-16 18:26:06 +03:00
|
|
|
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
|
|
|
|
.Length() == 1,
|
|
|
|
"Unexpected document mode string");
|
|
|
|
nsHtml5DocumentMode mode =
|
|
|
|
(nsHtml5DocumentMode)
|
|
|
|
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity
|
|
|
|
.First();
|
|
|
|
aExecutor->SetDocumentMode(mode);
|
|
|
|
} break;
|
2015-05-06 03:55:18 +03:00
|
|
|
case eSpeculativeLoadPreconnect:
|
2017-08-17 02:33:00 +03:00
|
|
|
aExecutor->Preconnect(mUrlOrSizes, mCrossOriginOrMedia);
|
2015-05-06 03:55:18 +03:00
|
|
|
break;
|
2010-02-26 12:18:38 +03:00
|
|
|
default:
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Bogus speculative load.");
|
2010-02-26 12:18:38 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|