зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1910698 - Add a struct to represent JS caller location and more general warning source location. r=smaug,necko-reviewers,anti-tracking-reviewers,dom-storage-reviewers,pbz,kershaw,janv
Use it liberally across the tree. This could be cleaned up even more in the future. Differential Revision: https://phabricator.services.mozilla.com/D218114
This commit is contained in:
Родитель
bbe59855a6
Коммит
198c331213
|
@ -7,6 +7,7 @@
|
||||||
#include "nsScriptSecurityManager.h"
|
#include "nsScriptSecurityManager.h"
|
||||||
|
|
||||||
#include "mozilla/ArrayUtils.h"
|
#include "mozilla/ArrayUtils.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "mozilla/StaticPrefs_extensions.h"
|
#include "mozilla/StaticPrefs_extensions.h"
|
||||||
#include "mozilla/StaticPrefs_security.h"
|
#include "mozilla/StaticPrefs_security.h"
|
||||||
#include "mozilla/StoragePrincipalHelper.h"
|
#include "mozilla/StoragePrincipalHelper.h"
|
||||||
|
@ -542,18 +543,7 @@ bool nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reportViolation) {
|
if (reportViolation) {
|
||||||
JS::AutoFilename scriptFilename;
|
auto caller = JSCallingLocation::Get(cx);
|
||||||
nsAutoString fileName;
|
|
||||||
uint32_t lineNum = 0;
|
|
||||||
JS::ColumnNumberOneOrigin columnNum;
|
|
||||||
if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum, &columnNum)) {
|
|
||||||
if (const char* file = scriptFilename.get()) {
|
|
||||||
CopyUTF8toUTF16(nsDependentCString(file), fileName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
MOZ_ASSERT(!JS_IsExceptionPending(cx));
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoJSString scriptSample;
|
nsAutoJSString scriptSample;
|
||||||
if (aKind == JS::RuntimeCode::JS &&
|
if (aKind == JS::RuntimeCode::JS &&
|
||||||
NS_WARN_IF(!scriptSample.init(cx, aCode))) {
|
NS_WARN_IF(!scriptSample.init(cx, aCode))) {
|
||||||
|
@ -566,8 +556,8 @@ bool nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(
|
||||||
: nsIContentSecurityPolicy::VIOLATION_TYPE_WASM_EVAL;
|
: nsIContentSecurityPolicy::VIOLATION_TYPE_WASM_EVAL;
|
||||||
csp->LogViolationDetails(violationType,
|
csp->LogViolationDetails(violationType,
|
||||||
nullptr, // triggering element
|
nullptr, // triggering element
|
||||||
cspEventListener, fileName, scriptSample, lineNum,
|
cspEventListener, caller.FileName(), scriptSample,
|
||||||
columnNum.oneOriginValue(), u""_ns, u""_ns);
|
caller.mLine, caller.mColumn, u""_ns, u""_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
return evalOK;
|
return evalOK;
|
||||||
|
|
|
@ -3490,11 +3490,11 @@ static void WarnIfSandboxIneffective(nsIDocShell* aDocShell,
|
||||||
nsCOMPtr<Document> parentDocument = parentDocShell->GetDocument();
|
nsCOMPtr<Document> parentDocument = parentDocShell->GetDocument();
|
||||||
nsCOMPtr<nsIURI> iframeUri;
|
nsCOMPtr<nsIURI> iframeUri;
|
||||||
parentChannel->GetURI(getter_AddRefs(iframeUri));
|
parentChannel->GetURI(getter_AddRefs(iframeUri));
|
||||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
nsContentUtils::ReportToConsole(
|
||||||
"Iframe Sandbox"_ns, parentDocument,
|
nsIScriptError::warningFlag, "Iframe Sandbox"_ns, parentDocument,
|
||||||
nsContentUtils::eSECURITY_PROPERTIES,
|
nsContentUtils::eSECURITY_PROPERTIES,
|
||||||
"BothAllowScriptsAndSameOriginPresent",
|
"BothAllowScriptsAndSameOriginPresent", nsTArray<nsString>(),
|
||||||
nsTArray<nsString>(), iframeUri);
|
SourceLocation(iframeUri.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -346,9 +346,7 @@ class EventSourceImpl final : public nsIChannelEventSink,
|
||||||
// be the same as the Event Source owner window.
|
// be the same as the Event Source owner window.
|
||||||
// These attributes are used for error reporting. Should only be accessed on
|
// These attributes are used for error reporting. Should only be accessed on
|
||||||
// target thread
|
// target thread
|
||||||
nsString mScriptFile;
|
JSCallingLocation mCallingLocation;
|
||||||
uint32_t mScriptLine;
|
|
||||||
uint32_t mScriptColumn;
|
|
||||||
uint64_t mInnerWindowID;
|
uint64_t mInnerWindowID;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -389,8 +387,6 @@ EventSourceImpl::EventSourceImpl(EventSource* aEventSource,
|
||||||
mIsMainThread(NS_IsMainThread()),
|
mIsMainThread(NS_IsMainThread()),
|
||||||
mIsShutDown(false),
|
mIsShutDown(false),
|
||||||
mSharedData(SharedData{aEventSource}, "EventSourceImpl::mSharedData"),
|
mSharedData(SharedData{aEventSource}, "EventSourceImpl::mSharedData"),
|
||||||
mScriptLine(0),
|
|
||||||
mScriptColumn(1),
|
|
||||||
mInnerWindowID(0),
|
mInnerWindowID(0),
|
||||||
mCookieJarSettings(aCookieJarSettings),
|
mCookieJarSettings(aCookieJarSettings),
|
||||||
mTargetThread(NS_GetCurrentThread()) {
|
mTargetThread(NS_GetCurrentThread()) {
|
||||||
|
@ -645,8 +641,7 @@ void EventSourceImpl::Init(nsIGlobalObject* aWindowGlobal,
|
||||||
}
|
}
|
||||||
// The conditional here is historical and not necessarily sane.
|
// The conditional here is historical and not necessarily sane.
|
||||||
if (JSContext* cx = nsContentUtils::GetCurrentJSContext()) {
|
if (JSContext* cx = nsContentUtils::GetCurrentJSContext()) {
|
||||||
nsJSUtils::GetCallingLocation(cx, mScriptFile, &mScriptLine,
|
mCallingLocation = JSCallingLocation::Get();
|
||||||
&mScriptColumn);
|
|
||||||
mInnerWindowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx);
|
mInnerWindowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1296,9 +1291,10 @@ nsresult EventSourceImpl::PrintErrorOnConsole(
|
||||||
}
|
}
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
rv = errObj->InitWithWindowID(message, mScriptFile, u""_ns, mScriptLine,
|
rv = errObj->InitWithWindowID(
|
||||||
mScriptColumn, nsIScriptError::errorFlag,
|
message, NS_ConvertUTF8toUTF16(mCallingLocation.FileName()), u""_ns,
|
||||||
"Event Source", mInnerWindowID);
|
mCallingLocation.mLine, mCallingLocation.mColumn,
|
||||||
|
nsIScriptError::errorFlag, "Event Source", mInnerWindowID);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// print the error message directly to the JS console
|
// print the error message directly to the JS console
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
|
#include "nsContentUtils.h"
|
||||||
|
#include "jsapi.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
SourceLocation::SourceLocation() = default;
|
||||||
|
SourceLocation::~SourceLocation() = default;
|
||||||
|
|
||||||
|
SourceLocation::SourceLocation(nsCString&& aResource, uint32_t aLine,
|
||||||
|
uint32_t aCol, nsCString&& aSourceLine)
|
||||||
|
: mResource(std::move(aResource)),
|
||||||
|
mLine(aLine),
|
||||||
|
mColumn(aCol),
|
||||||
|
mSourceLine(std::move(aSourceLine)) {}
|
||||||
|
|
||||||
|
SourceLocation::SourceLocation(nsCOMPtr<nsIURI>&& aResource, uint32_t aLine,
|
||||||
|
uint32_t aCol, nsCString&& aSourceLine)
|
||||||
|
: mResource(std::move(aResource)),
|
||||||
|
mLine(aLine),
|
||||||
|
mColumn(aCol),
|
||||||
|
mSourceLine(std::move(aSourceLine)) {}
|
||||||
|
|
||||||
|
JSCallingLocation JSCallingLocation::Get() {
|
||||||
|
return Get(nsContentUtils::GetCurrentJSContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
JSCallingLocation JSCallingLocation::Get(JSContext* aCx) {
|
||||||
|
JSCallingLocation result;
|
||||||
|
if (!aCx) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
JS::AutoFilename filename;
|
||||||
|
uint32_t line;
|
||||||
|
JS::ColumnNumberOneOrigin column;
|
||||||
|
if (!JS::DescribeScriptedCaller(aCx, &filename, &line, &column)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
nsCString file;
|
||||||
|
if (!file.Assign(filename.get(), fallible)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result.mResource = AsVariant(std::move(file));
|
||||||
|
result.mLine = line;
|
||||||
|
result.mColumn = column.oneOriginValue();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mozilla
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#ifndef mozilla_SourceLocation_h
|
||||||
|
#define mozilla_SourceLocation_h
|
||||||
|
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "mozilla/Variant.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
struct JSContext;
|
||||||
|
class nsIURI;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
struct SourceLocation {
|
||||||
|
mozilla::Variant<nsCString, nsCOMPtr<nsIURI>> mResource{VoidCString()};
|
||||||
|
uint32_t mLine = 0;
|
||||||
|
uint32_t mColumn = 1;
|
||||||
|
nsCString mSourceLine;
|
||||||
|
|
||||||
|
SourceLocation();
|
||||||
|
explicit SourceLocation(nsCString&&, uint32_t aLine = 0, uint32_t aCol = 1,
|
||||||
|
nsCString&& aSourceLine = {});
|
||||||
|
explicit SourceLocation(nsCOMPtr<nsIURI>&&, uint32_t aLine = 0,
|
||||||
|
uint32_t aCol = 1, nsCString&& aSourceLine = {});
|
||||||
|
|
||||||
|
~SourceLocation();
|
||||||
|
|
||||||
|
bool IsEmpty() const {
|
||||||
|
return mResource.is<nsCString>() ? mResource.as<nsCString>().IsEmpty()
|
||||||
|
: !mResource.as<nsCOMPtr<nsIURI>>();
|
||||||
|
}
|
||||||
|
explicit operator bool() const { return !IsEmpty(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JSCallingLocation : SourceLocation {
|
||||||
|
const nsCString& FileName() const { return mResource.as<nsCString>(); }
|
||||||
|
|
||||||
|
static JSCallingLocation Get();
|
||||||
|
static JSCallingLocation Get(JSContext*);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/HoldDropJSObjects.h"
|
#include "mozilla/HoldDropJSObjects.h"
|
||||||
#include "nsJSUtils.h"
|
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
|
|
||||||
|
@ -16,22 +15,12 @@ namespace mozilla::dom {
|
||||||
// TimeoutHandler
|
// TimeoutHandler
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
TimeoutHandler::TimeoutHandler(JSContext* aCx) : TimeoutHandler() {
|
|
||||||
nsJSUtils::GetCallingLocation(aCx, mFileName, &mLineNo, &mColumn);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TimeoutHandler::Call(const char* /* unused */) { return false; }
|
bool TimeoutHandler::Call(const char* /* unused */) { return false; }
|
||||||
|
|
||||||
void TimeoutHandler::GetLocation(const char** aFileName, uint32_t* aLineNo,
|
|
||||||
uint32_t* aColumn) {
|
|
||||||
*aFileName = mFileName.get();
|
|
||||||
*aLineNo = mLineNo;
|
|
||||||
*aColumn = mColumn;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeoutHandler::GetDescription(nsACString& aOutString) {
|
void TimeoutHandler::GetDescription(nsACString& aOutString) {
|
||||||
aOutString.AppendPrintf("<generic handler> (%s:%d:%d)", mFileName.get(),
|
aOutString.AppendPrintf("<generic handler> (%s:%d:%d)",
|
||||||
mLineNo, mColumn);
|
mCaller.FileName().get(), mCaller.mLine,
|
||||||
|
mCaller.mColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -53,11 +42,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(ScriptTimeoutHandler)
|
||||||
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
||||||
nsAutoCString name("ScriptTimeoutHandler");
|
nsAutoCString name("ScriptTimeoutHandler");
|
||||||
name.AppendLiteral(" [");
|
name.AppendLiteral(" [");
|
||||||
name.Append(tmp->mFileName);
|
name.Append(tmp->mCaller.FileName());
|
||||||
name.Append(':');
|
name.Append(':');
|
||||||
name.AppendInt(tmp->mLineNo);
|
name.AppendInt(tmp->mCaller.mLine);
|
||||||
name.Append(':');
|
name.Append(':');
|
||||||
name.AppendInt(tmp->mColumn);
|
name.AppendInt(tmp->mCaller.mColumn);
|
||||||
name.Append(']');
|
name.Append(']');
|
||||||
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name.get());
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name.get());
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,12 +71,13 @@ void ScriptTimeoutHandler::GetDescription(nsACString& aOutString) {
|
||||||
if (mExpr.Length() > 15) {
|
if (mExpr.Length() > 15) {
|
||||||
aOutString.AppendPrintf(
|
aOutString.AppendPrintf(
|
||||||
"<string handler (truncated): \"%s...\"> (%s:%d:%d)",
|
"<string handler (truncated): \"%s...\"> (%s:%d:%d)",
|
||||||
NS_ConvertUTF16toUTF8(Substring(mExpr, 0, 13)).get(), mFileName.get(),
|
NS_ConvertUTF16toUTF8(Substring(mExpr, 0, 13)).get(),
|
||||||
mLineNo, mColumn);
|
mCaller.FileName().get(), mCaller.mLine, mCaller.mColumn);
|
||||||
} else {
|
} else {
|
||||||
aOutString.AppendPrintf("<string handler: \"%s\"> (%s:%d:%d)",
|
aOutString.AppendPrintf("<string handler: \"%s\"> (%s:%d:%d)",
|
||||||
NS_ConvertUTF16toUTF8(mExpr).get(), mFileName.get(),
|
NS_ConvertUTF16toUTF8(mExpr).get(),
|
||||||
mLineNo, mColumn);
|
mCaller.FileName().get(), mCaller.mLine,
|
||||||
|
mCaller.mColumn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "mozilla/dom/FunctionBinding.h"
|
#include "mozilla/dom/FunctionBinding.h"
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
|
@ -23,11 +24,6 @@ namespace mozilla::dom {
|
||||||
class TimeoutHandler : public nsISupports {
|
class TimeoutHandler : public nsISupports {
|
||||||
public:
|
public:
|
||||||
MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* /* unused */);
|
MOZ_CAN_RUN_SCRIPT virtual bool Call(const char* /* unused */);
|
||||||
// Get the location of the script.
|
|
||||||
// Note: The memory pointed to by aFileName is owned by the
|
|
||||||
// nsITimeoutHandler and should not be freed by the caller.
|
|
||||||
virtual void GetLocation(const char** aFileName, uint32_t* aLineNo,
|
|
||||||
uint32_t* aColumn);
|
|
||||||
// Append a UTF-8 string to aOutString that describes the callback function,
|
// Append a UTF-8 string to aOutString that describes the callback function,
|
||||||
// for use in logging or profiler markers.
|
// for use in logging or profiler markers.
|
||||||
// The string contains the function name and its source location, if
|
// The string contains the function name and its source location, if
|
||||||
|
@ -37,16 +33,15 @@ class TimeoutHandler : public nsISupports {
|
||||||
virtual void MarkForCC() {}
|
virtual void MarkForCC() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TimeoutHandler() : mFileName(""), mLineNo(0), mColumn(1) {}
|
TimeoutHandler() = default;
|
||||||
explicit TimeoutHandler(JSContext* aCx);
|
explicit TimeoutHandler(JSContext* aCx)
|
||||||
|
: mCaller(JSCallingLocation::Get(aCx)) {}
|
||||||
|
|
||||||
virtual ~TimeoutHandler() = default;
|
virtual ~TimeoutHandler() = default;
|
||||||
|
|
||||||
// filename, line number and JS language version string of the
|
// filename, line number and JS language version string of the
|
||||||
// caller of setTimeout()
|
// caller of setTimeout()
|
||||||
nsCString mFileName;
|
const JSCallingLocation mCaller;
|
||||||
uint32_t mLineNo;
|
|
||||||
uint32_t mColumn;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimeoutHandler(const TimeoutHandler&) = delete;
|
TimeoutHandler(const TimeoutHandler&) = delete;
|
||||||
|
|
|
@ -137,6 +137,7 @@ EXPORTS.mozilla += [
|
||||||
"ScriptableContentIterator.h",
|
"ScriptableContentIterator.h",
|
||||||
"ScrollingMetrics.h",
|
"ScrollingMetrics.h",
|
||||||
"SelectionChangeEventDispatcher.h",
|
"SelectionChangeEventDispatcher.h",
|
||||||
|
"SourceLocation.h",
|
||||||
"TextInputProcessor.h",
|
"TextInputProcessor.h",
|
||||||
"UseCounter.h",
|
"UseCounter.h",
|
||||||
]
|
]
|
||||||
|
@ -461,6 +462,7 @@ UNIFIED_SOURCES += [
|
||||||
"SelectionChangeEventDispatcher.cpp",
|
"SelectionChangeEventDispatcher.cpp",
|
||||||
"SerializedStackHolder.cpp",
|
"SerializedStackHolder.cpp",
|
||||||
"ShadowRoot.cpp",
|
"ShadowRoot.cpp",
|
||||||
|
"SourceLocation.cpp",
|
||||||
"StaticRange.cpp",
|
"StaticRange.cpp",
|
||||||
"StorageAccessPermissionRequest.cpp",
|
"StorageAccessPermissionRequest.cpp",
|
||||||
"StructuredCloneBlob.cpp",
|
"StructuredCloneBlob.cpp",
|
||||||
|
|
|
@ -4542,8 +4542,7 @@ void nsContentUtils::LogSimpleConsoleError(const nsAString& aErrorText,
|
||||||
nsresult nsContentUtils::ReportToConsole(
|
nsresult nsContentUtils::ReportToConsole(
|
||||||
uint32_t aErrorFlags, const nsACString& aCategory,
|
uint32_t aErrorFlags, const nsACString& aCategory,
|
||||||
const Document* aDocument, PropertiesFile aFile, const char* aMessageName,
|
const Document* aDocument, PropertiesFile aFile, const char* aMessageName,
|
||||||
const nsTArray<nsString>& aParams, nsIURI* aURI,
|
const nsTArray<nsString>& aParams, const SourceLocation& aLoc) {
|
||||||
const nsString& aSourceLine, uint32_t aLineNumber, uint32_t aColumnNumber) {
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsAutoString errorText;
|
nsAutoString errorText;
|
||||||
if (!aParams.IsEmpty()) {
|
if (!aParams.IsEmpty()) {
|
||||||
|
@ -4552,10 +4551,8 @@ nsresult nsContentUtils::ReportToConsole(
|
||||||
rv = GetLocalizedString(aFile, aMessageName, errorText);
|
rv = GetLocalizedString(aFile, aMessageName, errorText);
|
||||||
}
|
}
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
return ReportToConsoleNonLocalized(errorText, aErrorFlags, aCategory,
|
return ReportToConsoleNonLocalized(errorText, aErrorFlags, aCategory,
|
||||||
aDocument, aURI, aSourceLine, aLineNumber,
|
aDocument, aLoc);
|
||||||
aColumnNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
@ -4567,55 +4564,44 @@ void nsContentUtils::ReportEmptyGetElementByIdArg(const Document* aDoc) {
|
||||||
/* static */
|
/* static */
|
||||||
nsresult nsContentUtils::ReportToConsoleNonLocalized(
|
nsresult nsContentUtils::ReportToConsoleNonLocalized(
|
||||||
const nsAString& aErrorText, uint32_t aErrorFlags,
|
const nsAString& aErrorText, uint32_t aErrorFlags,
|
||||||
const nsACString& aCategory, const Document* aDocument, nsIURI* aURI,
|
const nsACString& aCategory, const Document* aDocument,
|
||||||
const nsString& aSourceLine, uint32_t aLineNumber, uint32_t aColumnNumber,
|
const SourceLocation& aLoc) {
|
||||||
MissingErrorLocationMode aLocationMode) {
|
uint64_t innerWindowID = aDocument ? aDocument->InnerWindowID() : 0;
|
||||||
uint64_t innerWindowID = 0;
|
if (aLoc || !aDocument || !aDocument->GetDocumentURI()) {
|
||||||
if (aDocument) {
|
return ReportToConsoleByWindowID(aErrorText, aErrorFlags, aCategory,
|
||||||
if (!aURI) {
|
innerWindowID, aLoc);
|
||||||
aURI = aDocument->GetDocumentURI();
|
|
||||||
}
|
|
||||||
innerWindowID = aDocument->InnerWindowID();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReportToConsoleByWindowID(aErrorText, aErrorFlags, aCategory,
|
return ReportToConsoleByWindowID(aErrorText, aErrorFlags, aCategory,
|
||||||
innerWindowID, aURI, aSourceLine,
|
innerWindowID,
|
||||||
aLineNumber, aColumnNumber, aLocationMode);
|
SourceLocation(aDocument->GetDocumentURI()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
nsresult nsContentUtils::ReportToConsoleByWindowID(
|
nsresult nsContentUtils::ReportToConsoleByWindowID(
|
||||||
const nsAString& aErrorText, uint32_t aErrorFlags,
|
const nsAString& aErrorText, uint32_t aErrorFlags,
|
||||||
const nsACString& aCategory, uint64_t aInnerWindowID, nsIURI* aURI,
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
||||||
const nsString& aSourceLine, uint32_t aLineNumber, uint32_t aColumnNumber,
|
const SourceLocation& aLocation) {
|
||||||
MissingErrorLocationMode aLocationMode) {
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (!sConsoleService) { // only need to bother null-checking here
|
if (!sConsoleService) { // only need to bother null-checking here
|
||||||
rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService);
|
rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString spec;
|
|
||||||
if (!aLineNumber && aLocationMode == eUSE_CALLING_LOCATION) {
|
|
||||||
JSContext* cx = GetCurrentJSContext();
|
|
||||||
if (cx) {
|
|
||||||
nsJSUtils::GetCallingLocation(cx, spec, &aLineNumber, &aColumnNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptError> errorObject =
|
nsCOMPtr<nsIScriptError> errorObject =
|
||||||
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (!spec.IsEmpty()) {
|
NS_ConvertUTF8toUTF16 sourceLine(aLocation.mSourceLine);
|
||||||
rv = errorObject->InitWithWindowID(aErrorText,
|
if (aLocation.mResource.is<nsCOMPtr<nsIURI>>()) {
|
||||||
spec, // file name
|
nsIURI* uri = aLocation.mResource.as<nsCOMPtr<nsIURI>>();
|
||||||
aSourceLine, aLineNumber, aColumnNumber,
|
rv = errorObject->InitWithSourceURI(aErrorText, uri, sourceLine,
|
||||||
aErrorFlags, aCategory, aInnerWindowID);
|
aLocation.mLine, aLocation.mColumn,
|
||||||
|
aErrorFlags, aCategory, aInnerWindowID);
|
||||||
} else {
|
} else {
|
||||||
rv = errorObject->InitWithSourceURI(aErrorText, aURI, aSourceLine,
|
rv = errorObject->InitWithWindowID(
|
||||||
aLineNumber, aColumnNumber, aErrorFlags,
|
aErrorText, NS_ConvertUTF8toUTF16(aLocation.mResource.as<nsCString>()),
|
||||||
aCategory, aInnerWindowID);
|
sourceLine, aLocation.mLine, aLocation.mColumn, aErrorFlags, aCategory,
|
||||||
|
aInnerWindowID);
|
||||||
}
|
}
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/BasicEvents.h"
|
#include "mozilla/BasicEvents.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "mozilla/CORSMode.h"
|
#include "mozilla/CORSMode.h"
|
||||||
#include "mozilla/CallState.h"
|
#include "mozilla/CallState.h"
|
||||||
#include "mozilla/Maybe.h"
|
#include "mozilla/Maybe.h"
|
||||||
|
@ -1274,29 +1275,13 @@ class nsContentUtils {
|
||||||
* @param aErrorFlags See nsIScriptError.
|
* @param aErrorFlags See nsIScriptError.
|
||||||
* @param aCategory Name of module reporting error.
|
* @param aCategory Name of module reporting error.
|
||||||
* @param aDocument Reference to the document which triggered the message.
|
* @param aDocument Reference to the document which triggered the message.
|
||||||
* @param [aURI=nullptr] (Optional) URI of resource containing error.
|
* @param aLocation message location. Pass the empty location to omit it.
|
||||||
* @param [aSourceLine=u""_ns] (Optional) The text of the line that
|
|
||||||
contains the error (may be empty).
|
|
||||||
* @param [aLineNumber=0] (Optional) Line number within resource
|
|
||||||
containing error.
|
|
||||||
* @param [aColumnNumber=0] (Optional) Column number within resource
|
|
||||||
containing error.
|
|
||||||
If aURI is null, then aDocument->GetDocumentURI() is used.
|
|
||||||
* @param [aLocationMode] (Optional) Specifies the behavior if
|
|
||||||
error location information is omitted.
|
|
||||||
*/
|
*/
|
||||||
enum MissingErrorLocationMode {
|
|
||||||
// Don't show location information in the error console.
|
|
||||||
eOMIT_LOCATION,
|
|
||||||
// Get location information from the currently executing script.
|
|
||||||
eUSE_CALLING_LOCATION
|
|
||||||
};
|
|
||||||
static nsresult ReportToConsoleNonLocalized(
|
static nsresult ReportToConsoleNonLocalized(
|
||||||
const nsAString& aErrorText, uint32_t aErrorFlags,
|
const nsAString& aErrorText, uint32_t aErrorFlags,
|
||||||
const nsACString& aCategory, const Document* aDocument,
|
const nsACString& aCategory, const Document* aDocument,
|
||||||
nsIURI* aURI = nullptr, const nsString& aSourceLine = u""_ns,
|
const mozilla::SourceLocation& aLocation =
|
||||||
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0,
|
mozilla::JSCallingLocation::Get());
|
||||||
MissingErrorLocationMode aLocationMode = eUSE_CALLING_LOCATION);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report a non-localized error message to the error console base on the
|
* Report a non-localized error message to the error console base on the
|
||||||
|
@ -1306,23 +1291,13 @@ class nsContentUtils {
|
||||||
* @param aCategory Name of module reporting error.
|
* @param aCategory Name of module reporting error.
|
||||||
* @param [aInnerWindowID] Inner window ID for document which triggered the
|
* @param [aInnerWindowID] Inner window ID for document which triggered the
|
||||||
* message.
|
* message.
|
||||||
* @param [aURI=nullptr] (Optional) URI of resource containing error.
|
* @param aLocation message location. Pass the empty location to omit it.
|
||||||
* @param [aSourceLine=u""_ns] (Optional) The text of the line that
|
|
||||||
contains the error (may be empty).
|
|
||||||
* @param [aLineNumber=0] (Optional) Line number within resource
|
|
||||||
containing error.
|
|
||||||
* @param [aColumnNumber=1] (Optional) Column number within resource
|
|
||||||
containing error.
|
|
||||||
If aURI is null, then aDocument->GetDocumentURI() is used.
|
|
||||||
* @param [aLocationMode] (Optional) Specifies the behavior if
|
|
||||||
error location information is omitted.
|
|
||||||
*/
|
*/
|
||||||
static nsresult ReportToConsoleByWindowID(
|
static nsresult ReportToConsoleByWindowID(
|
||||||
const nsAString& aErrorText, uint32_t aErrorFlags,
|
const nsAString& aErrorText, uint32_t aErrorFlags,
|
||||||
const nsACString& aCategory, uint64_t aInnerWindowID,
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
||||||
nsIURI* aURI = nullptr, const nsString& aSourceLine = u""_ns,
|
const mozilla::SourceLocation& aLocation =
|
||||||
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 1,
|
mozilla::JSCallingLocation::Get());
|
||||||
MissingErrorLocationMode aLocationMode = eUSE_CALLING_LOCATION);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report a localized error message to the error console.
|
* Report a localized error message to the error console.
|
||||||
|
@ -1333,14 +1308,7 @@ class nsContentUtils {
|
||||||
* @param aMessageName Name of localized message.
|
* @param aMessageName Name of localized message.
|
||||||
* @param [aParams=empty-array] (Optional) Parameters to be substituted into
|
* @param [aParams=empty-array] (Optional) Parameters to be substituted into
|
||||||
localized message.
|
localized message.
|
||||||
* @param [aURI=nullptr] (Optional) URI of resource containing error.
|
* @param aLocation message location. Pass the empty location to omit it.
|
||||||
* @param [aSourceLine=u""_ns] (Optional) The text of the line that
|
|
||||||
contains the error (may be empty).
|
|
||||||
* @param [aLineNumber=0] (Optional) Line number within resource
|
|
||||||
containing error.
|
|
||||||
* @param [aColumnNumber=0] (Optional) Column number within resource
|
|
||||||
containing error.
|
|
||||||
If aURI is null, then aDocument->GetDocumentURI() is used.
|
|
||||||
*/
|
*/
|
||||||
enum PropertiesFile {
|
enum PropertiesFile {
|
||||||
eCSS_PROPERTIES,
|
eCSS_PROPERTIES,
|
||||||
|
@ -1364,8 +1332,8 @@ class nsContentUtils {
|
||||||
uint32_t aErrorFlags, const nsACString& aCategory,
|
uint32_t aErrorFlags, const nsACString& aCategory,
|
||||||
const Document* aDocument, PropertiesFile aFile, const char* aMessageName,
|
const Document* aDocument, PropertiesFile aFile, const char* aMessageName,
|
||||||
const nsTArray<nsString>& aParams = nsTArray<nsString>(),
|
const nsTArray<nsString>& aParams = nsTArray<nsString>(),
|
||||||
nsIURI* aURI = nullptr, const nsString& aSourceLine = u""_ns,
|
const mozilla::SourceLocation& aLocation =
|
||||||
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0);
|
mozilla::JSCallingLocation::Get());
|
||||||
|
|
||||||
static void ReportEmptyGetElementByIdArg(const Document* aDoc);
|
static void ReportEmptyGetElementByIdArg(const Document* aDoc);
|
||||||
|
|
||||||
|
|
|
@ -1478,7 +1478,7 @@ void LogWarningFullscreenWindowRaise(Element* aElement) {
|
||||||
Unused << nsContentUtils::ReportToConsoleByWindowID(
|
Unused << nsContentUtils::ReportToConsoleByWindowID(
|
||||||
localizedMsg, nsIScriptError::warningFlag, "DOM"_ns,
|
localizedMsg, nsIScriptError::warningFlag, "DOM"_ns,
|
||||||
windowGlobalParent->InnerWindowId(),
|
windowGlobalParent->InnerWindowId(),
|
||||||
windowGlobalParent->GetDocumentURI());
|
SourceLocation(windowGlobalParent->GetDocumentURI()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that when an embedded popup with a noautofocus attribute
|
// Ensure that when an embedded popup with a noautofocus attribute
|
||||||
|
|
|
@ -455,17 +455,15 @@ bool nsFrameMessageManager::GetParamsForMessage(JSContext* aCx,
|
||||||
nsCOMPtr<nsIConsoleService> console(
|
nsCOMPtr<nsIConsoleService> console(
|
||||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
||||||
if (console) {
|
if (console) {
|
||||||
nsAutoString filename;
|
auto location = JSCallingLocation::Get(aCx);
|
||||||
uint32_t lineno = 0, column = 1;
|
|
||||||
nsJSUtils::GetCallingLocation(aCx, filename, &lineno, &column);
|
|
||||||
nsCOMPtr<nsIScriptError> error(
|
nsCOMPtr<nsIScriptError> error(
|
||||||
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
||||||
error->Init(
|
error->Init(
|
||||||
u"Sending message that cannot be cloned. Are "
|
u"Sending message that cannot be cloned. Are "
|
||||||
"you trying to send an XPCOM object?"_ns,
|
"you trying to send an XPCOM object?"_ns,
|
||||||
filename, u""_ns, lineno, column, nsIScriptError::warningFlag,
|
NS_ConvertUTF8toUTF16(location.FileName()), u""_ns, location.mLine,
|
||||||
"chrome javascript"_ns, false /* from private window */,
|
location.mColumn, nsIScriptError::warningFlag, "chrome javascript"_ns,
|
||||||
true /* from chrome context */);
|
false /* from private window */, true /* from chrome context */);
|
||||||
console->LogMessage(error);
|
console->LogMessage(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6063,7 +6063,7 @@ bool WindowScriptTimeoutHandler::Call(const char* aExecutionReason) {
|
||||||
nsAutoMicroTask mt;
|
nsAutoMicroTask mt;
|
||||||
AutoEntryScript aes(mGlobal, aExecutionReason, true);
|
AutoEntryScript aes(mGlobal, aExecutionReason, true);
|
||||||
JS::CompileOptions options(aes.cx());
|
JS::CompileOptions options(aes.cx());
|
||||||
options.setFileAndLine(mFileName.get(), mLineNo);
|
options.setFileAndLine(mCaller.FileName().get(), mCaller.mLine);
|
||||||
options.setNoScriptRval(true);
|
options.setNoScriptRval(true);
|
||||||
options.setIntroductionType("domTimer");
|
options.setIntroductionType("domTimer");
|
||||||
JS::Rooted<JSObject*> global(aes.cx(), mGlobal->GetGlobalJSObject());
|
JS::Rooted<JSObject*> global(aes.cx(), mGlobal->GetGlobalJSObject());
|
||||||
|
|
|
@ -48,34 +48,6 @@
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
|
||||||
bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsACString& aFilename,
|
|
||||||
uint32_t* aLineno, uint32_t* aColumn) {
|
|
||||||
JS::AutoFilename filename;
|
|
||||||
JS::ColumnNumberOneOrigin column;
|
|
||||||
if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, &column)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (aColumn) {
|
|
||||||
*aColumn = column.oneOriginValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return aFilename.Assign(filename.get(), fallible);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nsJSUtils::GetCallingLocation(JSContext* aContext, nsAString& aFilename,
|
|
||||||
uint32_t* aLineno, uint32_t* aColumn) {
|
|
||||||
JS::AutoFilename filename;
|
|
||||||
JS::ColumnNumberOneOrigin column;
|
|
||||||
if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, &column)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (aColumn) {
|
|
||||||
*aColumn = column.oneOriginValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return aFilename.Assign(NS_ConvertUTF8toUTF16(filename.get()), fallible);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(JSContext* aContext) {
|
uint64_t nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(JSContext* aContext) {
|
||||||
if (!aContext) return 0;
|
if (!aContext) return 0;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "jsapi.h"
|
#include "jsapi.h"
|
||||||
#include "js/CompileOptions.h"
|
#include "js/CompileOptions.h"
|
||||||
#include "js/Conversions.h"
|
#include "js/Conversions.h"
|
||||||
#include "js/SourceText.h"
|
|
||||||
#include "js/String.h" // JS::{,Lossy}CopyLinearStringChars, JS::CopyStringChars, JS::Get{,Linear}StringLength, JS::MaxStringLength, JS::StringHasLatin1Chars
|
#include "js/String.h" // JS::{,Lossy}CopyLinearStringChars, JS::CopyStringChars, JS::Get{,Linear}StringLength, JS::MaxStringLength, JS::StringHasLatin1Chars
|
||||||
#include "js/Utility.h" // JS::FreePolicy
|
#include "js/Utility.h" // JS::FreePolicy
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
@ -41,13 +40,6 @@ class Element;
|
||||||
|
|
||||||
class nsJSUtils {
|
class nsJSUtils {
|
||||||
public:
|
public:
|
||||||
static bool GetCallingLocation(JSContext* aContext, nsACString& aFilename,
|
|
||||||
uint32_t* aLineno = nullptr,
|
|
||||||
uint32_t* aColumn = nullptr);
|
|
||||||
static bool GetCallingLocation(JSContext* aContext, nsAString& aFilename,
|
|
||||||
uint32_t* aLineno = nullptr,
|
|
||||||
uint32_t* aColumn = nullptr);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the inner window ID based on the given JSContext.
|
* Retrieve the inner window ID based on the given JSContext.
|
||||||
*
|
*
|
||||||
|
|
|
@ -4048,7 +4048,7 @@ static const char* kDeprecatedOperations[] = {
|
||||||
|
|
||||||
void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
|
void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
|
||||||
DeprecatedOperations aOperation,
|
DeprecatedOperations aOperation,
|
||||||
const nsAString& aFileName,
|
const nsACString& aFileName,
|
||||||
const Nullable<uint32_t>& aLineNumber,
|
const Nullable<uint32_t>& aLineNumber,
|
||||||
const Nullable<uint32_t>& aColumnNumber) {
|
const Nullable<uint32_t>& aColumnNumber) {
|
||||||
MOZ_ASSERT(aURI);
|
MOZ_ASSERT(aURI);
|
||||||
|
@ -4156,21 +4156,18 @@ void MaybeReportDeprecation(const GlobalObject& aGlobal,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString fileName;
|
auto location = JSCallingLocation::Get(aGlobal.Context());
|
||||||
Nullable<uint32_t> lineNumber;
|
Nullable<uint32_t> lineNumber;
|
||||||
Nullable<uint32_t> columnNumber;
|
Nullable<uint32_t> columnNumber;
|
||||||
uint32_t line = 0;
|
if (location) {
|
||||||
uint32_t column = 1;
|
lineNumber.SetValue(location.mLine);
|
||||||
if (nsJSUtils::GetCallingLocation(aGlobal.Context(), fileName, &line,
|
columnNumber.SetValue(location.mColumn);
|
||||||
&column)) {
|
|
||||||
lineNumber.SetValue(line);
|
|
||||||
columnNumber.SetValue(column);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||||
MOZ_ASSERT(global);
|
MOZ_ASSERT(global);
|
||||||
|
|
||||||
ReportDeprecation(global, uri, aOperation, fileName, lineNumber,
|
ReportDeprecation(global, uri, aOperation, location.FileName(), lineNumber,
|
||||||
columnNumber);
|
columnNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ dictionary ConsoleEvent {
|
||||||
DOMString consoleID = "";
|
DOMString consoleID = "";
|
||||||
DOMString addonId = "";
|
DOMString addonId = "";
|
||||||
DOMString level = "";
|
DOMString level = "";
|
||||||
DOMString filename = "";
|
UTF8String filename = "";
|
||||||
// Unique identifier within the process for the script source this event is
|
// Unique identifier within the process for the script source this event is
|
||||||
// associated with, or zero.
|
// associated with, or zero.
|
||||||
unsigned long sourceId = 0;
|
unsigned long sourceId = 0;
|
||||||
|
@ -52,7 +52,7 @@ dictionary ConsoleProfileEvent {
|
||||||
// This dictionary is used to manage stack trace data.
|
// This dictionary is used to manage stack trace data.
|
||||||
[GenerateConversionToJS]
|
[GenerateConversionToJS]
|
||||||
dictionary ConsoleStackEntry {
|
dictionary ConsoleStackEntry {
|
||||||
DOMString filename = "";
|
UTF8String filename = "";
|
||||||
// Unique identifier within the process for the script source this entry is
|
// Unique identifier within the process for the script source this entry is
|
||||||
// associated with, or zero.
|
// associated with, or zero.
|
||||||
unsigned long sourceId = 0;
|
unsigned long sourceId = 0;
|
||||||
|
@ -173,7 +173,8 @@ enum ConsoleLevel { "log", "warning", "error" };
|
||||||
partial interface ConsoleInstance {
|
partial interface ConsoleInstance {
|
||||||
[ChromeOnly]
|
[ChromeOnly]
|
||||||
undefined reportForServiceWorkerScope(DOMString scope, DOMString message,
|
undefined reportForServiceWorkerScope(DOMString scope, DOMString message,
|
||||||
DOMString filename, unsigned long lineNumber,
|
UTF8String filename,
|
||||||
|
unsigned long lineNumber,
|
||||||
unsigned long columnNumber,
|
unsigned long columnNumber,
|
||||||
ConsoleLevel level);
|
ConsoleLevel level);
|
||||||
};
|
};
|
||||||
|
|
|
@ -682,7 +682,7 @@ class ConsoleCallDataWorkerRunnable final : public ConsoleWorkerRunnable {
|
||||||
frame = *mCallData->mTopStackFrame;
|
frame = *mCallData->mTopStackFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsString id = frame.mFilename;
|
nsCString id = frame.mFilename;
|
||||||
nsString innerID;
|
nsString innerID;
|
||||||
if (aWorkerPrivate->IsSharedWorker()) {
|
if (aWorkerPrivate->IsSharedWorker()) {
|
||||||
innerID = u"SharedWorker"_ns;
|
innerID = u"SharedWorker"_ns;
|
||||||
|
@ -690,12 +690,12 @@ class ConsoleCallDataWorkerRunnable final : public ConsoleWorkerRunnable {
|
||||||
innerID = u"ServiceWorker"_ns;
|
innerID = u"ServiceWorker"_ns;
|
||||||
// Use scope as ID so the webconsole can decide if the message should
|
// Use scope as ID so the webconsole can decide if the message should
|
||||||
// show up per tab
|
// show up per tab
|
||||||
CopyASCIItoUTF16(aWorkerPrivate->ServiceWorkerScope(), id);
|
id = aWorkerPrivate->ServiceWorkerScope();
|
||||||
} else {
|
} else {
|
||||||
innerID = u"Worker"_ns;
|
innerID = u"Worker"_ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
mCallData->SetIDs(id, innerID);
|
mCallData->SetIDs(NS_ConvertUTF8toUTF16(id), innerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
mClonedData.mGlobal = aGlobal;
|
mClonedData.mGlobal = aGlobal;
|
||||||
|
@ -1223,7 +1223,9 @@ void StackFrameToStackEntry(JSContext* aCx, nsIStackFrame* aStackFrame,
|
||||||
ConsoleStackEntry& aStackEntry) {
|
ConsoleStackEntry& aStackEntry) {
|
||||||
MOZ_ASSERT(aStackFrame);
|
MOZ_ASSERT(aStackFrame);
|
||||||
|
|
||||||
aStackFrame->GetFilename(aCx, aStackEntry.mFilename);
|
nsAutoString filename;
|
||||||
|
aStackFrame->GetFilename(aCx, filename);
|
||||||
|
CopyUTF16toUTF8(filename, aStackEntry.mFilename);
|
||||||
|
|
||||||
aStackEntry.mSourceId = aStackFrame->GetSourceId(aCx);
|
aStackEntry.mSourceId = aStackFrame->GetSourceId(aCx);
|
||||||
aStackEntry.mLineNumber = aStackFrame->GetLineNumber(aCx);
|
aStackEntry.mLineNumber = aStackFrame->GetLineNumber(aCx);
|
||||||
|
@ -1412,12 +1414,12 @@ void Console::MethodInternal(JSContext* aCx, MethodName aMethodName,
|
||||||
} else if (!mPassedInnerID.IsEmpty()) {
|
} else if (!mPassedInnerID.IsEmpty()) {
|
||||||
callData->SetIDs(u"jsm"_ns, mPassedInnerID);
|
callData->SetIDs(u"jsm"_ns, mPassedInnerID);
|
||||||
} else {
|
} else {
|
||||||
nsAutoString filename;
|
nsAutoCString filename;
|
||||||
if (callData->mTopStackFrame.isSome()) {
|
if (callData->mTopStackFrame.isSome()) {
|
||||||
filename = callData->mTopStackFrame->mFilename;
|
filename = callData->mTopStackFrame->mFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
callData->SetIDs(u"jsm"_ns, filename);
|
callData->SetIDs(u"jsm"_ns, NS_ConvertUTF8toUTF16(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
GetOrCreateMainThreadData()->ProcessCallData(aCx, callData, aData);
|
GetOrCreateMainThreadData()->ProcessCallData(aCx, callData, aData);
|
||||||
|
@ -1604,7 +1606,7 @@ bool Console::PopulateConsoleNotificationInTheTargetScope(
|
||||||
do_QueryInterface(filenameURI);
|
do_QueryInterface(filenameURI);
|
||||||
nsAutoCString spec;
|
nsAutoCString spec;
|
||||||
if (safeURI && NS_SUCCEEDED(safeURI->GetSensitiveInfoHiddenSpec(spec))) {
|
if (safeURI && NS_SUCCEEDED(safeURI->GetSensitiveInfoHiddenSpec(spec))) {
|
||||||
CopyUTF8toUTF16(spec, event.mFilename);
|
event.mFilename = spec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -268,7 +268,7 @@ bool ConsoleInstance::ShouldLog(ConsoleLogLevel aLevel) {
|
||||||
|
|
||||||
void ConsoleInstance::ReportForServiceWorkerScope(const nsAString& aScope,
|
void ConsoleInstance::ReportForServiceWorkerScope(const nsAString& aScope,
|
||||||
const nsAString& aMessage,
|
const nsAString& aMessage,
|
||||||
const nsAString& aFilename,
|
const nsACString& aFilename,
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber,
|
uint32_t aColumnNumber,
|
||||||
ConsoleLevel aLevel) {
|
ConsoleLevel aLevel) {
|
||||||
|
|
|
@ -102,7 +102,7 @@ class ConsoleInstance final : public nsISupports, public nsWrapperCache {
|
||||||
// For testing only.
|
// For testing only.
|
||||||
void ReportForServiceWorkerScope(const nsAString& aScope,
|
void ReportForServiceWorkerScope(const nsAString& aScope,
|
||||||
const nsAString& aMessage,
|
const nsAString& aMessage,
|
||||||
const nsAString& aFilename,
|
const nsACString& aFilename,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
||||||
ConsoleLevel aLevel);
|
ConsoleLevel aLevel);
|
||||||
|
|
||||||
|
|
|
@ -79,9 +79,11 @@ void ConsoleReportCollector::FlushReportsToConsole(uint64_t aInnerWindowID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SourceLocation loc{std::move(uri), report.mLineNumber,
|
||||||
|
report.mColumnNumber};
|
||||||
|
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
errorText, report.mErrorFlags, report.mCategory, aInnerWindowID, uri,
|
errorText, report.mErrorFlags, report.mCategory, aInnerWindowID, loc);
|
||||||
u""_ns, report.mLineNumber, report.mColumnNumber);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,9 +131,8 @@ void ConsoleReportCollector::FlushReportsToConsoleForServiceWorkerScope(
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleUtils::ReportForServiceWorkerScope(
|
ConsoleUtils::ReportForServiceWorkerScope(
|
||||||
NS_ConvertUTF8toUTF16(aScope), errorText,
|
NS_ConvertUTF8toUTF16(aScope), errorText, report.mSourceFileURI,
|
||||||
NS_ConvertUTF8toUTF16(report.mSourceFileURI), report.mLineNumber,
|
report.mLineNumber, report.mColumnNumber, level);
|
||||||
report.mColumnNumber, level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ ConsoleUtils::~ConsoleUtils() = default;
|
||||||
/* static */
|
/* static */
|
||||||
void ConsoleUtils::ReportForServiceWorkerScope(const nsAString& aScope,
|
void ConsoleUtils::ReportForServiceWorkerScope(const nsAString& aScope,
|
||||||
const nsAString& aMessage,
|
const nsAString& aMessage,
|
||||||
const nsAString& aFilename,
|
const nsACString& aFilename,
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber,
|
uint32_t aColumnNumber,
|
||||||
Level aLevel) {
|
Level aLevel) {
|
||||||
|
@ -62,7 +62,7 @@ void ConsoleUtils::ReportForServiceWorkerScope(const nsAString& aScope,
|
||||||
|
|
||||||
void ConsoleUtils::ReportForServiceWorkerScopeInternal(
|
void ConsoleUtils::ReportForServiceWorkerScopeInternal(
|
||||||
const nsAString& aScope, const nsAString& aMessage,
|
const nsAString& aScope, const nsAString& aMessage,
|
||||||
const nsAString& aFilename, uint32_t aLineNumber, uint32_t aColumnNumber,
|
const nsACString& aFilename, uint32_t aLineNumber, uint32_t aColumnNumber,
|
||||||
Level aLevel) {
|
Level aLevel) {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class ConsoleUtils final {
|
||||||
// Main-thread only, reports a console message from a ServiceWorker.
|
// Main-thread only, reports a console message from a ServiceWorker.
|
||||||
static void ReportForServiceWorkerScope(const nsAString& aScope,
|
static void ReportForServiceWorkerScope(const nsAString& aScope,
|
||||||
const nsAString& aMessage,
|
const nsAString& aMessage,
|
||||||
const nsAString& aFilename,
|
const nsACString& aFilename,
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, Level aLevel);
|
uint32_t aColumnNumber, Level aLevel);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class ConsoleUtils final {
|
||||||
|
|
||||||
void ReportForServiceWorkerScopeInternal(const nsAString& aScope,
|
void ReportForServiceWorkerScopeInternal(const nsAString& aScope,
|
||||||
const nsAString& aMessage,
|
const nsAString& aMessage,
|
||||||
const nsAString& aFilename,
|
const nsACString& aFilename,
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber,
|
uint32_t aColumnNumber,
|
||||||
Level aLevel);
|
Level aLevel);
|
||||||
|
|
|
@ -667,10 +667,9 @@ void KeyEventHandler::ReportKeyConflict(const char16_t* aKey,
|
||||||
params.AppendElement(aKey);
|
params.AppendElement(aKey);
|
||||||
params.AppendElement(aModifiers);
|
params.AppendElement(aModifiers);
|
||||||
params.AppendElement(id);
|
params.AppendElement(id);
|
||||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
nsContentUtils::ReportToConsole(
|
||||||
"Key dom::Event Handler"_ns, doc,
|
nsIScriptError::warningFlag, "Key dom::Event Handler"_ns, doc,
|
||||||
nsContentUtils::eDOM_PROPERTIES, aMessageName,
|
nsContentUtils::eDOM_PROPERTIES, aMessageName, params);
|
||||||
params, nullptr, u""_ns, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyEventHandler::ModifiersMatchMask(
|
bool KeyEventHandler::ModifiersMatchMask(
|
||||||
|
|
|
@ -232,7 +232,7 @@ void HTMLFormElement::ReportInvalidUnfocusableElements(
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::errorFlag, "DOM"_ns, element->GetOwnerDocument(),
|
nsIScriptError::errorFlag, "DOM"_ns, element->GetOwnerDocument(),
|
||||||
nsContentUtils::eDOM_PROPERTIES, messageName.get(), params,
|
nsContentUtils::eDOM_PROPERTIES, messageName.get(), params,
|
||||||
element->GetBaseURI());
|
SourceLocation(element->GetBaseURI()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1659,7 +1659,7 @@ nsresult HTMLFormElement::GetActionURL(nsIURI** aActionURL,
|
||||||
|
|
||||||
CSP_LogLocalizedStr(
|
CSP_LogLocalizedStr(
|
||||||
"upgradeInsecureRequest", params,
|
"upgradeInsecureRequest", params,
|
||||||
u""_ns, // aSourceFile
|
""_ns, // aSourceFile
|
||||||
u""_ns, // aScriptSample
|
u""_ns, // aScriptSample
|
||||||
0, // aLineNumber
|
0, // aLineNumber
|
||||||
1, // aColumnNumber
|
1, // aColumnNumber
|
||||||
|
|
|
@ -185,6 +185,8 @@ void HTMLScriptElement::FreezeExecutionAttrs(const Document* aOwnerDoc) {
|
||||||
// because it will return the base URL when the attr value is "".
|
// because it will return the base URL when the attr value is "".
|
||||||
nsAutoString src;
|
nsAutoString src;
|
||||||
if (GetAttr(nsGkAtoms::src, src)) {
|
if (GetAttr(nsGkAtoms::src, src)) {
|
||||||
|
SourceLocation loc{OwnerDoc()->GetDocumentURI(), GetScriptLineNumber(),
|
||||||
|
GetScriptColumnNumber().oneOriginValue()};
|
||||||
// Empty src should be treated as invalid URL.
|
// Empty src should be treated as invalid URL.
|
||||||
if (!src.IsEmpty()) {
|
if (!src.IsEmpty()) {
|
||||||
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(mUri), src,
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(mUri), src,
|
||||||
|
@ -193,20 +195,16 @@ void HTMLScriptElement::FreezeExecutionAttrs(const Document* aOwnerDoc) {
|
||||||
if (!mUri) {
|
if (!mUri) {
|
||||||
AutoTArray<nsString, 2> params = {u"src"_ns, src};
|
AutoTArray<nsString, 2> params = {u"src"_ns, src};
|
||||||
|
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "HTML"_ns,
|
||||||
nsIScriptError::warningFlag, "HTML"_ns, OwnerDoc(),
|
OwnerDoc(),
|
||||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri", params,
|
nsContentUtils::eDOM_PROPERTIES,
|
||||||
nullptr, u""_ns, GetScriptLineNumber(),
|
"ScriptSourceInvalidUri", params, loc);
|
||||||
GetScriptColumnNumber().oneOriginValue());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
AutoTArray<nsString, 1> params = {u"src"_ns};
|
AutoTArray<nsString, 1> params = {u"src"_ns};
|
||||||
|
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::warningFlag, "HTML"_ns, OwnerDoc(),
|
nsIScriptError::warningFlag, "HTML"_ns, OwnerDoc(),
|
||||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty", params, nullptr,
|
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty", params, loc);
|
||||||
u""_ns, GetScriptLineNumber(),
|
|
||||||
GetScriptColumnNumber().oneOriginValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point mUri will be null for invalid URLs.
|
// At this point mUri will be null for invalid URLs.
|
||||||
|
|
|
@ -732,12 +732,7 @@ void IDBDatabase::AbortTransactions(bool aShouldWarn) {
|
||||||
|
|
||||||
for (IDBTransaction* transaction : transactionsThatNeedWarning) {
|
for (IDBTransaction* transaction : transactionsThatNeedWarning) {
|
||||||
MOZ_ASSERT(transaction);
|
MOZ_ASSERT(transaction);
|
||||||
|
LogWarning(kWarningMessage, transaction->GetCallerLocation());
|
||||||
nsString filename;
|
|
||||||
uint32_t lineNo, column;
|
|
||||||
transaction->GetCallerLocation(filename, &lineNo, &column);
|
|
||||||
|
|
||||||
LogWarning(kWarningMessage, filename, lineNo, column);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,15 +874,13 @@ void IDBDatabase::NoteInactiveTransactionDelayed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDBDatabase::LogWarning(const char* aMessageName,
|
void IDBDatabase::LogWarning(const char* aMessageName,
|
||||||
const nsAString& aFilename, uint32_t aLineNumber,
|
const JSCallingLocation& aLoc) {
|
||||||
uint32_t aColumnNumber) {
|
|
||||||
AssertIsOnOwningThread();
|
AssertIsOnOwningThread();
|
||||||
MOZ_ASSERT(aMessageName);
|
MOZ_ASSERT(aMessageName);
|
||||||
|
|
||||||
ScriptErrorHelper::DumpLocalizedMessage(
|
ScriptErrorHelper::DumpLocalizedMessage(
|
||||||
nsDependentCString(aMessageName), aFilename, aLineNumber, aColumnNumber,
|
nsDependentCString(aMessageName), aLoc, nsIScriptError::warningFlag,
|
||||||
nsIScriptError::warningFlag, mFactory->IsChrome(),
|
mFactory->IsChrome(), mFactory->InnerWindowID());
|
||||||
mFactory->InnerWindowID());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(IDBDatabase, DOMEventTargetHelper)
|
NS_IMPL_ADDREF_INHERITED(IDBDatabase, DOMEventTargetHelper)
|
||||||
|
|
|
@ -23,6 +23,7 @@ class nsIGlobalObject;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
struct JSCallingLocation;
|
||||||
class ErrorResult;
|
class ErrorResult;
|
||||||
class EventChainPostVisitor;
|
class EventChainPostVisitor;
|
||||||
|
|
||||||
|
@ -229,8 +230,7 @@ class IDBDatabase final : public DOMEventTargetHelper {
|
||||||
|
|
||||||
void NoteInactiveTransactionDelayed();
|
void NoteInactiveTransactionDelayed();
|
||||||
|
|
||||||
void LogWarning(const char* aMessageName, const nsAString& aFilename,
|
void LogWarning(const char* aMessageName, const JSCallingLocation&);
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber);
|
|
||||||
|
|
||||||
// Only accessed by IDBObjectStore.
|
// Only accessed by IDBObjectStore.
|
||||||
nsresult RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName);
|
nsresult RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName);
|
||||||
|
|
|
@ -44,8 +44,6 @@ using namespace mozilla::ipc;
|
||||||
IDBRequest::IDBRequest(IDBDatabase* aDatabase)
|
IDBRequest::IDBRequest(IDBDatabase* aDatabase)
|
||||||
: DOMEventTargetHelper(aDatabase),
|
: DOMEventTargetHelper(aDatabase),
|
||||||
mLoggingSerialNumber(0),
|
mLoggingSerialNumber(0),
|
||||||
mLineNo(0),
|
|
||||||
mColumn(0),
|
|
||||||
mHaveResultOrErrorCode(false) {
|
mHaveResultOrErrorCode(false) {
|
||||||
MOZ_ASSERT(aDatabase);
|
MOZ_ASSERT(aDatabase);
|
||||||
aDatabase->AssertIsOnOwningThread();
|
aDatabase->AssertIsOnOwningThread();
|
||||||
|
@ -56,8 +54,6 @@ IDBRequest::IDBRequest(IDBDatabase* aDatabase)
|
||||||
IDBRequest::IDBRequest(nsIGlobalObject* aGlobal)
|
IDBRequest::IDBRequest(nsIGlobalObject* aGlobal)
|
||||||
: DOMEventTargetHelper(aGlobal),
|
: DOMEventTargetHelper(aGlobal),
|
||||||
mLoggingSerialNumber(0),
|
mLoggingSerialNumber(0),
|
||||||
mLineNo(0),
|
|
||||||
mColumn(0),
|
|
||||||
mHaveResultOrErrorCode(false) {
|
mHaveResultOrErrorCode(false) {
|
||||||
InitMembers();
|
InitMembers();
|
||||||
}
|
}
|
||||||
|
@ -73,8 +69,6 @@ void IDBRequest::InitMembers() {
|
||||||
mResultVal.setUndefined();
|
mResultVal.setUndefined();
|
||||||
mLoggingSerialNumber = NextSerialNumber();
|
mLoggingSerialNumber = NextSerialNumber();
|
||||||
mErrorCode = NS_OK;
|
mErrorCode = NS_OK;
|
||||||
mLineNo = 0;
|
|
||||||
mColumn = 0;
|
|
||||||
mHaveResultOrErrorCode = false;
|
mHaveResultOrErrorCode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +81,7 @@ MovingNotNull<RefPtr<IDBRequest>> IDBRequest::Create(
|
||||||
aDatabase->AssertIsOnOwningThread();
|
aDatabase->AssertIsOnOwningThread();
|
||||||
|
|
||||||
RefPtr<IDBRequest> request = new IDBRequest(aDatabase);
|
RefPtr<IDBRequest> request = new IDBRequest(aDatabase);
|
||||||
CaptureCaller(aCx, request->mFilename, &request->mLineNo, &request->mColumn);
|
request->mCallerLocation = JSCallingLocation::Get(aCx);
|
||||||
|
|
||||||
request->mTransaction = std::move(aTransaction);
|
request->mTransaction = std::move(aTransaction);
|
||||||
|
|
||||||
|
@ -143,15 +137,6 @@ void IDBRequest::SetLoggingSerialNumber(uint64_t aLoggingSerialNumber) {
|
||||||
mLoggingSerialNumber = aLoggingSerialNumber;
|
mLoggingSerialNumber = aLoggingSerialNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDBRequest::CaptureCaller(JSContext* aCx, nsAString& aFilename,
|
|
||||||
uint32_t* aLineNo, uint32_t* aColumn) {
|
|
||||||
MOZ_ASSERT(aFilename.IsEmpty());
|
|
||||||
MOZ_ASSERT(aLineNo);
|
|
||||||
MOZ_ASSERT(aColumn);
|
|
||||||
|
|
||||||
nsJSUtils::GetCallingLocation(aCx, aFilename, aLineNo, aColumn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IDBRequest::GetSource(
|
void IDBRequest::GetSource(
|
||||||
Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const {
|
Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor>& aSource) const {
|
||||||
AssertIsOnOwningThread();
|
AssertIsOnOwningThread();
|
||||||
|
@ -213,17 +198,6 @@ DOMException* IDBRequest::GetErrorAfterResult() const {
|
||||||
|
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
void IDBRequest::GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
|
||||||
uint32_t* aColumn) const {
|
|
||||||
AssertIsOnOwningThread();
|
|
||||||
MOZ_ASSERT(aLineNo);
|
|
||||||
MOZ_ASSERT(aColumn);
|
|
||||||
|
|
||||||
aFilename = mFilename;
|
|
||||||
*aLineNo = mLineNo;
|
|
||||||
*aColumn = mColumn;
|
|
||||||
}
|
|
||||||
|
|
||||||
IDBRequestReadyState IDBRequest::ReadyState() const {
|
IDBRequestReadyState IDBRequest::ReadyState() const {
|
||||||
AssertIsOnOwningThread();
|
AssertIsOnOwningThread();
|
||||||
|
|
||||||
|
@ -335,7 +309,7 @@ RefPtr<IDBOpenDBRequest> IDBOpenDBRequest::Create(
|
||||||
|
|
||||||
RefPtr<IDBOpenDBRequest> request =
|
RefPtr<IDBOpenDBRequest> request =
|
||||||
new IDBOpenDBRequest(std::move(aFactory), aGlobal);
|
new IDBOpenDBRequest(std::move(aFactory), aGlobal);
|
||||||
CaptureCaller(aCx, request->mFilename, &request->mLineNo, &request->mColumn);
|
request->mCallerLocation = JSCallingLocation::Get(aCx);
|
||||||
|
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "js/RootingAPI.h"
|
#include "js/RootingAPI.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/EventForwards.h"
|
#include "mozilla/EventForwards.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "mozilla/dom/DOMException.h"
|
#include "mozilla/dom/DOMException.h"
|
||||||
#include "mozilla/dom/IDBRequestBinding.h"
|
#include "mozilla/dom/IDBRequestBinding.h"
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
|
@ -69,11 +70,9 @@ class IDBRequest : public DOMEventTargetHelper {
|
||||||
JS::Heap<JS::Value> mResultVal;
|
JS::Heap<JS::Value> mResultVal;
|
||||||
RefPtr<DOMException> mError;
|
RefPtr<DOMException> mError;
|
||||||
|
|
||||||
nsString mFilename;
|
JSCallingLocation mCallerLocation;
|
||||||
uint64_t mLoggingSerialNumber;
|
uint64_t mLoggingSerialNumber;
|
||||||
nsresult mErrorCode;
|
nsresult mErrorCode;
|
||||||
uint32_t mLineNo;
|
|
||||||
uint32_t mColumn;
|
|
||||||
bool mHaveResultOrErrorCode;
|
bool mHaveResultOrErrorCode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -89,9 +88,6 @@ class IDBRequest : public DOMEventTargetHelper {
|
||||||
JSContext* aCx, IDBIndex* aSource, IDBDatabase* aDatabase,
|
JSContext* aCx, IDBIndex* aSource, IDBDatabase* aDatabase,
|
||||||
SafeRefPtr<IDBTransaction> aTransaction);
|
SafeRefPtr<IDBTransaction> aTransaction);
|
||||||
|
|
||||||
static void CaptureCaller(JSContext* aCx, nsAString& aFilename,
|
|
||||||
uint32_t* aLineNo, uint32_t* aColumn);
|
|
||||||
|
|
||||||
static uint64_t NextSerialNumber();
|
static uint64_t NextSerialNumber();
|
||||||
|
|
||||||
// EventTarget
|
// EventTarget
|
||||||
|
@ -174,8 +170,7 @@ class IDBRequest : public DOMEventTargetHelper {
|
||||||
|
|
||||||
DOMException* GetError(ErrorResult& aRv);
|
DOMException* GetError(ErrorResult& aRv);
|
||||||
|
|
||||||
void GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
const JSCallingLocation& GetCallerLocation() const { return mCallerLocation; }
|
||||||
uint32_t* aColumn) const;
|
|
||||||
|
|
||||||
bool IsPending() const { return !mHaveResultOrErrorCode; }
|
bool IsPending() const { return !mHaveResultOrErrorCode; }
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,7 @@ auto IDBTransaction::DoWithTransactionChild(const Func& aFunc) const {
|
||||||
IDBTransaction::IDBTransaction(IDBDatabase* const aDatabase,
|
IDBTransaction::IDBTransaction(IDBDatabase* const aDatabase,
|
||||||
const nsTArray<nsString>& aObjectStoreNames,
|
const nsTArray<nsString>& aObjectStoreNames,
|
||||||
const Mode aMode, const Durability aDurability,
|
const Mode aMode, const Durability aDurability,
|
||||||
nsString aFilename, const uint32_t aLineNo,
|
JSCallingLocation&& aCallerLocation,
|
||||||
const uint32_t aColumn,
|
|
||||||
CreatedFromFactoryFunction /*aDummy*/)
|
CreatedFromFactoryFunction /*aDummy*/)
|
||||||
: DOMEventTargetHelper(aDatabase),
|
: DOMEventTargetHelper(aDatabase),
|
||||||
mDatabase(aDatabase),
|
mDatabase(aDatabase),
|
||||||
|
@ -102,9 +101,7 @@ IDBTransaction::IDBTransaction(IDBDatabase* const aDatabase,
|
||||||
mNextRequestId(0),
|
mNextRequestId(0),
|
||||||
mAbortCode(NS_OK),
|
mAbortCode(NS_OK),
|
||||||
mPendingRequestCount(0),
|
mPendingRequestCount(0),
|
||||||
mFilename(std::move(aFilename)),
|
mCallerLocation(std::move(aCallerLocation)),
|
||||||
mLineNo(aLineNo),
|
|
||||||
mColumn(aColumn),
|
|
||||||
mMode(aMode),
|
mMode(aMode),
|
||||||
mDurability(aDurability),
|
mDurability(aDurability),
|
||||||
mRegistered(false),
|
mRegistered(false),
|
||||||
|
@ -177,13 +174,10 @@ SafeRefPtr<IDBTransaction> IDBTransaction::CreateVersionChange(
|
||||||
|
|
||||||
const nsTArray<nsString> emptyObjectStoreNames;
|
const nsTArray<nsString> emptyObjectStoreNames;
|
||||||
|
|
||||||
nsString filename;
|
|
||||||
uint32_t lineNo, column;
|
|
||||||
aOpenRequest->GetCallerLocation(filename, &lineNo, &column);
|
|
||||||
// XXX: What should we have as durability hint here?
|
// XXX: What should we have as durability hint here?
|
||||||
auto transaction = MakeSafeRefPtr<IDBTransaction>(
|
auto transaction = MakeSafeRefPtr<IDBTransaction>(
|
||||||
aDatabase, emptyObjectStoreNames, Mode::VersionChange,
|
aDatabase, emptyObjectStoreNames, Mode::VersionChange,
|
||||||
Durability::Default, std::move(filename), lineNo, column,
|
Durability::Default, JSCallingLocation(aOpenRequest->GetCallerLocation()),
|
||||||
CreatedFromFactoryFunction{});
|
CreatedFromFactoryFunction{});
|
||||||
|
|
||||||
transaction->NoteActiveTransaction();
|
transaction->NoteActiveTransaction();
|
||||||
|
@ -209,12 +203,9 @@ SafeRefPtr<IDBTransaction> IDBTransaction::Create(
|
||||||
MOZ_ASSERT(aMode == Mode::ReadOnly || aMode == Mode::ReadWrite ||
|
MOZ_ASSERT(aMode == Mode::ReadOnly || aMode == Mode::ReadWrite ||
|
||||||
aMode == Mode::ReadWriteFlush || aMode == Mode::Cleanup);
|
aMode == Mode::ReadWriteFlush || aMode == Mode::Cleanup);
|
||||||
|
|
||||||
nsString filename;
|
|
||||||
uint32_t lineNo, column;
|
|
||||||
IDBRequest::CaptureCaller(aCx, filename, &lineNo, &column);
|
|
||||||
auto transaction = MakeSafeRefPtr<IDBTransaction>(
|
auto transaction = MakeSafeRefPtr<IDBTransaction>(
|
||||||
aDatabase, aObjectStoreNames, aMode, aDurability, std::move(filename),
|
aDatabase, aObjectStoreNames, aMode, aDurability,
|
||||||
lineNo, column, CreatedFromFactoryFunction{});
|
JSCallingLocation::Get(aCx), CreatedFromFactoryFunction{});
|
||||||
|
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
WorkerPrivate* const workerPrivate = GetCurrentThreadWorkerPrivate();
|
WorkerPrivate* const workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||||
|
@ -462,18 +453,6 @@ void IDBTransaction::MaybeNoteInactiveTransaction() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDBTransaction::GetCallerLocation(nsAString& aFilename,
|
|
||||||
uint32_t* const aLineNo,
|
|
||||||
uint32_t* const aColumn) const {
|
|
||||||
AssertIsOnOwningThread();
|
|
||||||
MOZ_ASSERT(aLineNo);
|
|
||||||
MOZ_ASSERT(aColumn);
|
|
||||||
|
|
||||||
aFilename = mFilename;
|
|
||||||
*aLineNo = mLineNo;
|
|
||||||
*aColumn = mColumn;
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<IDBObjectStore> IDBTransaction::CreateObjectStore(
|
RefPtr<IDBObjectStore> IDBTransaction::CreateObjectStore(
|
||||||
ObjectStoreSpec& aSpec) {
|
ObjectStoreSpec& aSpec) {
|
||||||
AssertIsOnOwningThread();
|
AssertIsOnOwningThread();
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "FlippedOnce.h"
|
#include "FlippedOnce.h"
|
||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "mozilla/dom/IDBTransactionBinding.h"
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
||||||
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
|
#include "mozilla/dom/quota/CheckedUnsafePtr.h"
|
||||||
#include "mozilla/DOMEventTargetHelper.h"
|
#include "mozilla/DOMEventTargetHelper.h"
|
||||||
|
@ -115,9 +116,7 @@ class IDBTransaction final
|
||||||
///< transaction can auto-commit when the last
|
///< transaction can auto-commit when the last
|
||||||
///< pending request finished.
|
///< pending request finished.
|
||||||
|
|
||||||
const nsString mFilename;
|
const JSCallingLocation mCallerLocation;
|
||||||
const uint32_t mLineNo;
|
|
||||||
const uint32_t mColumn;
|
|
||||||
|
|
||||||
ReadyState mReadyState = ReadyState::Active;
|
ReadyState mReadyState = ReadyState::Active;
|
||||||
FlippedOnce<false> mStarted;
|
FlippedOnce<false> mStarted;
|
||||||
|
@ -239,8 +238,10 @@ class IDBTransaction final
|
||||||
return mAbortCode;
|
return mAbortCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
const JSCallingLocation& GetCallerLocation() const {
|
||||||
uint32_t* aColumn) const;
|
AssertIsOnOwningThread();
|
||||||
|
return mCallerLocation;
|
||||||
|
}
|
||||||
|
|
||||||
// 'Get' prefix is to avoid name collisions with the enum
|
// 'Get' prefix is to avoid name collisions with the enum
|
||||||
Mode GetMode() const {
|
Mode GetMode() const {
|
||||||
|
@ -349,8 +350,8 @@ class IDBTransaction final
|
||||||
public:
|
public:
|
||||||
IDBTransaction(IDBDatabase* aDatabase,
|
IDBTransaction(IDBDatabase* aDatabase,
|
||||||
const nsTArray<nsString>& aObjectStoreNames, Mode aMode,
|
const nsTArray<nsString>& aObjectStoreNames, Mode aMode,
|
||||||
Durability aDurability, nsString aFilename, uint32_t aLineNo,
|
Durability aDurability, JSCallingLocation&& aCallerLocation,
|
||||||
uint32_t aColumn, CreatedFromFactoryFunction aDummy);
|
CreatedFromFactoryFunction aDummy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~IDBTransaction();
|
~IDBTransaction();
|
||||||
|
|
|
@ -7,13 +7,7 @@
|
||||||
#include "ScriptErrorHelper.h"
|
#include "ScriptErrorHelper.h"
|
||||||
|
|
||||||
#include "MainThreadUtils.h"
|
#include "MainThreadUtils.h"
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsComponentManagerUtils.h"
|
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsIConsoleService.h"
|
|
||||||
#include "nsIScriptError.h"
|
|
||||||
#include "nsServiceManagerUtils.h"
|
|
||||||
#include "nsString.h"
|
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
|
||||||
#include "mozilla/SchedulerGroup.h"
|
#include "mozilla/SchedulerGroup.h"
|
||||||
|
@ -23,23 +17,19 @@ namespace {
|
||||||
class ScriptErrorRunnable final : public mozilla::Runnable {
|
class ScriptErrorRunnable final : public mozilla::Runnable {
|
||||||
nsString mMessage;
|
nsString mMessage;
|
||||||
nsCString mMessageName;
|
nsCString mMessageName;
|
||||||
nsString mFilename;
|
mozilla::JSCallingLocation mCallingLocation;
|
||||||
uint32_t mLineNumber;
|
|
||||||
uint32_t mColumnNumber;
|
|
||||||
uint32_t mSeverityFlag;
|
uint32_t mSeverityFlag;
|
||||||
uint64_t mInnerWindowID;
|
uint64_t mInnerWindowID;
|
||||||
bool mIsChrome;
|
bool mIsChrome;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptErrorRunnable(const nsAString& aMessage, const nsAString& aFilename,
|
ScriptErrorRunnable(const nsAString& aMessage,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
const mozilla::JSCallingLocation& aCallingLocation,
|
||||||
uint32_t aSeverityFlag, bool aIsChrome,
|
uint32_t aSeverityFlag, bool aIsChrome,
|
||||||
uint64_t aInnerWindowID)
|
uint64_t aInnerWindowID)
|
||||||
: mozilla::Runnable("ScriptErrorRunnable"),
|
: mozilla::Runnable("ScriptErrorRunnable"),
|
||||||
mMessage(aMessage),
|
mMessage(aMessage),
|
||||||
mFilename(aFilename),
|
mCallingLocation(aCallingLocation),
|
||||||
mLineNumber(aLineNumber),
|
|
||||||
mColumnNumber(aColumnNumber),
|
|
||||||
mSeverityFlag(aSeverityFlag),
|
mSeverityFlag(aSeverityFlag),
|
||||||
mInnerWindowID(aInnerWindowID),
|
mInnerWindowID(aInnerWindowID),
|
||||||
mIsChrome(aIsChrome) {
|
mIsChrome(aIsChrome) {
|
||||||
|
@ -48,14 +38,12 @@ class ScriptErrorRunnable final : public mozilla::Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptErrorRunnable(const nsACString& aMessageName,
|
ScriptErrorRunnable(const nsACString& aMessageName,
|
||||||
const nsAString& aFilename, uint32_t aLineNumber,
|
const mozilla::JSCallingLocation& aCallingLocation,
|
||||||
uint32_t aColumnNumber, uint32_t aSeverityFlag,
|
uint32_t aSeverityFlag, bool aIsChrome,
|
||||||
bool aIsChrome, uint64_t aInnerWindowID)
|
uint64_t aInnerWindowID)
|
||||||
: mozilla::Runnable("ScriptErrorRunnable"),
|
: mozilla::Runnable("ScriptErrorRunnable"),
|
||||||
mMessageName(aMessageName),
|
mMessageName(aMessageName),
|
||||||
mFilename(aFilename),
|
mCallingLocation(aCallingLocation),
|
||||||
mLineNumber(aLineNumber),
|
|
||||||
mColumnNumber(aColumnNumber),
|
|
||||||
mSeverityFlag(aSeverityFlag),
|
mSeverityFlag(aSeverityFlag),
|
||||||
mInnerWindowID(aInnerWindowID),
|
mInnerWindowID(aInnerWindowID),
|
||||||
mIsChrome(aIsChrome) {
|
mIsChrome(aIsChrome) {
|
||||||
|
@ -63,11 +51,10 @@ class ScriptErrorRunnable final : public mozilla::Runnable {
|
||||||
mMessage.SetIsVoid(true);
|
mMessage.SetIsVoid(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DumpLocalizedMessage(const nsACString& aMessageName,
|
static void DumpLocalizedMessage(
|
||||||
const nsAString& aFilename,
|
const nsACString& aMessageName,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
const mozilla::JSCallingLocation& aCallingLocation, uint32_t aSeverityFlag,
|
||||||
uint32_t aSeverityFlag, bool aIsChrome,
|
bool aIsChrome, uint64_t aInnerWindowID) {
|
||||||
uint64_t aInnerWindowID) {
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
MOZ_ASSERT(!aMessageName.IsEmpty());
|
MOZ_ASSERT(!aMessageName.IsEmpty());
|
||||||
|
|
||||||
|
@ -77,13 +64,12 @@ class ScriptErrorRunnable final : public mozilla::Runnable {
|
||||||
localizedMessage)))) {
|
localizedMessage)))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Dump(localizedMessage, aCallingLocation, aSeverityFlag, aIsChrome,
|
||||||
Dump(localizedMessage, aFilename, aLineNumber, aColumnNumber, aSeverityFlag,
|
aInnerWindowID);
|
||||||
aIsChrome, aInnerWindowID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Dump(const nsAString& aMessage, const nsAString& aFilename,
|
static void Dump(const nsAString& aMessage,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
const mozilla::JSCallingLocation& aCallingLocation,
|
||||||
uint32_t aSeverityFlag, bool aIsChrome,
|
uint32_t aSeverityFlag, bool aIsChrome,
|
||||||
uint64_t aInnerWindowID) {
|
uint64_t aInnerWindowID) {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
@ -95,37 +81,8 @@ class ScriptErrorRunnable final : public mozilla::Runnable {
|
||||||
category.AssignLiteral("content ");
|
category.AssignLiteral("content ");
|
||||||
}
|
}
|
||||||
category.AppendLiteral("javascript");
|
category.AppendLiteral("javascript");
|
||||||
|
nsContentUtils::ReportToConsoleByWindowID(aMessage, aSeverityFlag, category,
|
||||||
nsCOMPtr<nsIConsoleService> consoleService =
|
aInnerWindowID, aCallingLocation);
|
||||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptError> scriptError =
|
|
||||||
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
||||||
// We may not be able to create the script error object when we're shutting
|
|
||||||
// down.
|
|
||||||
if (!scriptError) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aInnerWindowID) {
|
|
||||||
MOZ_ALWAYS_SUCCEEDS(scriptError->InitWithWindowID(
|
|
||||||
aMessage, aFilename,
|
|
||||||
/* aSourceLine */ u""_ns, aLineNumber, aColumnNumber, aSeverityFlag,
|
|
||||||
category, aInnerWindowID));
|
|
||||||
} else {
|
|
||||||
MOZ_ALWAYS_SUCCEEDS(scriptError->Init(
|
|
||||||
aMessage, aFilename,
|
|
||||||
/* aSourceLine */ u""_ns, aLineNumber, aColumnNumber, aSeverityFlag,
|
|
||||||
category,
|
|
||||||
/* IDB doesn't run on Private browsing mode */ false,
|
|
||||||
/* from chrome context */ aIsChrome));
|
|
||||||
}
|
|
||||||
|
|
||||||
// We may not be able to obtain the console service when we're shutting
|
|
||||||
// down.
|
|
||||||
if (consoleService) {
|
|
||||||
MOZ_ALWAYS_SUCCEEDS(consoleService->LogMessage(scriptError));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHOD
|
NS_IMETHOD
|
||||||
|
@ -134,13 +91,13 @@ class ScriptErrorRunnable final : public mozilla::Runnable {
|
||||||
MOZ_ASSERT(mMessage.IsVoid() != mMessageName.IsVoid());
|
MOZ_ASSERT(mMessage.IsVoid() != mMessageName.IsVoid());
|
||||||
|
|
||||||
if (!mMessage.IsVoid()) {
|
if (!mMessage.IsVoid()) {
|
||||||
Dump(mMessage, mFilename, mLineNumber, mColumnNumber, mSeverityFlag,
|
Dump(mMessage, mCallingLocation, mSeverityFlag, mIsChrome,
|
||||||
mIsChrome, mInnerWindowID);
|
mInnerWindowID);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DumpLocalizedMessage(mMessageName, mFilename, mLineNumber, mColumnNumber,
|
DumpLocalizedMessage(mMessageName, mCallingLocation, mSeverityFlag,
|
||||||
mSeverityFlag, mIsChrome, mInnerWindowID);
|
mIsChrome, mInnerWindowID);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -155,33 +112,30 @@ namespace mozilla::dom::indexedDB {
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
void ScriptErrorHelper::Dump(const nsAString& aMessage,
|
void ScriptErrorHelper::Dump(const nsAString& aMessage,
|
||||||
const nsAString& aFilename, uint32_t aLineNumber,
|
const JSCallingLocation& aCallingLocation, uint32_t aSeverityFlag,
|
||||||
uint32_t aColumnNumber, uint32_t aSeverityFlag,
|
|
||||||
bool aIsChrome, uint64_t aInnerWindowID) {
|
bool aIsChrome, uint64_t aInnerWindowID) {
|
||||||
if (NS_IsMainThread()) {
|
if (NS_IsMainThread()) {
|
||||||
ScriptErrorRunnable::Dump(aMessage, aFilename, aLineNumber, aColumnNumber,
|
ScriptErrorRunnable::Dump(aMessage, aCallingLocation, aSeverityFlag, aIsChrome,
|
||||||
aSeverityFlag, aIsChrome, aInnerWindowID);
|
aInnerWindowID);
|
||||||
} else {
|
} else {
|
||||||
RefPtr<ScriptErrorRunnable> runnable =
|
RefPtr<ScriptErrorRunnable> runnable = new ScriptErrorRunnable(
|
||||||
new ScriptErrorRunnable(aMessage, aFilename, aLineNumber, aColumnNumber,
|
aMessage, aCallingLocation, aSeverityFlag, aIsChrome, aInnerWindowID);
|
||||||
aSeverityFlag, aIsChrome, aInnerWindowID);
|
|
||||||
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(runnable.forget()));
|
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(runnable.forget()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
void ScriptErrorHelper::DumpLocalizedMessage(
|
void ScriptErrorHelper::DumpLocalizedMessage(const nsACString& aMessageName,
|
||||||
const nsACString& aMessageName, const nsAString& aFilename,
|
const JSCallingLocation& aCallingLocation,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber, uint32_t aSeverityFlag,
|
uint32_t aSeverityFlag,
|
||||||
bool aIsChrome, uint64_t aInnerWindowID) {
|
bool aIsChrome,
|
||||||
|
uint64_t aInnerWindowID) {
|
||||||
if (NS_IsMainThread()) {
|
if (NS_IsMainThread()) {
|
||||||
ScriptErrorRunnable::DumpLocalizedMessage(
|
ScriptErrorRunnable::DumpLocalizedMessage(aMessageName, aCallingLocation, aSeverityFlag,
|
||||||
aMessageName, aFilename, aLineNumber, aColumnNumber, aSeverityFlag,
|
aIsChrome, aInnerWindowID);
|
||||||
aIsChrome, aInnerWindowID);
|
|
||||||
} else {
|
} else {
|
||||||
RefPtr<ScriptErrorRunnable> runnable = new ScriptErrorRunnable(
|
RefPtr<ScriptErrorRunnable> runnable = new ScriptErrorRunnable(
|
||||||
aMessageName, aFilename, aLineNumber, aColumnNumber, aSeverityFlag,
|
aMessageName, aCallingLocation, aSeverityFlag, aIsChrome, aInnerWindowID);
|
||||||
aIsChrome, aInnerWindowID);
|
|
||||||
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(runnable.forget()));
|
MOZ_ALWAYS_SUCCEEDS(SchedulerGroup::Dispatch(runnable.forget()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,19 +10,21 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "nsStringFwd.h"
|
#include "nsStringFwd.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
struct JSCallingLocation;
|
||||||
|
}
|
||||||
|
|
||||||
namespace mozilla::dom::indexedDB {
|
namespace mozilla::dom::indexedDB {
|
||||||
|
|
||||||
// Helper to report a script error to the main thread.
|
// Helper to report a script error to the main thread.
|
||||||
class ScriptErrorHelper {
|
class ScriptErrorHelper {
|
||||||
public:
|
public:
|
||||||
static void Dump(const nsAString& aMessage, const nsAString& aFilename,
|
static void Dump(const nsAString& aMessage, const JSCallingLocation&,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
|
||||||
uint32_t aSeverityFlag, /* nsIScriptError::xxxFlag */
|
uint32_t aSeverityFlag, /* nsIScriptError::xxxFlag */
|
||||||
bool aIsChrome, uint64_t aInnerWindowID);
|
bool aIsChrome, uint64_t aInnerWindowID);
|
||||||
|
|
||||||
static void DumpLocalizedMessage(
|
static void DumpLocalizedMessage(
|
||||||
const nsACString& aMessageName, const nsAString& aFilename,
|
const nsACString& aMessageName, const JSCallingLocation&,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
|
||||||
uint32_t aSeverityFlag, /* nsIScriptError::xxxFlag */
|
uint32_t aSeverityFlag, /* nsIScriptError::xxxFlag */
|
||||||
bool aIsChrome, uint64_t aInnerWindowID);
|
bool aIsChrome, uint64_t aInnerWindowID);
|
||||||
};
|
};
|
||||||
|
|
|
@ -230,7 +230,7 @@ interface nsIContentSecurityPolicy : nsISerializable
|
||||||
void logViolationDetails(in unsigned short violationType,
|
void logViolationDetails(in unsigned short violationType,
|
||||||
in Element triggeringElement,
|
in Element triggeringElement,
|
||||||
in nsICSPEventListener aCSPEventListener,
|
in nsICSPEventListener aCSPEventListener,
|
||||||
in AString sourceFile,
|
in ACString sourceFile,
|
||||||
in AString scriptSample,
|
in AString scriptSample,
|
||||||
in int32_t lineNum,
|
in int32_t lineNum,
|
||||||
in int32_t columnNum,
|
in int32_t columnNum,
|
||||||
|
|
|
@ -73,41 +73,17 @@ void WebAudioUtils::LogToDeveloperConsole(uint64_t aWindowID,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIConsoleService> console(
|
|
||||||
do_GetService("@mozilla.org/consoleservice;1"));
|
|
||||||
if (!console) {
|
|
||||||
NS_WARNING("Failed to log message to console.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoString spec;
|
|
||||||
uint32_t aLineNumber = 0, aColumnNumber = 1;
|
|
||||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
||||||
if (cx) {
|
|
||||||
nsJSUtils::GetCallingLocation(cx, spec, &aLineNumber, &aColumnNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv;
|
|
||||||
nsCOMPtr<nsIScriptError> errorObject =
|
|
||||||
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
|
|
||||||
if (!errorObject) {
|
|
||||||
NS_WARNING("Failed to log message to console.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoString result;
|
nsAutoString result;
|
||||||
rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES, aKey,
|
nsresult rv = nsContentUtils::GetLocalizedString(
|
||||||
result);
|
nsContentUtils::eDOM_PROPERTIES, aKey, result);
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("Failed to log message to console.");
|
NS_WARNING("Failed to log message to console.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
errorObject->InitWithWindowID(result, spec, u""_ns, aLineNumber,
|
nsContentUtils::ReportToConsoleByWindowID(result, nsIScriptError::warningFlag,
|
||||||
aColumnNumber, nsIScriptError::warningFlag,
|
"Web Audio"_ns, aWindowID);
|
||||||
"Web Audio", aWindowID);
|
|
||||||
console->LogMessage(errorObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
|
|
@ -453,7 +453,7 @@ nsresult PrototypeDocumentContentSink::ResumeWalk() {
|
||||||
nsContentUtils::ReportToConsoleNonLocalized(
|
nsContentUtils::ReportToConsoleNonLocalized(
|
||||||
u"Failed to load document from prototype document."_ns,
|
u"Failed to load document from prototype document."_ns,
|
||||||
nsIScriptError::errorFlag, "Prototype Document"_ns, mDocument,
|
nsIScriptError::errorFlag, "Prototype Document"_ns, mDocument,
|
||||||
mDocumentURI);
|
SourceLocation{mDocumentURI.get()});
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -594,10 +594,10 @@ nsresult PrototypeDocumentContentSink::ResumeWalkInternal() {
|
||||||
if (piProto->mTarget.EqualsLiteral("xml-stylesheet")) {
|
if (piProto->mTarget.EqualsLiteral("xml-stylesheet")) {
|
||||||
AutoTArray<nsString, 1> params = {piProto->mTarget};
|
AutoTArray<nsString, 1> params = {piProto->mTarget};
|
||||||
|
|
||||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
nsContentUtils::ReportToConsole(
|
||||||
"XUL Document"_ns, nullptr,
|
nsIScriptError::warningFlag, "XUL Document"_ns, nullptr,
|
||||||
nsContentUtils::eXUL_PROPERTIES,
|
nsContentUtils::eXUL_PROPERTIES, "PINotInProlog", params,
|
||||||
"PINotInProlog", params, docURI);
|
SourceLocation(docURI.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIContent* parent = element.get();
|
nsIContent* parent = element.get();
|
||||||
|
|
|
@ -390,21 +390,16 @@ nsresult PushErrorDispatcher::NotifyWorkers() {
|
||||||
// For system subscriptions, log the error directly to the browser console.
|
// For system subscriptions, log the error directly to the browser console.
|
||||||
return nsContentUtils::ReportToConsoleNonLocalized(
|
return nsContentUtils::ReportToConsoleNonLocalized(
|
||||||
mMessage, mFlags, "Push"_ns, nullptr, /* aDocument */
|
mMessage, mFlags, "Push"_ns, nullptr, /* aDocument */
|
||||||
nullptr, /* aURI */
|
SourceLocation());
|
||||||
u""_ns, /* aLine */
|
|
||||||
0, /* aLineNumber */
|
|
||||||
0, /* aColumnNumber */
|
|
||||||
nsContentUtils::eOMIT_LOCATION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For service worker subscriptions, report the error to all clients.
|
// For service worker subscriptions, report the error to all clients.
|
||||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||||
if (swm) {
|
if (swm) {
|
||||||
swm->ReportToAllClients(mScope, mMessage,
|
swm->ReportToAllClients(mScope, mMessage, mScope, /* aFilename */
|
||||||
NS_ConvertUTF8toUTF16(mScope), /* aFilename */
|
u""_ns, /* aLine */
|
||||||
u""_ns, /* aLine */
|
0, /* aLineNumber */
|
||||||
0, /* aLineNumber */
|
0, /* aColumnNumber */
|
||||||
0, /* aColumnNumber */
|
|
||||||
mFlags);
|
mFlags);
|
||||||
}
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -426,12 +421,8 @@ nsresult PushErrorDispatcher::HandleNoChildProcesses() {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
return nsContentUtils::ReportToConsoleNonLocalized(
|
return nsContentUtils::ReportToConsoleNonLocalized(
|
||||||
mMessage, mFlags, "Push"_ns, nullptr, /* aDocument */
|
mMessage, mFlags, "Push"_ns, /* aDocument = */ nullptr,
|
||||||
scopeURI, /* aURI */
|
SourceLocation(scopeURI.get()));
|
||||||
u""_ns, /* aLine */
|
|
||||||
0, /* aLineNumber */
|
|
||||||
0, /* aColumnNumber */
|
|
||||||
nsContentUtils::eOMIT_LOCATION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mozilla::dom
|
} // namespace mozilla::dom
|
||||||
|
|
|
@ -19,7 +19,7 @@ CSPViolationReportBody::CSPViolationReportBody(
|
||||||
mReferrer(aEvent.mReferrer),
|
mReferrer(aEvent.mReferrer),
|
||||||
mEffectiveDirective(aEvent.mEffectiveDirective),
|
mEffectiveDirective(aEvent.mEffectiveDirective),
|
||||||
mOriginalPolicy(aEvent.mOriginalPolicy),
|
mOriginalPolicy(aEvent.mOriginalPolicy),
|
||||||
mSourceFile(aEvent.mSourceFile),
|
mSourceFile(NS_ConvertUTF16toUTF8(aEvent.mSourceFile)),
|
||||||
mSample(aEvent.mSample),
|
mSample(aEvent.mSample),
|
||||||
mDisposition(aEvent.mDisposition),
|
mDisposition(aEvent.mDisposition),
|
||||||
mStatusCode(aEvent.mStatusCode),
|
mStatusCode(aEvent.mStatusCode),
|
||||||
|
@ -54,7 +54,7 @@ void CSPViolationReportBody::GetOriginalPolicy(nsAString& aPolicy) const {
|
||||||
aPolicy = mOriginalPolicy;
|
aPolicy = mOriginalPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSPViolationReportBody::GetSourceFile(nsAString& aFile) const {
|
void CSPViolationReportBody::GetSourceFile(nsACString& aFile) const {
|
||||||
aFile = mSourceFile;
|
aFile = mSourceFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,8 +115,7 @@ void CSPViolationReportBody::ToJSON(JSONWriter& aJSONWriter) const {
|
||||||
if (mSourceFile.IsEmpty()) {
|
if (mSourceFile.IsEmpty()) {
|
||||||
aJSONWriter.NullProperty("sourceFile");
|
aJSONWriter.NullProperty("sourceFile");
|
||||||
} else {
|
} else {
|
||||||
aJSONWriter.StringProperty("sourceFile",
|
aJSONWriter.StringProperty("sourceFile", mSourceFile);
|
||||||
NS_ConvertUTF16toUTF8(mSourceFile));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSample.IsEmpty()) {
|
if (mSample.IsEmpty()) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ class CSPViolationReportBody final : public ReportBody {
|
||||||
|
|
||||||
void GetOriginalPolicy(nsAString& aPolicy) const;
|
void GetOriginalPolicy(nsAString& aPolicy) const;
|
||||||
|
|
||||||
void GetSourceFile(nsAString& aFile) const;
|
void GetSourceFile(nsACString& aFile) const;
|
||||||
|
|
||||||
void GetSample(nsAString& aSample) const;
|
void GetSample(nsAString& aSample) const;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class CSPViolationReportBody final : public ReportBody {
|
||||||
const nsString mReferrer;
|
const nsString mReferrer;
|
||||||
const nsString mEffectiveDirective;
|
const nsString mEffectiveDirective;
|
||||||
const nsString mOriginalPolicy;
|
const nsString mOriginalPolicy;
|
||||||
const nsString mSourceFile;
|
const nsCString mSourceFile;
|
||||||
const nsString mSample;
|
const nsString mSample;
|
||||||
const mozilla::dom::SecurityPolicyViolationEventDisposition mDisposition;
|
const mozilla::dom::SecurityPolicyViolationEventDisposition mDisposition;
|
||||||
const uint16_t mStatusCode;
|
const uint16_t mStatusCode;
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace mozilla::dom {
|
||||||
DeprecationReportBody::DeprecationReportBody(
|
DeprecationReportBody::DeprecationReportBody(
|
||||||
nsIGlobalObject* aGlobal, const nsAString& aId,
|
nsIGlobalObject* aGlobal, const nsAString& aId,
|
||||||
const Nullable<uint64_t>& aDate, const nsAString& aMessage,
|
const Nullable<uint64_t>& aDate, const nsAString& aMessage,
|
||||||
const nsAString& aSourceFile, const Nullable<uint32_t>& aLineNumber,
|
const nsACString& aSourceFile, const Nullable<uint32_t>& aLineNumber,
|
||||||
const Nullable<uint32_t>& aColumnNumber)
|
const Nullable<uint32_t>& aColumnNumber)
|
||||||
: ReportBody(aGlobal),
|
: ReportBody(aGlobal),
|
||||||
mId(aId),
|
mId(aId),
|
||||||
|
@ -42,7 +42,7 @@ void DeprecationReportBody::GetMessage(nsAString& aMessage) const {
|
||||||
aMessage = mMessage;
|
aMessage = mMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeprecationReportBody::GetSourceFile(nsAString& aSourceFile) const {
|
void DeprecationReportBody::GetSourceFile(nsACString& aSourceFile) const {
|
||||||
aSourceFile = mSourceFile;
|
aSourceFile = mSourceFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ void DeprecationReportBody::ToJSON(JSONWriter& aWriter) const {
|
||||||
if (mSourceFile.IsEmpty()) {
|
if (mSourceFile.IsEmpty()) {
|
||||||
aWriter.NullProperty("sourceFile");
|
aWriter.NullProperty("sourceFile");
|
||||||
} else {
|
} else {
|
||||||
aWriter.StringProperty("sourceFile", NS_ConvertUTF16toUTF8(mSourceFile));
|
aWriter.StringProperty("sourceFile", mSourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLineNumber.IsNull()) {
|
if (mLineNumber.IsNull()) {
|
||||||
|
|
|
@ -17,7 +17,8 @@ class DeprecationReportBody final : public ReportBody {
|
||||||
public:
|
public:
|
||||||
DeprecationReportBody(nsIGlobalObject* aGlobal, const nsAString& aId,
|
DeprecationReportBody(nsIGlobalObject* aGlobal, const nsAString& aId,
|
||||||
const Nullable<uint64_t>& aDate,
|
const Nullable<uint64_t>& aDate,
|
||||||
const nsAString& aMessage, const nsAString& aSourceFile,
|
const nsAString& aMessage,
|
||||||
|
const nsACString& aSourceFile,
|
||||||
const Nullable<uint32_t>& aLineNumber,
|
const Nullable<uint32_t>& aLineNumber,
|
||||||
const Nullable<uint32_t>& aColumnNumber);
|
const Nullable<uint32_t>& aColumnNumber);
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ class DeprecationReportBody final : public ReportBody {
|
||||||
|
|
||||||
void GetMessage(nsAString& aMessage) const;
|
void GetMessage(nsAString& aMessage) const;
|
||||||
|
|
||||||
void GetSourceFile(nsAString& aSourceFile) const;
|
void GetSourceFile(nsACString& aSourceFile) const;
|
||||||
|
|
||||||
Nullable<uint32_t> GetLineNumber() const;
|
Nullable<uint32_t> GetLineNumber() const;
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ class DeprecationReportBody final : public ReportBody {
|
||||||
const nsString mId;
|
const nsString mId;
|
||||||
const Nullable<uint64_t> mDate;
|
const Nullable<uint64_t> mDate;
|
||||||
const nsString mMessage;
|
const nsString mMessage;
|
||||||
const nsString mSourceFile;
|
const nsCString mSourceFile;
|
||||||
const Nullable<uint32_t> mLineNumber;
|
const Nullable<uint32_t> mLineNumber;
|
||||||
const Nullable<uint32_t> mColumnNumber;
|
const Nullable<uint32_t> mColumnNumber;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace mozilla::dom {
|
||||||
|
|
||||||
FeaturePolicyViolationReportBody::FeaturePolicyViolationReportBody(
|
FeaturePolicyViolationReportBody::FeaturePolicyViolationReportBody(
|
||||||
nsIGlobalObject* aGlobal, const nsAString& aFeatureId,
|
nsIGlobalObject* aGlobal, const nsAString& aFeatureId,
|
||||||
const nsAString& aSourceFile, const Nullable<int32_t>& aLineNumber,
|
const nsACString& aSourceFile, const Nullable<int32_t>& aLineNumber,
|
||||||
const Nullable<int32_t>& aColumnNumber, const nsAString& aDisposition)
|
const Nullable<int32_t>& aColumnNumber, const nsAString& aDisposition)
|
||||||
: ReportBody(aGlobal),
|
: ReportBody(aGlobal),
|
||||||
mFeatureId(aFeatureId),
|
mFeatureId(aFeatureId),
|
||||||
|
@ -35,7 +35,7 @@ void FeaturePolicyViolationReportBody::GetFeatureId(
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeaturePolicyViolationReportBody::GetSourceFile(
|
void FeaturePolicyViolationReportBody::GetSourceFile(
|
||||||
nsAString& aSourceFile) const {
|
nsACString& aSourceFile) const {
|
||||||
aSourceFile = mSourceFile;
|
aSourceFile = mSourceFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ void FeaturePolicyViolationReportBody::ToJSON(JSONWriter& aWriter) const {
|
||||||
if (mSourceFile.IsEmpty()) {
|
if (mSourceFile.IsEmpty()) {
|
||||||
aWriter.NullProperty("sourceFile");
|
aWriter.NullProperty("sourceFile");
|
||||||
} else {
|
} else {
|
||||||
aWriter.StringProperty("sourceFile", NS_ConvertUTF16toUTF8(mSourceFile));
|
aWriter.StringProperty("sourceFile", mSourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mLineNumber.IsNull()) {
|
if (mLineNumber.IsNull()) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ class FeaturePolicyViolationReportBody final : public ReportBody {
|
||||||
public:
|
public:
|
||||||
FeaturePolicyViolationReportBody(nsIGlobalObject* aGlobal,
|
FeaturePolicyViolationReportBody(nsIGlobalObject* aGlobal,
|
||||||
const nsAString& aFeatureId,
|
const nsAString& aFeatureId,
|
||||||
const nsAString& aSourceFile,
|
const nsACString& aSourceFile,
|
||||||
const Nullable<int32_t>& aLineNumber,
|
const Nullable<int32_t>& aLineNumber,
|
||||||
const Nullable<int32_t>& aColumnNumber,
|
const Nullable<int32_t>& aColumnNumber,
|
||||||
const nsAString& aDisposition);
|
const nsAString& aDisposition);
|
||||||
|
@ -27,7 +27,7 @@ class FeaturePolicyViolationReportBody final : public ReportBody {
|
||||||
|
|
||||||
void GetFeatureId(nsAString& aFeatureId) const;
|
void GetFeatureId(nsAString& aFeatureId) const;
|
||||||
|
|
||||||
void GetSourceFile(nsAString& aSourceFile) const;
|
void GetSourceFile(nsACString& aSourceFile) const;
|
||||||
|
|
||||||
Nullable<int32_t> GetLineNumber() const;
|
Nullable<int32_t> GetLineNumber() const;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class FeaturePolicyViolationReportBody final : public ReportBody {
|
||||||
~FeaturePolicyViolationReportBody();
|
~FeaturePolicyViolationReportBody();
|
||||||
|
|
||||||
const nsString mFeatureId;
|
const nsString mFeatureId;
|
||||||
const nsString mSourceFile;
|
const nsCString mSourceFile;
|
||||||
const Nullable<int32_t> mLineNumber;
|
const Nullable<int32_t> mLineNumber;
|
||||||
const Nullable<int32_t> mColumnNumber;
|
const Nullable<int32_t> mColumnNumber;
|
||||||
const nsString mDisposition;
|
const nsString mDisposition;
|
||||||
|
|
|
@ -577,7 +577,8 @@ void ReportingHeader::LogToConsoleInternal(nsIHttpChannel* aChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = nsContentUtils::ReportToConsoleByWindowID(
|
rv = nsContentUtils::ReportToConsoleByWindowID(
|
||||||
localizedMsg, nsIScriptError::infoFlag, "Reporting"_ns, windowID, aURI);
|
localizedMsg, nsIScriptError::infoFlag, "Reporting"_ns, windowID,
|
||||||
|
SourceLocation(aURI));
|
||||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3627,8 +3627,9 @@ void ScriptLoader::ReportErrorToConsole(ScriptLoadRequest* aRequest,
|
||||||
|
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::warningFlag, "Script Loader"_ns, mDocument,
|
nsIScriptError::warningFlag, "Script Loader"_ns, mDocument,
|
||||||
nsContentUtils::eDOM_PROPERTIES, message, params, nullptr, u""_ns, lineNo,
|
nsContentUtils::eDOM_PROPERTIES, message, params,
|
||||||
columnNo.oneOriginValue());
|
SourceLocation{mDocument->GetDocumentURI(), lineNo,
|
||||||
|
columnNo.oneOriginValue()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptLoader::ReportWarningToConsole(
|
void ScriptLoader::ReportWarningToConsole(
|
||||||
|
@ -3639,8 +3640,9 @@ void ScriptLoader::ReportWarningToConsole(
|
||||||
aRequest->GetScriptLoadContext()->GetScriptColumnNumber();
|
aRequest->GetScriptLoadContext()->GetScriptColumnNumber();
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::warningFlag, "Script Loader"_ns, mDocument,
|
nsIScriptError::warningFlag, "Script Loader"_ns, mDocument,
|
||||||
nsContentUtils::eDOM_PROPERTIES, aMessageName, aParams, nullptr, u""_ns,
|
nsContentUtils::eDOM_PROPERTIES, aMessageName, aParams,
|
||||||
lineNo, columnNo.oneOriginValue());
|
SourceLocation{mDocument->GetDocumentURI(), lineNo,
|
||||||
|
columnNo.oneOriginValue()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptLoader::ReportPreloadErrorsToConsole(ScriptLoadRequest* aRequest) {
|
void ScriptLoader::ReportPreloadErrorsToConsole(ScriptLoadRequest* aRequest) {
|
||||||
|
|
|
@ -8,14 +8,11 @@
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/WorkerPrivate.h"
|
#include "mozilla/dom/WorkerPrivate.h"
|
||||||
#include "mozilla/dom/WorkerRunnable.h"
|
#include "mozilla/dom/WorkerRunnable.h"
|
||||||
#include "mozilla/BasePrincipal.h"
|
|
||||||
#include "mozilla/ErrorResult.h"
|
#include "mozilla/ErrorResult.h"
|
||||||
#include "nsIParentChannel.h"
|
|
||||||
#include "nsGlobalWindowInner.h"
|
#include "nsGlobalWindowInner.h"
|
||||||
#include "nsContentSecurityUtils.h"
|
#include "nsContentSecurityUtils.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsJSUtils.h"
|
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
@ -28,8 +25,7 @@ nsresult CheckInternal(nsIContentSecurityPolicy* aCSP,
|
||||||
nsICSPEventListener* aCSPEventListener,
|
nsICSPEventListener* aCSPEventListener,
|
||||||
nsIPrincipal* aSubjectPrincipal,
|
nsIPrincipal* aSubjectPrincipal,
|
||||||
const nsAString& aExpression,
|
const nsAString& aExpression,
|
||||||
const nsAString& aFileNameString, uint32_t aLineNum,
|
const JSCallingLocation& aCaller, bool* aAllowed) {
|
||||||
uint32_t aColumnNum, bool* aAllowed) {
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
MOZ_ASSERT(aAllowed);
|
MOZ_ASSERT(aAllowed);
|
||||||
|
|
||||||
|
@ -61,8 +57,9 @@ nsresult CheckInternal(nsIContentSecurityPolicy* aCSP,
|
||||||
if (reportViolation) {
|
if (reportViolation) {
|
||||||
aCSP->LogViolationDetails(nsIContentSecurityPolicy::VIOLATION_TYPE_EVAL,
|
aCSP->LogViolationDetails(nsIContentSecurityPolicy::VIOLATION_TYPE_EVAL,
|
||||||
nullptr, // triggering element
|
nullptr, // triggering element
|
||||||
aCSPEventListener, aFileNameString, aExpression,
|
aCSPEventListener, aCaller.FileName(),
|
||||||
aLineNum, aColumnNum, u""_ns, u""_ns);
|
aExpression, aCaller.mLine, aCaller.mColumn,
|
||||||
|
u""_ns, u""_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -72,22 +69,19 @@ class WorkerCSPCheckRunnable final : public WorkerMainThreadRunnable {
|
||||||
public:
|
public:
|
||||||
WorkerCSPCheckRunnable(WorkerPrivate* aWorkerPrivate,
|
WorkerCSPCheckRunnable(WorkerPrivate* aWorkerPrivate,
|
||||||
const nsAString& aExpression,
|
const nsAString& aExpression,
|
||||||
const nsAString& aFileNameString, uint32_t aLineNum,
|
JSCallingLocation&& aCaller)
|
||||||
uint32_t aColumnNum)
|
|
||||||
: WorkerMainThreadRunnable(aWorkerPrivate, "CSP Eval Check"_ns),
|
: WorkerMainThreadRunnable(aWorkerPrivate, "CSP Eval Check"_ns),
|
||||||
mExpression(aExpression),
|
mExpression(aExpression),
|
||||||
mFileNameString(aFileNameString),
|
mCaller(std::move(aCaller)),
|
||||||
mLineNum(aLineNum),
|
|
||||||
mColumnNum(aColumnNum),
|
|
||||||
mEvalAllowed(false) {}
|
mEvalAllowed(false) {}
|
||||||
|
|
||||||
bool MainThreadRun() override {
|
bool MainThreadRun() override {
|
||||||
MOZ_ASSERT(mWorkerRef);
|
MOZ_ASSERT(mWorkerRef);
|
||||||
WorkerPrivate* workerPrivate = mWorkerRef->Private();
|
WorkerPrivate* workerPrivate = mWorkerRef->Private();
|
||||||
mResult = CheckInternal(
|
mResult = CheckInternal(workerPrivate->GetCsp(),
|
||||||
workerPrivate->GetCsp(), workerPrivate->CSPEventListener(),
|
workerPrivate->CSPEventListener(),
|
||||||
workerPrivate->GetLoadingPrincipal(), mExpression, mFileNameString,
|
workerPrivate->GetLoadingPrincipal(), mExpression,
|
||||||
mLineNum, mColumnNum, &mEvalAllowed);
|
mCaller, &mEvalAllowed);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +93,7 @@ class WorkerCSPCheckRunnable final : public WorkerMainThreadRunnable {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const nsString mExpression;
|
const nsString mExpression;
|
||||||
const nsString mFileNameString;
|
const JSCallingLocation mCaller;
|
||||||
const uint32_t mLineNum;
|
|
||||||
const uint32_t mColumnNum;
|
|
||||||
bool mEvalAllowed;
|
bool mEvalAllowed;
|
||||||
nsresult mResult;
|
nsresult mResult;
|
||||||
};
|
};
|
||||||
|
@ -131,19 +123,10 @@ nsresult CSPEvalChecker::CheckForWindow(JSContext* aCx,
|
||||||
|
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
// Get the calling location.
|
auto location = JSCallingLocation::Get(aCx);
|
||||||
uint32_t lineNum = 0;
|
|
||||||
uint32_t columnNum = 1;
|
|
||||||
nsAutoString fileNameString;
|
|
||||||
if (!nsJSUtils::GetCallingLocation(aCx, fileNameString, &lineNum,
|
|
||||||
&columnNum)) {
|
|
||||||
fileNameString.AssignLiteral("unknown");
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContentSecurityPolicy> csp = doc->GetCsp();
|
nsCOMPtr<nsIContentSecurityPolicy> csp = doc->GetCsp();
|
||||||
rv = CheckInternal(csp, nullptr /* no CSPEventListener for window */,
|
rv = CheckInternal(csp, nullptr /* no CSPEventListener for window */,
|
||||||
doc->NodePrincipal(), aExpression, fileNameString, lineNum,
|
doc->NodePrincipal(), aExpression, location, aAllowEval);
|
||||||
columnNum, aAllowEval);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
*aAllowEval = false;
|
*aAllowEval = false;
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -164,17 +147,8 @@ nsresult CSPEvalChecker::CheckForWorker(JSContext* aCx,
|
||||||
// The value is set at any "return", but better to have a default value here.
|
// The value is set at any "return", but better to have a default value here.
|
||||||
*aAllowEval = false;
|
*aAllowEval = false;
|
||||||
|
|
||||||
// Get the calling location.
|
|
||||||
uint32_t lineNum = 0;
|
|
||||||
uint32_t columnNum = 1;
|
|
||||||
nsAutoString fileNameString;
|
|
||||||
if (!nsJSUtils::GetCallingLocation(aCx, fileNameString, &lineNum,
|
|
||||||
&columnNum)) {
|
|
||||||
fileNameString.AssignLiteral("unknown");
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<WorkerCSPCheckRunnable> r = new WorkerCSPCheckRunnable(
|
RefPtr<WorkerCSPCheckRunnable> r = new WorkerCSPCheckRunnable(
|
||||||
aWorkerPrivate, aExpression, fileNameString, lineNum, columnNum);
|
aWorkerPrivate, aExpression, JSCallingLocation::Get(aCx));
|
||||||
ErrorResult error;
|
ErrorResult error;
|
||||||
r->Dispatch(aWorkerPrivate, Canceling, error);
|
r->Dispatch(aWorkerPrivate, Canceling, error);
|
||||||
if (NS_WARN_IF(error.Failed())) {
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ static nsString MaybeTruncateSample(const nsAString& aSample) {
|
||||||
CSPViolationData::CSPViolationData(uint32_t aViolatedPolicyIndex,
|
CSPViolationData::CSPViolationData(uint32_t aViolatedPolicyIndex,
|
||||||
Resource&& aResource,
|
Resource&& aResource,
|
||||||
const CSPDirective aEffectiveDirective,
|
const CSPDirective aEffectiveDirective,
|
||||||
const nsAString& aSourceFile,
|
const nsACString& aSourceFile,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
||||||
Element* aElement, const nsAString& aSample)
|
Element* aElement, const nsAString& aSample)
|
||||||
: mViolatedPolicyIndex{aViolatedPolicyIndex},
|
: mViolatedPolicyIndex{aViolatedPolicyIndex},
|
||||||
|
|
|
@ -38,7 +38,7 @@ struct CSPViolationData {
|
||||||
// @param aSample Will be truncated if necessary.
|
// @param aSample Will be truncated if necessary.
|
||||||
CSPViolationData(uint32_t aViolatedPolicyIndex, Resource&& aResource,
|
CSPViolationData(uint32_t aViolatedPolicyIndex, Resource&& aResource,
|
||||||
const CSPDirective aEffectiveDirective,
|
const CSPDirective aEffectiveDirective,
|
||||||
const nsAString& aSourceFile, uint32_t aLineNumber,
|
const nsACString& aSourceFile, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, Element* aElement,
|
uint32_t aColumnNumber, Element* aElement,
|
||||||
const nsAString& aSample);
|
const nsAString& aSample);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ struct CSPViolationData {
|
||||||
const Resource mResource;
|
const Resource mResource;
|
||||||
const CSPDirective mEffectiveDirective;
|
const CSPDirective mEffectiveDirective;
|
||||||
// String representation of the URL. The empty string represents a null-URL.
|
// String representation of the URL. The empty string represents a null-URL.
|
||||||
const nsString mSourceFile;
|
const nsCString mSourceFile;
|
||||||
const uint32_t mLineNumber;
|
const uint32_t mLineNumber;
|
||||||
const uint32_t mColumnNumber;
|
const uint32_t mColumnNumber;
|
||||||
RefPtr<Element> mElement;
|
RefPtr<Element> mElement;
|
||||||
|
|
|
@ -34,12 +34,8 @@ void DOMSecurityMonitor::AuditParsingOfHTMLXMLFragments(
|
||||||
// check if there is a JS caller, if not, then we can can return early here
|
// check if there is a JS caller, if not, then we can can return early here
|
||||||
// because we only care about calls to the fragment parser (e.g. innerHTML)
|
// because we only care about calls to the fragment parser (e.g. innerHTML)
|
||||||
// originating from JS code.
|
// originating from JS code.
|
||||||
nsAutoString filename;
|
auto loc = mozilla::JSCallingLocation::Get();
|
||||||
uint32_t lineNum = 0;
|
if (!loc) {
|
||||||
uint32_t columnNum = 1;
|
|
||||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
||||||
if (!cx ||
|
|
||||||
!nsJSUtils::GetCallingLocation(cx, filename, &lineNum, &columnNum)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +84,7 @@ void DOMSecurityMonitor::AuditParsingOfHTMLXMLFragments(
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const nsLiteralCString& allowlistEntry : htmlFragmentAllowlist) {
|
for (const nsLiteralCString& allowlistEntry : htmlFragmentAllowlist) {
|
||||||
if (StringBeginsWith(NS_ConvertUTF16toUTF8(filename), allowlistEntry)) {
|
if (StringBeginsWith(loc.FileName(), allowlistEntry)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,8 +100,8 @@ void DOMSecurityMonitor::AuditParsingOfHTMLXMLFragments(
|
||||||
"Do not call the fragment parser (e.g innerHTML()) in chrome code "
|
"Do not call the fragment parser (e.g innerHTML()) in chrome code "
|
||||||
"or in about: pages, (uri: %s), (caller: %s, line: %d, col: %d), "
|
"or in about: pages, (uri: %s), (caller: %s, line: %d, col: %d), "
|
||||||
"(fragment: %s)",
|
"(fragment: %s)",
|
||||||
uriSpec.get(), NS_ConvertUTF16toUTF8(filename).get(), lineNum,
|
uriSpec.get(), loc.FileName().get(), loc.mLine, loc.mColumn,
|
||||||
columnNum, NS_ConvertUTF16toUTF8(aFragment).get());
|
NS_ConvertUTF16toUTF8(aFragment).get());
|
||||||
|
|
||||||
xpc_DumpJSStack(true, true, false);
|
xpc_DumpJSStack(true, true, false);
|
||||||
MOZ_ASSERT(false);
|
MOZ_ASSERT(false);
|
||||||
|
|
|
@ -860,7 +860,8 @@ void ReferrerInfo::LogMessageToConsole(
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = nsContentUtils::ReportToConsoleByWindowID(
|
rv = nsContentUtils::ReportToConsoleByWindowID(
|
||||||
localizedMsg, nsIScriptError::infoFlag, "Security"_ns, windowID, uri);
|
localizedMsg, nsIScriptError::infoFlag, "Security"_ns, windowID,
|
||||||
|
SourceLocation(std::move(uri)));
|
||||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,14 +222,12 @@ void FeaturePolicyUtils::ReportViolation(Document* aDocument,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString fileName;
|
|
||||||
Nullable<int32_t> lineNumber;
|
Nullable<int32_t> lineNumber;
|
||||||
Nullable<int32_t> columnNumber;
|
Nullable<int32_t> columnNumber;
|
||||||
uint32_t line = 0;
|
auto loc = JSCallingLocation::Get();
|
||||||
uint32_t column = 0;
|
if (loc) {
|
||||||
if (nsJSUtils::GetCallingLocation(cx, fileName, &line, &column)) {
|
lineNumber.SetValue(static_cast<int32_t>(loc.mLine));
|
||||||
lineNumber.SetValue(static_cast<int32_t>(line));
|
columnNumber.SetValue(static_cast<int32_t>(loc.mColumn));
|
||||||
columnNumber.SetValue(static_cast<int32_t>(column));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsPIDOMWindowInner* window = aDocument->GetInnerWindow();
|
nsPIDOMWindowInner* window = aDocument->GetInnerWindow();
|
||||||
|
@ -239,8 +237,8 @@ void FeaturePolicyUtils::ReportViolation(Document* aDocument,
|
||||||
|
|
||||||
RefPtr<FeaturePolicyViolationReportBody> body =
|
RefPtr<FeaturePolicyViolationReportBody> body =
|
||||||
new FeaturePolicyViolationReportBody(window->AsGlobal(), aFeatureName,
|
new FeaturePolicyViolationReportBody(window->AsGlobal(), aFeatureName,
|
||||||
fileName, lineNumber, columnNumber,
|
loc.FileName(), lineNumber,
|
||||||
u"enforce"_ns);
|
columnNumber, u"enforce"_ns);
|
||||||
|
|
||||||
ReportingUtils::Report(window->AsGlobal(), nsGkAtoms::featurePolicyViolation,
|
ReportingUtils::Report(window->AsGlobal(), nsGkAtoms::featurePolicyViolation,
|
||||||
u"default"_ns, NS_ConvertUTF8toUTF16(spec), body);
|
u"default"_ns, NS_ConvertUTF8toUTF16(spec), body);
|
||||||
|
|
|
@ -212,15 +212,7 @@ bool nsCSPContext::permitsInternal(
|
||||||
// preload - the decision may be wrong due to the inability to get the
|
// preload - the decision may be wrong due to the inability to get the
|
||||||
// nonce, and will incorrectly fail the unit tests.
|
// nonce, and will incorrectly fail the unit tests.
|
||||||
if (aSendViolationReports) {
|
if (aSendViolationReports) {
|
||||||
uint32_t lineNumber = 0;
|
auto loc = JSCallingLocation::Get();
|
||||||
uint32_t columnNumber = 1;
|
|
||||||
nsAutoString spec;
|
|
||||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
||||||
if (cx) {
|
|
||||||
nsJSUtils::GetCallingLocation(cx, spec, &lineNumber, &columnNumber);
|
|
||||||
// If GetCallingLocation fails linenumber & columnNumber are set to
|
|
||||||
// (0, 1) anyway so we can skip checking if that is the case.
|
|
||||||
}
|
|
||||||
|
|
||||||
using Resource = CSPViolationData::Resource;
|
using Resource = CSPViolationData::Resource;
|
||||||
Resource resource =
|
Resource resource =
|
||||||
|
@ -231,9 +223,9 @@ bool nsCSPContext::permitsInternal(
|
||||||
CSPViolationData cspViolationData{p,
|
CSPViolationData cspViolationData{p,
|
||||||
std::move(resource),
|
std::move(resource),
|
||||||
aDir,
|
aDir,
|
||||||
spec,
|
loc.FileName(),
|
||||||
lineNumber,
|
loc.mLine,
|
||||||
columnNumber,
|
loc.mColumn,
|
||||||
aTriggeringElement,
|
aTriggeringElement,
|
||||||
/* aSample */ u""_ns};
|
/* aSample */ u""_ns};
|
||||||
|
|
||||||
|
@ -553,21 +545,16 @@ void nsCSPContext::reportInlineViolation(
|
||||||
STYLE_HASH_VIOLATION_OBSERVER_TOPIC);
|
STYLE_HASH_VIOLATION_OBSERVER_TOPIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString sourceFile;
|
auto loc = JSCallingLocation::Get();
|
||||||
uint32_t lineNumber;
|
if (!loc) {
|
||||||
uint32_t columnNumber;
|
nsCString sourceFile;
|
||||||
|
// use selfURI as the source
|
||||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
||||||
if (!cx || !nsJSUtils::GetCallingLocation(cx, sourceFile, &lineNumber,
|
|
||||||
&columnNumber)) {
|
|
||||||
// use selfURI as the sourceFile
|
|
||||||
if (mSelfURI) {
|
if (mSelfURI) {
|
||||||
nsAutoCString cSourceFile;
|
mSelfURI->GetSpec(sourceFile);
|
||||||
mSelfURI->GetSpec(cSourceFile);
|
loc.mResource = AsVariant(std::move(sourceFile));
|
||||||
sourceFile.Assign(NS_ConvertUTF8toUTF16(cSourceFile));
|
|
||||||
}
|
}
|
||||||
lineNumber = aLineNumber;
|
loc.mLine = aLineNumber;
|
||||||
columnNumber = aColumnNumber;
|
loc.mColumn = aColumnNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSPViolationData cspViolationData{
|
CSPViolationData cspViolationData{
|
||||||
|
@ -575,9 +562,9 @@ void nsCSPContext::reportInlineViolation(
|
||||||
CSPViolationData::Resource{
|
CSPViolationData::Resource{
|
||||||
CSPViolationData::BlockedContentSource::Inline},
|
CSPViolationData::BlockedContentSource::Inline},
|
||||||
aEffectiveDirective,
|
aEffectiveDirective,
|
||||||
sourceFile,
|
loc.FileName(),
|
||||||
lineNumber,
|
loc.mLine,
|
||||||
columnNumber,
|
loc.mColumn,
|
||||||
aTriggeringElement,
|
aTriggeringElement,
|
||||||
aSample};
|
aSample};
|
||||||
|
|
||||||
|
@ -730,7 +717,7 @@ nsCSPContext::GetAllowsInline(CSPDirective aDirective, bool aHasUnsafeHash,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsCSPContext::LogViolationDetails(
|
nsCSPContext::LogViolationDetails(
|
||||||
uint16_t aViolationType, Element* aTriggeringElement,
|
uint16_t aViolationType, Element* aTriggeringElement,
|
||||||
nsICSPEventListener* aCSPEventListener, const nsAString& aSourceFile,
|
nsICSPEventListener* aCSPEventListener, const nsACString& aSourceFile,
|
||||||
const nsAString& aScriptSample, int32_t aLineNum, int32_t aColumnNum,
|
const nsAString& aScriptSample, int32_t aLineNum, int32_t aColumnNum,
|
||||||
const nsAString& aNonce, const nsAString& aContent) {
|
const nsAString& aNonce, const nsAString& aContent) {
|
||||||
EnsureIPCPoliciesRead();
|
EnsureIPCPoliciesRead();
|
||||||
|
@ -895,7 +882,7 @@ nsCSPContext::EnsureEventTarget(nsIEventTarget* aEventTarget) {
|
||||||
|
|
||||||
struct ConsoleMsgQueueElem {
|
struct ConsoleMsgQueueElem {
|
||||||
nsString mMsg;
|
nsString mMsg;
|
||||||
nsString mSourceName;
|
nsCString mSourceName;
|
||||||
nsString mSourceLine;
|
nsString mSourceLine;
|
||||||
uint32_t mLineNumber;
|
uint32_t mLineNumber;
|
||||||
uint32_t mColumnNumber;
|
uint32_t mColumnNumber;
|
||||||
|
@ -927,7 +914,7 @@ void nsCSPContext::flushConsoleMessages() {
|
||||||
|
|
||||||
void nsCSPContext::logToConsole(const char* aName,
|
void nsCSPContext::logToConsole(const char* aName,
|
||||||
const nsTArray<nsString>& aParams,
|
const nsTArray<nsString>& aParams,
|
||||||
const nsAString& aSourceName,
|
const nsACString& aSourceName,
|
||||||
const nsAString& aSourceLine,
|
const nsAString& aSourceLine,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
||||||
uint32_t aSeverityFlag) {
|
uint32_t aSeverityFlag) {
|
||||||
|
@ -936,20 +923,20 @@ void nsCSPContext::logToConsole(const char* aName,
|
||||||
nsDependentCString category(aName);
|
nsDependentCString category(aName);
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
nsAutoString sourceName(aSourceName);
|
nsAutoCString spec;
|
||||||
if (sourceName.IsEmpty() && mSelfURI) {
|
if (aSourceName.IsEmpty() && mSelfURI) {
|
||||||
nsAutoCString spec;
|
|
||||||
mSelfURI->GetSpec(spec);
|
mSelfURI->GetSpec(spec);
|
||||||
CopyUTF8toUTF16(spec, sourceName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto& sourceName = aSourceName.IsEmpty() ? spec : aSourceName;
|
||||||
|
|
||||||
// let's check if we have to queue up console messages
|
// let's check if we have to queue up console messages
|
||||||
if (mQueueUpMessages) {
|
if (mQueueUpMessages) {
|
||||||
nsAutoString msg;
|
nsAutoString msg;
|
||||||
CSP_GetLocalizedStr(aName, aParams, msg);
|
CSP_GetLocalizedStr(aName, aParams, msg);
|
||||||
ConsoleMsgQueueElem& elem = *mConsoleMsgQueue.AppendElement();
|
ConsoleMsgQueueElem& elem = *mConsoleMsgQueue.AppendElement();
|
||||||
elem.mMsg = msg;
|
elem.mMsg = msg;
|
||||||
elem.mSourceName = PromiseFlatString(sourceName);
|
elem.mSourceName = sourceName;
|
||||||
elem.mSourceLine = PromiseFlatString(aSourceLine);
|
elem.mSourceLine = PromiseFlatString(aSourceLine);
|
||||||
elem.mLineNumber = aLineNumber;
|
elem.mLineNumber = aLineNumber;
|
||||||
elem.mColumnNumber = aColumnNumber;
|
elem.mColumnNumber = aColumnNumber;
|
||||||
|
@ -959,8 +946,7 @@ void nsCSPContext::logToConsole(const char* aName,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool privateWindow = false;
|
bool privateWindow = false;
|
||||||
nsCOMPtr<Document> doc = do_QueryReferent(mLoadingContext);
|
if (nsCOMPtr<Document> doc = do_QueryReferent(mLoadingContext)) {
|
||||||
if (doc) {
|
|
||||||
privateWindow =
|
privateWindow =
|
||||||
doc->NodePrincipal()->OriginAttributesRef().IsPrivateBrowsing();
|
doc->NodePrincipal()->OriginAttributesRef().IsPrivateBrowsing();
|
||||||
}
|
}
|
||||||
|
@ -1082,11 +1068,12 @@ nsresult nsCSPContext::GatherSecurityPolicyViolationEventData(
|
||||||
nsCOMPtr<nsIURI> sourceURI;
|
nsCOMPtr<nsIURI> sourceURI;
|
||||||
NS_NewURI(getter_AddRefs(sourceURI), aCSPViolationData.mSourceFile);
|
NS_NewURI(getter_AddRefs(sourceURI), aCSPViolationData.mSourceFile);
|
||||||
if (sourceURI) {
|
if (sourceURI) {
|
||||||
nsAutoCString spec;
|
nsAutoCString stripped;
|
||||||
StripURIForReporting(mSelfURI, sourceURI, aEffectiveDirective, spec);
|
StripURIForReporting(mSelfURI, sourceURI, aEffectiveDirective, stripped);
|
||||||
CopyUTF8toUTF16(spec, aViolationEventInit.mSourceFile);
|
CopyUTF8toUTF16(stripped, aViolationEventInit.mSourceFile);
|
||||||
} else {
|
} else {
|
||||||
aViolationEventInit.mSourceFile = aCSPViolationData.mSourceFile;
|
CopyUTF8toUTF16(aCSPViolationData.mSourceFile,
|
||||||
|
aViolationEventInit.mSourceFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1160,7 +1147,8 @@ bool nsCSPContext::ShouldThrottleReport(
|
||||||
|
|
||||||
// Rate limit reached
|
// Rate limit reached
|
||||||
if (!mWarnedAboutTooManyReports) {
|
if (!mWarnedAboutTooManyReports) {
|
||||||
logToConsole("tooManyReports", {}, aViolationEventInit.mSourceFile,
|
logToConsole("tooManyReports", {},
|
||||||
|
NS_ConvertUTF16toUTF8(aViolationEventInit.mSourceFile),
|
||||||
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
||||||
aViolationEventInit.mColumnNumber, nsIScriptError::errorFlag);
|
aViolationEventInit.mColumnNumber, nsIScriptError::errorFlag);
|
||||||
mWarnedAboutTooManyReports = true;
|
mWarnedAboutTooManyReports = true;
|
||||||
|
@ -1251,7 +1239,8 @@ nsresult nsCSPContext::SendReportsToURIs(
|
||||||
// source-file
|
// source-file
|
||||||
if (!aViolationEventInit.mSourceFile.IsEmpty()) {
|
if (!aViolationEventInit.mSourceFile.IsEmpty()) {
|
||||||
report.mCsp_report.mSource_file.Construct();
|
report.mCsp_report.mSource_file.Construct();
|
||||||
report.mCsp_report.mSource_file.Value() = aViolationEventInit.mSourceFile;
|
CopyUTF16toUTF8(aViolationEventInit.mSourceFile,
|
||||||
|
report.mCsp_report.mSource_file.Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
// script-sample
|
// script-sample
|
||||||
|
@ -1291,7 +1280,8 @@ nsresult nsCSPContext::SendReportsToURIs(
|
||||||
AutoTArray<nsString, 1> params = {reportURIs[r]};
|
AutoTArray<nsString, 1> params = {reportURIs[r]};
|
||||||
CSPCONTEXTLOG(("Could not create nsIURI for report URI %s",
|
CSPCONTEXTLOG(("Could not create nsIURI for report URI %s",
|
||||||
reportURICstring.get()));
|
reportURICstring.get()));
|
||||||
logToConsole("triedToSendReport", params, aViolationEventInit.mSourceFile,
|
logToConsole("triedToSendReport", params,
|
||||||
|
NS_ConvertUTF16toUTF8(aViolationEventInit.mSourceFile),
|
||||||
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
||||||
aViolationEventInit.mColumnNumber,
|
aViolationEventInit.mColumnNumber,
|
||||||
nsIScriptError::errorFlag);
|
nsIScriptError::errorFlag);
|
||||||
|
@ -1323,10 +1313,11 @@ nsresult nsCSPContext::SendReportsToURIs(
|
||||||
|
|
||||||
if (!isHttpScheme) {
|
if (!isHttpScheme) {
|
||||||
AutoTArray<nsString, 1> params = {reportURIs[r]};
|
AutoTArray<nsString, 1> params = {reportURIs[r]};
|
||||||
logToConsole(
|
logToConsole("reportURInotHttpsOrHttp2", params,
|
||||||
"reportURInotHttpsOrHttp2", params, aViolationEventInit.mSourceFile,
|
NS_ConvertUTF16toUTF8(aViolationEventInit.mSourceFile),
|
||||||
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
||||||
aViolationEventInit.mColumnNumber, nsIScriptError::errorFlag);
|
aViolationEventInit.mColumnNumber,
|
||||||
|
nsIScriptError::errorFlag);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1396,7 +1387,8 @@ nsresult nsCSPContext::SendReportsToURIs(
|
||||||
AutoTArray<nsString, 1> params = {reportURIs[r]};
|
AutoTArray<nsString, 1> params = {reportURIs[r]};
|
||||||
CSPCONTEXTLOG(("AsyncOpen failed for report URI %s",
|
CSPCONTEXTLOG(("AsyncOpen failed for report URI %s",
|
||||||
NS_ConvertUTF16toUTF8(params[0]).get()));
|
NS_ConvertUTF16toUTF8(params[0]).get()));
|
||||||
logToConsole("triedToSendReport", params, aViolationEventInit.mSourceFile,
|
logToConsole("triedToSendReport", params,
|
||||||
|
NS_ConvertUTF16toUTF8(aViolationEventInit.mSourceFile),
|
||||||
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
aViolationEventInit.mSample, aViolationEventInit.mLineNumber,
|
||||||
aViolationEventInit.mColumnNumber,
|
aViolationEventInit.mColumnNumber,
|
||||||
nsIScriptError::errorFlag);
|
nsIScriptError::errorFlag);
|
||||||
|
@ -1907,7 +1899,7 @@ nsCSPContext::GetCSPSandboxFlags(uint32_t* aOutSandboxFlags) {
|
||||||
NS_ConvertUTF16toUTF8(policy).get()));
|
NS_ConvertUTF16toUTF8(policy).get()));
|
||||||
|
|
||||||
AutoTArray<nsString, 1> params = {policy};
|
AutoTArray<nsString, 1> params = {policy};
|
||||||
logToConsole("ignoringReportOnlyDirective", params, u""_ns, u""_ns, 0, 1,
|
logToConsole("ignoringReportOnlyDirective", params, ""_ns, u""_ns, 0, 1,
|
||||||
nsIScriptError::warningFlag);
|
nsIScriptError::warningFlag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ class nsCSPContext : public nsIContentSecurityPolicy {
|
||||||
void flushConsoleMessages();
|
void flushConsoleMessages();
|
||||||
|
|
||||||
void logToConsole(const char* aName, const nsTArray<nsString>& aParams,
|
void logToConsole(const char* aName, const nsTArray<nsString>& aParams,
|
||||||
const nsAString& aSourceName, const nsAString& aSourceLine,
|
const nsACString& aSourceName, const nsAString& aSourceLine,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
||||||
uint32_t aSeverityFlag);
|
uint32_t aSeverityFlag);
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ void nsCSPParser::logWarningErrorToConsole(uint32_t aSeverityFlag,
|
||||||
// send console messages off to the context and let the context
|
// send console messages off to the context and let the context
|
||||||
// deal with it (potentially messages need to be queued up)
|
// deal with it (potentially messages need to be queued up)
|
||||||
mCSPContext->logToConsole(aProperty, aParams,
|
mCSPContext->logToConsole(aProperty, aParams,
|
||||||
u""_ns, // aSourceName
|
""_ns, // aSourceName
|
||||||
u""_ns, // aSourceLine
|
u""_ns, // aSourceLine
|
||||||
0, // aLineNumber
|
0, // aLineNumber
|
||||||
1, // aColumnNumber
|
1, // aColumnNumber
|
||||||
|
|
|
@ -191,7 +191,7 @@ void CSP_LogStrMessage(const nsAString& aMsg) {
|
||||||
console->LogStringMessage(msg.get());
|
console->LogStringMessage(msg.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSP_LogMessage(const nsAString& aMessage, const nsAString& aSourceName,
|
void CSP_LogMessage(const nsAString& aMessage, const nsACString& aSourceName,
|
||||||
const nsAString& aSourceLine, uint32_t aLineNumber,
|
const nsAString& aSourceLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags,
|
uint32_t aColumnNumber, uint32_t aFlags,
|
||||||
const nsACString& aCategory, uint64_t aInnerWindowID,
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
||||||
|
@ -230,13 +230,13 @@ void CSP_LogMessage(const nsAString& aMessage, const nsAString& aSourceName,
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (aInnerWindowID > 0) {
|
if (aInnerWindowID > 0) {
|
||||||
rv = error->InitWithWindowID(cspMsg, aSourceName, aSourceLine, aLineNumber,
|
rv = error->InitWithWindowID(cspMsg, NS_ConvertUTF8toUTF16(aSourceName),
|
||||||
aColumnNumber, aFlags, category,
|
aSourceLine, aLineNumber, aColumnNumber,
|
||||||
aInnerWindowID);
|
aFlags, category, aInnerWindowID);
|
||||||
} else {
|
} else {
|
||||||
rv = error->Init(cspMsg, aSourceName, aSourceLine, aLineNumber,
|
rv = error->Init(cspMsg, NS_ConvertUTF8toUTF16(aSourceName), aSourceLine,
|
||||||
aColumnNumber, aFlags, category, aFromPrivateWindow,
|
aLineNumber, aColumnNumber, aFlags, category,
|
||||||
true /* from chrome context */);
|
aFromPrivateWindow, true /* from chrome context */);
|
||||||
}
|
}
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return;
|
return;
|
||||||
|
@ -262,7 +262,7 @@ CSPDirective CSP_StringToCSPDirective(const nsAString& aDir) {
|
||||||
* Combines CSP_LogMessage and CSP_GetLocalizedStr into one call.
|
* Combines CSP_LogMessage and CSP_GetLocalizedStr into one call.
|
||||||
*/
|
*/
|
||||||
void CSP_LogLocalizedStr(const char* aName, const nsTArray<nsString>& aParams,
|
void CSP_LogLocalizedStr(const char* aName, const nsTArray<nsString>& aParams,
|
||||||
const nsAString& aSourceName,
|
const nsACString& aSourceName,
|
||||||
const nsAString& aSourceLine, uint32_t aLineNumber,
|
const nsAString& aSourceLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags,
|
uint32_t aColumnNumber, uint32_t aFlags,
|
||||||
const nsACString& aCategory, uint64_t aInnerWindowID,
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Document;
|
||||||
/* =============== Logging =================== */
|
/* =============== Logging =================== */
|
||||||
|
|
||||||
void CSP_LogLocalizedStr(const char* aName, const nsTArray<nsString>& aParams,
|
void CSP_LogLocalizedStr(const char* aName, const nsTArray<nsString>& aParams,
|
||||||
const nsAString& aSourceName,
|
const nsACString& aSourceName,
|
||||||
const nsAString& aSourceLine, uint32_t aLineNumber,
|
const nsAString& aSourceLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags,
|
uint32_t aColumnNumber, uint32_t aFlags,
|
||||||
const nsACString& aCategory, uint64_t aInnerWindowID,
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
||||||
|
@ -38,7 +38,7 @@ void CSP_GetLocalizedStr(const char* aName, const nsTArray<nsString>& aParams,
|
||||||
|
|
||||||
void CSP_LogStrMessage(const nsAString& aMsg);
|
void CSP_LogStrMessage(const nsAString& aMsg);
|
||||||
|
|
||||||
void CSP_LogMessage(const nsAString& aMessage, const nsAString& aSourceName,
|
void CSP_LogMessage(const nsAString& aMessage, const nsACString& aSourceName,
|
||||||
const nsAString& aSourceLine, uint32_t aLineNumber,
|
const nsAString& aSourceLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags,
|
uint32_t aColumnNumber, uint32_t aFlags,
|
||||||
const nsACString& aCategory, uint64_t aInnerWindowID,
|
const nsACString& aCategory, uint64_t aInnerWindowID,
|
||||||
|
|
|
@ -810,17 +810,13 @@ void nsContentSecurityManager::MeasureUnexpectedPrivilegedLoads(
|
||||||
nsAutoCString uriString;
|
nsAutoCString uriString;
|
||||||
if (aFinalURI) {
|
if (aFinalURI) {
|
||||||
aFinalURI->GetAsciiSpec(uriString);
|
aFinalURI->GetAsciiSpec(uriString);
|
||||||
} else {
|
|
||||||
uriString.AssignLiteral("");
|
|
||||||
}
|
}
|
||||||
FilenameTypeAndDetails fileNameTypeAndDetails =
|
FilenameTypeAndDetails fileNameTypeAndDetails =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(
|
nsContentSecurityUtils::FilenameToFilenameType(uriString, true);
|
||||||
NS_ConvertUTF8toUTF16(uriString), true);
|
|
||||||
|
|
||||||
nsCString loggedFileDetails = "unknown"_ns;
|
nsCString loggedFileDetails = "unknown"_ns;
|
||||||
if (fileNameTypeAndDetails.second.isSome()) {
|
if (fileNameTypeAndDetails.second.isSome()) {
|
||||||
loggedFileDetails.Assign(
|
loggedFileDetails.Assign(fileNameTypeAndDetails.second.value());
|
||||||
NS_ConvertUTF16toUTF8(fileNameTypeAndDetails.second.value()));
|
|
||||||
}
|
}
|
||||||
// sanitize remoteType because it may contain sensitive
|
// sanitize remoteType because it may contain sensitive
|
||||||
// info, like URLs. e.g. `webIsolated=https://example.com`
|
// info, like URLs. e.g. `webIsolated=https://example.com`
|
||||||
|
|
|
@ -272,23 +272,21 @@ nsCString nsContentSecurityUtils::SmartFormatCrashString(
|
||||||
* Telemetry Events extra data only supports 80 characters, so we optimize the
|
* Telemetry Events extra data only supports 80 characters, so we optimize the
|
||||||
* filename to be smaller and collect more data.
|
* filename to be smaller and collect more data.
|
||||||
*/
|
*/
|
||||||
nsString OptimizeFileName(const nsAString& aFileName) {
|
nsCString OptimizeFileName(const nsAString& aFileName) {
|
||||||
nsString optimizedName(aFileName);
|
NS_ConvertUTF16toUTF8 optimizedName(aFileName);
|
||||||
|
|
||||||
MOZ_LOG(
|
MOZ_LOG(sCSMLog, LogLevel::Verbose,
|
||||||
sCSMLog, LogLevel::Verbose,
|
("Optimizing FileName: %s", optimizedName.get()));
|
||||||
("Optimizing FileName: %s", NS_ConvertUTF16toUTF8(optimizedName).get()));
|
|
||||||
|
|
||||||
optimizedName.ReplaceSubstring(u".xpi!"_ns, u"!"_ns);
|
optimizedName.ReplaceSubstring(".xpi!"_ns, "!"_ns);
|
||||||
optimizedName.ReplaceSubstring(u"shield.mozilla.org!"_ns, u"s!"_ns);
|
optimizedName.ReplaceSubstring("shield.mozilla.org!"_ns, "s!"_ns);
|
||||||
optimizedName.ReplaceSubstring(u"mozilla.org!"_ns, u"m!"_ns);
|
optimizedName.ReplaceSubstring("mozilla.org!"_ns, "m!"_ns);
|
||||||
if (optimizedName.Length() > 80) {
|
if (optimizedName.Length() > 80) {
|
||||||
optimizedName.Truncate(80);
|
optimizedName.Truncate(80);
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_LOG(
|
MOZ_LOG(sCSMLog, LogLevel::Verbose,
|
||||||
sCSMLog, LogLevel::Verbose,
|
("Optimized FileName: %s", optimizedName.get()));
|
||||||
("Optimized FileName: %s", NS_ConvertUTF16toUTF8(optimizedName).get()));
|
|
||||||
return optimizedName;
|
return optimizedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +304,7 @@ nsString OptimizeFileName(const nsAString& aFileName) {
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
const nsString& fileName, bool collectAdditionalExtensionData) {
|
const nsACString& fileName, bool collectAdditionalExtensionData) {
|
||||||
// These are strings because the Telemetry Events API only accepts strings
|
// These are strings because the Telemetry Events API only accepts strings
|
||||||
static constexpr auto kChromeURI = "chromeuri"_ns;
|
static constexpr auto kChromeURI = "chromeuri"_ns;
|
||||||
static constexpr auto kResourceURI = "resourceuri"_ns;
|
static constexpr auto kResourceURI = "resourceuri"_ns;
|
||||||
|
@ -337,31 +335,33 @@ FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
}
|
}
|
||||||
|
|
||||||
// resource:// and chrome://
|
// resource:// and chrome://
|
||||||
if (StringBeginsWith(fileName, u"chrome://"_ns)) {
|
if (StringBeginsWith(fileName, "chrome://"_ns)) {
|
||||||
return FilenameTypeAndDetails(kChromeURI, Some(fileName));
|
return FilenameTypeAndDetails(kChromeURI, Some(nsCString(fileName)));
|
||||||
}
|
}
|
||||||
if (StringBeginsWith(fileName, u"resource://"_ns)) {
|
if (StringBeginsWith(fileName, "resource://"_ns)) {
|
||||||
return FilenameTypeAndDetails(kResourceURI, Some(fileName));
|
return FilenameTypeAndDetails(kResourceURI, Some(nsCString(fileName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// blob: and data:
|
// blob: and data:
|
||||||
if (StringBeginsWith(fileName, u"blob:"_ns)) {
|
if (StringBeginsWith(fileName, "blob:"_ns)) {
|
||||||
return FilenameTypeAndDetails(kBlobUri, Nothing());
|
return FilenameTypeAndDetails(kBlobUri, Nothing());
|
||||||
}
|
}
|
||||||
if (StringBeginsWith(fileName, u"data:text/css;extension=style;"_ns)) {
|
if (StringBeginsWith(fileName, "data:text/css;extension=style;"_ns)) {
|
||||||
return FilenameTypeAndDetails(kDataUriWebExtCStyle, Nothing());
|
return FilenameTypeAndDetails(kDataUriWebExtCStyle, Nothing());
|
||||||
}
|
}
|
||||||
if (StringBeginsWith(fileName, u"data:"_ns)) {
|
if (StringBeginsWith(fileName, "data:"_ns)) {
|
||||||
return FilenameTypeAndDetails(kDataUri, Nothing());
|
return FilenameTypeAndDetails(kDataUri, Nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't do regex matching off-main-thread
|
// Can't do regex matching off-main-thread
|
||||||
if (NS_IsMainThread()) {
|
if (NS_IsMainThread()) {
|
||||||
|
NS_ConvertUTF8toUTF16 fileNameA(fileName);
|
||||||
// Extension as loaded via a file://
|
// Extension as loaded via a file://
|
||||||
bool regexMatch;
|
bool regexMatch;
|
||||||
nsTArray<nsString> regexResults;
|
nsTArray<nsString> regexResults;
|
||||||
nsresult rv = RegexEval(kExtensionRegex, fileName, /* aOnlyMatch = */ false,
|
nsresult rv =
|
||||||
regexMatch, ®exResults);
|
RegexEval(kExtensionRegex, fileNameA,
|
||||||
|
/* aOnlyMatch = */ false, regexMatch, ®exResults);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return FilenameTypeAndDetails(kRegexFailure, Nothing());
|
return FilenameTypeAndDetails(kRegexFailure, Nothing());
|
||||||
}
|
}
|
||||||
|
@ -376,17 +376,17 @@ FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single File
|
// Single File
|
||||||
rv = RegexEval(kSingleFileRegex, fileName, /* aOnlyMatch = */ true,
|
rv = RegexEval(kSingleFileRegex, fileNameA, /* aOnlyMatch = */ true,
|
||||||
regexMatch);
|
regexMatch);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return FilenameTypeAndDetails(kRegexFailure, Nothing());
|
return FilenameTypeAndDetails(kRegexFailure, Nothing());
|
||||||
}
|
}
|
||||||
if (regexMatch) {
|
if (regexMatch) {
|
||||||
return FilenameTypeAndDetails(kSingleString, Some(fileName));
|
return FilenameTypeAndDetails(kSingleString, Some(nsCString(fileName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suspected userChromeJS script
|
// Suspected userChromeJS script
|
||||||
rv = RegexEval(kUCJSRegex, fileName, /* aOnlyMatch = */ true, regexMatch);
|
rv = RegexEval(kUCJSRegex, fileNameA, /* aOnlyMatch = */ true, regexMatch);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return FilenameTypeAndDetails(kRegexFailure, Nothing());
|
return FilenameTypeAndDetails(kRegexFailure, Nothing());
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Something loaded via an about:// URI.
|
// Something loaded via an about:// URI.
|
||||||
if (StringBeginsWith(fileName, u"about:"_ns)) {
|
if (StringBeginsWith(fileName, "about:"_ns)) {
|
||||||
// Remove any querystrings and such
|
// Remove any querystrings and such
|
||||||
long int desired_length = fileName.Length();
|
long int desired_length = fileName.Length();
|
||||||
long int possible_new_length = 0;
|
long int possible_new_length = 0;
|
||||||
|
@ -413,17 +413,17 @@ FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
|
|
||||||
auto subFileName = Substring(fileName, 0, desired_length);
|
auto subFileName = Substring(fileName, 0, desired_length);
|
||||||
|
|
||||||
return FilenameTypeAndDetails(kAboutUri, Some(subFileName));
|
return FilenameTypeAndDetails(kAboutUri, Some(nsCString(subFileName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Something loaded via a moz-extension:// URI.
|
// Something loaded via a moz-extension:// URI.
|
||||||
if (StringBeginsWith(fileName, u"moz-extension://"_ns)) {
|
if (StringBeginsWith(fileName, "moz-extension://"_ns)) {
|
||||||
if (!collectAdditionalExtensionData) {
|
if (!collectAdditionalExtensionData) {
|
||||||
return FilenameTypeAndDetails(kExtensionURI, Nothing());
|
return FilenameTypeAndDetails(kExtensionURI, Nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString sanitizedPathAndScheme;
|
nsAutoCString sanitizedPathAndScheme;
|
||||||
sanitizedPathAndScheme.Append(u"moz-extension://["_ns);
|
sanitizedPathAndScheme.Append("moz-extension://["_ns);
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), fileName);
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), fileName);
|
||||||
|
@ -442,36 +442,37 @@ FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
nsString addOnId;
|
nsString addOnId;
|
||||||
policy->GetId(addOnId);
|
policy->GetId(addOnId);
|
||||||
|
|
||||||
sanitizedPathAndScheme.Append(addOnId);
|
sanitizedPathAndScheme.Append(NS_ConvertUTF16toUTF8(addOnId));
|
||||||
sanitizedPathAndScheme.Append(u": "_ns);
|
sanitizedPathAndScheme.Append(": "_ns);
|
||||||
sanitizedPathAndScheme.Append(policy->Name());
|
sanitizedPathAndScheme.Append(NS_ConvertUTF16toUTF8(policy->Name()));
|
||||||
sanitizedPathAndScheme.Append(u"]"_ns);
|
sanitizedPathAndScheme.Append("]"_ns);
|
||||||
|
|
||||||
if (policy->IsPrivileged()) {
|
if (policy->IsPrivileged()) {
|
||||||
sanitizedPathAndScheme.Append(u"P=1"_ns);
|
sanitizedPathAndScheme.Append("P=1"_ns);
|
||||||
} else {
|
} else {
|
||||||
sanitizedPathAndScheme.Append(u"P=0"_ns);
|
sanitizedPathAndScheme.Append("P=0"_ns);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sanitizedPathAndScheme.Append(u"failed finding addon by host]"_ns);
|
sanitizedPathAndScheme.Append("failed finding addon by host]"_ns);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sanitizedPathAndScheme.Append(u"can't get addon off main thread]"_ns);
|
sanitizedPathAndScheme.Append("can't get addon off main thread]"_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendUTF8toUTF16(url.FilePath(), sanitizedPathAndScheme);
|
sanitizedPathAndScheme.Append(url.FilePath());
|
||||||
return FilenameTypeAndDetails(kExtensionURI, Some(sanitizedPathAndScheme));
|
return FilenameTypeAndDetails(kExtensionURI, Some(sanitizedPathAndScheme));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
auto flags = mozilla::widget::WinUtils::PathTransformFlags::Default |
|
auto flags = mozilla::widget::WinUtils::PathTransformFlags::Default |
|
||||||
mozilla::widget::WinUtils::PathTransformFlags::RequireFilePath;
|
mozilla::widget::WinUtils::PathTransformFlags::RequireFilePath;
|
||||||
nsAutoString strSanitizedPath(fileName);
|
const NS_ConvertUTF8toUTF16 fileNameA(fileName);
|
||||||
|
nsAutoString strSanitizedPath(fileNameA);
|
||||||
if (widget::WinUtils::PreparePathForTelemetry(strSanitizedPath, flags)) {
|
if (widget::WinUtils::PreparePathForTelemetry(strSanitizedPath, flags)) {
|
||||||
DWORD cchDecodedUrl = INTERNET_MAX_URL_LENGTH;
|
DWORD cchDecodedUrl = INTERNET_MAX_URL_LENGTH;
|
||||||
WCHAR szOut[INTERNET_MAX_URL_LENGTH];
|
WCHAR szOut[INTERNET_MAX_URL_LENGTH];
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
SAFECALL_URLMON_FUNC(CoInternetParseUrl, fileName.get(), PARSE_SCHEMA, 0,
|
SAFECALL_URLMON_FUNC(CoInternetParseUrl, fileNameA.get(), PARSE_SCHEMA, 0,
|
||||||
szOut, INTERNET_MAX_URL_LENGTH, &cchDecodedUrl, 0);
|
szOut, INTERNET_MAX_URL_LENGTH, &cchDecodedUrl, 0);
|
||||||
if (hr == S_OK && cchDecodedUrl) {
|
if (hr == S_OK && cchDecodedUrl) {
|
||||||
nsAutoString sanitizedPathAndScheme;
|
nsAutoString sanitizedPathAndScheme;
|
||||||
|
@ -480,11 +481,12 @@ FilenameTypeAndDetails nsContentSecurityUtils::FilenameToFilenameType(
|
||||||
sanitizedPathAndScheme.Append(u"://.../"_ns);
|
sanitizedPathAndScheme.Append(u"://.../"_ns);
|
||||||
sanitizedPathAndScheme.Append(strSanitizedPath);
|
sanitizedPathAndScheme.Append(strSanitizedPath);
|
||||||
}
|
}
|
||||||
return FilenameTypeAndDetails(kSanitizedWindowsURL,
|
return FilenameTypeAndDetails(
|
||||||
Some(sanitizedPathAndScheme));
|
kSanitizedWindowsURL,
|
||||||
|
Some(NS_ConvertUTF16toUTF8(sanitizedPathAndScheme)));
|
||||||
} else {
|
} else {
|
||||||
return FilenameTypeAndDetails(kSanitizedWindowsPath,
|
return FilenameTypeAndDetails(
|
||||||
Some(strSanitizedPath));
|
kSanitizedWindowsPath, Some(NS_ConvertUTF16toUTF8(strSanitizedPath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -562,19 +564,18 @@ void PossiblyCrash(const char* aPrefSuffix, const char* aUnsafeCrashString,
|
||||||
class EvalUsageNotificationRunnable final : public Runnable {
|
class EvalUsageNotificationRunnable final : public Runnable {
|
||||||
public:
|
public:
|
||||||
EvalUsageNotificationRunnable(bool aIsSystemPrincipal,
|
EvalUsageNotificationRunnable(bool aIsSystemPrincipal,
|
||||||
NS_ConvertUTF8toUTF16& aFileNameA,
|
const nsACString& aFileName, uint64_t aWindowID,
|
||||||
uint64_t aWindowID, uint32_t aLineNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber)
|
||||||
uint32_t aColumnNumber)
|
|
||||||
: mozilla::Runnable("EvalUsageNotificationRunnable"),
|
: mozilla::Runnable("EvalUsageNotificationRunnable"),
|
||||||
mIsSystemPrincipal(aIsSystemPrincipal),
|
mIsSystemPrincipal(aIsSystemPrincipal),
|
||||||
mFileNameA(aFileNameA),
|
mFileName(aFileName),
|
||||||
mWindowID(aWindowID),
|
mWindowID(aWindowID),
|
||||||
mLineNumber(aLineNumber),
|
mLineNumber(aLineNumber),
|
||||||
mColumnNumber(aColumnNumber) {}
|
mColumnNumber(aColumnNumber) {}
|
||||||
|
|
||||||
NS_IMETHOD Run() override {
|
NS_IMETHOD Run() override {
|
||||||
nsContentSecurityUtils::NotifyEvalUsage(
|
nsContentSecurityUtils::NotifyEvalUsage(
|
||||||
mIsSystemPrincipal, mFileNameA, mWindowID, mLineNumber, mColumnNumber);
|
mIsSystemPrincipal, mFileName, mWindowID, mLineNumber, mColumnNumber);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,7 +583,7 @@ class EvalUsageNotificationRunnable final : public Runnable {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mIsSystemPrincipal;
|
bool mIsSystemPrincipal;
|
||||||
NS_ConvertUTF8toUTF16 mFileNameA;
|
nsCString mFileName;
|
||||||
uint64_t mWindowID;
|
uint64_t mWindowID;
|
||||||
uint32_t mLineNumber;
|
uint32_t mLineNumber;
|
||||||
uint32_t mColumnNumber;
|
uint32_t mColumnNumber;
|
||||||
|
@ -686,14 +687,8 @@ bool nsContentSecurityUtils::IsEvalAllowed(JSContext* cx,
|
||||||
|
|
||||||
// Check the allowlist for the provided filename. getFilename is a helper
|
// Check the allowlist for the provided filename. getFilename is a helper
|
||||||
// function
|
// function
|
||||||
nsAutoCString fileName;
|
auto location = JSCallingLocation::Get(cx);
|
||||||
uint32_t lineNumber = 0, columnNumber = 1;
|
const nsCString& fileName = location.FileName();
|
||||||
nsJSUtils::GetCallingLocation(cx, fileName, &lineNumber, &columnNumber);
|
|
||||||
if (fileName.IsEmpty()) {
|
|
||||||
fileName = "unknown-file"_ns;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_ConvertUTF8toUTF16 fileNameA(fileName);
|
|
||||||
for (const nsLiteralCString& allowlistEntry : evalAllowlist) {
|
for (const nsLiteralCString& allowlistEntry : evalAllowlist) {
|
||||||
// checking if current filename begins with entry, because JS Engine
|
// checking if current filename begins with entry, because JS Engine
|
||||||
// gives us additional stuff for code inside eval or Function ctor
|
// gives us additional stuff for code inside eval or Function ctor
|
||||||
|
@ -711,11 +706,13 @@ bool nsContentSecurityUtils::IsEvalAllowed(JSContext* cx,
|
||||||
// Send Telemetry and Log to the Console
|
// Send Telemetry and Log to the Console
|
||||||
uint64_t windowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx);
|
uint64_t windowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx);
|
||||||
if (NS_IsMainThread()) {
|
if (NS_IsMainThread()) {
|
||||||
nsContentSecurityUtils::NotifyEvalUsage(aIsSystemPrincipal, fileNameA,
|
nsContentSecurityUtils::NotifyEvalUsage(aIsSystemPrincipal, fileName,
|
||||||
windowID, lineNumber, columnNumber);
|
windowID, location.mLine,
|
||||||
|
location.mColumn);
|
||||||
} else {
|
} else {
|
||||||
auto runnable = new EvalUsageNotificationRunnable(
|
auto runnable = new EvalUsageNotificationRunnable(
|
||||||
aIsSystemPrincipal, fileNameA, windowID, lineNumber, columnNumber);
|
aIsSystemPrincipal, fileName, windowID, location.mLine,
|
||||||
|
location.mColumn);
|
||||||
NS_DispatchToMainThread(runnable);
|
NS_DispatchToMainThread(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +738,7 @@ bool nsContentSecurityUtils::IsEvalAllowed(JSContext* cx,
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
void nsContentSecurityUtils::NotifyEvalUsage(bool aIsSystemPrincipal,
|
void nsContentSecurityUtils::NotifyEvalUsage(bool aIsSystemPrincipal,
|
||||||
NS_ConvertUTF8toUTF16& aFileNameA,
|
const nsACString& aFileName,
|
||||||
uint64_t aWindowID,
|
uint64_t aWindowID,
|
||||||
uint32_t aLineNumber,
|
uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber) {
|
uint32_t aColumnNumber) {
|
||||||
|
@ -751,12 +748,11 @@ void nsContentSecurityUtils::NotifyEvalUsage(bool aIsSystemPrincipal,
|
||||||
: Telemetry::EventID::Security_Evalusage_Parentprocess;
|
: Telemetry::EventID::Security_Evalusage_Parentprocess;
|
||||||
|
|
||||||
FilenameTypeAndDetails fileNameTypeAndDetails =
|
FilenameTypeAndDetails fileNameTypeAndDetails =
|
||||||
FilenameToFilenameType(aFileNameA, false);
|
FilenameToFilenameType(aFileName, false);
|
||||||
mozilla::Maybe<nsTArray<EventExtraEntry>> extra;
|
mozilla::Maybe<nsTArray<EventExtraEntry>> extra;
|
||||||
if (fileNameTypeAndDetails.second.isSome()) {
|
if (fileNameTypeAndDetails.second.isSome()) {
|
||||||
extra = Some<nsTArray<EventExtraEntry>>({EventExtraEntry{
|
extra = Some<nsTArray<EventExtraEntry>>({EventExtraEntry{
|
||||||
"fileinfo"_ns,
|
"fileinfo"_ns, fileNameTypeAndDetails.second.value()}});
|
||||||
NS_ConvertUTF16toUTF8(fileNameTypeAndDetails.second.value())}});
|
|
||||||
} else {
|
} else {
|
||||||
extra = Nothing();
|
extra = Nothing();
|
||||||
}
|
}
|
||||||
|
@ -790,14 +786,15 @@ void nsContentSecurityUtils::NotifyEvalUsage(bool aIsSystemPrincipal,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nsAutoString message;
|
nsAutoString message;
|
||||||
AutoTArray<nsString, 1> formatStrings = {aFileNameA};
|
NS_ConvertUTF8toUTF16 fileNameA(aFileName);
|
||||||
|
AutoTArray<nsString, 1> formatStrings = {fileNameA};
|
||||||
nsresult rv = bundle->FormatStringFromName("RestrictBrowserEvalUsage",
|
nsresult rv = bundle->FormatStringFromName("RestrictBrowserEvalUsage",
|
||||||
formatStrings, message);
|
formatStrings, message);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = error->InitWithWindowID(message, aFileNameA, u""_ns, aLineNumber,
|
rv = error->InitWithWindowID(message, fileNameA, u""_ns, aLineNumber,
|
||||||
aColumnNumber, nsIScriptError::errorFlag,
|
aColumnNumber, nsIScriptError::errorFlag,
|
||||||
"BrowserEvalUsage", aWindowID,
|
"BrowserEvalUsage", aWindowID,
|
||||||
true /* From chrome context */);
|
true /* From chrome context */);
|
||||||
|
@ -1149,7 +1146,7 @@ void EnforceXFrameOptionsCheck(nsIChannel* aChannel,
|
||||||
AutoTArray<nsString, 2> params = {u"x-frame-options"_ns,
|
AutoTArray<nsString, 2> params = {u"x-frame-options"_ns,
|
||||||
u"frame-ancestors"_ns};
|
u"frame-ancestors"_ns};
|
||||||
CSP_LogLocalizedStr("IgnoringSrcBecauseOfDirective", params,
|
CSP_LogLocalizedStr("IgnoringSrcBecauseOfDirective", params,
|
||||||
u""_ns, // no sourcefile
|
""_ns, // no sourcefile
|
||||||
u""_ns, // no scriptsample
|
u""_ns, // no scriptsample
|
||||||
0, // no linenumber
|
0, // no linenumber
|
||||||
1, // no columnnumber
|
1, // no columnnumber
|
||||||
|
@ -1457,10 +1454,10 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
|
|
||||||
// If we have allowed eval (because of a user configuration or more
|
// If we have allowed eval (because of a user configuration or more
|
||||||
// likely a test has requested it), and the script is an eval, allow it.
|
// likely a test has requested it), and the script is an eval, allow it.
|
||||||
NS_ConvertUTF8toUTF16 filenameU(aFilename);
|
nsDependentCString filename(aFilename);
|
||||||
if (StaticPrefs::security_allow_eval_with_system_principal() ||
|
if (StaticPrefs::security_allow_eval_with_system_principal() ||
|
||||||
StaticPrefs::security_allow_eval_in_parent_process()) {
|
StaticPrefs::security_allow_eval_in_parent_process()) {
|
||||||
if (StringEndsWith(filenameU, u"> eval"_ns)) {
|
if (StringEndsWith(filename, "> eval"_ns)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1493,29 +1490,29 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringBeginsWith(filenameU, u"chrome://"_ns)) {
|
if (StringBeginsWith(filename, "chrome://"_ns)) {
|
||||||
// If it's a chrome:// url, allow it
|
// If it's a chrome:// url, allow it
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (StringBeginsWith(filenameU, u"resource://"_ns)) {
|
if (StringBeginsWith(filename, "resource://"_ns)) {
|
||||||
// If it's a resource:// url, allow it
|
// If it's a resource:// url, allow it
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (StringBeginsWith(filenameU, u"file://"_ns)) {
|
if (StringBeginsWith(filename, "file://"_ns)) {
|
||||||
// We will temporarily allow all file:// URIs through for now
|
// We will temporarily allow all file:// URIs through for now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (StringBeginsWith(filenameU, u"jar:file://"_ns)) {
|
if (StringBeginsWith(filename, "jar:file://"_ns)) {
|
||||||
// We will temporarily allow all jar URIs through for now
|
// We will temporarily allow all jar URIs through for now
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (filenameU.Equals(u"about:sync-log"_ns)) {
|
if (filename.Equals("about:sync-log"_ns)) {
|
||||||
// about:sync-log runs in the parent process and displays a directory
|
// about:sync-log runs in the parent process and displays a directory
|
||||||
// listing. The listing has inline javascript that executes on load.
|
// listing. The listing has inline javascript that executes on load.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringBeginsWith(filenameU, u"moz-extension://"_ns)) {
|
if (StringBeginsWith(filename, "moz-extension://"_ns)) {
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aFilename);
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), aFilename);
|
||||||
if (!NS_FAILED(rv) && NS_IsMainThread()) {
|
if (!NS_FAILED(rv) && NS_IsMainThread()) {
|
||||||
|
@ -1544,11 +1541,11 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
|
|
||||||
auto kAllowedFilenamesExact = {
|
auto kAllowedFilenamesExact = {
|
||||||
// Allow through the injection provided by about:sync addon
|
// Allow through the injection provided by about:sync addon
|
||||||
u"data:,new function() {\n const { AboutSyncRedirector } = ChromeUtils.import(\"chrome://aboutsync/content/AboutSyncRedirector.js\");\n AboutSyncRedirector.register();\n}"_ns,
|
"data:,new function() {\n const { AboutSyncRedirector } = ChromeUtils.import(\"chrome://aboutsync/content/AboutSyncRedirector.js\");\n AboutSyncRedirector.register();\n}"_ns,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto allowedFilename : kAllowedFilenamesExact) {
|
for (auto allowedFilename : kAllowedFilenamesExact) {
|
||||||
if (filenameU == allowedFilename) {
|
if (filename == allowedFilename) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1556,16 +1553,16 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
auto kAllowedFilenamesPrefix = {
|
auto kAllowedFilenamesPrefix = {
|
||||||
// Until 371900 is fixed, we need to do something about about:downloads
|
// Until 371900 is fixed, we need to do something about about:downloads
|
||||||
// and this is the most reasonable. See 1727770
|
// and this is the most reasonable. See 1727770
|
||||||
u"about:downloads"_ns,
|
"about:downloads"_ns,
|
||||||
// We think this is the same problem as about:downloads
|
// We think this is the same problem as about:downloads
|
||||||
u"about:preferences"_ns, u"about:settings"_ns,
|
"about:preferences"_ns, "about:settings"_ns,
|
||||||
// Browser console will give a filename of 'debugger' See 1763943
|
// Browser console will give a filename of 'debugger' See 1763943
|
||||||
// Sometimes it's 'debugger eager eval code', other times just 'debugger
|
// Sometimes it's 'debugger eager eval code', other times just 'debugger
|
||||||
// eval code'
|
// eval code'
|
||||||
u"debugger"_ns};
|
"debugger"_ns};
|
||||||
|
|
||||||
for (auto allowedFilenamePrefix : kAllowedFilenamesPrefix) {
|
for (auto allowedFilenamePrefix : kAllowedFilenamesPrefix) {
|
||||||
if (StringBeginsWith(filenameU, allowedFilenamePrefix)) {
|
if (StringBeginsWith(filename, allowedFilenamePrefix)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1576,7 +1573,7 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
|
|
||||||
// Send Telemetry
|
// Send Telemetry
|
||||||
FilenameTypeAndDetails fileNameTypeAndDetails =
|
FilenameTypeAndDetails fileNameTypeAndDetails =
|
||||||
FilenameToFilenameType(filenameU, true);
|
FilenameToFilenameType(filename, true);
|
||||||
|
|
||||||
Telemetry::EventID eventType =
|
Telemetry::EventID eventType =
|
||||||
Telemetry::EventID::Security_Javascriptload_Parentprocess;
|
Telemetry::EventID::Security_Javascriptload_Parentprocess;
|
||||||
|
@ -1584,8 +1581,7 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
mozilla::Maybe<nsTArray<EventExtraEntry>> extra;
|
mozilla::Maybe<nsTArray<EventExtraEntry>> extra;
|
||||||
if (fileNameTypeAndDetails.second.isSome()) {
|
if (fileNameTypeAndDetails.second.isSome()) {
|
||||||
extra = Some<nsTArray<EventExtraEntry>>({EventExtraEntry{
|
extra = Some<nsTArray<EventExtraEntry>>({EventExtraEntry{
|
||||||
"fileinfo"_ns,
|
"fileinfo"_ns, fileNameTypeAndDetails.second.value()}});
|
||||||
NS_ConvertUTF16toUTF8(fileNameTypeAndDetails.second.value())}});
|
|
||||||
} else {
|
} else {
|
||||||
extra = Nothing();
|
extra = Nothing();
|
||||||
}
|
}
|
||||||
|
@ -1601,7 +1597,7 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
auto crashString = nsContentSecurityUtils::SmartFormatCrashString(
|
auto crashString = nsContentSecurityUtils::SmartFormatCrashString(
|
||||||
aFilename,
|
aFilename,
|
||||||
fileNameTypeAndDetails.second.isSome()
|
fileNameTypeAndDetails.second.isSome()
|
||||||
? NS_ConvertUTF16toUTF8(fileNameTypeAndDetails.second.value()).get()
|
? fileNameTypeAndDetails.second.value().get()
|
||||||
: "(None)",
|
: "(None)",
|
||||||
"Blocking a script load %s from file %s");
|
"Blocking a script load %s from file %s");
|
||||||
MOZ_CRASH_UNSAFE_PRINTF("%s", crashString.get());
|
MOZ_CRASH_UNSAFE_PRINTF("%s", crashString.get());
|
||||||
|
@ -1612,7 +1608,7 @@ bool nsContentSecurityUtils::ValidateScriptFilename(JSContext* cx,
|
||||||
// in Event Telemetry and have received data review.
|
// in Event Telemetry and have received data review.
|
||||||
if (fileNameTypeAndDetails.second.isSome()) {
|
if (fileNameTypeAndDetails.second.isSome()) {
|
||||||
PossiblyCrash("js_load_1", aFilename,
|
PossiblyCrash("js_load_1", aFilename,
|
||||||
NS_ConvertUTF16toUTF8(fileNameTypeAndDetails.second.value()));
|
fileNameTypeAndDetails.second.value());
|
||||||
} else {
|
} else {
|
||||||
PossiblyCrash("js_load_1", aFilename, "(None)"_ns);
|
PossiblyCrash("js_load_1", aFilename, "(None)"_ns);
|
||||||
}
|
}
|
||||||
|
@ -1659,7 +1655,8 @@ void nsContentSecurityUtils::LogMessageToConsole(nsIHttpChannel* aChannel,
|
||||||
}
|
}
|
||||||
|
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
localizedMsg, nsIScriptError::warningFlag, "Security"_ns, windowID, uri);
|
localizedMsg, nsIScriptError::warningFlag, "Security"_ns, windowID,
|
||||||
|
SourceLocation{uri.get()});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Document;
|
||||||
class Element;
|
class Element;
|
||||||
} // namespace mozilla::dom
|
} // namespace mozilla::dom
|
||||||
|
|
||||||
using FilenameTypeAndDetails = std::pair<nsCString, mozilla::Maybe<nsString>>;
|
using FilenameTypeAndDetails = std::pair<nsCString, mozilla::Maybe<nsCString>>;
|
||||||
|
|
||||||
class nsContentSecurityUtils {
|
class nsContentSecurityUtils {
|
||||||
public:
|
public:
|
||||||
|
@ -39,9 +39,8 @@ class nsContentSecurityUtils {
|
||||||
static bool IsEvalAllowed(JSContext* cx, bool aIsSystemPrincipal,
|
static bool IsEvalAllowed(JSContext* cx, bool aIsSystemPrincipal,
|
||||||
const nsAString& aScript);
|
const nsAString& aScript);
|
||||||
static void NotifyEvalUsage(bool aIsSystemPrincipal,
|
static void NotifyEvalUsage(bool aIsSystemPrincipal,
|
||||||
NS_ConvertUTF8toUTF16& aFileNameA,
|
const nsACString& aFileName, uint64_t aWindowID,
|
||||||
uint64_t aWindowID, uint32_t aLineNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber);
|
||||||
uint32_t aColumnNumber);
|
|
||||||
|
|
||||||
// Helper function for various checks:
|
// Helper function for various checks:
|
||||||
// This function detects profiles with userChrome.js or extension signatures
|
// This function detects profiles with userChrome.js or extension signatures
|
||||||
|
@ -80,7 +79,7 @@ class nsContentSecurityUtils {
|
||||||
|
|
||||||
// Public only for testing
|
// Public only for testing
|
||||||
static FilenameTypeAndDetails FilenameToFilenameType(
|
static FilenameTypeAndDetails FilenameToFilenameType(
|
||||||
const nsString& fileName, bool collectAdditionalExtensionData);
|
const nsACString& fileName, bool collectAdditionalExtensionData);
|
||||||
static char* SmartFormatCrashString(const char* str);
|
static char* SmartFormatCrashString(const char* str);
|
||||||
static char* SmartFormatCrashString(char* str);
|
static char* SmartFormatCrashString(char* str);
|
||||||
static nsCString SmartFormatCrashString(const char* part1, const char* part2,
|
static nsCString SmartFormatCrashString(const char* part1, const char* part2,
|
||||||
|
|
|
@ -843,8 +843,8 @@ void nsHTTPSOnlyUtils::LogMessage(const nsAString& aMessage, uint32_t aFlags,
|
||||||
}
|
}
|
||||||
if (windowId) {
|
if (windowId) {
|
||||||
// Send to content console
|
// Send to content console
|
||||||
nsContentUtils::ReportToConsoleByWindowID(message, aFlags, category,
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
windowId, aURI);
|
message, aFlags, category, windowId, mozilla::SourceLocation(aURI));
|
||||||
} else {
|
} else {
|
||||||
// Send to browser console
|
// Send to browser console
|
||||||
bool isPrivateWin = aLoadInfo->GetOriginAttributes().IsPrivateBrowsing();
|
bool isPrivateWin = aLoadInfo->GetOriginAttributes().IsPrivateBrowsing();
|
||||||
|
|
|
@ -115,9 +115,9 @@ static void LogMixedContentMessage(
|
||||||
messageLookupKey.get(), params,
|
messageLookupKey.get(), params,
|
||||||
localizedMsg);
|
localizedMsg);
|
||||||
|
|
||||||
nsContentUtils::ReportToConsoleByWindowID(localizedMsg, severityFlag,
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
messageCategory, aInnerWindowID,
|
localizedMsg, severityFlag, messageCategory, aInnerWindowID,
|
||||||
aRequestingLocation);
|
SourceLocation(aRequestingLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nsIChannelEventSink implementation
|
/* nsIChannelEventSink implementation
|
||||||
|
@ -802,7 +802,7 @@ nsresult nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
|
||||||
CopyUTF8toUTF16(spec, *params.AppendElement());
|
CopyUTF8toUTF16(spec, *params.AppendElement());
|
||||||
|
|
||||||
CSP_LogLocalizedStr("blockAllMixedContent", params,
|
CSP_LogLocalizedStr("blockAllMixedContent", params,
|
||||||
u""_ns, // aSourceFile
|
""_ns, // aSourceFile
|
||||||
u""_ns, // aScriptSample
|
u""_ns, // aScriptSample
|
||||||
0, // aLineNumber
|
0, // aLineNumber
|
||||||
1, // aColumnNumber
|
1, // aColumnNumber
|
||||||
|
|
|
@ -46,14 +46,14 @@ static constexpr auto kOther = "other"_ns;
|
||||||
TEST(FilenameEvalParser, ResourceChrome)
|
TEST(FilenameEvalParser, ResourceChrome)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
constexpr auto str = u"chrome://firegestures/content/browser.js"_ns;
|
constexpr auto str = "chrome://firegestures/content/browser.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kChromeURI && ret.second.isSome() &&
|
ASSERT_TRUE(ret.first == kChromeURI && ret.second.isSome() &&
|
||||||
ret.second.value() == str);
|
ret.second.value() == str);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"resource://firegestures/content/browser.js"_ns;
|
constexpr auto str = "resource://firegestures/content/browser.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kResourceURI && ret.second.isSome() &&
|
ASSERT_TRUE(ret.first == kResourceURI && ret.second.isSome() &&
|
||||||
|
@ -64,25 +64,25 @@ TEST(FilenameEvalParser, ResourceChrome)
|
||||||
TEST(FilenameEvalParser, BlobData)
|
TEST(FilenameEvalParser, BlobData)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
constexpr auto str = u"blob://000-000"_ns;
|
constexpr auto str = "blob://000-000"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kBlobUri && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kBlobUri && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"blob:000-000"_ns;
|
constexpr auto str = "blob:000-000"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kBlobUri && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kBlobUri && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"data://blahblahblah"_ns;
|
constexpr auto str = "data://blahblahblah"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kDataUri && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kDataUri && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"data:blahblahblah"_ns;
|
constexpr auto str = "data:blahblahblah"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kDataUri && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kDataUri && !ret.second.isSome());
|
||||||
|
@ -93,20 +93,20 @@ TEST(FilenameEvalParser, MozExtension)
|
||||||
{
|
{
|
||||||
{ // Test shield.mozilla.org replacing
|
{ // Test shield.mozilla.org replacing
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"jar:file:///c:/users/bob/appdata/roaming/mozilla/firefox/profiles/"
|
"jar:file:///c:/users/bob/appdata/roaming/mozilla/firefox/profiles/"
|
||||||
u"foo/"
|
"foo/"
|
||||||
"extensions/federated-learning@shield.mozilla.org.xpi!/experiments/"
|
"extensions/federated-learning@shield.mozilla.org.xpi!/experiments/"
|
||||||
"study/api.js"_ns;
|
"study/api.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kMozillaExtensionFile &&
|
ASSERT_TRUE(ret.first == kMozillaExtensionFile &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
u"federated-learning@s!/experiments/study/api.js"_ns);
|
"federated-learning@s!/experiments/study/api.js"_ns);
|
||||||
}
|
}
|
||||||
{ // Test mozilla.org replacing
|
{ // Test mozilla.org replacing
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"jar:file:///c:/users/bob/appdata/roaming/mozilla/firefox/profiles/"
|
"jar:file:///c:/users/bob/appdata/roaming/mozilla/firefox/profiles/"
|
||||||
u"foo/"
|
"foo/"
|
||||||
"extensions/federated-learning@shigeld.mozilla.org.xpi!/experiments/"
|
"extensions/federated-learning@shigeld.mozilla.org.xpi!/experiments/"
|
||||||
"study/api.js"_ns;
|
"study/api.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
|
@ -114,20 +114,19 @@ TEST(FilenameEvalParser, MozExtension)
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
ret.first == kMozillaExtensionFile &&
|
ret.first == kMozillaExtensionFile &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
nsLiteralString(
|
"federated-learning@shigeld.m!/experiments/study/api.js"_ns);
|
||||||
u"federated-learning@shigeld.m!/experiments/study/api.js"));
|
|
||||||
}
|
}
|
||||||
{ // Test truncating
|
{ // Test truncating
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"jar:file:///c:/users/bob/appdata/roaming/mozilla/firefox/profiles/"
|
"jar:file:///c:/users/bob/appdata/roaming/mozilla/firefox/profiles/"
|
||||||
u"foo/"
|
"foo/"
|
||||||
"extensions/federated-learning@shigeld.mozilla.org.xpi!/experiments/"
|
"extensions/federated-learning@shigeld.mozilla.org.xpi!/experiments/"
|
||||||
"study/apiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.js"_ns;
|
"study/apiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kMozillaExtensionFile &&
|
ASSERT_TRUE(ret.first == kMozillaExtensionFile &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
u"federated-learning@shigeld.m!/experiments/"
|
"federated-learning@shigeld.m!/experiments/"
|
||||||
"study/apiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"_ns);
|
"study/apiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"_ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,26 +134,26 @@ TEST(FilenameEvalParser, MozExtension)
|
||||||
TEST(FilenameEvalParser, UserChromeJS)
|
TEST(FilenameEvalParser, UserChromeJS)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
constexpr auto str = u"firegestures/content/browser.uc.js"_ns;
|
constexpr auto str = "firegestures/content/browser.uc.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kSuspectedUserChromeJS && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kSuspectedUserChromeJS && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"firegestures/content/browser.uc.js?"_ns;
|
constexpr auto str = "firegestures/content/browser.uc.js?"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kSuspectedUserChromeJS && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kSuspectedUserChromeJS && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"firegestures/content/browser.uc.js?243244224"_ns;
|
constexpr auto str = "firegestures/content/browser.uc.js?243244224"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kSuspectedUserChromeJS && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kSuspectedUserChromeJS && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"file:///b:/fxprofiles/mark/chrome/"
|
"file:///b:/fxprofiles/mark/chrome/"
|
||||||
"addbookmarkherewithmiddleclick.uc.js?1558444389291"_ns;
|
"addbookmarkherewithmiddleclick.uc.js?1558444389291"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
|
@ -165,14 +164,14 @@ TEST(FilenameEvalParser, UserChromeJS)
|
||||||
TEST(FilenameEvalParser, SingleFile)
|
TEST(FilenameEvalParser, SingleFile)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
constexpr auto str = u"browser.uc.js?2456"_ns;
|
constexpr auto str = "browser.uc.js?2456"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kSingleString && ret.second.isSome() &&
|
ASSERT_TRUE(ret.first == kSingleString && ret.second.isSome() &&
|
||||||
ret.second.value() == str);
|
ret.second.value() == str);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"debugger"_ns;
|
constexpr auto str = "debugger"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kSingleString && ret.second.isSome() &&
|
ASSERT_TRUE(ret.first == kSingleString && ret.second.isSome() &&
|
||||||
|
@ -183,13 +182,13 @@ TEST(FilenameEvalParser, SingleFile)
|
||||||
TEST(FilenameEvalParser, Other)
|
TEST(FilenameEvalParser, Other)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
constexpr auto str = u"firegestures--content"_ns;
|
constexpr auto str = "firegestures--content"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kOther && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kOther && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"gallop://thing/fire"_ns;
|
constexpr auto str = "gallop://thing/fire"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -200,7 +199,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"gallop://fire"_ns;
|
constexpr auto str = "gallop://fire"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -211,7 +210,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"firegestures/content"_ns;
|
constexpr auto str = "firegestures/content"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -222,7 +221,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"firegestures\\content"_ns;
|
constexpr auto str = "firegestures\\content"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -233,7 +232,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"/home/tom/files/thing"_ns;
|
constexpr auto str = "/home/tom/files/thing"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -244,7 +243,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"file://c/uers/tom/file.txt"_ns;
|
constexpr auto str = "file://c/uers/tom/file.txt"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -255,7 +254,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"c:/uers/tom/file.txt"_ns;
|
constexpr auto str = "c:/uers/tom/file.txt"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -266,7 +265,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"http://example.com/"_ns;
|
constexpr auto str = "http://example.com/"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -277,7 +276,7 @@ TEST(FilenameEvalParser, Other)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"http://example.com/thing.html"_ns;
|
constexpr auto str = "http://example.com/thing.html"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
@ -327,13 +326,13 @@ TEST(FilenameEvalParser, WebExtensionPathParser)
|
||||||
w->SetActive(true, eR);
|
w->SetActive(true, eR);
|
||||||
|
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/file.js"_ns;
|
"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/file.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
||||||
|
|
||||||
ASSERT_TRUE(ret.first == kExtensionURI &&
|
ASSERT_TRUE(ret.first == kExtensionURI &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
u"moz-extension://[gtesttestextension@mozilla.org: "
|
"moz-extension://[gtesttestextension@mozilla.org: "
|
||||||
"gtest Test Extension]P=0/path/to/file.js"_ns);
|
"gtest Test Extension]P=0/path/to/file.js"_ns);
|
||||||
|
|
||||||
w->SetActive(false, eR);
|
w->SetActive(false, eR);
|
||||||
|
@ -376,13 +375,13 @@ TEST(FilenameEvalParser, WebExtensionPathParser)
|
||||||
w->SetActive(true, eR);
|
w->SetActive(true, eR);
|
||||||
|
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/file.js"_ns;
|
"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/file.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
||||||
|
|
||||||
ASSERT_TRUE(ret.first == kExtensionURI &&
|
ASSERT_TRUE(ret.first == kExtensionURI &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
u"moz-extension://[gtesttestextension@mozilla.org: "
|
"moz-extension://[gtesttestextension@mozilla.org: "
|
||||||
"gtest Test Extension]P=1/path/to/file.js"_ns);
|
"gtest Test Extension]P=1/path/to/file.js"_ns);
|
||||||
|
|
||||||
w->SetActive(false, eR);
|
w->SetActive(false, eR);
|
||||||
|
@ -391,31 +390,30 @@ TEST(FilenameEvalParser, WebExtensionPathParser)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/file.js"_ns;
|
"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/file.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kExtensionURI && !ret.second.isSome());
|
ASSERT_TRUE(ret.first == kExtensionURI && !ret.second.isSome());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/file.js"_ns;
|
"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/file.js"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
ret.first == kExtensionURI &&
|
ret.first == kExtensionURI &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
nsLiteralString(
|
"moz-extension://[failed finding addon by host]/file.js"_ns);
|
||||||
u"moz-extension://[failed finding addon by host]/file.js"));
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str =
|
constexpr auto str =
|
||||||
u"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/"
|
"moz-extension://e37c3c08-beac-a04b-8032-c4f699a1a856/path/to/"
|
||||||
"file.js?querystringx=6"_ns;
|
"file.js?querystringx=6"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
nsContentSecurityUtils::FilenameToFilenameType(str, true);
|
||||||
ASSERT_TRUE(ret.first == kExtensionURI &&
|
ASSERT_TRUE(ret.first == kExtensionURI &&
|
||||||
ret.second.value() ==
|
ret.second.value() ==
|
||||||
u"moz-extension://[failed finding addon "
|
"moz-extension://[failed finding addon "
|
||||||
"by host]/path/to/file.js"_ns);
|
"by host]/path/to/file.js"_ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,31 +421,31 @@ TEST(FilenameEvalParser, WebExtensionPathParser)
|
||||||
TEST(FilenameEvalParser, AboutPageParser)
|
TEST(FilenameEvalParser, AboutPageParser)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
constexpr auto str = u"about:about"_ns;
|
constexpr auto str = "about:about"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kAboutUri &&
|
ASSERT_TRUE(ret.first == kAboutUri &&
|
||||||
ret.second.value() == u"about:about"_ns);
|
ret.second.value() == "about:about"_ns);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"about:about?hello"_ns;
|
constexpr auto str = "about:about?hello"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kAboutUri &&
|
ASSERT_TRUE(ret.first == kAboutUri &&
|
||||||
ret.second.value() == u"about:about"_ns);
|
ret.second.value() == "about:about"_ns);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"about:about#mom"_ns;
|
constexpr auto str = "about:about#mom"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kAboutUri &&
|
ASSERT_TRUE(ret.first == kAboutUri &&
|
||||||
ret.second.value() == u"about:about"_ns);
|
ret.second.value() == "about:about"_ns);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr auto str = u"about:about?hello=there#mom"_ns;
|
constexpr auto str = "about:about?hello=there#mom"_ns;
|
||||||
FilenameTypeAndDetails ret =
|
FilenameTypeAndDetails ret =
|
||||||
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
nsContentSecurityUtils::FilenameToFilenameType(str, false);
|
||||||
ASSERT_TRUE(ret.first == kAboutUri &&
|
ASSERT_TRUE(ret.first == kAboutUri &&
|
||||||
ret.second.value() == u"about:about"_ns);
|
ret.second.value() == "about:about"_ns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
#include "mozilla/dom/TrustedTypePolicy.h"
|
#include "mozilla/dom/TrustedTypePolicy.h"
|
||||||
#include "mozilla/dom/nsCSPUtils.h"
|
#include "mozilla/dom/nsCSPUtils.h"
|
||||||
|
|
||||||
#include "jsapi.h"
|
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TrustedTypePolicyFactory, mGlobalObject)
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TrustedTypePolicyFactory, mGlobalObject)
|
||||||
|
@ -31,17 +29,7 @@ constexpr size_t kCreatePolicyCSPViolationMaxSampleLength = 40;
|
||||||
static CSPViolationData CreateCSPViolationData(JSContext* aJSContext,
|
static CSPViolationData CreateCSPViolationData(JSContext* aJSContext,
|
||||||
uint32_t aPolicyIndex,
|
uint32_t aPolicyIndex,
|
||||||
const nsAString& aPolicyName) {
|
const nsAString& aPolicyName) {
|
||||||
JS::AutoFilename autoFilename;
|
auto caller = JSCallingLocation::Get(aJSContext);
|
||||||
nsAutoString fileName;
|
|
||||||
uint32_t lineNumber{0};
|
|
||||||
JS::ColumnNumberOneOrigin columnNumber;
|
|
||||||
if (JS::DescribeScriptedCaller(aJSContext, &autoFilename, &lineNumber,
|
|
||||||
&columnNumber)) {
|
|
||||||
if (const char* file = autoFilename.get()) {
|
|
||||||
CopyUTF8toUTF16(nsDependentCString(file), fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const nsAString& sample =
|
const nsAString& sample =
|
||||||
Substring(aPolicyName, /* aStartPos */ 0,
|
Substring(aPolicyName, /* aStartPos */ 0,
|
||||||
/* aLength */ kCreatePolicyCSPViolationMaxSampleLength);
|
/* aLength */ kCreatePolicyCSPViolationMaxSampleLength);
|
||||||
|
@ -53,9 +41,9 @@ static CSPViolationData CreateCSPViolationData(JSContext* aJSContext,
|
||||||
CSPViolationData::Resource{
|
CSPViolationData::Resource{
|
||||||
CSPViolationData::BlockedContentSource::TrustedTypesPolicy},
|
CSPViolationData::BlockedContentSource::TrustedTypesPolicy},
|
||||||
nsIContentSecurityPolicy::TRUSTED_TYPES_DIRECTIVE,
|
nsIContentSecurityPolicy::TRUSTED_TYPES_DIRECTIVE,
|
||||||
fileName,
|
caller.FileName(),
|
||||||
lineNumber,
|
caller.mLine,
|
||||||
columnNumber.oneOriginValue(),
|
caller.mColumn,
|
||||||
/* aElement */ nullptr,
|
/* aElement */ nullptr,
|
||||||
sample};
|
sample};
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,10 +109,7 @@ CancelChannelRunnable::Run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchEvent::FetchEvent(EventTarget* aOwner)
|
FetchEvent::FetchEvent(EventTarget* aOwner)
|
||||||
: ExtendableEvent(aOwner),
|
: ExtendableEvent(aOwner), mWaitToRespond(false) {}
|
||||||
mPreventDefaultLineNumber(0),
|
|
||||||
mPreventDefaultColumnNumber(1),
|
|
||||||
mWaitToRespond(false) {}
|
|
||||||
|
|
||||||
FetchEvent::~FetchEvent() = default;
|
FetchEvent::~FetchEvent() = default;
|
||||||
|
|
||||||
|
@ -767,11 +764,7 @@ void FetchEvent::RespondWith(JSContext* aCx, Promise& aArg, ErrorResult& aRv) {
|
||||||
// Record where respondWith() was called in the script so we can include the
|
// Record where respondWith() was called in the script so we can include the
|
||||||
// information in any error reporting. We should be guaranteed not to get
|
// information in any error reporting. We should be guaranteed not to get
|
||||||
// a file:// string here because service workers require http/https.
|
// a file:// string here because service workers require http/https.
|
||||||
nsCString spec;
|
auto location = JSCallingLocation::Get(aCx);
|
||||||
uint32_t line = 0;
|
|
||||||
uint32_t column = 1;
|
|
||||||
nsJSUtils::GetCallingLocation(aCx, spec, &line, &column);
|
|
||||||
|
|
||||||
SafeRefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
|
SafeRefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
|
||||||
|
|
||||||
nsAutoCString requestURL;
|
nsAutoCString requestURL;
|
||||||
|
@ -784,12 +777,14 @@ void FetchEvent::RespondWith(JSContext* aCx, Promise& aArg, ErrorResult& aRv) {
|
||||||
RefPtr<RespondWithHandler> handler = new RespondWithHandler(
|
RefPtr<RespondWithHandler> handler = new RespondWithHandler(
|
||||||
mChannel, mRegistration, mRequest->Mode(), ir->IsClientRequest(),
|
mChannel, mRegistration, mRequest->Mode(), ir->IsClientRequest(),
|
||||||
mRequest->Redirect(), mScriptSpec, NS_ConvertUTF8toUTF16(requestURL),
|
mRequest->Redirect(), mScriptSpec, NS_ConvertUTF8toUTF16(requestURL),
|
||||||
ir->GetFragment(), spec, line, column);
|
ir->GetFragment(), location.FileName(), location.mLine,
|
||||||
|
location.mColumn);
|
||||||
|
|
||||||
aArg.AppendNativeHandler(handler);
|
aArg.AppendNativeHandler(handler);
|
||||||
// mRespondWithHandler can be nullptr for self-dispatched FetchEvent.
|
// mRespondWithHandler can be nullptr for self-dispatched FetchEvent.
|
||||||
} else if (mRespondWithHandler) {
|
} else if (mRespondWithHandler) {
|
||||||
mRespondWithHandler->RespondWithCalledAt(spec, line, column);
|
mRespondWithHandler->RespondWithCalledAt(location.FileName(),
|
||||||
|
location.mLine, location.mColumn);
|
||||||
aArg.AppendNativeHandler(mRespondWithHandler);
|
aArg.AppendNativeHandler(mRespondWithHandler);
|
||||||
mRespondWithHandler = nullptr;
|
mRespondWithHandler = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -804,22 +799,20 @@ void FetchEvent::PreventDefault(JSContext* aCx, CallerType aCallerType) {
|
||||||
MOZ_ASSERT(aCallerType != CallerType::System,
|
MOZ_ASSERT(aCallerType != CallerType::System,
|
||||||
"Since when do we support system-principal service workers?");
|
"Since when do we support system-principal service workers?");
|
||||||
|
|
||||||
if (mPreventDefaultScriptSpec.IsEmpty()) {
|
if (!mPreventDefaultLocation) {
|
||||||
// Note when the FetchEvent might have been canceled by script, but don't
|
// Note when the FetchEvent might have been canceled by script, but don't
|
||||||
// actually log the location until we are sure it matters. This is
|
// actually log the location until we are sure it matters. This is
|
||||||
// determined in ServiceWorkerPrivate.cpp. We only remember the first
|
// determined in ServiceWorkerPrivate.cpp. We only remember the first
|
||||||
// call to preventDefault() as its the most likely to have actually canceled
|
// call to preventDefault() as its the most likely to have actually canceled
|
||||||
// the event.
|
// the event.
|
||||||
nsJSUtils::GetCallingLocation(aCx, mPreventDefaultScriptSpec,
|
mPreventDefaultLocation = JSCallingLocation::Get(aCx);
|
||||||
&mPreventDefaultLineNumber,
|
|
||||||
&mPreventDefaultColumnNumber);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::PreventDefault(aCx, aCallerType);
|
Event::PreventDefault(aCx, aCallerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FetchEvent::ReportCanceled() {
|
void FetchEvent::ReportCanceled() {
|
||||||
MOZ_ASSERT(!mPreventDefaultScriptSpec.IsEmpty());
|
MOZ_ASSERT(mPreventDefaultLocation);
|
||||||
|
|
||||||
SafeRefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
|
SafeRefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
|
||||||
nsAutoCString url;
|
nsAutoCString url;
|
||||||
|
@ -832,14 +825,14 @@ void FetchEvent::ReportCanceled() {
|
||||||
// CopyUTF8toUTF16(url, requestURL);
|
// CopyUTF8toUTF16(url, requestURL);
|
||||||
|
|
||||||
if (mChannel) {
|
if (mChannel) {
|
||||||
::AsyncLog(mChannel.get(), mPreventDefaultScriptSpec,
|
::AsyncLog(mChannel.get(), mPreventDefaultLocation.FileName(),
|
||||||
mPreventDefaultLineNumber, mPreventDefaultColumnNumber,
|
mPreventDefaultLocation.mLine, mPreventDefaultLocation.mColumn,
|
||||||
"InterceptionCanceledWithURL"_ns, requestURL);
|
"InterceptionCanceledWithURL"_ns, requestURL);
|
||||||
// mRespondWithHandler could be nullptr for self-dispatched FetchEvent.
|
// mRespondWithHandler could be nullptr for self-dispatched FetchEvent.
|
||||||
} else if (mRespondWithHandler) {
|
} else if (mRespondWithHandler) {
|
||||||
mRespondWithHandler->ReportCanceled(mPreventDefaultScriptSpec,
|
mRespondWithHandler->ReportCanceled(mPreventDefaultLocation.FileName(),
|
||||||
mPreventDefaultLineNumber,
|
mPreventDefaultLocation.mLine,
|
||||||
mPreventDefaultColumnNumber);
|
mPreventDefaultLocation.mColumn);
|
||||||
mRespondWithHandler = nullptr;
|
mRespondWithHandler = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,9 +841,7 @@ namespace {
|
||||||
|
|
||||||
class WaitUntilHandler final : public PromiseNativeHandler {
|
class WaitUntilHandler final : public PromiseNativeHandler {
|
||||||
const nsCString mScope;
|
const nsCString mScope;
|
||||||
nsString mSourceSpec;
|
JSCallingLocation mLocation;
|
||||||
uint32_t mLine;
|
|
||||||
uint32_t mColumn;
|
|
||||||
nsString mRejectValue;
|
nsString mRejectValue;
|
||||||
|
|
||||||
~WaitUntilHandler() = default;
|
~WaitUntilHandler() = default;
|
||||||
|
@ -860,13 +851,8 @@ class WaitUntilHandler final : public PromiseNativeHandler {
|
||||||
|
|
||||||
WaitUntilHandler(WorkerPrivate* aWorkerPrivate, JSContext* aCx)
|
WaitUntilHandler(WorkerPrivate* aWorkerPrivate, JSContext* aCx)
|
||||||
: mScope(GetCurrentThreadWorkerPrivate()->ServiceWorkerScope()),
|
: mScope(GetCurrentThreadWorkerPrivate()->ServiceWorkerScope()),
|
||||||
mLine(0),
|
mLocation(JSCallingLocation::Get(aCx)) {
|
||||||
mColumn(1) {
|
|
||||||
MOZ_ASSERT(GetCurrentThreadWorkerPrivate());
|
MOZ_ASSERT(GetCurrentThreadWorkerPrivate());
|
||||||
|
|
||||||
// Save the location of the waitUntil() call itself as a fallback
|
|
||||||
// in case the rejection value does not contain any location info.
|
|
||||||
nsJSUtils::GetCallingLocation(aCx, mSourceSpec, &mLine, &mColumn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu,
|
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu,
|
||||||
|
@ -879,7 +865,7 @@ class WaitUntilHandler final : public PromiseNativeHandler {
|
||||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||||
MOZ_ASSERT(workerPrivate);
|
MOZ_ASSERT(workerPrivate);
|
||||||
|
|
||||||
nsString spec;
|
nsCString spec;
|
||||||
uint32_t line = 0;
|
uint32_t line = 0;
|
||||||
uint32_t column = 0;
|
uint32_t column = 0;
|
||||||
nsContentUtils::ExtractErrorValues(aCx, aValue, spec, &line, &column,
|
nsContentUtils::ExtractErrorValues(aCx, aValue, spec, &line, &column,
|
||||||
|
@ -887,9 +873,9 @@ class WaitUntilHandler final : public PromiseNativeHandler {
|
||||||
|
|
||||||
// only use the extracted location if we found one
|
// only use the extracted location if we found one
|
||||||
if (!spec.IsEmpty()) {
|
if (!spec.IsEmpty()) {
|
||||||
mSourceSpec = spec;
|
mLocation.mResource = AsVariant(std::move(spec));
|
||||||
mLine = line;
|
mLocation.mLine = line;
|
||||||
mColumn = column;
|
mLocation.mColumn = column;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(
|
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(
|
||||||
|
@ -920,8 +906,9 @@ class WaitUntilHandler final : public PromiseNativeHandler {
|
||||||
// because there is no documeny yet, and the navigation is no longer
|
// because there is no documeny yet, and the navigation is no longer
|
||||||
// being intercepted.
|
// being intercepted.
|
||||||
|
|
||||||
swm->ReportToAllClients(mScope, message, mSourceSpec, u""_ns, mLine,
|
swm->ReportToAllClients(mScope, message, mLocation.FileName(), u""_ns,
|
||||||
mColumn, nsIScriptError::errorFlag);
|
mLocation.mLine, mLocation.mColumn,
|
||||||
|
nsIScriptError::errorFlag);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -140,11 +140,9 @@ class FetchEvent final : public ExtendableEvent {
|
||||||
RefPtr<Promise> mHandled;
|
RefPtr<Promise> mHandled;
|
||||||
RefPtr<Promise> mPreloadResponse;
|
RefPtr<Promise> mPreloadResponse;
|
||||||
nsCString mScriptSpec;
|
nsCString mScriptSpec;
|
||||||
nsCString mPreventDefaultScriptSpec;
|
|
||||||
nsString mClientId;
|
nsString mClientId;
|
||||||
nsString mResultingClientId;
|
nsString mResultingClientId;
|
||||||
uint32_t mPreventDefaultLineNumber;
|
JSCallingLocation mPreventDefaultLocation;
|
||||||
uint32_t mPreventDefaultColumnNumber;
|
|
||||||
bool mWaitToRespond;
|
bool mWaitToRespond;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1447,7 +1447,7 @@ already_AddRefed<ServiceWorkerManager> ServiceWorkerManager::GetInstance() {
|
||||||
|
|
||||||
void ServiceWorkerManager::ReportToAllClients(
|
void ServiceWorkerManager::ReportToAllClients(
|
||||||
const nsCString& aScope, const nsString& aMessage,
|
const nsCString& aScope, const nsString& aMessage,
|
||||||
const nsString& aFilename, const nsString& aLine, uint32_t aLineNumber,
|
const nsCString& aFilename, const nsString& aLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags) {
|
uint32_t aColumnNumber, uint32_t aFlags) {
|
||||||
ConsoleUtils::ReportForServiceWorkerScope(
|
ConsoleUtils::ReportForServiceWorkerScope(
|
||||||
NS_ConvertUTF8toUTF16(aScope), aMessage, aFilename, aLineNumber,
|
NS_ConvertUTF8toUTF16(aScope), aMessage, aFilename, aLineNumber,
|
||||||
|
@ -1458,7 +1458,7 @@ void ServiceWorkerManager::ReportToAllClients(
|
||||||
void ServiceWorkerManager::LocalizeAndReportToAllClients(
|
void ServiceWorkerManager::LocalizeAndReportToAllClients(
|
||||||
const nsCString& aScope, const char* aStringKey,
|
const nsCString& aScope, const char* aStringKey,
|
||||||
const nsTArray<nsString>& aParamArray, uint32_t aFlags,
|
const nsTArray<nsString>& aParamArray, uint32_t aFlags,
|
||||||
const nsString& aFilename, const nsString& aLine, uint32_t aLineNumber,
|
const nsCString& aFilename, const nsString& aLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber) {
|
uint32_t aColumnNumber) {
|
||||||
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
||||||
if (!swm) {
|
if (!swm) {
|
||||||
|
@ -1479,8 +1479,8 @@ void ServiceWorkerManager::LocalizeAndReportToAllClients(
|
||||||
|
|
||||||
void ServiceWorkerManager::HandleError(
|
void ServiceWorkerManager::HandleError(
|
||||||
JSContext* aCx, nsIPrincipal* aPrincipal, const nsCString& aScope,
|
JSContext* aCx, nsIPrincipal* aPrincipal, const nsCString& aScope,
|
||||||
const nsString& aWorkerURL, const nsString& aMessage,
|
const nsCString& aWorkerURL, const nsString& aMessage,
|
||||||
const nsString& aFilename, const nsString& aLine, uint32_t aLineNumber,
|
const nsCString& aFilename, const nsString& aLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags, JSExnType aExnType) {
|
uint32_t aColumnNumber, uint32_t aFlags, JSExnType aExnType) {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
MOZ_ASSERT(aPrincipal);
|
MOZ_ASSERT(aPrincipal);
|
||||||
|
|
|
@ -180,7 +180,7 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager,
|
||||||
* localizing the error.
|
* localizing the error.
|
||||||
*/
|
*/
|
||||||
void ReportToAllClients(const nsCString& aScope, const nsString& aMessage,
|
void ReportToAllClients(const nsCString& aScope, const nsString& aMessage,
|
||||||
const nsString& aFilename, const nsString& aLine,
|
const nsCString& aFilename, const nsString& aLine,
|
||||||
uint32_t aLineNumber, uint32_t aColumnNumber,
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
||||||
uint32_t aFlags);
|
uint32_t aFlags);
|
||||||
|
|
||||||
|
@ -204,14 +204,14 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager,
|
||||||
static void LocalizeAndReportToAllClients(
|
static void LocalizeAndReportToAllClients(
|
||||||
const nsCString& aScope, const char* aStringKey,
|
const nsCString& aScope, const char* aStringKey,
|
||||||
const nsTArray<nsString>& aParamArray, uint32_t aFlags = 0x0,
|
const nsTArray<nsString>& aParamArray, uint32_t aFlags = 0x0,
|
||||||
const nsString& aFilename = u""_ns, const nsString& aLine = u""_ns,
|
const nsCString& aFilename = ""_ns, const nsString& aLine = u""_ns,
|
||||||
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0);
|
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0);
|
||||||
|
|
||||||
// Always consumes the error by reporting to consoles of all controlled
|
// Always consumes the error by reporting to consoles of all controlled
|
||||||
// documents.
|
// documents.
|
||||||
void HandleError(JSContext* aCx, nsIPrincipal* aPrincipal,
|
void HandleError(JSContext* aCx, nsIPrincipal* aPrincipal,
|
||||||
const nsCString& aScope, const nsString& aWorkerURL,
|
const nsCString& aScope, const nsCString& aWorkerURL,
|
||||||
const nsString& aMessage, const nsString& aFilename,
|
const nsString& aMessage, const nsCString& aFilename,
|
||||||
const nsString& aLine, uint32_t aLineNumber,
|
const nsString& aLine, uint32_t aLineNumber,
|
||||||
uint32_t aColumnNumber, uint32_t aFlags, JSExnType aExnType);
|
uint32_t aColumnNumber, uint32_t aFlags, JSExnType aExnType);
|
||||||
|
|
||||||
|
|
|
@ -1575,8 +1575,8 @@ void ServiceWorkerPrivate::ErrorReceived(const ErrorValue& aError) {
|
||||||
ServiceWorkerInfo* info = mInfo;
|
ServiceWorkerInfo* info = mInfo;
|
||||||
|
|
||||||
swm->HandleError(nullptr, info->Principal(), info->Scope(),
|
swm->HandleError(nullptr, info->Principal(), info->Scope(),
|
||||||
NS_ConvertUTF8toUTF16(info->ScriptSpec()), u""_ns, u""_ns,
|
info->ScriptSpec(), u""_ns, ""_ns, u""_ns, 0, 0,
|
||||||
u""_ns, 0, 0, nsIScriptError::errorFlag, JSEXN_ERR);
|
nsIScriptError::errorFlag, JSEXN_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServiceWorkerPrivate::Terminated() {
|
void ServiceWorkerPrivate::Terminated() {
|
||||||
|
|
|
@ -387,7 +387,7 @@ void ServiceWorkerUpdateJob::ComparisonResult(nsresult aStatus,
|
||||||
message, nsContentUtils::eDOM_PROPERTIES,
|
message, nsContentUtils::eDOM_PROPERTIES,
|
||||||
"ServiceWorkerScopePathMismatch", reportScope, reportMaxPrefix);
|
"ServiceWorkerScopePathMismatch", reportScope, reportMaxPrefix);
|
||||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to format localized string");
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to format localized string");
|
||||||
swm->ReportToAllClients(mScope, message, u""_ns, u""_ns, 0, 0,
|
swm->ReportToAllClients(mScope, message, ""_ns, u""_ns, 0, 0,
|
||||||
nsIScriptError::errorFlag);
|
nsIScriptError::errorFlag);
|
||||||
FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR);
|
FailUpdateJob(NS_ERROR_DOM_SECURITY_ERR);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "mozilla/dom/SVGScriptElement.h"
|
#include "mozilla/dom/SVGScriptElement.h"
|
||||||
|
|
||||||
|
#include "mozilla/dom/Document.h"
|
||||||
#include "mozilla/dom/FetchPriority.h"
|
#include "mozilla/dom/FetchPriority.h"
|
||||||
#include "nsGkAtoms.h"
|
#include "nsGkAtoms.h"
|
||||||
#include "nsNetUtil.h"
|
#include "nsNetUtil.h"
|
||||||
|
@ -130,6 +131,8 @@ void SVGScriptElement::FreezeExecutionAttrs(const Document* aOwnerDoc) {
|
||||||
mStringAttributes[XLINK_HREF].GetAnimValue(src, this);
|
mStringAttributes[XLINK_HREF].GetAnimValue(src, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SourceLocation loc{OwnerDoc()->GetDocumentURI(), GetScriptLineNumber(),
|
||||||
|
GetScriptColumnNumber().oneOriginValue()};
|
||||||
// Empty src should be treated as invalid URL.
|
// Empty src should be treated as invalid URL.
|
||||||
if (!src.IsEmpty()) {
|
if (!src.IsEmpty()) {
|
||||||
NS_NewURI(getter_AddRefs(mUri), src, nullptr, GetBaseURI());
|
NS_NewURI(getter_AddRefs(mUri), src, nullptr, GetBaseURI());
|
||||||
|
@ -138,20 +141,17 @@ void SVGScriptElement::FreezeExecutionAttrs(const Document* aOwnerDoc) {
|
||||||
AutoTArray<nsString, 2> params = {
|
AutoTArray<nsString, 2> params = {
|
||||||
isHref ? u"href"_ns : u"xlink:href"_ns, src};
|
isHref ? u"href"_ns : u"xlink:href"_ns, src};
|
||||||
|
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "SVG"_ns,
|
||||||
nsIScriptError::warningFlag, "SVG"_ns, OwnerDoc(),
|
OwnerDoc(),
|
||||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceInvalidUri", params,
|
nsContentUtils::eDOM_PROPERTIES,
|
||||||
nullptr, u""_ns, GetScriptLineNumber(),
|
"ScriptSourceInvalidUri", params, loc);
|
||||||
GetScriptColumnNumber().oneOriginValue());
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
AutoTArray<nsString, 1> params = {isHref ? u"href"_ns : u"xlink:href"_ns};
|
AutoTArray<nsString, 1> params = {isHref ? u"href"_ns : u"xlink:href"_ns};
|
||||||
|
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::warningFlag, "SVG"_ns, OwnerDoc(),
|
nsIScriptError::warningFlag, "SVG"_ns, OwnerDoc(),
|
||||||
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty", params, nullptr,
|
nsContentUtils::eDOM_PROPERTIES, "ScriptSourceEmpty", params, loc);
|
||||||
u""_ns, GetScriptLineNumber(),
|
|
||||||
GetScriptColumnNumber().oneOriginValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point mUri will be null for invalid URLs.
|
// At this point mUri will be null for invalid URLs.
|
||||||
|
|
|
@ -19,7 +19,7 @@ dictionary CSPReportProperties {
|
||||||
SecurityPolicyViolationEventDisposition disposition = "report";
|
SecurityPolicyViolationEventDisposition disposition = "report";
|
||||||
long status-code = 0;
|
long status-code = 0;
|
||||||
|
|
||||||
DOMString source-file;
|
UTF8String source-file;
|
||||||
DOMString script-sample;
|
DOMString script-sample;
|
||||||
long line-number;
|
long line-number;
|
||||||
long column-number;
|
long column-number;
|
||||||
|
|
|
@ -20,7 +20,7 @@ interface FeaturePolicy {
|
||||||
Exposed=Window]
|
Exposed=Window]
|
||||||
interface FeaturePolicyViolationReportBody : ReportBody {
|
interface FeaturePolicyViolationReportBody : ReportBody {
|
||||||
readonly attribute DOMString featureId;
|
readonly attribute DOMString featureId;
|
||||||
readonly attribute DOMString? sourceFile;
|
readonly attribute UTF8String? sourceFile;
|
||||||
readonly attribute long? lineNumber;
|
readonly attribute long? lineNumber;
|
||||||
readonly attribute long? columnNumber;
|
readonly attribute long? columnNumber;
|
||||||
readonly attribute DOMString disposition;
|
readonly attribute DOMString disposition;
|
||||||
|
|
|
@ -52,7 +52,7 @@ interface DeprecationReportBody : ReportBody {
|
||||||
// here.
|
// here.
|
||||||
readonly attribute DOMTimeStamp? anticipatedRemoval;
|
readonly attribute DOMTimeStamp? anticipatedRemoval;
|
||||||
readonly attribute DOMString message;
|
readonly attribute DOMString message;
|
||||||
readonly attribute DOMString? sourceFile;
|
readonly attribute UTF8String? sourceFile;
|
||||||
readonly attribute unsigned long? lineNumber;
|
readonly attribute unsigned long? lineNumber;
|
||||||
readonly attribute unsigned long? columnNumber;
|
readonly attribute unsigned long? columnNumber;
|
||||||
};
|
};
|
||||||
|
@ -78,7 +78,7 @@ interface CSPViolationReportBody : ReportBody {
|
||||||
readonly attribute USVString? blockedURL;
|
readonly attribute USVString? blockedURL;
|
||||||
readonly attribute DOMString effectiveDirective;
|
readonly attribute DOMString effectiveDirective;
|
||||||
readonly attribute DOMString originalPolicy;
|
readonly attribute DOMString originalPolicy;
|
||||||
readonly attribute USVString? sourceFile;
|
readonly attribute UTF8String? sourceFile;
|
||||||
readonly attribute DOMString? sample;
|
readonly attribute DOMString? sample;
|
||||||
readonly attribute SecurityPolicyViolationEventDisposition disposition;
|
readonly attribute SecurityPolicyViolationEventDisposition disposition;
|
||||||
readonly attribute unsigned short statusCode;
|
readonly attribute unsigned short statusCode;
|
||||||
|
|
|
@ -40,6 +40,8 @@ dictionary SecurityPolicyViolationEventInit : EventInit
|
||||||
DOMString violatedDirective = "";
|
DOMString violatedDirective = "";
|
||||||
DOMString effectiveDirective = "";
|
DOMString effectiveDirective = "";
|
||||||
DOMString originalPolicy = "";
|
DOMString originalPolicy = "";
|
||||||
|
// TODO: We could avoid some string copies if these were USVStrings or
|
||||||
|
// UTF8Strings, see https://github.com/w3c/webappsec-csp/issues/674
|
||||||
DOMString sourceFile = "";
|
DOMString sourceFile = "";
|
||||||
DOMString sample = "";
|
DOMString sample = "";
|
||||||
SecurityPolicyViolationEventDisposition disposition = "enforce";
|
SecurityPolicyViolationEventDisposition disposition = "enforce";
|
||||||
|
|
|
@ -1780,7 +1780,7 @@ nsresult WebSocketImpl::Init(nsIGlobalObject* aWindowGlobal, JSContext* aCx,
|
||||||
|
|
||||||
params.AppendElement(u"wss"_ns);
|
params.AppendElement(u"wss"_ns);
|
||||||
CSP_LogLocalizedStr("upgradeInsecureRequest", params,
|
CSP_LogLocalizedStr("upgradeInsecureRequest", params,
|
||||||
u""_ns, // aSourceFile
|
""_ns, // aSourceFile
|
||||||
u""_ns, // aScriptSample
|
u""_ns, // aScriptSample
|
||||||
0, // aLineNumber
|
0, // aLineNumber
|
||||||
1, // aColumnNumber
|
1, // aColumnNumber
|
||||||
|
|
|
@ -475,14 +475,14 @@ MOZ_CAN_RUN_SCRIPT bool InterruptCallback(JSContext* aCx) {
|
||||||
|
|
||||||
class LogViolationDetailsRunnable final : public WorkerMainThreadRunnable {
|
class LogViolationDetailsRunnable final : public WorkerMainThreadRunnable {
|
||||||
uint16_t mViolationType;
|
uint16_t mViolationType;
|
||||||
nsString mFileName;
|
nsCString mFileName;
|
||||||
uint32_t mLineNum;
|
uint32_t mLineNum;
|
||||||
uint32_t mColumnNum;
|
uint32_t mColumnNum;
|
||||||
nsString mScriptSample;
|
nsString mScriptSample;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogViolationDetailsRunnable(WorkerPrivate* aWorker, uint16_t aViolationType,
|
LogViolationDetailsRunnable(WorkerPrivate* aWorker, uint16_t aViolationType,
|
||||||
const nsString& aFileName, uint32_t aLineNum,
|
const nsCString& aFileName, uint32_t aLineNum,
|
||||||
uint32_t aColumnNum,
|
uint32_t aColumnNum,
|
||||||
const nsAString& aScriptSample)
|
const nsAString& aScriptSample)
|
||||||
: WorkerMainThreadRunnable(aWorker,
|
: WorkerMainThreadRunnable(aWorker,
|
||||||
|
@ -531,22 +531,11 @@ bool ContentSecurityPolicyAllows(JSContext* aCx, JS::RuntimeCode aKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reportViolation) {
|
if (reportViolation) {
|
||||||
nsString fileName;
|
auto caller = JSCallingLocation::Get(aCx);
|
||||||
uint32_t lineNum = 0;
|
|
||||||
JS::ColumnNumberOneOrigin columnNum;
|
|
||||||
|
|
||||||
JS::AutoFilename file;
|
|
||||||
if (JS::DescribeScriptedCaller(aCx, &file, &lineNum, &columnNum) &&
|
|
||||||
file.get()) {
|
|
||||||
CopyUTF8toUTF16(MakeStringSpan(file.get()), fileName);
|
|
||||||
} else {
|
|
||||||
MOZ_ASSERT(!JS_IsExceptionPending(aCx));
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<LogViolationDetailsRunnable> runnable =
|
RefPtr<LogViolationDetailsRunnable> runnable =
|
||||||
new LogViolationDetailsRunnable(worker, violationType, fileName,
|
new LogViolationDetailsRunnable(worker, violationType,
|
||||||
lineNum, columnNum.oneOriginValue(),
|
caller.FileName(), caller.mLine,
|
||||||
scriptSample);
|
caller.mColumn, scriptSample);
|
||||||
|
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
runnable->Dispatch(worker, Killing, rv);
|
runnable->Dispatch(worker, Killing, rv);
|
||||||
|
|
|
@ -170,7 +170,8 @@ bool WorkerScriptTimeoutHandler::Call(const char* aExecutionReason) {
|
||||||
|
|
||||||
JSContext* cx = aes.cx();
|
JSContext* cx = aes.cx();
|
||||||
JS::CompileOptions options(cx);
|
JS::CompileOptions options(cx);
|
||||||
options.setFileAndLine(mFileName.get(), mLineNo).setNoScriptRval(true);
|
options.setFileAndLine(mCaller.FileName().get(), mCaller.mLine)
|
||||||
|
.setNoScriptRval(true);
|
||||||
options.setIntroductionType("domTimer");
|
options.setIntroductionType("domTimer");
|
||||||
|
|
||||||
JS::Rooted<JS::Value> unused(cx);
|
JS::Rooted<JS::Value> unused(cx);
|
||||||
|
@ -1156,9 +1157,7 @@ namespace {
|
||||||
|
|
||||||
class ReportFetchListenerWarningRunnable final : public Runnable {
|
class ReportFetchListenerWarningRunnable final : public Runnable {
|
||||||
const nsCString mScope;
|
const nsCString mScope;
|
||||||
nsString mSourceSpec;
|
mozilla::JSCallingLocation mCaller;
|
||||||
uint32_t mLine;
|
|
||||||
uint32_t mColumn;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ReportFetchListenerWarningRunnable(const nsString& aScope)
|
explicit ReportFetchListenerWarningRunnable(const nsString& aScope)
|
||||||
|
@ -1169,7 +1168,7 @@ class ReportFetchListenerWarningRunnable final : public Runnable {
|
||||||
JSContext* cx = workerPrivate->GetJSContext();
|
JSContext* cx = workerPrivate->GetJSContext();
|
||||||
MOZ_ASSERT(cx);
|
MOZ_ASSERT(cx);
|
||||||
|
|
||||||
nsJSUtils::GetCallingLocation(cx, mSourceSpec, &mLine, &mColumn);
|
mCaller = JSCallingLocation::Get(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHOD
|
NS_IMETHOD
|
||||||
|
@ -1178,7 +1177,8 @@ class ReportFetchListenerWarningRunnable final : public Runnable {
|
||||||
|
|
||||||
ServiceWorkerManager::LocalizeAndReportToAllClients(
|
ServiceWorkerManager::LocalizeAndReportToAllClients(
|
||||||
mScope, "ServiceWorkerNoFetchHandler", nsTArray<nsString>{},
|
mScope, "ServiceWorkerNoFetchHandler", nsTArray<nsString>{},
|
||||||
nsIScriptError::warningFlag, mSourceSpec, u""_ns, mLine, mColumn);
|
nsIScriptError::warningFlag, mCaller.FileName(), u""_ns, mCaller.mLine,
|
||||||
|
mCaller.mColumn);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -696,7 +696,7 @@ nsresult XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
|
||||||
u"Versioned JavaScripts are no longer supported. "
|
u"Versioned JavaScripts are no longer supported. "
|
||||||
"Please remove the version parameter."_ns,
|
"Please remove the version parameter."_ns,
|
||||||
nsIScriptError::errorFlag, "XUL Document"_ns, nullptr,
|
nsIScriptError::errorFlag, "XUL Document"_ns, nullptr,
|
||||||
mDocumentURL, u""_ns, aLineNumber);
|
SourceLocation(mDocumentURL.get()));
|
||||||
isJavaScript = false;
|
isJavaScript = false;
|
||||||
} else if (rv != NS_ERROR_INVALID_ARG) {
|
} else if (rv != NS_ERROR_INVALID_ARG) {
|
||||||
return rv;
|
return rv;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "js/Wrapper.h"
|
#include "js/Wrapper.h"
|
||||||
|
|
||||||
#include "mozilla/MemoryReporting.h"
|
#include "mozilla/MemoryReporting.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "nsIScriptError.h"
|
#include "nsIScriptError.h"
|
||||||
#include "nsPrintfCString.h"
|
#include "nsPrintfCString.h"
|
||||||
#include "nsPointerHashKeys.h"
|
#include "nsPointerHashKeys.h"
|
||||||
|
@ -198,14 +199,13 @@ already_AddRefed<XPCNativeInterface> XPCNativeInterface::NewInstance(
|
||||||
nsPrintfCString errorMsg("Use of %s in content process is deprecated.",
|
nsPrintfCString errorMsg("Use of %s in content process is deprecated.",
|
||||||
intfNameChars);
|
intfNameChars);
|
||||||
|
|
||||||
nsAutoString filename;
|
auto location = JSCallingLocation::Get(cx);
|
||||||
uint32_t lineno = 0, column = 1;
|
|
||||||
nsJSUtils::GetCallingLocation(cx, filename, &lineno, &column);
|
|
||||||
nsCOMPtr<nsIScriptError> error(
|
nsCOMPtr<nsIScriptError> error(
|
||||||
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
||||||
error->Init(NS_ConvertUTF8toUTF16(errorMsg), filename, u""_ns, lineno,
|
error->Init(NS_ConvertUTF8toUTF16(errorMsg),
|
||||||
column, nsIScriptError::warningFlag, "chrome javascript"_ns,
|
NS_ConvertUTF8toUTF16(location.FileName()), u""_ns,
|
||||||
false /* from private window */,
|
location.mLine, location.mColumn, nsIScriptError::warningFlag,
|
||||||
|
"chrome javascript"_ns, false /* from private window */,
|
||||||
true /* from chrome context */);
|
true /* from chrome context */);
|
||||||
console->LogMessage(error);
|
console->LogMessage(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,9 @@ static void logMessage(nsIContent* aContent, const nsAString& aCoordsSpec,
|
||||||
aFlags, "Layout: ImageMap"_ns, aContent->OwnerDoc(),
|
aFlags, "Layout: ImageMap"_ns, aContent->OwnerDoc(),
|
||||||
nsContentUtils::eLAYOUT_PROPERTIES, aMessageName,
|
nsContentUtils::eLAYOUT_PROPERTIES, aMessageName,
|
||||||
nsTArray<nsString>(), /* params */
|
nsTArray<nsString>(), /* params */
|
||||||
nullptr,
|
SourceLocation(aContent->OwnerDoc()->GetDocumentURI(), 0, 1,
|
||||||
PromiseFlatString(u"coords=\""_ns + aCoordsSpec +
|
NS_ConvertUTF16toUTF8(u"coords=\""_ns + aCoordsSpec +
|
||||||
u"\""_ns)); /* source line */
|
u"\""_ns))); /* source line */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Area::ParseCoords(const nsAString& aSpec) {
|
void Area::ParseCoords(const nsAString& aSpec) {
|
||||||
|
|
|
@ -815,7 +815,8 @@ nsresult SheetLoadData::VerifySheetReadyToParse(
|
||||||
nsCOMPtr<nsIURI> referrer = ReferrerInfo()->GetOriginalReferrer();
|
nsCOMPtr<nsIURI> referrer = ReferrerInfo()->GetOriginalReferrer();
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
errorFlag, "CSS Loader"_ns, mLoader->mDocument,
|
errorFlag, "CSS Loader"_ns, mLoader->mDocument,
|
||||||
nsContentUtils::eCSS_PROPERTIES, errorMessage, strings, referrer);
|
nsContentUtils::eCSS_PROPERTIES, errorMessage, strings,
|
||||||
|
SourceLocation(referrer.get()));
|
||||||
|
|
||||||
if (errorFlag == nsIScriptError::errorFlag) {
|
if (errorFlag == nsIScriptError::errorFlag) {
|
||||||
LOG_WARN(
|
LOG_WARN(
|
||||||
|
|
|
@ -2993,7 +2993,7 @@ static bool ShouldSecureUpgradeNoHSTS(nsIURI* aURI, nsILoadInfo* aLoadInfo) {
|
||||||
AutoTArray<nsString, 2> params = {reportSpec, reportScheme};
|
AutoTArray<nsString, 2> params = {reportSpec, reportScheme};
|
||||||
uint64_t innerWindowId = aLoadInfo->GetInnerWindowID();
|
uint64_t innerWindowId = aLoadInfo->GetInnerWindowID();
|
||||||
CSP_LogLocalizedStr("upgradeInsecureRequest", params,
|
CSP_LogLocalizedStr("upgradeInsecureRequest", params,
|
||||||
u""_ns, // aSourceFile
|
""_ns, // aSourceFile
|
||||||
u""_ns, // aScriptSample
|
u""_ns, // aScriptSample
|
||||||
0, // aLineNumber
|
0, // aLineNumber
|
||||||
1, // aColumnNumber
|
1, // aColumnNumber
|
||||||
|
@ -3027,7 +3027,7 @@ static bool ShouldSecureUpgradeNoHSTS(nsIURI* aURI, nsILoadInfo* aLoadInfo) {
|
||||||
uint64_t innerWindowId = aLoadInfo->GetInnerWindowID();
|
uint64_t innerWindowId = aLoadInfo->GetInnerWindowID();
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
message, nsIScriptError::warningFlag, "Mixed Content Message"_ns,
|
message, nsIScriptError::warningFlag, "Mixed Content Message"_ns,
|
||||||
innerWindowId, aURI);
|
innerWindowId, SourceLocation(aURI));
|
||||||
|
|
||||||
// Set this flag so we know we'll upgrade because of
|
// Set this flag so we know we'll upgrade because of
|
||||||
// 'security.mixed_content.upgrade_display_content'.
|
// 'security.mixed_content.upgrade_display_content'.
|
||||||
|
|
|
@ -6639,7 +6639,8 @@ void HttpBaseChannel::LogORBError(
|
||||||
if (contentWindowId) {
|
if (contentWindowId) {
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
u"A resource is blocked by OpaqueResponseBlocking, please check browser console for details."_ns,
|
u"A resource is blocked by OpaqueResponseBlocking, please check browser console for details."_ns,
|
||||||
nsIScriptError::warningFlag, "ORB"_ns, contentWindowId, mURI);
|
nsIScriptError::warningFlag, "ORB"_ns, contentWindowId,
|
||||||
|
SourceLocation(mURI.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoTArray<nsString, 2> params;
|
AutoTArray<nsString, 2> params;
|
||||||
|
|
|
@ -803,14 +803,10 @@ Maybe<nsCString> CallingScriptLocationString() {
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString fileNameString;
|
auto location = JSCallingLocation::Get(cx);
|
||||||
uint32_t line = 0, col = 0;
|
|
||||||
if (!nsJSUtils::GetCallingLocation(cx, fileNameString, &line, &col)) {
|
|
||||||
return Nothing();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCString logString = ""_ns;
|
nsCString logString = ""_ns;
|
||||||
logString.AppendPrintf("%s:%u:%u", fileNameString.get(), line, col);
|
logString.AppendPrintf("%s:%u:%u", location.FileName().get(), location.mLine,
|
||||||
|
location.mColumn);
|
||||||
return Some(logString);
|
return Some(logString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2671,9 +2671,10 @@ void nsHtml5StreamParser::ContinueAfterScriptsOrEncodingCommitment(
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::warningFlag, "DOM Events"_ns,
|
nsIScriptError::warningFlag, "DOM Events"_ns,
|
||||||
mExecutor->GetDocument(), nsContentUtils::eDOM_PROPERTIES,
|
mExecutor->GetDocument(), nsContentUtils::eDOM_PROPERTIES,
|
||||||
"SpeculationFailed2", nsTArray<nsString>(), nullptr, u""_ns,
|
"SpeculationFailed2", nsTArray<nsString>(),
|
||||||
speculation->GetStartLineNumber(),
|
SourceLocation(mExecutor->GetDocument()->GetDocumentURI(),
|
||||||
speculation->GetStartColumnNumber());
|
speculation->GetStartLineNumber(),
|
||||||
|
speculation->GetStartColumnNumber()));
|
||||||
|
|
||||||
nsHtml5OwningUTF16Buffer* buffer = mFirstBuffer->next;
|
nsHtml5OwningUTF16Buffer* buffer = mFirstBuffer->next;
|
||||||
while (buffer) {
|
while (buffer) {
|
||||||
|
|
|
@ -1031,7 +1031,8 @@ void nsHtml5TreeOpExecutor::MaybeComplainAboutCharset(const char* aMsgId,
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
aError ? nsIScriptError::errorFlag : nsIScriptError::warningFlag,
|
aError ? nsIScriptError::errorFlag : nsIScriptError::warningFlag,
|
||||||
"HTML parser"_ns, mDocument, nsContentUtils::eHTMLPARSER_PROPERTIES,
|
"HTML parser"_ns, mDocument, nsContentUtils::eHTMLPARSER_PROPERTIES,
|
||||||
aMsgId, nsTArray<nsString>(), nullptr, u""_ns, aLineNumber);
|
aMsgId, nsTArray<nsString>(),
|
||||||
|
SourceLocation{mDocument->GetDocumentURI(), aLineNumber});
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsHtml5TreeOpExecutor::ComplainAboutBogusProtocolCharset(
|
void nsHtml5TreeOpExecutor::ComplainAboutBogusProtocolCharset(
|
||||||
|
@ -1053,7 +1054,8 @@ void nsHtml5TreeOpExecutor::MaybeComplainAboutDeepTree(uint32_t aLineNumber) {
|
||||||
nsContentUtils::ReportToConsole(
|
nsContentUtils::ReportToConsole(
|
||||||
nsIScriptError::errorFlag, "HTML parser"_ns, mDocument,
|
nsIScriptError::errorFlag, "HTML parser"_ns, mDocument,
|
||||||
nsContentUtils::eHTMLPARSER_PROPERTIES, "errDeepTree",
|
nsContentUtils::eHTMLPARSER_PROPERTIES, "errDeepTree",
|
||||||
nsTArray<nsString>(), nullptr, u""_ns, aLineNumber);
|
nsTArray<nsString>(),
|
||||||
|
SourceLocation{mDocument->GetDocumentURI(), aLineNumber});
|
||||||
}
|
}
|
||||||
|
|
||||||
nsHtml5Parser* nsHtml5TreeOpExecutor::GetParser() {
|
nsHtml5Parser* nsHtml5TreeOpExecutor::GetParser() {
|
||||||
|
|
|
@ -521,9 +521,11 @@ void nsExpatDriver::HandleStartElementForSystemPrincipal(
|
||||||
error.AppendLiteral("> created from entity value.");
|
error.AppendLiteral("> created from entity value.");
|
||||||
|
|
||||||
nsContentUtils::ReportToConsoleNonLocalized(
|
nsContentUtils::ReportToConsoleNonLocalized(
|
||||||
error, nsIScriptError::warningFlag, "XML Document"_ns, doc, nullptr,
|
error, nsIScriptError::warningFlag, "XML Document"_ns, doc,
|
||||||
u""_ns, lineNumber.unverified_safe_because(RLBOX_SAFE_PRINT),
|
mozilla::SourceLocation(
|
||||||
colNumber.unverified_safe_because(RLBOX_SAFE_PRINT));
|
doc->GetDocumentURI(),
|
||||||
|
lineNumber.unverified_safe_because(RLBOX_SAFE_PRINT),
|
||||||
|
colNumber.unverified_safe_because(RLBOX_SAFE_PRINT)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "mozilla/EventQueue.h"
|
#include "mozilla/EventQueue.h"
|
||||||
#include "mozilla/StaticPrefs_privacy.h"
|
#include "mozilla/StaticPrefs_privacy.h"
|
||||||
|
#include "mozilla/SourceLocation.h"
|
||||||
#include "mozilla/dom/BrowserChild.h"
|
#include "mozilla/dom/BrowserChild.h"
|
||||||
#include "mozilla/dom/BrowsingContext.h"
|
#include "mozilla/dom/BrowsingContext.h"
|
||||||
#include "mozilla/dom/Document.h"
|
#include "mozilla/dom/Document.h"
|
||||||
|
@ -21,13 +22,11 @@
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
#include "nsIOService.h"
|
#include "nsIOService.h"
|
||||||
#include "nsGlobalWindowOuter.h"
|
#include "nsGlobalWindowOuter.h"
|
||||||
#include "nsJSUtils.h"
|
|
||||||
#include "mozIThirdPartyUtil.h"
|
#include "mozIThirdPartyUtil.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
using mozilla::dom::BrowsingContext;
|
using mozilla::dom::BrowsingContext;
|
||||||
using mozilla::dom::ContentChild;
|
|
||||||
using mozilla::dom::Document;
|
using mozilla::dom::Document;
|
||||||
|
|
||||||
static const uint32_t kMaxConsoleOutputDelayMs = 100;
|
static const uint32_t kMaxConsoleOutputDelayMs = 100;
|
||||||
|
@ -58,20 +57,16 @@ void ReportUnblockingToConsole(
|
||||||
MOZ_ASSERT(aWindowID);
|
MOZ_ASSERT(aWindowID);
|
||||||
MOZ_ASSERT(aPrincipal);
|
MOZ_ASSERT(aPrincipal);
|
||||||
|
|
||||||
nsAutoString sourceLine;
|
// Grab the calling location now since the runnable will run without a JS
|
||||||
uint32_t lineNumber = 0, columnNumber = 1;
|
// context on the stack.
|
||||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
auto location = JSCallingLocation::Get();
|
||||||
if (cx) {
|
|
||||||
nsJSUtils::GetCallingLocation(cx, sourceLine, &lineNumber, &columnNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPrincipal> principal(aPrincipal);
|
nsCOMPtr<nsIPrincipal> principal(aPrincipal);
|
||||||
nsAutoString trackingOrigin(aTrackingOrigin);
|
nsAutoString trackingOrigin(aTrackingOrigin);
|
||||||
|
|
||||||
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
|
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
|
||||||
"ReportUnblockingToConsoleDelayed",
|
"ReportUnblockingToConsoleDelayed",
|
||||||
[aWindowID, sourceLine, lineNumber, columnNumber, principal,
|
[aWindowID, loc = std::move(location), principal, trackingOrigin,
|
||||||
trackingOrigin, aReason]() {
|
aReason]() {
|
||||||
const char* messageWithSameOrigin = nullptr;
|
const char* messageWithSameOrigin = nullptr;
|
||||||
|
|
||||||
switch (aReason) {
|
switch (aReason) {
|
||||||
|
@ -105,8 +100,7 @@ void ReportUnblockingToConsole(
|
||||||
|
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
errorText, nsIScriptError::warningFlag,
|
errorText, nsIScriptError::warningFlag,
|
||||||
ANTITRACKING_CONSOLE_CATEGORY, aWindowID, nullptr, sourceLine,
|
ANTITRACKING_CONSOLE_CATEGORY, aWindowID, loc);
|
||||||
lineNumber, columnNumber);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RunConsoleReportingRunnable(runnable.forget());
|
RunConsoleReportingRunnable(runnable.forget());
|
||||||
|
@ -148,18 +142,13 @@ void ReportBlockingToConsole(uint64_t aWindowID, nsIURI* aURI,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString sourceLine;
|
auto location = JSCallingLocation::Get();
|
||||||
uint32_t lineNumber = 0, columnNumber = 1;
|
|
||||||
JSContext* cx = nsContentUtils::GetCurrentJSContext();
|
|
||||||
if (cx) {
|
|
||||||
nsJSUtils::GetCallingLocation(cx, sourceLine, &lineNumber, &columnNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri(aURI);
|
nsCOMPtr<nsIURI> uri(aURI);
|
||||||
|
|
||||||
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
|
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
|
||||||
"ReportBlockingToConsoleDelayed", [aWindowID, sourceLine, lineNumber,
|
"ReportBlockingToConsoleDelayed",
|
||||||
columnNumber, uri, aRejectedReason]() {
|
[aWindowID, loc = std::move(location), uri, aRejectedReason]() {
|
||||||
const char* message = nullptr;
|
const char* message = nullptr;
|
||||||
nsAutoCString category;
|
nsAutoCString category;
|
||||||
// When changing this list, please make sure to update the corresponding
|
// When changing this list, please make sure to update the corresponding
|
||||||
|
@ -215,8 +204,7 @@ void ReportBlockingToConsole(uint64_t aWindowID, nsIURI* aURI,
|
||||||
NS_ENSURE_SUCCESS_VOID(rv);
|
NS_ENSURE_SUCCESS_VOID(rv);
|
||||||
|
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
errorText, nsIScriptError::warningFlag, category, aWindowID,
|
errorText, nsIScriptError::warningFlag, category, aWindowID, loc);
|
||||||
nullptr, sourceLine, lineNumber, columnNumber);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RunConsoleReportingRunnable(runnable.forget());
|
RunConsoleReportingRunnable(runnable.forget());
|
||||||
|
|
|
@ -1058,7 +1058,7 @@ nsExternalHelperAppService::LoadURI(nsIURI* aURI,
|
||||||
nsContentUtils::ReportToConsoleByWindowID(
|
nsContentUtils::ReportToConsoleByWindowID(
|
||||||
localizedMsg, nsIScriptError::errorFlag, "Security"_ns,
|
localizedMsg, nsIScriptError::errorFlag, "Security"_ns,
|
||||||
windowContext->InnerWindowId(),
|
windowContext->InnerWindowId(),
|
||||||
windowContext->Canonical()->GetDocumentURI());
|
SourceLocation(windowContext->Canonical()->GetDocumentURI()));
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче