From a3a9b7abb1fb817d94b1a74e2e297a02b74a586e Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Tue, 4 Mar 2014 11:48:00 -0500 Subject: [PATCH] Bug 979034 - [Australis] Make CustomizationTabPreloader kick-off when the user opens the menu panel. r=ttaubert. --- .../customizableui/content/panelUI.js | 4 ++ .../customizableui/src/CustomizeMode.jsm | 5 ++ browser/components/nsBrowserGlue.js | 1 - browser/modules/CustomizationTabPreloader.jsm | 52 +++++-------------- 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/browser/components/customizableui/content/panelUI.js b/browser/components/customizableui/content/panelUI.js index 3902a34c586..935c740ab58 100644 --- a/browser/components/customizableui/content/panelUI.js +++ b/browser/components/customizableui/content/panelUI.js @@ -154,6 +154,10 @@ const PanelUI = { this.panel.addEventListener("popupshown", function onPopupShown() { this.removeEventListener("popupshown", onPopupShown); + // As an optimization for the customize mode transition, we preload + // about:customizing in the background once the menu panel is first + // shown. + gCustomizationTabPreloader.ensurePreloading(); deferred.resolve(); }); }); diff --git a/browser/components/customizableui/src/CustomizeMode.jsm b/browser/components/customizableui/src/CustomizeMode.jsm index f728543469c..d346b9c230f 100644 --- a/browser/components/customizableui/src/CustomizeMode.jsm +++ b/browser/components/customizableui/src/CustomizeMode.jsm @@ -269,6 +269,11 @@ CustomizeMode.prototype = { panelContents.removeAttribute("customize-transitioning"); CustomizableUI.dispatchToolboxEvent("customizationready", {}, window); + + // It's possible that we didn't enter customize mode via the menu panel, + // meaning we didn't kick off about:customizing preloading. If that's + // the case, let's kick it off for the next time we load this mode. + window.gCustomizationTabPreloader.ensurePreloading(); if (!this._wantToBeInCustomizeMode) { this.exit(); } diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 82b2949ec0c..c299a6e7dc6 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -472,7 +472,6 @@ BrowserGlue.prototype = { PageThumbs.init(); NewTabUtils.init(); BrowserNewTabPreloader.init(); - CustomizationTabPreloader.init(); SignInToWebsiteUX.init(); PdfJs.init(); #ifdef NIGHTLY_BUILD diff --git a/browser/modules/CustomizationTabPreloader.jsm b/browser/modules/CustomizationTabPreloader.jsm index bc4c9d61021..1ccdaa0d136 100644 --- a/browser/modules/CustomizationTabPreloader.jsm +++ b/browser/modules/CustomizationTabPreloader.jsm @@ -21,12 +21,6 @@ const CUSTOMIZATION_URL = "about:customizing"; // The interval between swapping in a preload docShell and kicking off the // next preload in the background. const PRELOADER_INTERVAL_MS = 600; -// The initial delay before we start preloading our first customization page. The -// timer is started after the first 'browser-delayed-startup' has been sent. -const PRELOADER_INIT_DELAY_MS = 7000; - -const TOPIC_TIMER_CALLBACK = "timer-callback"; -const TOPIC_DELAYED_STARTUP = "browser-delayed-startup-finished"; function createTimer(obj, delay) { let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); @@ -42,10 +36,6 @@ function clearTimer(timer) { } this.CustomizationTabPreloader = { - init: function() { - CustomizationTabPreloaderInternal.init(); - }, - uninit: function () { CustomizationTabPreloaderInternal.uninit(); }, @@ -53,28 +43,23 @@ this.CustomizationTabPreloader = { newTab: function (aTab) { return CustomizationTabPreloaderInternal.newTab(aTab); }, + + /** + * ensurePreloading starts the preloading of the about:customizing + * content page. This function is idempotent (until a call to uninit), + * so multiple calls to it are fine. + */ + ensurePreloading: function() { + CustomizationTabPreloaderInternal.ensurePreloading(); + }, }; Object.freeze(CustomizationTabPreloader); this.CustomizationTabPreloaderInternal = { _browser: null, - _timer: null, - _observing: false, - - init: function () { - Services.obs.addObserver(this, TOPIC_DELAYED_STARTUP, false); - this._observing = true; - }, uninit: function () { - this._timer = clearTimer(this._timer); - - if (this._observing) { - Services.obs.removeObserver(this, TOPIC_DELAYED_STARTUP); - this._observing = false; - } - HostFrame.destroy(); if (this._browser) { @@ -92,23 +77,10 @@ this.CustomizationTabPreloaderInternal = { return false; }, - observe: function (aSubject, aTopic, aData) { - if (aTopic == TOPIC_DELAYED_STARTUP) { - Services.obs.removeObserver(this, TOPIC_DELAYED_STARTUP); - this._observing = false; - this._startTimer(); - } else if (aTopic == TOPIC_TIMER_CALLBACK) { - this._timer = null; - this._startPreloader(); + ensurePreloading: function () { + if (!this._browser) { + this._browser = new HiddenBrowser(); } - }, - - _startTimer: function () { - this._timer = createTimer(this, PRELOADER_INIT_DELAY_MS); - }, - - _startPreloader: function () { - this._browser = new HiddenBrowser(); } };