Bug 1590239 - Send a "browsing-context-discarded" notification when detaching, r=nika

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kashav Madan 2019-10-29 17:15:29 +00:00
parent 71d7fa0656
commit 498ac84e23
3 changed files with 45 additions and 0 deletions

View File

@ -29,11 +29,13 @@
#include "mozilla/Components.h"
#include "mozilla/HashTable.h"
#include "mozilla/Logging.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "nsIURIFixup.h"
#include "nsDocShell.h"
#include "nsGlobalWindowOuter.h"
#include "nsIObserverService.h"
#include "nsContentUtils.h"
#include "nsScriptError.h"
#include "nsThreadUtils.h"
@ -362,6 +364,12 @@ void BrowsingContext::Detach(bool aFromIPC) {
mGroup->Unregister(this);
mIsDiscarded = true;
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
obs->NotifyObservers(ToSupports(this), "browsing-context-discarded",
nullptr);
}
// NOTE: Doesn't use SetClosed, as it will be set in all processes
// automatically by calls to Detach()
mClosed = true;

View File

@ -145,3 +145,4 @@ support-files =
[browser_cross_process_csp_inheritance.js]
skip-if = !e10s # e10s specific test.
[browser_tab_replace_while_loading.js]
[browser_browsing_context_discarded.js]

View File

@ -0,0 +1,36 @@
"use strict";
const TOPIC = "browsing-context-discarded";
add_task(async function toplevel() {
let win = await BrowserTestUtils.openNewBrowserWindow();
let bc = await SpecialPowers.spawn(
win.gBrowser.selectedBrowser,
[],
() => content.docShell.browsingContext
);
let promise = BrowserUtils.promiseObserved(TOPIC, subject => subject === bc);
await BrowserTestUtils.closeWindow(win);
await promise;
// If we make it here, then we've received the notification.
ok(true, "got top-level notification");
});
add_task(async function subframe() {
let win = await BrowserTestUtils.openNewBrowserWindow();
let bc = await SpecialPowers.spawn(win.gBrowser.selectedBrowser, [], () => {
let iframe = content.document.createElement("iframe");
content.document.body.appendChild(iframe);
iframe.contentWindow.location = "https://example.com/";
return iframe.browsingContext;
});
let promise = BrowserUtils.promiseObserved(TOPIC, subject => subject === bc);
await BrowserTestUtils.closeWindow(win);
await promise;
// If we make it here, then we've received the notification.
ok(true, "got subframe notification");
});