browser/modules/HomePage.jsm
author L10n Bumper Bot <release+l10nbumper@mozilla.com>
Mon, 14 Jan 2019 05:00:14 -0800
changeset 506681 ac40678709f6f3af82e30819cea10260b6e497fc
parent 489310 d7fcfbc15cfe5e33cce5a12ff009e9b6aec07811
child 513677 6b56696d713a7f7858f16235e37baa8307e73b49
permissions -rw-r--r--
no bug - Bumping Fennec l10n changesets r=release a=l10n-bump DONTBUILD en-CA -> 1df3b5370c30 es-CL -> ff997f81eae6 es-MX -> 7d161fdf265c eu -> 506f20acd46d hi-IN -> 504d2fde3fc7 hu -> 6477fd6ddf64 mai -> d524e539eefb nn-NO -> 656adee29da6 sq -> f7c2ccfb7710 ta -> 047b3e205cca ur -> 03708a03f1b8 zh-CN -> b9c275f71f13 zh-TW -> f2b2ea4cd960

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/* globals ChromeUtils, Services */
/* exported HomePage */

"use strict";

var EXPORTED_SYMBOLS = ["HomePage"];

ChromeUtils.import("resource://gre/modules/Services.jsm");

const kPrefName = "browser.startup.homepage";

function getHomepagePref(useDefault) {
  let homePage;
  let prefs = Services.prefs;
  if (useDefault) {
    prefs = prefs.getDefaultBranch(null);
  }
  try {
    // Historically, this was a localizable pref, but default Firefox builds
    // don't use this.
    // Distributions and local customizations might still use this, so let's
    // keep it.
    homePage = prefs.getComplexValue(kPrefName,
                                     Ci.nsIPrefLocalizedString).data;
  } catch (ex) {}

  if (!homePage) {
    homePage = prefs.getStringPref(kPrefName);
  }

  // Apparently at some point users ended up with blank home pages somehow.
  // If that happens, reset the pref and read it again.
  if (!homePage && !useDefault) {
    Services.prefs.clearUserPref(kPrefName);
    homePage = getHomepagePref(true);
  }

  return homePage;
}

let HomePage = {
  get() {
    return getHomepagePref();
  },

  getDefault() {
    return getHomepagePref(true);
  },

  get overridden() {
    return Services.prefs.prefHasUserValue(kPrefName);
  },

  set(value) {
    Services.prefs.setStringPref(kPrefName, value);
  },

  reset() {
    Services.prefs.clearUserPref(kPrefName);
  },
};