From 2ae4d6a15b6706e9d9863b2d50223dcfefaae69e Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Thu, 21 Jan 2021 08:44:51 +0000 Subject: [PATCH] Bug 1644911, add access to the childID from the frame crashed event, r=nika Differential Revision: https://phabricator.services.mozilla.com/D98206 --- dom/base/nsFrameLoader.cpp | 4 +++- dom/base/nsFrameLoader.h | 2 ++ dom/ipc/BrowserParent.cpp | 3 ++- dom/ipc/tests/browser_crash_oopiframe.js | 1 + dom/webidl/FrameCrashedEvent.webidl | 8 ++++++++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 41933fad197b..37d7ef874098 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -2672,7 +2672,7 @@ bool nsFrameLoader::TryRemoteBrowser() { // Check if we should report a browser-crashed error because the browser // failed to start. if (XRE_IsParentProcess() && mOwnerContent && mOwnerContent->IsXULElement()) { - MaybeNotifyCrashed(nullptr, nullptr); + MaybeNotifyCrashed(nullptr, ContentParentId(), nullptr); } return false; @@ -3684,6 +3684,7 @@ void nsFrameLoader::SetWillChangeProcess() { } void nsFrameLoader::MaybeNotifyCrashed(BrowsingContext* aBrowsingContext, + ContentParentId aChildID, mozilla::ipc::MessageChannel* aChannel) { if (mTabProcessCrashFired) { return; @@ -3731,6 +3732,7 @@ void nsFrameLoader::MaybeNotifyCrashed(BrowsingContext* aBrowsingContext, if (aBrowsingContext) { init.mBrowsingContextId = aBrowsingContext->Id(); init.mIsTopFrame = aBrowsingContext->IsTop(); + init.mChildID = aChildID; } RefPtr event = FrameCrashedEvent::Constructor( diff --git a/dom/base/nsFrameLoader.h b/dom/base/nsFrameLoader.h index a432b660f1e9..ed5ab61934c8 100644 --- a/dom/base/nsFrameLoader.h +++ b/dom/base/nsFrameLoader.h @@ -24,6 +24,7 @@ #include "mozilla/dom/Nullable.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/WindowProxyHolder.h" +#include "mozilla/dom/ipc/IdType.h" #include "mozilla/layers/LayersTypes.h" #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" @@ -410,6 +411,7 @@ class nsFrameLoader final : public nsStubMutationObserver, mozilla::dom::ContentParent* aContentParent); void MaybeNotifyCrashed(mozilla::dom::BrowsingContext* aBrowsingContext, + mozilla::dom::ContentParentId aChildID, mozilla::ipc::MessageChannel* aChannel); void FireErrorEvent(); diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp index 3b03d9fcd2c7..5ede68022d04 100644 --- a/dom/ipc/BrowserParent.cpp +++ b/dom/ipc/BrowserParent.cpp @@ -742,7 +742,8 @@ void BrowserParent::ActorDestroy(ActorDestroyReason why) { // If this was a crash, tell our nsFrameLoader to fire crash events. if (why == AbnormalShutdown) { - frameLoader->MaybeNotifyCrashed(mBrowsingContext, GetIPCChannel()); + frameLoader->MaybeNotifyCrashed(mBrowsingContext, Manager()->ChildID(), + GetIPCChannel()); auto* bridge = GetBrowserBridgeParent(); if (bridge && bridge->CanSend() && !mBrowsingContext->IsDiscarded()) { diff --git a/dom/ipc/tests/browser_crash_oopiframe.js b/dom/ipc/tests/browser_crash_oopiframe.js index 68d1994a4675..6d134b40ffa5 100644 --- a/dom/ipc/tests/browser_crash_oopiframe.js +++ b/dom/ipc/tests/browser_crash_oopiframe.js @@ -51,6 +51,7 @@ add_task(async function() { info("Waiting for oop-browser-crashed event."); await eventFiredPromise.then(event => { ok(!event.isTopFrame, "should not be reporting top-level frame crash"); + ok(event.childID != 0, "childID is non-zero"); isnot( event.browsingContextId, diff --git a/dom/webidl/FrameCrashedEvent.webidl b/dom/webidl/FrameCrashedEvent.webidl index 234649b29704..b6d88f275763 100644 --- a/dom/webidl/FrameCrashedEvent.webidl +++ b/dom/webidl/FrameCrashedEvent.webidl @@ -20,10 +20,18 @@ interface FrameCrashedEvent : Event * True if the top-most frame crashed. */ readonly attribute boolean isTopFrame; + + /** + * Internal process identifier of the frame that crashed. This will be + * 0 if this identifier is not known, for example a process that failed + * to start. + */ + readonly attribute unsigned long long childID; }; dictionary FrameCrashedEventInit : EventInit { unsigned long long browsingContextId = 0; boolean isTopFrame = true; + unsigned long long childID = 0; };