mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 247996 - Add JS console warnings for every script element with an src that fails to load/execute it. r=bzbarsky
MozReview-Commit-ID: 4fH6UFqUhfY
This commit is contained in:
parent
d48350696a
commit
0d9b07ec14
@ -1575,6 +1575,24 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||
|
||||
rv = StartLoad(request);
|
||||
if (NS_FAILED(rv)) {
|
||||
const char* message = "ScriptSourceLoadFailed";
|
||||
|
||||
if (rv == NS_ERROR_MALFORMED_URI) {
|
||||
message = "ScriptSourceMalformed";
|
||||
}
|
||||
else if (rv == NS_ERROR_DOM_BAD_URI) {
|
||||
message = "ScriptSourceNotAllowed";
|
||||
}
|
||||
|
||||
NS_ConvertUTF8toUTF16 url(scriptURI->GetSpecOrDefault());
|
||||
const char16_t* params[] = { url.get() };
|
||||
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
NS_LITERAL_CSTRING("Script Loader"), mDocument,
|
||||
nsContentUtils::eDOM_PROPERTIES, message,
|
||||
params, ArrayLength(params), nullptr,
|
||||
EmptyString(), aElement->GetScriptLineNumber());
|
||||
|
||||
// Asynchronously report the load failure
|
||||
NS_DispatchToCurrentThread(
|
||||
NewRunnableMethod(aElement,
|
||||
@ -2548,11 +2566,31 @@ nsScriptLoader::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
bool sriOk = NS_SUCCEEDED(rv);
|
||||
|
||||
if (sriOk) {
|
||||
rv = PrepareLoadedRequest(aRequest, aLoader, aChannelStatus);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
if (sriOk && aRequest->mElement) {
|
||||
|
||||
uint32_t lineNo = aRequest->mElement->GetScriptLineNumber();
|
||||
|
||||
nsAutoString url;
|
||||
if (aRequest->mURI) {
|
||||
AppendUTF8toUTF16(aRequest->mURI->GetSpecOrDefault(), url);
|
||||
}
|
||||
|
||||
const char16_t* params[] = { url.get() };
|
||||
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
NS_LITERAL_CSTRING("Script Loader"), mDocument,
|
||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceLoadFailed",
|
||||
params, ArrayLength(params), nullptr,
|
||||
EmptyString(), lineNo);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle script not loading error because source was a tracking URL.
|
||||
* We make a note of this script node by including it in a dedicated
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "nsIArray.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsDOMJSUtils.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/dom/HTMLScriptElement.h"
|
||||
#include "mozilla/dom/HTMLScriptElementBinding.h"
|
||||
@ -283,6 +284,24 @@ HTMLScriptElement::FreezeUriAsyncDefer()
|
||||
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
||||
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(mUri),
|
||||
src, OwnerDoc(), baseURI);
|
||||
|
||||
if (!mUri) {
|
||||
const char16_t* params[] = { u"src", src.get() };
|
||||
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
NS_LITERAL_CSTRING("HTML"), OwnerDoc(),
|
||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri",
|
||||
params, ArrayLength(params), nullptr,
|
||||
EmptyString(), GetScriptLineNumber());
|
||||
}
|
||||
} else {
|
||||
const char16_t* params[] = { u"src" };
|
||||
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
NS_LITERAL_CSTRING("HTML"), OwnerDoc(),
|
||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty",
|
||||
params, ArrayLength(params), nullptr,
|
||||
EmptyString(), GetScriptLineNumber());
|
||||
}
|
||||
|
||||
// At this point mUri will be null for invalid URLs.
|
||||
|
@ -325,3 +325,13 @@ LargeAllocationNonWin32=This page would be loaded in a new process due to a Larg
|
||||
URLCreateObjectURL_MediaStream=URL.createObjectURL(MediaStream) is deprecated and will be removed soon.
|
||||
# LOCALIZATION NOTE: Do not translate xml:base.
|
||||
XMLBaseAttributeWarning=Use of xml:base attribute is deprecated and will be removed soon. Please remove any use of it.
|
||||
# LOCALIZATION NOTE: Do not translate "<script>".
|
||||
ScriptSourceEmpty=‘%S’ attribute of <script> element is empty.
|
||||
# LOCALIZATION NOTE: Do not translate "<script>".
|
||||
ScriptSourceInvalidUri=‘%S’ attribute of <script> element is not a valid URI: “%S”
|
||||
# LOCALIZATION NOTE: Do not translate "<script>".
|
||||
ScriptSourceLoadFailed=Loading failed for the <script> with source “%S”.
|
||||
# LOCALIZATION NOTE: Do not translate "<script>".
|
||||
ScriptSourceMalformed=<script> source URI is malformed: “%S”.
|
||||
# LOCALIZATION NOTE: Do not translate "<script>".
|
||||
ScriptSourceNotAllowed=<script> source URI is not allowed in this document: “%S”.
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/SVGScriptElement.h"
|
||||
#include "mozilla/dom/SVGScriptElementBinding.h"
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT_CHECK_PARSER(Script)
|
||||
|
||||
@ -147,9 +148,11 @@ SVGScriptElement::FreezeUriAsyncDefer()
|
||||
mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
|
||||
// variation of this code in nsHTMLScriptElement - check if changes
|
||||
// need to be transfered when modifying
|
||||
bool isHref = false;
|
||||
nsAutoString src;
|
||||
if (mStringAttributes[HREF].IsExplicitlySet()) {
|
||||
mStringAttributes[HREF].GetAnimValue(src, this);
|
||||
isHref = true;
|
||||
} else {
|
||||
mStringAttributes[XLINK_HREF].GetAnimValue(src, this);
|
||||
}
|
||||
@ -158,6 +161,24 @@ SVGScriptElement::FreezeUriAsyncDefer()
|
||||
if (!src.IsEmpty()) {
|
||||
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
||||
NS_NewURI(getter_AddRefs(mUri), src, nullptr, baseURI);
|
||||
|
||||
if (!mUri) {
|
||||
const char16_t* params[] = { isHref ? u"href" : u"xlink:href", src.get() };
|
||||
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
NS_LITERAL_CSTRING("SVG"), OwnerDoc(),
|
||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri",
|
||||
params, ArrayLength(params), nullptr,
|
||||
EmptyString(), GetScriptLineNumber());
|
||||
}
|
||||
} else {
|
||||
const char16_t* params[] = { isHref ? u"href" : u"xlink:href" };
|
||||
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
NS_LITERAL_CSTRING("SVG"), OwnerDoc(),
|
||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty",
|
||||
params, ArrayLength(params), nullptr,
|
||||
EmptyString(), GetScriptLineNumber());
|
||||
}
|
||||
|
||||
// At this point mUri will be null for invalid URLs.
|
||||
|
Loading…
x
Reference in New Issue
Block a user