Bug 1428745 - Remove support for version parameter from script loader, r=jonco

This commit is contained in:
Andrea Marchesini 2018-01-09 17:00:49 +01:00
Родитель 7755d675bb
Коммит 9d1d1b1ff3
7 изменённых файлов: 11 добавлений и 102 удалений

Просмотреть файл

@ -29,7 +29,6 @@ NS_IMPL_RELEASE_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
nsIScriptElement* aElement,
ValidJSVersion aValidJSVersion,
CORSMode aCORSMode,
const SRIMetadata& aIntegrity,
nsIURI* aReferrer,
@ -38,7 +37,6 @@ ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
: ScriptLoadRequest(ScriptKind::eModule,
aURI,
aElement,
aValidJSVersion,
aCORSMode,
aIntegrity,
aReferrer,
@ -55,7 +53,6 @@ ModuleLoadRequest::ModuleLoadRequest(nsIURI* aURI,
: ScriptLoadRequest(ScriptKind::eModule,
aURI,
aParent->mElement,
aParent->mValidJSVersion,
aParent->mCORSMode,
SRIMetadata(),
aParent->mURI,

Просмотреть файл

@ -45,7 +45,6 @@ public:
// Create a top-level module load request.
ModuleLoadRequest(nsIURI* aURI,
nsIScriptElement* aElement,
ValidJSVersion aValidJSVersion,
CORSMode aCORSMode,
const SRIMetadata& aIntegrity,
nsIURI* aReferrer,

Просмотреть файл

@ -41,7 +41,6 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind,
nsIURI* aURI,
nsIScriptElement* aElement,
ValidJSVersion aValidJSVersion,
mozilla::CORSMode aCORSMode,
const SRIMetadata& aIntegrity,
nsIURI* aReferrer,
@ -65,7 +64,6 @@ ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind,
, mScriptText()
, mScriptBytecode()
, mBytecodeOffset(0)
, mValidJSVersion(aValidJSVersion)
, mURI(aURI)
, mLineNo(1)
, mCORSMode(aCORSMode)

Просмотреть файл

@ -29,11 +29,6 @@ enum class ScriptKind {
eModule
};
enum class ValidJSVersion : bool {
eInvalid,
eValid
};
/*
* A class that handles loading and evaluation of <script> elements.
*/
@ -54,7 +49,6 @@ public:
ScriptLoadRequest(ScriptKind aKind,
nsIURI* aURI,
nsIScriptElement* aElement,
ValidJSVersion aValidJSVersion,
mozilla::CORSMode aCORSMode,
const SRIMetadata &aIntegrity,
nsIURI* aReferrer,
@ -217,7 +211,6 @@ public:
mozilla::Vector<uint8_t> mScriptBytecode;
uint32_t mBytecodeOffset; // Offset of the bytecode in mScriptBytecode
ValidJSVersion mValidJSVersion;
const nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> mOriginPrincipal;

Просмотреть файл

@ -1059,12 +1059,11 @@ ScriptLoader::StartLoad(ScriptLoadRequest* aRequest)
NS_ENSURE_SUCCESS(rv, rv);
// To avoid decoding issues, the JSVersion is explicitly guarded here, and the
// build-id is part of the JSBytecodeMimeType constant.
// To avoid decoding issues, the build-id is part of the JSBytecodeMimeType
// constant.
aRequest->mCacheInfo = nullptr;
nsCOMPtr<nsICacheInfoChannel> cic(do_QueryInterface(channel));
if (cic && nsContentUtils::IsBytecodeCacheEnabled() &&
aRequest->mValidJSVersion == ValidJSVersion::eValid) {
if (cic && nsContentUtils::IsBytecodeCacheEnabled()) {
if (!aRequest->IsLoadingSource()) {
// Inform the HTTP cache that we prefer to have information coming from the
// bytecode cache instead of the sources, if such entry is already registered.
@ -1174,63 +1173,6 @@ ScriptLoader::PreloadURIComparator::Equals(const PreloadInfo& aPi,
same;
}
/**
* Returns ValidJSVersion::eValid if aVersionStr is a string of the form '1.n',
* n = 0, ..., 8, and ValidJSVersion::eInvalid for other strings.
*/
static ValidJSVersion
ParseJavascriptVersion(const nsAString& aVersionStr)
{
if (aVersionStr.Length() != 3 || aVersionStr[0] != '1' ||
aVersionStr[1] != '.') {
return ValidJSVersion::eInvalid;
}
if ('0' <= aVersionStr[2] && aVersionStr[2] <= '8') {
return ValidJSVersion::eValid;
}
return ValidJSVersion::eInvalid;
}
static inline bool
ParseTypeAttribute(const nsAString& aType, ValidJSVersion* aVersion)
{
MOZ_ASSERT(!aType.IsEmpty());
MOZ_ASSERT(aVersion);
MOZ_ASSERT(*aVersion == ValidJSVersion::eValid);
nsContentTypeParser parser(aType);
nsAutoString mimeType;
nsresult rv = parser.GetType(mimeType);
NS_ENSURE_SUCCESS(rv, false);
if (!nsContentUtils::IsJavascriptMIMEType(mimeType)) {
return false;
}
// Get the version string, and ensure the language supports it.
nsAutoString versionName;
rv = parser.GetParameter("version", versionName);
if (rv == NS_ERROR_INVALID_ARG) {
Telemetry::Accumulate(Telemetry::SCRIPT_LOADED_WITH_VERSION, false);
// Argument not set.
return true;
}
if (NS_FAILED(rv)) {
return false;
}
*aVersion = ParseJavascriptVersion(versionName);
if (*aVersion == ValidJSVersion::eValid) {
Telemetry::Accumulate(Telemetry::SCRIPT_LOADED_WITH_VERSION, true);
return true;
}
return true;
}
static bool
CSPAllowsInlineScript(nsIScriptElement* aElement, nsIDocument* aDocument)
{
@ -1263,7 +1205,6 @@ ScriptLoadRequest*
ScriptLoader::CreateLoadRequest(ScriptKind aKind,
nsIURI* aURI,
nsIScriptElement* aElement,
ValidJSVersion aValidJSVersion,
CORSMode aCORSMode,
const SRIMetadata& aIntegrity,
mozilla::net::ReferrerPolicy aReferrerPolicy)
@ -1272,7 +1213,7 @@ ScriptLoader::CreateLoadRequest(ScriptKind aKind,
if (aKind == ScriptKind::eClassic) {
ScriptLoadRequest* slr = new ScriptLoadRequest(aKind, aURI, aElement,
aValidJSVersion, aCORSMode, aIntegrity,
aCORSMode, aIntegrity,
referrer, aReferrerPolicy);
LOG(("ScriptLoader %p creates ScriptLoadRequest %p", this, slr));
@ -1280,8 +1221,8 @@ ScriptLoader::CreateLoadRequest(ScriptKind aKind,
}
MOZ_ASSERT(aKind == ScriptKind::eModule);
return new ModuleLoadRequest(aURI, aElement, aValidJSVersion, aCORSMode,
aIntegrity, referrer, aReferrerPolicy, this);
return new ModuleLoadRequest(aURI, aElement, aCORSMode, aIntegrity, referrer,
aReferrerPolicy, this);
}
bool
@ -1310,13 +1251,11 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
return false;
}
ValidJSVersion validJSVersion = ValidJSVersion::eValid;
// For classic scripts, check the type attribute to determine language and
// version. If type exists, it trumps the deprecated 'language='
if (scriptKind == ScriptKind::eClassic) {
if (!type.IsEmpty()) {
NS_ENSURE_TRUE(ParseTypeAttribute(type, &validJSVersion), false);
NS_ENSURE_TRUE(nsContentUtils::IsJavascriptMIMEType(type), false);
} else if (!hasType) {
// no 'type=' element
// "language" is a deprecated attribute of HTML, so we check it only for
@ -1429,9 +1368,8 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
principal = scriptContent->NodePrincipal();
}
request = CreateLoadRequest(scriptKind, scriptURI, aElement,
validJSVersion, ourCORSMode, sriMetadata,
ourRefPolicy);
request = CreateLoadRequest(scriptKind, scriptURI, aElement, ourCORSMode,
sriMetadata, ourRefPolicy);
request->mTriggeringPrincipal = Move(principal);
request->mIsInline = false;
request->SetScriptMode(aElement->GetScriptDeferred(),
@ -1456,8 +1394,6 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
NS_ASSERTION(!request->InCompilingStage(),
"Request should not yet be in compiling stage.");
request->mValidJSVersion = validJSVersion;
if (request->IsAsyncScript()) {
AddAsyncRequest(request);
if (request->IsReadyToRun()) {
@ -1560,10 +1496,9 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
}
request = CreateLoadRequest(scriptKind, mDocument->GetDocumentURI(), aElement,
validJSVersion, corsMode,
corsMode,
SRIMetadata(), // SRI doesn't apply
ourRefPolicy);
request->mValidJSVersion = validJSVersion;
request->mIsInline = true;
request->mTriggeringPrincipal = mDocument->NodePrincipal();
request->mLineNo = aElement->GetScriptLineNumber();
@ -2192,10 +2127,6 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
return NS_ERROR_FAILURE;
}
if (aRequest->mValidJSVersion == ValidJSVersion::eInvalid) {
return NS_OK;
}
// New script entry point required, due to the "Create a script" sub-step of
// http://www.whatwg.org/specs/web-apps/current-work/#execute-the-script-block
nsAutoMicroTask mt;
@ -3210,7 +3141,7 @@ ScriptLoader::PreloadURI(nsIURI* aURI, const nsAString& aCharset,
}
RefPtr<ScriptLoadRequest> request =
CreateLoadRequest(ScriptKind::eClassic, aURI, nullptr, ValidJSVersion::eValid,
CreateLoadRequest(ScriptKind::eClassic, aURI, nullptr,
Element::StringToCORSMode(aCrossOrigin), sriMetadata,
aReferrerPolicy);
request->mTriggeringPrincipal = mDocument->NodePrincipal();

Просмотреть файл

@ -342,7 +342,6 @@ private:
ScriptLoadRequest* CreateLoadRequest(ScriptKind aKind,
nsIURI* aURI,
nsIScriptElement* aElement,
ValidJSVersion aValidJSVersion,
mozilla::CORSMode aCORSMode,
const SRIMetadata& aIntegrity,
mozilla::net::ReferrerPolicy aReferrerPolicy);

Просмотреть файл

@ -13862,14 +13862,6 @@
"description": "Amount of time in milliseconds the main thread spends waiting for the paint thread to complete, if the time was greater than 200us.",
"bug_numbers": [1386968]
},
"SCRIPT_LOADED_WITH_VERSION": {
"record_in_processes": ["main", "content"],
"alert_emails": ["amarchesini@mozilla.com"],
"bug_numbers": [1418860],
"expires_in_version": "60",
"kind": "boolean",
"description": "Tracking how often scripts are loaded with a 'valid' version parameter. This telemetry ID helps us to decide if and when remove the support of script versioning."
},
"STYLO_PARALLEL_RESTYLE_FRACTION": {
"record_in_processes": ["content"],
"alert_emails": ["manish@mozilla.com"],