Bug 1559167 - Updated logMessage to support logging of scriptErrors from parent to content process. r=baku

Differential Revision: https://phabricator.services.mozilla.com/D42295

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Zuehlcke 2019-08-27 17:37:55 +00:00
Родитель 43084d5e54
Коммит 735128f5c7
6 изменённых файлов: 128 добавлений и 7 удалений

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

@ -107,6 +107,7 @@
#include "nsIWorkerDebuggerManager.h"
#include "nsGeolocation.h"
#include "audio_thread_priority.h"
#include "nsIConsoleService.h"
#if !defined(XP_WIN)
# include "mozilla/Omnijar.h"
@ -512,7 +513,7 @@ ConsoleListener::Observe(nsIConsoleMessage* aMessage) {
}
mChild->SendScriptError(msg, sourceName, sourceLine, lineNum, colNum, flags,
category, fromPrivateWindow, fromChromeContext);
category, fromPrivateWindow, 0, fromChromeContext);
return NS_OK;
}
@ -4007,6 +4008,31 @@ void ContentChild::ReleaseBrowsingContextGroup(BrowsingContextGroup* aBCG) {
mBrowsingContextGroupHolder.RemoveElement(aBCG);
}
mozilla::ipc::IPCResult ContentChild::RecvScriptError(
const nsString& aMessage, const nsString& aSourceName,
const nsString& aSourceLine, const uint32_t& aLineNumber,
const uint32_t& aColNumber, const uint32_t& aFlags,
const nsCString& aCategory, const bool& aFromPrivateWindow,
const uint64_t& aInnerWindowId, const bool& aFromChromeContext) {
nsresult rv = NS_OK;
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, IPC_FAIL(this, "Failed to get console service"));
nsCOMPtr<nsIScriptError> scriptError(
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
NS_ENSURE_TRUE(scriptError,
IPC_FAIL(this, "Failed to construct nsIScriptError"));
scriptError->InitWithWindowID(aMessage, aSourceName, aSourceLine, aLineNumber,
aColNumber, aFlags, aCategory, aInnerWindowId,
aFromChromeContext);
rv = consoleService->LogMessage(scriptError);
NS_ENSURE_SUCCESS(rv, IPC_FAIL(this, "Failed to log script error"));
return IPC_OK();
}
} // namespace dom
#if defined(__OpenBSD__) && defined(MOZ_SANDBOX)

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

@ -734,6 +734,13 @@ class ContentChild final : public PContentChild,
BrowsingContext* aContext, BrowsingContext::Transaction&& aTransaction,
uint64_t aEpoch);
mozilla::ipc::IPCResult RecvScriptError(
const nsString& aMessage, const nsString& aSourceName,
const nsString& aSourceLine, const uint32_t& aLineNumber,
const uint32_t& aColNumber, const uint32_t& aFlags,
const nsCString& aCategory, const bool& aFromPrivateWindow,
const uint64_t& aInnerWindowId, const bool& aFromChromeContext);
#ifdef NIGHTLY_BUILD
virtual PContentChild::Result OnMessageReceived(const Message& aMsg) override;
#else

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

@ -4138,7 +4138,7 @@ mozilla::ipc::IPCResult ContentParent::RecvScriptError(
const nsString& aSourceLine, const uint32_t& aLineNumber,
const uint32_t& aColNumber, const uint32_t& aFlags,
const nsCString& aCategory, const bool& aFromPrivateWindow,
const bool& aFromChromeContext) {
const uint64_t& aInnerWindowId, const bool& aFromChromeContext) {
return RecvScriptErrorInternal(aMessage, aSourceName, aSourceLine,
aLineNumber, aColNumber, aFlags, aCategory,
aFromPrivateWindow, aFromChromeContext);

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

@ -1010,7 +1010,7 @@ class ContentParent final : public PContentParent,
const nsString& aSourceLine, const uint32_t& aLineNumber,
const uint32_t& aColNumber, const uint32_t& aFlags,
const nsCString& aCategory, const bool& aIsFromPrivateWindow,
const bool& aIsFromChromeContext);
const uint64_t& aInnerWindowId, const bool& aIsFromChromeContext);
mozilla::ipc::IPCResult RecvScriptErrorWithStack(
const nsString& aMessage, const nsString& aSourceName,

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

@ -961,10 +961,6 @@ parent:
async SetGeolocationHigherAccuracy(bool enable);
async ConsoleMessage(nsString message);
async ScriptError(nsString message, nsString sourceName, nsString sourceLine,
uint32_t lineNumber, uint32_t colNumber, uint32_t flags,
nsCString category, bool privateWindow,
bool fromChromeContext);
async ScriptErrorWithStack(nsString message, nsString sourceName, nsString sourceLine,
uint32_t lineNumber, uint32_t colNumber, uint32_t flags,
nsCString category, bool privateWindow,
@ -1406,6 +1402,11 @@ parent:
async NotifyMediaAudibleChanged(BrowsingContext aContext, bool aAudible);
both:
async ScriptError(nsString message, nsString sourceName, nsString sourceLine,
uint32_t lineNumber, uint32_t colNumber, uint32_t flags,
nsCString category, bool privateWindow, uint64_t innerWindowId,
bool fromChromeContext);
async CommitBrowsingContextTransaction(BrowsingContext aContext,
BrowsingContextTransaction aTransaction,
uint64_t aEpoch);

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

@ -24,6 +24,8 @@
#include "nsProxyRelease.h"
#include "nsIScriptError.h"
#include "nsISupportsPrimitives.h"
#include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
@ -171,12 +173,97 @@ class LogMessageRunnable : public Runnable {
private:
nsCOMPtr<nsIConsoleMessage> mMessage;
RefPtr<nsConsoleService> mService;
NS_IMETHODIMP maybeForwardScriptError(bool* sent);
};
NS_IMETHODIMP
LogMessageRunnable::maybeForwardScriptError(bool* sent) {
*sent = false;
nsCOMPtr<nsIScriptError> scriptError = do_QueryInterface(mMessage);
if (!scriptError) {
// Not an nsIScriptError
return NS_OK;
}
uint64_t windowID;
nsresult rv;
rv = scriptError->GetInnerWindowID(&windowID);
NS_ENSURE_SUCCESS(rv, rv);
if (!windowID) {
// Does not set window id
return NS_OK;
}
RefPtr<mozilla::dom::WindowGlobalParent> windowGlobalParent =
mozilla::dom::WindowGlobalParent::GetByInnerWindowId(windowID);
if (!windowGlobalParent) {
// Could not find parent window by id
return NS_OK;
}
RefPtr<mozilla::dom::BrowserParent> browserParent =
windowGlobalParent->GetBrowserParent();
if (!browserParent) {
return NS_OK;
}
mozilla::dom::ContentParent* contentParent = browserParent->Manager();
if (!contentParent) {
return NS_ERROR_FAILURE;
}
nsAutoString msg, sourceName, sourceLine;
nsCString category;
uint32_t lineNum, colNum, flags;
uint64_t innerWindowId;
bool fromPrivateWindow, fromChromeContext;
rv = scriptError->GetErrorMessage(msg);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetSourceName(sourceName);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetSourceLine(sourceLine);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetCategory(getter_Copies(category));
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetLineNumber(&lineNum);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetColumnNumber(&colNum);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetFlags(&flags);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetIsFromPrivateWindow(&fromPrivateWindow);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetIsFromChromeContext(&fromChromeContext);
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetInnerWindowID(&innerWindowId);
NS_ENSURE_SUCCESS(rv, rv);
*sent = contentParent->SendScriptError(
msg, sourceName, sourceLine, lineNum, colNum, flags, category,
fromPrivateWindow, innerWindowId, fromChromeContext);
return NS_OK;
}
NS_IMETHODIMP
LogMessageRunnable::Run() {
MOZ_ASSERT(NS_IsMainThread());
if (XRE_IsParentProcess()) {
// If mMessage is a scriptError with an innerWindowId set,
// forward it to the matching ContentParent
// This enables logging from parent to content process
bool sent;
nsresult rv = LogMessageRunnable::maybeForwardScriptError(&sent);
NS_ENSURE_SUCCESS(rv, rv);
if (sent) {
return NS_OK;
}
}
// Snapshot of listeners so that we don't reenter this hash during
// enumeration.
nsCOMArray<nsIConsoleListener> listeners;