1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
10 XPCOMUtils.defineLazyModuleGetters(lazy, {
11 SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
12 TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm",
15 // A list of all of the open about:tabcrashed pages.
16 let gAboutTabCrashedPages = new Map();
18 export class AboutTabCrashedParent extends JSWindowActorParent {
20 this.removeCrashedPage();
23 async receiveMessage(message) {
24 let browser = this.browsingContext.top.embedderElement;
26 // If there is no browser, remove the crashed page from the set
28 this.removeCrashedPage();
32 let gBrowser = browser.getTabBrowser();
33 let tab = gBrowser.getTabForBrowser(browser);
35 switch (message.name) {
37 gAboutTabCrashedPages.set(this, browser);
38 this.updateTabCrashedCount();
40 let report = lazy.TabCrashHandler.onAboutTabCrashedLoad(browser);
41 this.sendAsyncMessage("SetCrashReportAvailable", report);
46 lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
47 gBrowser.removeTab(tab, { animate: true });
52 lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
53 lazy.SessionStore.reviveCrashedTab(tab);
58 lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
59 lazy.SessionStore.reviveAllCrashedTabs();
67 this.browsingContext.top.embedderElement ||
68 gAboutTabCrashedPages.get(this);
70 gAboutTabCrashedPages.delete(this);
71 this.updateTabCrashedCount();
73 lazy.TabCrashHandler.onAboutTabCrashedUnload(browser);
76 updateTabCrashedCount() {
77 // Broadcast to all about:tabcrashed pages a count of
78 // how many about:tabcrashed pages exist, so that they
79 // can decide whether or not to display the "Restore All
80 // Crashed Tabs" button.
81 let count = gAboutTabCrashedPages.size;
83 for (let actor of gAboutTabCrashedPages.keys()) {
84 let browser = actor.browsingContext.top.embedderElement;
86 browser.sendMessageToActor("UpdateCount", { count }, "AboutTabCrashed");