summaryrefslogtreecommitdiffstats
path: root/browser/actors/AboutTabCrashedParent.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /browser/actors/AboutTabCrashedParent.sys.mjs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/actors/AboutTabCrashedParent.sys.mjs')
-rw-r--r--browser/actors/AboutTabCrashedParent.sys.mjs87
1 files changed, 87 insertions, 0 deletions
diff --git a/browser/actors/AboutTabCrashedParent.sys.mjs b/browser/actors/AboutTabCrashedParent.sys.mjs
new file mode 100644
index 0000000000..d24b838a23
--- /dev/null
+++ b/browser/actors/AboutTabCrashedParent.sys.mjs
@@ -0,0 +1,87 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
+ TabCrashHandler: "resource:///modules/ContentCrashHandlers.sys.mjs",
+});
+
+// A list of all of the open about:tabcrashed pages.
+let gAboutTabCrashedPages = new Map();
+
+export class AboutTabCrashedParent extends JSWindowActorParent {
+ didDestroy() {
+ this.removeCrashedPage();
+ }
+
+ async receiveMessage(message) {
+ let browser = this.browsingContext.top.embedderElement;
+ if (!browser) {
+ // If there is no browser, remove the crashed page from the set
+ // and return.
+ this.removeCrashedPage();
+ return;
+ }
+
+ let gBrowser = browser.getTabBrowser();
+ let tab = gBrowser.getTabForBrowser(browser);
+
+ switch (message.name) {
+ case "Load": {
+ gAboutTabCrashedPages.set(this, browser);
+ this.updateTabCrashedCount();
+
+ let report = lazy.TabCrashHandler.onAboutTabCrashedLoad(browser);
+ this.sendAsyncMessage("SetCrashReportAvailable", report);
+ break;
+ }
+
+ case "closeTab": {
+ lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
+ gBrowser.removeTab(tab, { animate: true });
+ break;
+ }
+
+ case "restoreTab": {
+ lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
+ lazy.SessionStore.reviveCrashedTab(tab);
+ break;
+ }
+
+ case "restoreAll": {
+ lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
+ lazy.SessionStore.reviveAllCrashedTabs();
+ break;
+ }
+ }
+ }
+
+ removeCrashedPage() {
+ let browser =
+ this.browsingContext.top.embedderElement ||
+ gAboutTabCrashedPages.get(this);
+
+ gAboutTabCrashedPages.delete(this);
+ this.updateTabCrashedCount();
+
+ lazy.TabCrashHandler.onAboutTabCrashedUnload(browser);
+ }
+
+ updateTabCrashedCount() {
+ // Broadcast to all about:tabcrashed pages a count of
+ // how many about:tabcrashed pages exist, so that they
+ // can decide whether or not to display the "Restore All
+ // Crashed Tabs" button.
+ let count = gAboutTabCrashedPages.size;
+
+ for (let actor of gAboutTabCrashedPages.keys()) {
+ let browser = actor.browsingContext.top.embedderElement;
+ if (browser) {
+ browser.sendMessageToActor("UpdateCount", { count }, "AboutTabCrashed");
+ }
+ }
+ }
+}