Bug 1525762: Part 3b - Get rid of LWT update code. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 08 Feb 2019 14:28:37 -0800
changeset 466976 eb90dbf5abc88a452434245a0a1b2fae0ed835d6
parent 466975 2c10bcdc3d96942c9413984e8e25ef4c29de6e31
child 466977 9b72a80ec78c1cf423c1fc9314df0bed0edd844a
push id35789
push userbtara@mozilla.com
push dateSun, 31 Mar 2019 09:00:52 +0000
treeherdermozilla-central@c06dfc552c64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1525762
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525762: Part 3b - Get rid of LWT update code. r=aswan
browser/app/profile/firefox.js
toolkit/mozapps/extensions/LightweightThemeManager.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -177,19 +177,16 @@ pref("app.update.service.enabled", true)
 pref("extensions.update.enabled", true);
 pref("extensions.update.url", "https://versioncheck.addons.mozilla.org/update/VersionCheck.php?reqVersion=%REQ_VERSION%&id=%ITEM_ID%&version=%ITEM_VERSION%&maxAppVersion=%ITEM_MAXAPPVERSION%&status=%ITEM_STATUS%&appID=%APP_ID%&appVersion=%APP_VERSION%&appOS=%APP_OS%&appABI=%APP_ABI%&locale=%APP_LOCALE%&currentAppVersion=%CURRENT_APP_VERSION%&updateType=%UPDATE_TYPE%&compatMode=%COMPATIBILITY_MODE%");
 pref("extensions.update.background.url", "https://versioncheck-bg.addons.mozilla.org/update/VersionCheck.php?reqVersion=%REQ_VERSION%&id=%ITEM_ID%&version=%ITEM_VERSION%&maxAppVersion=%ITEM_MAXAPPVERSION%&status=%ITEM_STATUS%&appID=%APP_ID%&appVersion=%APP_VERSION%&appOS=%APP_OS%&appABI=%APP_ABI%&locale=%APP_LOCALE%&currentAppVersion=%CURRENT_APP_VERSION%&updateType=%UPDATE_TYPE%&compatMode=%COMPATIBILITY_MODE%");
 pref("extensions.update.interval", 86400);  // Check for updates to Extensions and
                                             // Themes every day
 
 pref("extensions.webextensions.themes.icons.buttons", "back,forward,reload,stop,bookmark_star,bookmark_menu,downloads,home,app_menu,cut,copy,paste,new_window,new_private_window,save_page,print,history,full_screen,find,options,addons,developer,synced_tabs,open_file,sidebars,share_page,subscribe,text_encoding,email_link,forget,pocket");
 
-pref("lightweightThemes.update.enabled", true);
-pref("lightweightThemes.getMoreURL", "https://addons.mozilla.org/%LOCALE%/firefox/themes");
-
 #if defined(MOZ_WIDEVINE_EME)
 pref("browser.eme.ui.enabled", true);
 #else
 pref("browser.eme.ui.enabled", false);
 #endif
 
 // UI tour experience.
 pref("browser.uitour.enabled", true);
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -2,45 +2,39 @@
  * 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/. */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["LightweightThemeManager"];
 
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-const {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const DEFAULT_THEME_ID = "default-theme@mozilla.org";
 
 const MAX_PREVIEW_SECONDS = 30;
 
 const MANDATORY = ["id", "name"];
 const OPTIONAL = ["headerURL", "textcolor", "accentcolor",
                   "iconURL", "previewURL", "author", "description",
-                  "homepageURL", "updateURL", "version"];
+                  "homepageURL", "version"];
 
 ChromeUtils.defineModuleGetter(this, "LightweightThemePersister",
   "resource://gre/modules/addons/LightweightThemePersister.jsm");
 ChromeUtils.defineModuleGetter(this, "LightweightThemeImageOptimizer",
   "resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
 ChromeUtils.defineModuleGetter(this, "AppConstants",
   "resource://gre/modules/AppConstants.jsm");
-ChromeUtils.defineModuleGetter(this, "ServiceRequest",
-  "resource://gre/modules/ServiceRequest.jsm");
 
 
 XPCOMUtils.defineLazyGetter(this, "_prefs", () => {
   return Services.prefs.getBranch("lightweightThemes.");
 });
 
-XPCOMUtils.defineLazyPreferenceGetter(this, "requireSecureUpdates",
-                                      "extensions.checkUpdateSecurity", true);
-
 
 // Holds optional fallback theme data that will be returned when no data for an
 // active theme can be found. This the case for WebExtension Themes, for example.
 var _fallbackThemeData = null;
 
 // Holds whether or not the default theme should display in dark mode. This is
 // typically the case when the OS has a dark system appearance.
 var _defaultThemeIsInDarkMode = false;
@@ -234,124 +228,16 @@ var LightweightThemeManager = {
   parseTheme(aString, aBaseURI) {
     try {
       return _sanitizeTheme(JSON.parse(aString), aBaseURI, false);
     } catch (e) {
       return null;
     }
   },
 
-  /*
-   * Try to update a single LWT.  If there is an XPI update, apply it
-   * immediately.  If there is a regular LWT update, only apply it if
-   * this is the current theme.
-   *
-   * Returns the LWT object (which could be the old one or a new one)
-   * if this theme is still an LWT, or null if this theme should be
-   * removed from the usedThemes list (ie, because it was updated to an
-   * xpi packaged theme).
-   */
-  async _updateOneTheme(theme, isCurrent) {
-    if (!theme.updateURL) {
-      return theme;
-    }
-
-    let req = new ServiceRequest({mozAnon: true});
-
-    req.mozBackgroundRequest = true;
-    req.overrideMimeType("text/plain");
-    req.open("GET", theme.updateURL, true);
-    // Prevent the request from reading from the cache.
-    req.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
-    // Prevent the request from writing to the cache.
-    req.channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
-
-    await new Promise(resolve => {
-      req.addEventListener("load", resolve, {once: true});
-      req.addEventListener("error", resolve, {once: true});
-      req.send(null);
-    });
-
-    if (req.status != 200)
-      return theme;
-
-    let parsed;
-    try {
-      parsed = JSON.parse(req.responseText);
-    } catch (e) {
-      return theme;
-    }
-
-    if ("converted_theme" in parsed) {
-      const {url, hash} = parsed.converted_theme;
-      let install = await AddonManager.getInstallForURL(url, {
-        hash,
-        telemetryInfo: {source: "lwt-converted-theme"},
-      });
-
-      install.addListener({
-        onDownloadEnded() {
-          if (install.addon && install.type !== "theme") {
-            Cu.reportError(`Refusing to update lightweight theme to a ${install.type} (from ${url})`);
-            install.cancel();
-            return false;
-          }
-          return true;
-        },
-      });
-
-      let updated = null;
-      try {
-        updated = await install.install();
-      } catch (e) { }
-
-      if (updated) {
-        if (isCurrent) {
-          await updated.enable();
-        }
-        return null;
-      }
-    } else if (isCurrent) {
-      // Double-parse of the response.  meh.
-      let newData = this.parseTheme(req.responseText, theme.updateURL);
-      if (!newData ||
-          newData.id != theme.id ||
-          _version(newData) == _version(theme))
-        return theme;
-
-      var currentTheme = this.currentTheme;
-      if (currentTheme && currentTheme.id == theme.id) {
-        this.currentTheme = newData;
-        // Careful: the currentTheme setter has the side effect of
-        // copying installDate which is not present in newData.
-        return this.currentTheme;
-      }
-    }
-
-    return theme;
-  },
-
-  async updateThemes() {
-    if (!_prefs.getBoolPref("update.enabled", false))
-      return;
-
-    let allThemes;
-    try {
-      allThemes = JSON.parse(_prefs.getStringPref("usedThemes"));
-    } catch (e) {
-      return;
-    }
-
-    let selectedID = _prefs.getStringPref("selectedThemeID", DEFAULT_THEME_ID);
-    let newThemes = await Promise.all(allThemes.map(
-      t => this._updateOneTheme(t, t.id == selectedID).catch(err => {})));
-    newThemes = newThemes.filter(t => t);
-    _prefs.setStringPref("usedThemes", JSON.stringify(newThemes));
-  },
-
   /**
    * Switches to a new lightweight theme.
    *
    * @param  aData
    *         The lightweight theme to switch to
    */
   themeChanged(aData) {
     if (_previewTimer) {
@@ -500,20 +386,16 @@ function _sanitizeTheme(aData, aBaseURI,
       return val;
 
     try {
       val = _makeURI(val, aBaseURI ? _makeURI(aBaseURI) : null).spec;
 
       if (!resourceProtocolExp.test(val)) {
         return null;
       }
-      if (prop == "updateURL" && requireSecureUpdates &&
-          !val.startsWith("https:")) {
-         return null;
-      }
       return val;
     } catch (e) {
       return null;
     }
   }
 
   let result = {};
   for (let mandatoryProperty of MANDATORY) {
@@ -534,20 +416,16 @@ function _sanitizeTheme(aData, aBaseURI,
 }
 
 function _usedThemesExceptId(aId) {
   return LightweightThemeManager.usedThemes.filter(function(t) {
       return "id" in t && t.id != aId;
     });
 }
 
-function _version(aThemeData) {
-  return aThemeData.version || "";
-}
-
 function _makeURI(aURL, aBaseURI) {
   return Services.io.newURI(aURL, null, aBaseURI);
 }
 
 function _updateUsedThemes(aList) {
   // Remove app-specific themes before saving them to the usedThemes pref.
   aList = aList.filter(theme => !LightweightThemeManager._builtInThemes.has(theme.id));