Bug 1791785 - When dumping symbols never emit INLINE_ORIGIN directives with an empty...
[gecko.git] / browser / actors / AboutTabCrashedParent.sys.mjs
blob95032d5380b3d53ab7d2764d62531cf594806505
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/. */
5 "use strict";
7 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
9 const lazy = {};
10 XPCOMUtils.defineLazyModuleGetters(lazy, {
11   SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
12   TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm",
13 });
15 // A list of all of the open about:tabcrashed pages.
16 let gAboutTabCrashedPages = new Map();
18 export class AboutTabCrashedParent extends JSWindowActorParent {
19   didDestroy() {
20     this.removeCrashedPage();
21   }
23   async receiveMessage(message) {
24     let browser = this.browsingContext.top.embedderElement;
25     if (!browser) {
26       // If there is no browser, remove the crashed page from the set
27       // and return.
28       this.removeCrashedPage();
29       return;
30     }
32     let gBrowser = browser.getTabBrowser();
33     let tab = gBrowser.getTabForBrowser(browser);
35     switch (message.name) {
36       case "Load": {
37         gAboutTabCrashedPages.set(this, browser);
38         this.updateTabCrashedCount();
40         let report = lazy.TabCrashHandler.onAboutTabCrashedLoad(browser);
41         this.sendAsyncMessage("SetCrashReportAvailable", report);
42         break;
43       }
45       case "closeTab": {
46         lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
47         gBrowser.removeTab(tab, { animate: true });
48         break;
49       }
51       case "restoreTab": {
52         lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
53         lazy.SessionStore.reviveCrashedTab(tab);
54         break;
55       }
57       case "restoreAll": {
58         lazy.TabCrashHandler.maybeSendCrashReport(browser, message);
59         lazy.SessionStore.reviveAllCrashedTabs();
60         break;
61       }
62     }
63   }
65   removeCrashedPage() {
66     let browser =
67       this.browsingContext.top.embedderElement ||
68       gAboutTabCrashedPages.get(this);
70     gAboutTabCrashedPages.delete(this);
71     this.updateTabCrashedCount();
73     lazy.TabCrashHandler.onAboutTabCrashedUnload(browser);
74   }
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;
85       if (browser) {
86         browser.sendMessageToActor("UpdateCount", { count }, "AboutTabCrashed");
87       }
88     }
89   }