From 775e800ca09a8756a7963204992703039c08f1bf Mon Sep 17 00:00:00 2001 From: JustOff Date: Tue, 18 Sep 2018 00:13:21 +0300 Subject: Use SessionStore.promiseInitialized() to avoid race condition in "about:home" (#774) * Use SessionStore.promiseInitialized() to avoid race condition in "about:home" * Improve code style of [d6c3adb91c9f29786f8ed8d93baa14c076494017] --- application/palemoon/base/content/browser.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index 5cf43850a..4167f186c 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -2421,11 +2421,18 @@ function BrowserOnAboutPageLoad(doc) { /* === about:home === */ if (doc.documentURI.toLowerCase() == "about:home") { - let ss = Components.classes["@mozilla.org/browser/sessionstore;1"]. - getService(Components.interfaces.nsISessionStore); - if (ss.canRestoreLastSession && - !PrivateBrowsingUtils.isWindowPrivate(window)) - doc.getElementById("launcher").setAttribute("session", "true"); + if (!PrivateBrowsingUtils.isWindowPrivate(window)) { + let wrapper = {}; + Cu.import("resource:///modules/sessionstore/SessionStore.jsm", wrapper); + let ss = wrapper.SessionStore; + ss.promiseInitialized.then(function() { + if (ss.canRestoreLastSession) { + doc.getElementById("launcher").setAttribute("session", "true"); + } + }).then(null, function onError(x) { + Cu.reportError("Error in SessionStore init while processing 'about:home': " + x); + }); + } // Inject search engine and snippets URL. let docElt = doc.documentElement; -- cgit v1.2.3