From 39ea4c06d05d76b7ad98b1ff4c29afe2b806cc7f Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Wed, 19 Nov 2014 12:52:36 +0100 Subject: [PATCH] Bug 1077652 - SessionStore should accept :setupSyncHandler and :update messages from browsers without tabs r=smacleod By making SessionStore accept :setupSyncHandler and :update messages from s without a tab assigned we can preload a in the background and assign a tab later. SessionStore will have the correct sync handler and know about the current content loaded in that browser. If the browser will never be assigned to a tab the received data will simply be discarded when the browser goes away due to the use of WeakMaps in SessionStore. --- .../components/sessionstore/SessionStore.jsm | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index f9b31bfa89e..538cf11ad6e 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -74,6 +74,16 @@ const FMM_MESSAGES = [ "SessionStore:reloadPendingTab", ]; +// The list of messages we accept from s that have no tab +// assigned. Those are for example the ones that preload about:newtab pages. +const FMM_NOTAB_MESSAGES = new Set([ + // For a description see above. + "SessionStore:setupSyncHandler", + + // For a description see above. + "SessionStore:update", +]); + // Messages that will be received via the Parent Process Message Manager. const PPMM_MESSAGES = [ // A tab is being revived from the crashed state. The sender of this @@ -605,9 +615,12 @@ let SessionStoreInternal = { var browser = aMessage.target; var win = browser.ownerDocument.defaultView; let tab = win.gBrowser.getTabForBrowser(browser); - if (!tab) { - // Ignore messages from elements that are not tabs. - return; + + // Ensure we receive only specific messages from s that + // have no tab assigned, e.g. the ones that preload aobut:newtab pages. + if (!tab && !FMM_NOTAB_MESSAGES.has(aMessage.name)) { + throw new Error(`received unexpected message '${aMessage.name}' ` + + `from a browser that has no tab`); } switch (aMessage.name) { @@ -691,7 +704,7 @@ let SessionStoreInternal = { } break; default: - debug(`received unknown message '${aMessage.name}'`); + throw new Error(`received unknown message '${aMessage.name}'`); break; } },