Skip to content

Commit

Permalink
Bug 1886852 - Avoid registering unnecessary MessageManager listeners …
Browse files Browse the repository at this point in the history
…when SHIP is enabled, r=smaug!

Differential Revision: https://phabricator.services.mozilla.com/D205377
  • Loading branch information
mystor committed Mar 21, 2024
1 parent f0fb2f5 commit afbdf68
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions browser/components/sessionstore/SessionStore.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,13 @@ var SessionStoreInternal = {
* and thus enables communication with OOP tabs.
*/
receiveMessage(aMessage) {
if (Services.appinfo.sessionHistoryInParent) {
throw new Error(
`received unexpected message '${aMessage.name}' with ` +
`sessionHistoryInParent enabled`
);
}

// If we got here, that means we're dealing with a frame message
// manager message, so the target will be a <xul:browser>.
var browser = aMessage.target;
Expand Down Expand Up @@ -1910,14 +1917,14 @@ var SessionStoreInternal = {
// internal data about the window.
aWindow.__SSi = this._generateWindowID();

let mm = aWindow.getGroupMessageManager("browsers");
MESSAGES.forEach(msg => {
let listenWhenClosed = CLOSED_MESSAGES.has(msg);
mm.addMessageListener(msg, this, listenWhenClosed);
});

// Load the frame script after registering listeners.
if (!Services.appinfo.sessionHistoryInParent) {
let mm = aWindow.getGroupMessageManager("browsers");
MESSAGES.forEach(msg => {
let listenWhenClosed = CLOSED_MESSAGES.has(msg);
mm.addMessageListener(msg, this, listenWhenClosed);
});

// Load the frame script after registering listeners.
mm.loadFrameScript(
"chrome://browser/content/content-sessionStore.js",
true,
Expand Down Expand Up @@ -2395,8 +2402,10 @@ var SessionStoreInternal = {
// Cache the window state until it is completely gone.
DyingWindowCache.set(aWindow, winData);

let mm = aWindow.getGroupMessageManager("browsers");
MESSAGES.forEach(msg => mm.removeMessageListener(msg, this));
if (!Services.appinfo.sessionHistoryInParent) {
let mm = aWindow.getGroupMessageManager("browsers");
MESSAGES.forEach(msg => mm.removeMessageListener(msg, this));
}

this._saveableClosedWindowData.delete(winData);
delete aWindow.__SSi;
Expand Down

0 comments on commit afbdf68

Please sign in to comment.