mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
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:
parent
71d7fa0656
commit
498ac84e23
@ -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;
|
||||
|
@ -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]
|
||||
|
36
docshell/test/browser/browser_browsing_context_discarded.js
Normal file
36
docshell/test/browser/browser_browsing_context_discarded.js
Normal 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");
|
||||
});
|
Loading…
Reference in New Issue
Block a user