Skip to content

Commit

Permalink
Bug 1078085 - Simplify preference checking code in the newtab preload…
Browse files Browse the repository at this point in the history
…er r=gijs
  • Loading branch information
Tim Taubert committed Oct 7, 2014
1 parent 73ee6f0 commit 222b53c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 46 deletions.
4 changes: 1 addition & 3 deletions browser/base/content/newtab/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
const PREF_INTRO_SHOWN = "browser.newtabpage.introShown";

let gIntro = {
_introShown: Services.prefs.getBoolPref(PREF_INTRO_SHOWN),

_nodeIDSuffixes: [
"panel",
"what",
Expand All @@ -26,7 +24,7 @@ let gIntro = {
},

showIfNecessary: function() {
if (!this._introShown) {
if (!Services.prefs.getBoolPref(PREF_INTRO_SHOWN)) {
Services.prefs.setBoolPref(PREF_INTRO_SHOWN, true);
this.showPanel();
}
Expand Down
1 change: 0 additions & 1 deletion browser/components/nsBrowserGlue.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ BrowserGlue.prototype = {
NewTabUtils.init();
DirectoryLinksProvider.init();
NewTabUtils.links.addProvider(DirectoryLinksProvider);
BrowserNewTabPreloader.init();
#ifdef NIGHTLY_BUILD
if (Services.prefs.getBoolPref("dom.identity.enabled")) {
SignInToWebsiteUX.init();
Expand Down
51 changes: 9 additions & 42 deletions browser/modules/BrowserNewTabPreloader.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const HTML_NS = "http://www.w3.org/1999/xhtml";
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const XUL_PAGE = "data:application/vnd.mozilla.xul+xml;charset=utf-8,<window%20id='win'/>";
const NEWTAB_URL = "about:newtab";
const PREF_BRANCH = "browser.newtab.";

const PREF_NEWTAB_URL = "browser.newtab.url";
const PREF_NEWTAB_PRELOAD = "browser.newtab.preload";

// The interval between swapping in a preload docShell and kicking off the
// next preload in the background.
Expand All @@ -34,6 +36,11 @@ const TOPIC_XUL_WINDOW_CLOSED = "xul-window-destroyed";

const BROWSER_CONTENT_SCRIPT = "chrome://browser/content/content.js";

function isPreloadingEnabled() {
return Services.prefs.getBoolPref(PREF_NEWTAB_PRELOAD) &&
!Services.prefs.prefHasUserValue(PREF_NEWTAB_URL);
}

function createTimer(obj, delay) {
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.init(obj, delay, Ci.nsITimer.TYPE_ONE_SHOT);
Expand All @@ -48,18 +55,13 @@ function clearTimer(timer) {
}

this.BrowserNewTabPreloader = {
init: function Preloader_init() {
Preferences.init();
},

uninit: function Preloader_uninit() {
HostFrame.destroy();
Preferences.uninit();
HiddenBrowsers.uninit();
},

newTab: function Preloader_newTab(aTab) {
if (!Preferences.enabled) {
if (!isPreloadingEnabled()) {
return false;
}

Expand All @@ -81,41 +83,6 @@ this.BrowserNewTabPreloader = {

Object.freeze(BrowserNewTabPreloader);

let Preferences = {
_enabled: null,
_branch: null,

get enabled() {
if (this._enabled === null) {
this._enabled = this._branch.getBoolPref("preload") &&
!this._branch.prefHasUserValue("url");
}

return this._enabled;
},

init: function Preferences_init() {
this._branch = Services.prefs.getBranch(PREF_BRANCH);
this._branch.addObserver("", this, false);
},

uninit: function Preferences_uninit() {
if (this._branch) {
this._branch.removeObserver("", this);
this._branch = null;
}
},

observe: function Preferences_observe() {
let prevEnabled = this._enabled;
this._enabled = null;

if (prevEnabled && !this.enabled) {
HiddenBrowsers.uninit();
}
},
};

let HiddenBrowsers = {
_browsers: null,
_updateTimer: null,
Expand Down

0 comments on commit 222b53c

Please sign in to comment.