Bug 1360261 - Remove Preferences.jsm usage in GMPUtils. r=florian draft
authorDale Harvey <dale@arandomurl.com>
Wed, 05 Jul 2017 14:06:29 +0100
changeset 607039 2567a3d52753ef002c46538071b2b0e4052bf478
parent 607038 6c50a2e45d303a64d805485a2dc0eab1bef20c5e
child 636922 4e1377fdff8a191593a08d38cb4a005b4080596a
push id67871
push userbmo:dharvey@mozilla.com
push dateTue, 11 Jul 2017 19:27:46 +0000
reviewersflorian
bugs1360261
milestone56.0a1
Bug 1360261 - Remove Preferences.jsm usage in GMPUtils. r=florian MozReview-Commit-ID: WxerrrFZVi
toolkit/modules/GMPInstallManager.jsm
toolkit/modules/GMPUtils.jsm
toolkit/modules/UpdateUtils.jsm
toolkit/modules/tests/xpcshell/test_GMPInstallManager.js
toolkit/mozapps/extensions/internal/GMPProvider.jsm
toolkit/mozapps/extensions/internal/ProductAddonChecker.jsm
toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
--- a/toolkit/modules/GMPInstallManager.jsm
+++ b/toolkit/modules/GMPInstallManager.jsm
@@ -58,21 +58,21 @@ function GMPInstallManager() {
 GMPInstallManager.prototype = {
   /**
    * Obtains a URL with replacement of vars
    */
   _getURL() {
     let log = getScopedLogger("GMPInstallManager._getURL");
     // Use the override URL if it is specified.  The override URL is just like
     // the normal URL but it does not check the cert.
-    let url = GMPPrefs.get(GMPPrefs.KEY_URL_OVERRIDE);
+    let url = GMPPrefs.getString(GMPPrefs.KEY_URL_OVERRIDE, "");
     if (url) {
       log.info("Using override url: " + url);
     } else {
-      url = GMPPrefs.get(GMPPrefs.KEY_URL);
+      url = GMPPrefs.getString(GMPPrefs.KEY_URL);
       log.info("Using url: " + url);
     }
 
     url = UpdateUtils.formatUpdateURL(url);
 
     log.info("Using url (with replacement): " + url);
     return url;
   },
@@ -95,18 +95,18 @@ GMPInstallManager.prototype = {
         return Promise.reject({type: "alreadycalled"});
     }
     this._deferred = PromiseUtils.defer();
     let url = this._getURL();
 
     let allowNonBuiltIn = true;
     let certs = null;
     if (!Services.prefs.prefHasUserValue(GMPPrefs.KEY_URL_OVERRIDE)) {
-      allowNonBuiltIn = !GMPPrefs.get(GMPPrefs.KEY_CERT_REQUIREBUILTIN, true);
-      if (GMPPrefs.get(GMPPrefs.KEY_CERT_CHECKATTRS, true)) {
+      allowNonBuiltIn = !GMPPrefs.getString(GMPPrefs.KEY_CERT_REQUIREBUILTIN, true);
+      if (GMPPrefs.getBool(GMPPrefs.KEY_CERT_CHECKATTRS, true)) {
         certs = gCertUtils.readCertPrefs(GMPPrefs.KEY_CERTS_BRANCH);
       }
     }
 
     let addonPromise = ProductAddonChecker
       .getProductAddonList(url, allowNonBuiltIn, certs);
 
     addonPromise.then(res => {
@@ -143,45 +143,45 @@ GMPInstallManager.prototype = {
     }
     this.gmpDownloader = new GMPDownloader(gmpAddon);
     return this.gmpDownloader.start();
   },
   _getTimeSinceLastCheck() {
     let now = Math.round(Date.now() / 1000);
     // Default to 0 here because `now - 0` will be returned later if that case
     // is hit. We want a large value so a check will occur.
-    let lastCheck = GMPPrefs.get(GMPPrefs.KEY_UPDATE_LAST_CHECK, 0);
+    let lastCheck = GMPPrefs.getInt(GMPPrefs.KEY_UPDATE_LAST_CHECK, 0);
     // Handle clock jumps, return now since we want it to represent
     // a lot of time has passed since the last check.
     if (now < lastCheck) {
       return now;
     }
     return now - lastCheck;
   },
   get _isEMEEnabled() {
-    return GMPPrefs.get(GMPPrefs.KEY_EME_ENABLED, true);
+    return GMPPrefs.getBool(GMPPrefs.KEY_EME_ENABLED, true);
   },
   _isAddonEnabled(aAddon) {
-    return GMPPrefs.get(GMPPrefs.KEY_PLUGIN_ENABLED, true, aAddon);
+    return GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_ENABLED, true, aAddon);
   },
   _isAddonUpdateEnabled(aAddon) {
     return this._isAddonEnabled(aAddon) &&
-           GMPPrefs.get(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, aAddon);
+           GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, aAddon);
   },
   _updateLastCheck() {
     let now = Math.round(Date.now() / 1000);
-    GMPPrefs.set(GMPPrefs.KEY_UPDATE_LAST_CHECK, now);
+    GMPPrefs.setInt(GMPPrefs.KEY_UPDATE_LAST_CHECK, now);
   },
   _versionchangeOccurred() {
-    let savedBuildID = GMPPrefs.get(GMPPrefs.KEY_BUILDID, null);
-    let buildID = Services.appinfo.platformBuildID;
+    let savedBuildID = GMPPrefs.getString(GMPPrefs.KEY_BUILDID, "");
+    let buildID = Services.appinfo.platformBuildID || "";
     if (savedBuildID == buildID) {
       return false;
     }
-    GMPPrefs.set(GMPPrefs.KEY_BUILDID, buildID);
+    GMPPrefs.setString(GMPPrefs.KEY_BUILDID, buildID);
     return true;
   },
   /**
    * Wrapper for checkForAddons and installAddon.
    * Will only install if not already installed and will log the results.
    * This will only install/update the OpenH264 and EME plugins
    * @return a promise which will be resolved if all addons could be installed
    *         successfully, rejected otherwise.
@@ -190,18 +190,18 @@ GMPInstallManager.prototype = {
     let log = getScopedLogger("GMPInstallManager.simpleCheckAndInstall");
 
     if (this._versionchangeOccurred()) {
       log.info("A version change occurred. Ignoring " +
                "media.gmp-manager.lastCheck to check immediately for " +
                "new or updated GMPs.");
     } else {
       let secondsBetweenChecks =
-        GMPPrefs.get(GMPPrefs.KEY_SECONDS_BETWEEN_CHECKS,
-                     DEFAULT_SECONDS_BETWEEN_CHECKS)
+        GMPPrefs.getInt(GMPPrefs.KEY_SECONDS_BETWEEN_CHECKS,
+                        DEFAULT_SECONDS_BETWEEN_CHECKS)
       let secondsSinceLast = this._getTimeSinceLastCheck();
       log.info("Last check was: " + secondsSinceLast +
                " seconds ago, minimum seconds: " + secondsBetweenChecks);
       if (secondsBetweenChecks > secondsSinceLast) {
         log.info("Will not check for updates.");
         return {status: "too-frequent-no-check"};
       }
     }
@@ -345,28 +345,28 @@ GMPAddon.prototype = {
    * @return true if the addon is parsed and valid
    */
   get isValid() {
     return this.id && this.URL && this.version &&
       this.hashFunction && !!this.hashValue;
   },
   get isInstalled() {
     return this.version &&
-      GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VERSION, "", this.id) === this.version;
+      GMPPrefs.getString(GMPPrefs.KEY_PLUGIN_VERSION, "", this.id) === this.version;
   },
   get isEME() {
     return this.id == "gmp-widevinecdm" || this.id.indexOf("gmp-eme-") == 0;
   },
   /**
    * @return true if the addon has been previously installed and this is
    * a new version, if this is a fresh install return false
    */
   get isUpdate() {
     return this.version &&
-      GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VERSION, false, this.id);
+      GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_VERSION, false, this.id);
   },
 };
 /**
  * Constructs a GMPExtractor object which is used to extract a GMP zip
  * into the specified location. (Which typically leties per platform)
  * @param zipPath The path on disk of the zip file to extract
  */
 function GMPExtractor(zipPath, relativeInstallPath) {
@@ -439,22 +439,22 @@ GMPDownloader.prototype = {
       let relativePath = OS.Path.join(gmpAddon.id,
                                       gmpAddon.version);
       log.info("install to directory path: " + relativePath);
       let gmpInstaller = new GMPExtractor(zipPath, relativePath);
       let installPromise = gmpInstaller.install();
       return installPromise.then(extractedPaths => {
         // Success, set the prefs
         let now = Math.round(Date.now() / 1000);
-        GMPPrefs.set(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, now, gmpAddon.id);
+        GMPPrefs.setInt(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, now, gmpAddon.id);
         // Remember our ABI, so that if the profile is migrated to another
         // platform or from 32 -> 64 bit, we notice and don't try to load the
         // unexecutable plugin library.
-        GMPPrefs.set(GMPPrefs.KEY_PLUGIN_ABI, UpdateUtils.ABI, gmpAddon.id);
+        GMPPrefs.setString(GMPPrefs.KEY_PLUGIN_ABI, UpdateUtils.ABI, gmpAddon.id);
         // Setting the version pref signals installation completion to consumers,
         // if you need to set other prefs etc. do it before this.
-        GMPPrefs.set(GMPPrefs.KEY_PLUGIN_VERSION, gmpAddon.version,
-                     gmpAddon.id);
+        GMPPrefs.setString(GMPPrefs.KEY_PLUGIN_VERSION, gmpAddon.version,
+                           gmpAddon.id);
         return extractedPaths;
       });
     });
   },
 };
--- a/toolkit/modules/GMPUtils.jsm
+++ b/toolkit/modules/GMPUtils.jsm
@@ -8,17 +8,16 @@ const {classes: Cc, interfaces: Ci, resu
   Components;
 
 this.EXPORTED_SYMBOLS = [ "GMP_PLUGIN_IDS",
                           "GMPPrefs",
                           "GMPUtils",
                           "OPEN_H264_ID",
                           "WIDEVINE_ID" ];
 
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/AppConstants.jsm");
 
 // GMP IDs
 const OPEN_H264_ID  = "gmp-gmpopenh264";
 const WIDEVINE_ID   = "gmp-widevinecdm";
 const GMP_PLUGIN_IDS = [ OPEN_H264_ID, WIDEVINE_ID ];
 
@@ -49,17 +48,17 @@ this.GMPUtils = {
       return false;
     }
 
     if (!this._isPluginSupported(aPlugin) ||
         !this._isPluginVisible(aPlugin)) {
       return true;
     }
 
-    if (!GMPPrefs.get(GMPPrefs.KEY_EME_ENABLED, true)) {
+    if (!GMPPrefs.getBool(GMPPrefs.KEY_EME_ENABLED, true)) {
       return true;
     }
 
     return false;
   },
 
   /**
    * Checks whether or not a given plugin is supported by the current OS.
@@ -91,28 +90,28 @@ this.GMPUtils = {
   /**
    * Checks whether or not a given plugin is visible in the addons manager
    * UI and the "enable DRM" notification box. This can be used to test
    * plugins that aren't yet turned on in the mozconfig.
    * @param   aPlugin
    *          The plugin to check.
    */
   _isPluginVisible(aPlugin) {
-    return GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VISIBLE, false, aPlugin.id);
+    return GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_VISIBLE, false, aPlugin.id);
   },
 
   /**
    * Checks whether or not a given plugin is forced-supported. This is used
    * in automated tests to override the checks that prevent GMPs running on an
    * unsupported platform.
    * @param   aPlugin
    *          The plugin to check.
    */
   _isPluginForceSupported(aPlugin) {
-    return GMPPrefs.get(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, false, aPlugin.id);
+    return GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, false, aPlugin.id);
   },
 };
 
 /**
  * Manages preferences for GMP addons
  */
 this.GMPPrefs = {
   KEY_EME_ENABLED:              "media.eme.enabled",
@@ -135,59 +134,101 @@ this.GMPPrefs = {
   KEY_BUILDID:                  "media.gmp-manager.buildID",
   KEY_CERTS_BRANCH:             "media.gmp-manager.certs.",
   KEY_PROVIDER_ENABLED:         "media.gmp-provider.enabled",
   KEY_LOG_BASE:                 "media.gmp.log.",
   KEY_LOGGING_LEVEL:            "media.gmp.log.level",
   KEY_LOGGING_DUMP:             "media.gmp.log.dump",
 
   /**
-   * Obtains the specified preference in relation to the specified plugin.
+   * Obtains the specified string preference in relation to the specified plugin.
+   * @param aKey The preference key value to use.
+   * @param aDefaultValue The default value if no preference exists.
+   * @param aPlugin The plugin to scope the preference to.
+   * @return The obtained preference value, or the defaultValue if none exists.
+   */
+  getString(aKey, aDefaultValue, aPlugin) {
+    if (aKey === this.KEY_APP_DISTRIBUTION ||
+        aKey === this.KEY_APP_DISTRIBUTION_VERSION) {
+      return Services.prefs.getDefaultBranch(null).getCharPref(aKey, "default");
+    }
+    return Services.prefs.getStringPref(this.getPrefKey(aKey, aPlugin), aDefaultValue);
+  },
+
+  /**
+   * Obtains the specified int preference in relation to the specified plugin.
+   * @param aKey The preference key value to use.
+   * @param aDefaultValue The default value if no preference exists.
+   * @param aPlugin The plugin to scope the preference to.
+   * @return The obtained preference value, or the defaultValue if none exists.
+   */
+  getInt(aKey, aDefaultValue, aPlugin) {
+    return Services.prefs.getIntPref(this.getPrefKey(aKey, aPlugin), aDefaultValue);
+  },
+
+  /**
+   * Obtains the specified bool preference in relation to the specified plugin.
    * @param aKey The preference key value to use.
    * @param aDefaultValue The default value if no preference exists.
    * @param aPlugin The plugin to scope the preference to.
    * @return The obtained preference value, or the defaultValue if none exists.
    */
-  get(aKey, aDefaultValue, aPlugin) {
-    if (aKey === this.KEY_APP_DISTRIBUTION ||
-        aKey === this.KEY_APP_DISTRIBUTION_VERSION) {
-      return Services.prefs.getDefaultBranch(null).getCharPref(aKey, "default");
-    }
-    return Preferences.get(this.getPrefKey(aKey, aPlugin), aDefaultValue);
+  getBool(aKey, aDefaultValue, aPlugin) {
+    return Services.prefs.getBoolPref(this.getPrefKey(aKey, aPlugin), aDefaultValue);
   },
 
   /**
-   * Sets the specified preference in relation to the specified plugin.
+   * Sets the specified string preference in relation to the specified plugin.
    * @param aKey The preference key value to use.
    * @param aVal The value to set.
    * @param aPlugin The plugin to scope the preference to.
    */
-  set(aKey, aVal, aPlugin) {
-    Preferences.set(this.getPrefKey(aKey, aPlugin), aVal);
+  setString(aKey, aVal, aPlugin) {
+    Services.prefs.setStringPref(this.getPrefKey(aKey, aPlugin), aVal);
+  },
+
+  /**
+   * Sets the specified bool preference in relation to the specified plugin.
+   * @param aKey The preference key value to use.
+   * @param aVal The value to set.
+   * @param aPlugin The plugin to scope the preference to.
+   */
+  setBool(aKey, aVal, aPlugin) {
+    Services.prefs.setBoolPref(this.getPrefKey(aKey, aPlugin), aVal);
+  },
+
+  /**
+   * Sets the specified int preference in relation to the specified plugin.
+   * @param aKey The preference key value to use.
+   * @param aVal The value to set.
+   * @param aPlugin The plugin to scope the preference to.
+   */
+  setInt(aKey, aVal, aPlugin) {
+    Services.prefs.setIntPref(this.getPrefKey(aKey, aPlugin), aVal);
   },
 
   /**
    * Checks whether or not the specified preference is set in relation to the
    * specified plugin.
    * @param aKey The preference key value to use.
    * @param aPlugin The plugin to scope the preference to.
    * @return true if the preference is set, false otherwise.
    */
   isSet(aKey, aPlugin) {
-    return Preferences.isSet(this.getPrefKey(aKey, aPlugin));
+    return Services.prefs.prefHasUserValue(this.getPrefKey(aKey, aPlugin));
   },
 
   /**
    * Resets the specified preference in relation to the specified plugin to its
    * default.
    * @param aKey The preference key value to use.
    * @param aPlugin The plugin to scope the preference to.
    */
   reset(aKey, aPlugin) {
-    Preferences.reset(this.getPrefKey(aKey, aPlugin));
+    Services.prefs.clearUserPref(this.getPrefKey(aKey, aPlugin));
   },
 
   /**
    * Scopes the specified preference key to the specified plugin.
    * @param aKey The preference key value to use.
    * @param aPlugin The plugin to scope the preference to.
    * @return A preference key scoped to the specified plugin.
    */
--- a/toolkit/modules/UpdateUtils.jsm
+++ b/toolkit/modules/UpdateUtils.jsm
@@ -5,17 +5,16 @@
 this.EXPORTED_SYMBOLS = ["UpdateUtils"];
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/ctypes.jsm");
 
 const FILE_UPDATE_LOCALE                  = "update.locale";
 const PREF_APP_DISTRIBUTION               = "distribution.id";
 const PREF_APP_DISTRIBUTION_VERSION       = "distribution.version";
 const PREF_APP_UPDATE_CUSTOM              = "app.update.custom";
 
 
@@ -58,35 +57,45 @@ this.UpdateUtils = {
    * Formats a URL by replacing %...% values with OS, build and locale specific
    * values.
    *
    * @param  url
    *         The URL to format.
    * @return The formatted URL.
    */
   formatUpdateURL(url) {
-    url = url.replace(/%PRODUCT%/g, Services.appinfo.name);
-    url = url.replace(/%VERSION%/g, Services.appinfo.version);
-    url = url.replace(/%BUILD_ID%/g, Services.appinfo.appBuildID);
-    url = url.replace(/%BUILD_TARGET%/g, Services.appinfo.OS + "_" + this.ABI);
-    url = url.replace(/%OS_VERSION%/g, this.OSVersion);
-    url = url.replace(/%SYSTEM_CAPABILITIES%/g, getSystemCapabilities());
-    if (/%LOCALE%/.test(url)) {
-      url = url.replace(/%LOCALE%/g, this.Locale);
-    }
-    url = url.replace(/%CHANNEL%/g, this.UpdateChannel);
-    url = url.replace(/%PLATFORM_VERSION%/g, Services.appinfo.platformVersion);
-    url = url.replace(/%DISTRIBUTION%/g,
-                      getDistributionPrefValue(PREF_APP_DISTRIBUTION));
-    url = url.replace(/%DISTRIBUTION_VERSION%/g,
-                      getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION));
-    url = url.replace(/%CUSTOM%/g, Preferences.get(PREF_APP_UPDATE_CUSTOM, ""));
-    url = url.replace(/\+/g, "%2B");
-
-    return url;
+    return url.replace(/%(\w+)%/g, (match, name) => {
+      switch (name) {
+        case "PRODUCT":
+          return Services.appinfo.name;
+        case "VERSION":
+          return Services.appinfo.version;
+        case "BUILD_ID":
+          return Services.appinfo.appBuildID;
+        case "BUILD_TARGET":
+          return Services.appinfo.OS + "_" + this.ABI;
+        case "OS_VERSION":
+          return this.OSVersion;
+        case "LOCALE":
+          return this.Locale;
+        case "CHANNEL":
+          return this.UpdateChannel;
+        case "PLATFORM_VERSION":
+          return Services.appinfo.platformVersion;
+        case "SYSTEM_CAPABILITIES":
+          return getSystemCapabilities();
+        case "CUSTOM":
+          return Services.prefs.getStringPref(PREF_APP_UPDATE_CUSTOM, "");
+        case "DISTRIBUTION":
+          return getDistributionPrefValue(PREF_APP_DISTRIBUTION);
+        case "DISTRIBUTION_VERSION":
+          return getDistributionPrefValue(PREF_APP_DISTRIBUTION_VERSION);
+      }
+      return match;
+    }).replace(/\+/g, "%2B");
   }
 };
 
 /* Get the distribution pref values, from defaults only */
 function getDistributionPrefValue(aPrefName) {
   return Services.prefs.getDefaultBranch(null).getCharPref(aPrefName, "default");
 }
 
--- a/toolkit/modules/tests/xpcshell/test_GMPInstallManager.js
+++ b/toolkit/modules/tests/xpcshell/test_GMPInstallManager.js
@@ -26,36 +26,36 @@ function run_test() {
 }
 
 /**
  * Tests that the helper used for preferences works correctly
  */
 add_task(async function test_prefs() {
   let addon1 = "addon1", addon2 = "addon2";
 
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_URL, "http://not-really-used");
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_URL_OVERRIDE, "http://not-really-used-2");
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "1", addon1);
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "2", addon1);
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "3", addon2);
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "4", addon2);
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, false, addon2);
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_CERT_CHECKATTRS, true);
+  GMPScope.GMPPrefs.setString(GMPScope.GMPPrefs.KEY_URL, "http://not-really-used");
+  GMPScope.GMPPrefs.setString(GMPScope.GMPPrefs.KEY_URL_OVERRIDE, "http://not-really-used-2");
+  GMPScope.GMPPrefs.setInt(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, 1, addon1);
+  GMPScope.GMPPrefs.setString(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "2", addon1);
+  GMPScope.GMPPrefs.setInt(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, 3, addon2);
+  GMPScope.GMPPrefs.setInt(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, 4, addon2);
+  GMPScope.GMPPrefs.setBool(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, false, addon2);
+  GMPScope.GMPPrefs.setBool(GMPScope.GMPPrefs.KEY_CERT_CHECKATTRS, true);
 
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_URL), "http://not-really-used");
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_URL_OVERRIDE),
+  do_check_eq(GMPScope.GMPPrefs.getString(GMPScope.GMPPrefs.KEY_URL), "http://not-really-used");
+  do_check_eq(GMPScope.GMPPrefs.getString(GMPScope.GMPPrefs.KEY_URL_OVERRIDE),
               "http://not-really-used-2");
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "", addon1), "1");
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "", addon1), "2");
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "", addon2), "3");
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "", addon2), "4");
-  do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, undefined, addon2),
+  do_check_eq(GMPScope.GMPPrefs.getInt(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "", addon1), 1);
+  do_check_eq(GMPScope.GMPPrefs.getString(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "", addon1), "2");
+  do_check_eq(GMPScope.GMPPrefs.getInt(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "", addon2), 3);
+  do_check_eq(GMPScope.GMPPrefs.getInt(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "", addon2), 4);
+  do_check_eq(GMPScope.GMPPrefs.getBool(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, undefined, addon2),
               false);
-  do_check_true(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_CERT_CHECKATTRS));
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, addon2);
+  do_check_true(GMPScope.GMPPrefs.getBool(GMPScope.GMPPrefs.KEY_CERT_CHECKATTRS));
+  GMPScope.GMPPrefs.setBool(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, addon2);
 });
 
 /**
  * Tests that an uninit without a check works fine
  */
 add_task(async function test_checkForAddons_uninitWithoutCheck() {
   let installManager = new GMPInstallManager();
   installManager.uninit();
@@ -171,22 +171,22 @@ add_test(function test_checkForAddons_ti
 /**
  * Tests that we throw correctly in case of ssl certification error.
  */
 add_test(function test_checkForAddons_bad_ssl() {
   //
   // Add random stuff that cause CertUtil to require https.
   //
   let PREF_KEY_URL_OVERRIDE_BACKUP =
-    Preferences.get(GMPScope.GMPPrefs.KEY_URL_OVERRIDE, undefined);
+    Preferences.get(GMPScope.GMPPrefs.KEY_URL_OVERRIDE, "");
   Preferences.reset(GMPScope.GMPPrefs.KEY_URL_OVERRIDE);
 
   let CERTS_BRANCH_DOT_ONE = GMPScope.GMPPrefs.KEY_CERTS_BRANCH + ".1";
   let PREF_CERTS_BRANCH_DOT_ONE_BACKUP =
-    Preferences.get(CERTS_BRANCH_DOT_ONE, undefined);
+    Preferences.get(CERTS_BRANCH_DOT_ONE, "");
   Services.prefs.setCharPref(CERTS_BRANCH_DOT_ONE, "funky value");
 
 
   overrideXHR(200, "");
   let installManager = new GMPInstallManager();
   let promise = installManager.checkForAddons();
   promise.then(res => {
     do_check_true(res.usedFallback);
@@ -457,23 +457,23 @@ async function test_checkForAddons_insta
     let extractedFile = Cc["@mozilla.org/file/local;1"].
                         createInstance(Ci.nsIFile);
     extractedFile.initWithPath(extractedPath);
     do_check_true(extractedFile.exists());
     let readData = readStringFromFile(extractedFile);
     do_check_eq(readData, data);
 
     // Make sure the prefs are set correctly
-    do_check_true(!!GMPScope.GMPPrefs.get(
+    do_check_true(!!GMPScope.GMPPrefs.getInt(
       GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, "", gmpAddon.id));
-    do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "",
-                                      gmpAddon.id),
+    do_check_eq(GMPScope.GMPPrefs.getString(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, "",
+                                            gmpAddon.id),
                 "1.1");
-    do_check_eq(GMPScope.GMPPrefs.get(GMPScope.GMPPrefs.KEY_PLUGIN_ABI, "",
-                                      gmpAddon.id),
+    do_check_eq(GMPScope.GMPPrefs.getString(GMPScope.GMPPrefs.KEY_PLUGIN_ABI, "",
+                                            gmpAddon.id),
                 UpdateUtils.ABI);
     // Make sure it reports as being installed
     do_check_true(gmpAddon.isInstalled);
 
     // Cleanup
     extractedFile.parent.remove(true);
     zipFile.remove(false);
     httpServer.stop(function() {});
@@ -489,17 +489,17 @@ async function test_checkForAddons_insta
 add_task(test_checkForAddons_installAddon.bind(null, "1", true, false));
 add_task(test_checkForAddons_installAddon.bind(null, "2", false, false));
 add_task(test_checkForAddons_installAddon.bind(null, "3", true, true));
 
 /**
  * Tests simpleCheckAndInstall when autoupdate is disabled for a GMP
  */
 add_task(async function test_simpleCheckAndInstall_autoUpdateDisabled() {
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, false, GMPScope.OPEN_H264_ID);
+  GMPScope.GMPPrefs.setBool(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, false, GMPScope.OPEN_H264_ID);
   let responseXML =
     "<?xml version=\"1.0\"?>" +
     "<updates>" +
     "    <addons>" +
     // valid openh264
     "        <addon id=\"gmp-gmpopenh264\"" +
     "               URL=\"http://127.0.0.1:8011/gmp-gmpopenh264-1.1.zip\"" +
     "               hashFunction=\"sha256\"" +
@@ -508,17 +508,17 @@ add_task(async function test_simpleCheck
     "  </addons>" +
     "</updates>"
 
   overrideXHR(200, responseXML);
   let installManager = new GMPInstallManager();
   let result = await installManager.simpleCheckAndInstall();
   do_check_eq(result.status, "nothing-new-to-install");
   Preferences.reset(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK);
-  GMPScope.GMPPrefs.set(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, GMPScope.OPEN_H264_ID);
+  GMPScope.GMPPrefs.setBool(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, GMPScope.OPEN_H264_ID);
 });
 
 /**
  * Tests simpleCheckAndInstall nothing to install
  */
 add_task(async function test_simpleCheckAndInstall_nothingToInstall() {
   let responseXML =
     "<?xml version=\"1.0\"?>" +
--- a/toolkit/mozapps/extensions/internal/GMPProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/GMPProvider.jsm
@@ -78,19 +78,19 @@ var messageManager = Cc["@mozilla.org/gl
 var gLogger;
 var gLogAppenderDump = null;
 
 function configureLogging() {
   if (!gLogger) {
     gLogger = Log.repository.getLogger("Toolkit.GMP");
     gLogger.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));
   }
-  gLogger.level = GMPPrefs.get(GMPPrefs.KEY_LOGGING_LEVEL, Log.Level.Warn);
+  gLogger.level = GMPPrefs.getInt(GMPPrefs.KEY_LOGGING_LEVEL, Log.Level.Warn);
 
-  let logDumping = GMPPrefs.get(GMPPrefs.KEY_LOGGING_DUMP, false);
+  let logDumping = GMPPrefs.getBool(GMPPrefs.KEY_LOGGING_DUMP, false);
   if (logDumping != !!gLogAppenderDump) {
     if (logDumping) {
       gLogAppenderDump = new Log.DumpAppender(new Log.BasicFormatter());
       gLogger.addAppender(gLogAppenderDump);
     } else {
       gLogger.removeAppender(gLogAppenderDump);
       gLogAppenderDump = null;
     }
@@ -131,58 +131,55 @@ GMPWrapper.prototype = {
   optionsType: AddonManager.OPTIONS_TYPE_INLINE,
   get optionsURL() { return this._plugin.optionsURL; },
 
   set gmpPath(aPath) { this._gmpPath = aPath; },
   get gmpPath() {
     if (!this._gmpPath && this.isInstalled) {
       this._gmpPath = OS.Path.join(OS.Constants.Path.profileDir,
                                    this._plugin.id,
-                                   GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VERSION,
-                                                null, this._plugin.id));
+                                   GMPPrefs.getString(GMPPrefs.KEY_PLUGIN_VERSION,
+                                                      null, this._plugin.id));
     }
     return this._gmpPath;
   },
 
   get id() { return this._plugin.id; },
   get type() { return "plugin"; },
   get isGMPlugin() { return true; },
   get name() { return this._plugin.name; },
   get creator() { return null; },
   get homepageURL() { return this._plugin.homepageURL; },
 
   get description() { return this._plugin.description; },
   get fullDescription() { return this._plugin.fullDescription; },
 
   get version() {
- return GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VERSION, null,
-                                      this._plugin.id);
-},
+    return GMPPrefs.getString(GMPPrefs.KEY_PLUGIN_VERSION, null, this._plugin.id);
+  },
 
   get isActive() {
     return !this.appDisabled &&
            !this.userDisabled &&
            !GMPUtils.isPluginHidden(this._plugin);
   },
   get appDisabled() {
-    if (this._plugin.isEME && !GMPPrefs.get(GMPPrefs.KEY_EME_ENABLED, true)) {
+    if (this._plugin.isEME && !GMPPrefs.getBool(GMPPrefs.KEY_EME_ENABLED, true)) {
       // If "media.eme.enabled" is false, all EME plugins are disabled.
       return true;
     }
     return false;
   },
 
   get userDisabled() {
-    return !GMPPrefs.get(GMPPrefs.KEY_PLUGIN_ENABLED, true, this._plugin.id);
+    return !GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_ENABLED, true, this._plugin.id);
   },
   set userDisabled(aVal) {
- GMPPrefs.set(GMPPrefs.KEY_PLUGIN_ENABLED,
-                                        aVal === false,
-                                        this._plugin.id);
-},
+    GMPPrefs.setBool(GMPPrefs.KEY_PLUGIN_ENABLED, aVal === false, this._plugin.id);
+  },
 
   get blocklistState() { return Ci.nsIBlocklistService.STATE_NOT_BLOCKED; },
   get size() { return 0; },
   get scope() { return AddonManager.SCOPE_APPLICATION; },
   get pendingOperations() { return AddonManager.PENDING_NONE; },
 
   get operationsRequiringRestart() { return AddonManager.OP_NEEDS_RESTART_NONE },
 
@@ -192,19 +189,19 @@ GMPWrapper.prototype = {
       permissions |= AddonManager.PERM_CAN_UPGRADE;
       permissions |= this.userDisabled ? AddonManager.PERM_CAN_ENABLE :
                                          AddonManager.PERM_CAN_DISABLE;
     }
     return permissions;
   },
 
   get updateDate() {
-    let time = Number(GMPPrefs.get(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, null,
-                                   this._plugin.id));
-    if (!isNaN(time) && this.isInstalled) {
+    let time = Number(GMPPrefs.getInt(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, 0,
+                                      this._plugin.id));
+    if (this.isInstalled) {
       return new Date(time * 1000)
     }
     return null;
   },
 
   get isCompatible() {
     return true;
   },
@@ -225,27 +222,27 @@ GMPWrapper.prototype = {
     return true;
   },
 
   get applyBackgroundUpdates() {
     if (!GMPPrefs.isSet(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, this._plugin.id)) {
       return AddonManager.AUTOUPDATE_DEFAULT;
     }
 
-    return GMPPrefs.get(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, this._plugin.id) ?
+    return GMPPrefs.getBool(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, this._plugin.id) ?
       AddonManager.AUTOUPDATE_ENABLE : AddonManager.AUTOUPDATE_DISABLE;
   },
 
   set applyBackgroundUpdates(aVal) {
     if (aVal == AddonManager.AUTOUPDATE_DEFAULT) {
       GMPPrefs.reset(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, this._plugin.id);
     } else if (aVal == AddonManager.AUTOUPDATE_ENABLE) {
-      GMPPrefs.set(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, this._plugin.id);
+      GMPPrefs.setBool(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, true, this._plugin.id);
     } else if (aVal == AddonManager.AUTOUPDATE_DISABLE) {
-      GMPPrefs.set(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, false, this._plugin.id);
+      GMPPrefs.setBool(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, false, this._plugin.id);
     }
   },
 
   findUpdates(aListener, aReason, aAppVersion, aPlatformVersion) {
     this._log.trace("findUpdates() - " + this._plugin.id + " - reason=" +
                     aReason);
 
     AddonManagerPrivate.callNoUpdateListeners(this, aListener);
@@ -423,18 +420,18 @@ GMPWrapper.prototype = {
 
     AddonManagerPrivate.callInstallListeners("onExternalInstall", null, this,
                                              null, false);
     AddonManagerPrivate.callAddonListeners("onInstalling", this, false);
     this._gmpPath = null;
     if (this.isInstalled) {
       this._gmpPath = OS.Path.join(OS.Constants.Path.profileDir,
                                    this._plugin.id,
-                                   GMPPrefs.get(GMPPrefs.KEY_PLUGIN_VERSION,
-                                                null, this._plugin.id));
+                                   GMPPrefs.getString(GMPPrefs.KEY_PLUGIN_VERSION,
+                                                      null, this._plugin.id));
     }
     if (this._gmpPath && this.isActive) {
       this._log.info("onPrefVersionChanged() - registering gmp directory " +
                      this._gmpPath);
       gmpService.addPluginDirectory(this._gmpPath);
     }
     AddonManagerPrivate.callAddonListeners("onInstalled", this);
   },
@@ -492,17 +489,18 @@ GMPWrapper.prototype = {
     if (!this.isInstalled) {
       // Not installed -> Valid.
       return {
         installed: false,
         valid: true
       };
     }
 
-    let abi = GMPPrefs.get(GMPPrefs.KEY_PLUGIN_ABI, UpdateUtils.ABI, this._plugin.id);
+    let abi = GMPPrefs.getString(GMPPrefs.KEY_PLUGIN_ABI, UpdateUtils.ABI,
+                                 this._plugin.id);
     if (abi != UpdateUtils.ABI) {
       // ABI doesn't match. Possibly this is a profile migrated across platforms
       // or from 32 -> 64 bit.
       return {
         installed: true,
         mismatchedABI: true,
         valid: false
       };
@@ -628,17 +626,17 @@ var GMPProvider = {
     let results = Array.from(this._plugins.values())
       .filter(p => !GMPUtils.isPluginHidden(p))
       .map(p => p.wrapper);
 
     aCallback(results);
   },
 
   get isEnabled() {
-    return GMPPrefs.get(GMPPrefs.KEY_PROVIDER_ENABLED, false);
+    return GMPPrefs.getBool(GMPPrefs.KEY_PROVIDER_ENABLED, false);
   },
 
   generateFullDescription(aPlugin) {
     let rv = [];
     for (let [urlProp, labelId] of [["learnMoreURL", GMP_LEARN_MORE],
                                     ["licenseURL", aPlugin.id == WIDEVINE_ID ?
                                      GMP_PRIVACY_INFO : GMP_LICENSE_INFO]]) {
       if (aPlugin[urlProp]) {
@@ -663,17 +661,17 @@ var GMPProvider = {
       };
       plugin.fullDescription = this.generateFullDescription(aPlugin);
       plugin.wrapper = new GMPWrapper(plugin);
       this._plugins.set(plugin.id, plugin);
     }
   },
 
   ensureProperCDMInstallState() {
-    if (!GMPPrefs.get(GMPPrefs.KEY_EME_ENABLED, true)) {
+    if (!GMPPrefs.getBool(GMPPrefs.KEY_EME_ENABLED, true)) {
       for (let plugin of this._plugins.values()) {
         if (plugin.isEME && plugin.wrapper.isInstalled) {
           gmpService.addPluginDirectory(plugin.wrapper.gmpPath);
           plugin.wrapper.uninstallPlugin();
         }
       }
     }
   },
--- a/toolkit/mozapps/extensions/internal/ProductAddonChecker.jsm
+++ b/toolkit/mozapps/extensions/internal/ProductAddonChecker.jsm
@@ -227,17 +227,17 @@ function parseXML(document) {
 }
 
 /**
  * If downloading from the network fails (AUS server is down),
  * load the sources from local build configuration.
  */
 function downloadLocalConfig() {
 
-  if (!GMPPrefs.get(GMPPrefs.KEY_UPDATE_ENABLED, true)) {
+  if (!GMPPrefs.getBool(GMPPrefs.KEY_UPDATE_ENABLED, true)) {
     logger.info("Updates are disabled via media.gmp-manager.updateEnabled");
     return Promise.resolve({usedFallback: true, gmpAddons: []});
   }
 
   return Promise.all(LOCAL_EME_SOURCES.map(conf => {
     return downloadJSON(conf.src).then(addons => {
 
       let platforms = addons.vendors[conf.id].platforms;
@@ -421,17 +421,17 @@ const ProductAddonChecker = {
    * @param  allowedCerts
    *         The list of certificate attributes to match the SSL certificate
    *         against or null to skip checks.
    * @return a promise that resolves to an object containing the list of add-ons
    *         and whether the local fallback was used, or rejects with a JS
    *         exception in case of error.
    */
   getProductAddonList(url, allowNonBuiltIn = false, allowedCerts = null) {
-    if (!GMPPrefs.get(GMPPrefs.KEY_UPDATE_ENABLED, true)) {
+    if (!GMPPrefs.getBool(GMPPrefs.KEY_UPDATE_ENABLED, true)) {
       logger.info("Updates are disabled via media.gmp-manager.updateEnabled");
       return Promise.resolve({usedFallback: true, gmpAddons: []});
     }
 
     return downloadXML(url, allowNonBuiltIn, allowedCerts)
       .then(parseXML)
       .catch(downloadLocalConfig);
   },
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
@@ -139,18 +139,18 @@ add_task(async function test_installed()
   for (let addon of addons) {
     let mockAddon = gMockAddons.get(addon.id);
     Assert.notEqual(mockAddon, null);
 
     let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
     file.append(addon.id);
     file.append(TEST_VERSION);
     gPrefs.setBoolPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, mockAddon.id), false);
-    gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, mockAddon.id),
-                      "" + TEST_TIME_SEC);
+    gPrefs.setIntPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, mockAddon.id),
+                      TEST_TIME_SEC);
     gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, mockAddon.id),
                       TEST_VERSION);
 
     Assert.ok(addon.isInstalled);
     Assert.equal(addon.type, "plugin");
     Assert.ok(!addon.isActive);
     Assert.ok(!addon.appDisabled);
     Assert.ok(addon.userDisabled);