Skip to content

Commit

Permalink
Backed out changeset 7fa7d6e6dedc (bug 1442778) for devtools failures…
Browse files Browse the repository at this point in the history
… on browser_webconsole_check_stubs_console_api.js CLOSED TREE
  • Loading branch information
CosminSabou committed Mar 26, 2019
1 parent 34df3fc commit 7e69423
Show file tree
Hide file tree
Showing 37 changed files with 68 additions and 149 deletions.
4 changes: 2 additions & 2 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ nsScriptSecurityManager::GetChannelURIPrincipal(nsIChannel* aChannel,
return *aPrincipal ? NS_OK : NS_ERROR_FAILURE;
}


/////////////////////////////
// nsScriptSecurityManager //
/////////////////////////////
Expand Down Expand Up @@ -1148,8 +1149,7 @@ nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,

// using category of "SOP" so we can link to MDN
rv = error->Init(message, EmptyString(), EmptyString(), 0, 0,
nsIScriptError::errorFlag, "SOP", aFromPrivateWindow,
true /* From chrome context */);
nsIScriptError::errorFlag, "SOP", aFromPrivateWindow);
NS_ENSURE_SUCCESS(rv, rv);
console->LogMessage(error);
return NS_OK;
Expand Down
8 changes: 4 additions & 4 deletions chrome/nsChromeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ void nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber,
nsCString spec;
if (aURL) aURL->GetSpec(spec);

rv = error->Init(
NS_ConvertUTF8toUTF16(formatted.get()), NS_ConvertUTF8toUTF16(spec),
EmptyString(), aLineNumber, 0, flags, "chrome registration",
false /* from private window */, true /* from chrome context */);
rv = error->Init(NS_ConvertUTF8toUTF16(formatted.get()),
NS_ConvertUTF8toUTF16(spec), EmptyString(), aLineNumber, 0,
flags, "chrome registration",
false /* from private window */);

if (NS_FAILED(rv)) return;

Expand Down
8 changes: 4 additions & 4 deletions dom/base/PostMessageEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mozilla/dom/StructuredCloneTags.h"
#include "mozilla/dom/UnionConversions.h"
#include "mozilla/EventDispatcher.h"
#include "nsContentUtils.h"
#include "nsDocShell.h"
#include "nsGlobalWindow.h"
#include "nsIConsoleService.h"
Expand Down Expand Up @@ -135,10 +136,9 @@ PostMessageEvent::Run() {
rv = NS_GetSanitizedURIStringFromURI(callerDocumentURI, uriSpec);
NS_ENSURE_SUCCESS(rv, rv);

rv = errorObject->Init(
errorText, uriSpec, EmptyString(), 0, 0, nsIScriptError::errorFlag,
"DOM Window", mIsFromPrivateWindow,
nsContentUtils::IsSystemPrincipal(mProvidedPrincipal));
rv = errorObject->Init(errorText, uriSpec, EmptyString(), 0, 0,
nsIScriptError::errorFlag, "DOM Window",
mIsFromPrivateWindow);
}
NS_ENSURE_SUCCESS(rv, rv);

Expand Down
1 change: 0 additions & 1 deletion dom/base/PostMessageEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "nsCOMPtr.h"
#include "mozilla/MaybeOneOf.h"
#include "mozilla/RefPtr.h"
#include "nsContentUtils.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"

Expand Down
15 changes: 6 additions & 9 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3736,17 +3736,16 @@ nsresult nsContentUtils::FormatLocalizedString(
/* static */
void nsContentUtils::LogSimpleConsoleError(const nsAString& aErrorText,
const char* classification,
bool aFromPrivateWindow,
bool aFromChromeContext) {
bool aFromPrivateWindow) {
nsCOMPtr<nsIScriptError> scriptError =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
if (scriptError) {
nsCOMPtr<nsIConsoleService> console =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
if (console && NS_SUCCEEDED(scriptError->Init(
aErrorText, EmptyString(), EmptyString(), 0, 0,
nsIScriptError::errorFlag, classification,
aFromPrivateWindow, aFromChromeContext))) {
if (console &&
NS_SUCCEEDED(scriptError->Init(aErrorText, EmptyString(), EmptyString(),
0, 0, nsIScriptError::errorFlag,
classification, aFromPrivateWindow))) {
console->LogMessage(scriptError);
}
}
Expand Down Expand Up @@ -5300,7 +5299,6 @@ nsContentUtils::GetMostRecentNonPBWindow() {
void nsContentUtils::WarnScriptWasIgnored(Document* aDocument) {
nsAutoString msg;
bool privateBrowsing = false;
bool chromeContext = false;

if (aDocument) {
nsCOMPtr<nsIURI> uri = aDocument->GetDocumentURI();
Expand All @@ -5310,12 +5308,11 @@ void nsContentUtils::WarnScriptWasIgnored(Document* aDocument) {
}
privateBrowsing =
!!aDocument->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId;
chromeContext = IsSystemPrincipal(aDocument->NodePrincipal());
}

msg.AppendLiteral(
"Unable to run script because scripts are blocked internally.");
LogSimpleConsoleError(msg, "DOM", privateBrowsing, chromeContext);
LogSimpleConsoleError(msg, "DOM", privateBrowsing);
}

/* static */
Expand Down
3 changes: 1 addition & 2 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,7 @@ class nsContentUtils {
*/
static void LogSimpleConsoleError(const nsAString& aErrorText,
const char* classification,
bool aFromPrivateWindow,
bool aFromChromeContext);
bool aFromPrivateWindow);

/**
* Report a non-localized error message to the error console.
Expand Down
6 changes: 2 additions & 4 deletions dom/base/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ bool nsFrameMessageManager::GetParamsForMessage(JSContext* aCx,
"you trying to send an XPCOM object?"),
filename, EmptyString(), lineno, column,
nsIScriptError::warningFlag, "chrome javascript",
false /* from private window */,
true /* from chrome context */);
false /* from private window */);
console->LogMessage(error);
}

Expand Down Expand Up @@ -825,8 +824,7 @@ void nsFrameMessageManager::ReceiveMessage(
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
error->Init(msg, EmptyString(), EmptyString(), 0, 0,
nsIScriptError::warningFlag, "chrome javascript",
false /* from private window */,
true /* from chrome context */);
false /* from private window */);
console->LogMessage(error);
}

Expand Down
3 changes: 1 addition & 2 deletions dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5951,8 +5951,7 @@ bool nsGlobalWindowOuter::GetPrincipalForPostMessage(
R"(origin "%s" from a system principal scope with mismatched )"
R"(origin "%s".)",
targetURL.get(), targetOrigin.get(), sourceOrigin.get())),
"DOM", !!principal->PrivateBrowsingId(),
nsContentUtils::IsSystemPrincipal(principal));
"DOM", !!principal->PrivateBrowsingId());

attrs = principal->OriginAttributesRef();
}
Expand Down
5 changes: 1 addition & 4 deletions dom/bindings/nsIScriptError.idl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ interface nsIScriptError : nsIConsoleMessage

readonly attribute boolean isFromPrivateWindow;

readonly attribute boolean isFromChromeContext;

attribute jsval stack;

/**
Expand Down Expand Up @@ -127,8 +125,7 @@ interface nsIScriptError : nsIConsoleMessage
in uint32_t columnNumber,
in uint32_t flags,
in string category,
[optional] in bool fromPrivateWindow,
[optional] in bool fromChromeContext);
[optional] in bool fromPrivateWindow);

/* This should be called instead of nsIScriptError.init to
* initialize with a window id. The window id should be for the
Expand Down
28 changes: 3 additions & 25 deletions dom/bindings/nsScriptError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ nsScriptErrorBase::nsScriptErrorBase()
mTimeStamp(0),
mTimeWarpTarget(0),
mInitializedOnMainThread(false),
mIsFromPrivateWindow(false),
mIsFromChromeContext(false) {}
mIsFromPrivateWindow(false) {}

nsScriptErrorBase::~nsScriptErrorBase() {}

Expand All @@ -63,7 +62,7 @@ void nsScriptErrorBase::InitializeOnMainThread() {
if (window) {
nsPIDOMWindowOuter* outer = window->GetOuterWindow();
if (outer) mOuterWindowID = outer->WindowID();
mIsFromChromeContext = ComputeIsFromChromeContext(window);

mIsFromPrivateWindow = ComputeIsFromPrivateWindow(window);
}
}
Expand Down Expand Up @@ -205,15 +204,13 @@ NS_IMETHODIMP
nsScriptErrorBase::Init(const nsAString& message, const nsAString& sourceName,
const nsAString& sourceLine, uint32_t lineNumber,
uint32_t columnNumber, uint32_t flags,
const char* category, bool fromPrivateWindow,
bool fromChromeContext) {
const char* category, bool fromPrivateWindow) {
InitializationHelper(message, sourceLine, lineNumber, columnNumber, flags,
category ? nsDependentCString(category) : EmptyCString(),
0 /* inner Window ID */);
AssignSourceNameHelper(mSourceName, sourceName);

mIsFromPrivateWindow = fromPrivateWindow;
mIsFromChromeContext = fromChromeContext;
return NS_OK;
}

Expand Down Expand Up @@ -383,18 +380,6 @@ nsScriptErrorBase::GetTimeWarpTarget(uint64_t* aTarget) {
return NS_OK;
}

NS_IMETHODIMP
nsScriptErrorBase::GetIsFromChromeContext(bool* aIsFromChromeContext) {
NS_WARNING_ASSERTION(NS_IsMainThread() || mInitializedOnMainThread,
"This can't be safely determined off the main thread, "
"returning an inaccurate value!");
if (!mInitializedOnMainThread && NS_IsMainThread()) {
InitializeOnMainThread();
}
*aIsFromChromeContext = mIsFromChromeContext;
return NS_OK;
}

NS_IMETHODIMP
nsScriptErrorBase::GetNotes(nsIArray** aNotes) {
nsresult rv = NS_OK;
Expand All @@ -418,13 +403,6 @@ bool nsScriptErrorBase::ComputeIsFromPrivateWindow(
!nsContentUtils::IsSystemPrincipal(winPrincipal);
}

/* static */
bool nsScriptErrorBase::ComputeIsFromChromeContext(
nsGlobalWindowInner* aWindow) {
nsIPrincipal* winPrincipal = aWindow->GetPrincipal();
return nsContentUtils::IsSystemPrincipal(winPrincipal);
}

NS_IMPL_ISUPPORTS(nsScriptError, nsIConsoleMessage, nsIScriptError)

nsScriptErrorNote::nsScriptErrorNote()
Expand Down
7 changes: 2 additions & 5 deletions dom/bindings/nsScriptError.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ class nsScriptErrorBase : public nsIScriptError {

static bool ComputeIsFromPrivateWindow(nsGlobalWindowInner* aWindow);

static bool ComputeIsFromChromeContext(nsGlobalWindowInner* aWindow);

protected:
virtual ~nsScriptErrorBase();

Expand All @@ -82,11 +80,10 @@ class nsScriptErrorBase : public nsIScriptError {
uint64_t mInnerWindowID;
int64_t mTimeStamp;
uint64_t mTimeWarpTarget;
// mInitializedOnMainThread, mIsFromPrivateWindow and mIsFromChromeContext are
// set on the main thread from InitializeOnMainThread().
// mInitializedOnMainThread and mIsFromPrivateWindow are set on the main
// thread from InitializeOnMainThread().
mozilla::Atomic<bool> mInitializedOnMainThread;
bool mIsFromPrivateWindow;
bool mIsFromChromeContext;
};

class nsScriptError final : public nsScriptErrorBase {
Expand Down
3 changes: 0 additions & 3 deletions dom/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,6 @@ void Console::ProfileMethodMainthread(JSContext* aCx, const nsAString& aAction,

RootedDictionary<ConsoleProfileEvent> event(aCx);
event.mAction = aAction;
event.mChromeContext = nsContentUtils::ThreadsafeIsSystemCaller(aCx);

event.mArguments.Construct();
Sequence<JS::Value>& sequence = event.mArguments.Value();
Expand Down Expand Up @@ -1684,8 +1683,6 @@ bool Console::PopulateConsoleNotificationInTheTargetScope(
event.mID.Construct();
event.mInnerID.Construct();

event.mChromeContext = nsContentUtils::ThreadsafeIsSystemCaller(aCx);

if (aData->mIDType == ConsoleCallData::eString) {
event.mID.Value().SetAsString() = aData->mOuterIDString;
event.mInnerID.Value().SetAsString() = aData->mInnerIDString;
Expand Down
6 changes: 2 additions & 4 deletions dom/console/ConsoleInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ ConsoleLogLevel PrefToValue(const nsAString& aPref) {
"Console.maxLogLevelPref used with a non-existing pref: ");
message.Append(aPref);

nsContentUtils::LogSimpleConsoleError(message, "chrome", false,
true /* from chrome context*/);
nsContentUtils::LogSimpleConsoleError(message, "chrome", false);
return ConsoleLogLevel::All;
}

Expand All @@ -51,8 +50,7 @@ ConsoleLogLevel PrefToValue(const nsAString& aPref) {
message.AssignLiteral("Invalid Console.maxLogLevelPref value: ");
message.Append(NS_ConvertUTF8toUTF16(value));

nsContentUtils::LogSimpleConsoleError(message, "chrome", false,
true /* from chrome context*/);
nsContentUtils::LogSimpleConsoleError(message, "chrome", false);
return ConsoleLogLevel::All;
}

Expand Down
1 change: 0 additions & 1 deletion dom/console/tests/test_console_binding.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
observe(aSubject, aTopic, aData) {
if (aTopic == "console-api-log-event") {
var obj = aSubject.wrappedJSObject;
ok(!obj.chromeContext, "Thils is not a chrome context");
if (order + 1 == parseInt(obj.arguments[0])) {
ok(true, "Message received: " + obj.arguments[0]);
order++;
Expand Down
1 change: 0 additions & 1 deletion dom/console/tests/test_devtools_pref.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
let observer = {
observe: function listener(aSubject, aTopic, aData) {
var obj = aSubject.wrappedJSObject;
ok(!obj.chromeContext, "This is not a chrome context");
messages.push(parseInt(obj.arguments[0]));
if (messages.length == expected) {
SpecialPowers.removeObserver(observer, "console-api-log-event");
Expand Down
2 changes: 0 additions & 2 deletions dom/console/tests/test_jsm.xul
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ consoleListener.prototype = {
observe: function(aSubject, aTopic, aData) {
if (aTopic == "console-api-log-event") {
var obj = aSubject.wrappedJSObject;
ok(obj.chromeContext, "JSM is always a chrome context");
if (obj.innerID == JSM) {
is(obj.ID, "jsm", "ID and InnerID are correctly set.");
is(obj.arguments[0], "Hello world!", "Message matches");
Expand Down
3 changes: 1 addition & 2 deletions dom/indexedDB/ReportInternalError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ void ReportInternalError(const char* aFile, uint32_t aLine, const char* aStr) {
nsContentUtils::LogSimpleConsoleError(
NS_ConvertUTF8toUTF16(
nsPrintfCString("IndexedDB %s: %s:%" PRIu32, aStr, aFile, aLine)),
"indexedDB", false /* no IDB in private window */,
true /* Internal errors are chrome context only */);
"indexedDB", false /* no IDB in private window */);
}

} // namespace indexedDB
Expand Down
3 changes: 1 addition & 2 deletions dom/indexedDB/ScriptErrorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ class ScriptErrorRunnable final : public mozilla::Runnable {
aMessage, aFilename,
/* aSourceLine */ EmptyString(), aLineNumber, aColumnNumber,
aSeverityFlag, category.get(),
/* IDB doesn't run on Private browsing mode */ false,
/* from chrome context */ aIsChrome));
/* IDB doesn't run on Private browsing mode */ false));
}

MOZ_ALWAYS_SUCCEEDS(consoleService->LogMessage(scriptError));
Expand Down
Loading

0 comments on commit 7e69423

Please sign in to comment.