Bug 1525762: Part 7 - Remove defunct LightweightThemeOptimizer. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Fri, 29 Mar 2019 11:37:08 -0700
changeset 525801 ba1529f7fd786c0aa5340c4ccd5738dc69274935
parent 525800 5d58601921993a4ae6bf87849eb295b6ffe389ee
child 525802 e69d39b3ac8d9148b6f4c5bf439606304b49c141
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [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 7 - Remove defunct LightweightThemeOptimizer. r=aswan It only works with "persisted" theme images, which no longer exist. Differential Revision: https://phabricator.services.mozilla.com/D25451
toolkit/modules/LightweightThemeConsumer.jsm
toolkit/mozapps/extensions/LightweightThemeManager.jsm
toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm
toolkit/mozapps/extensions/internal/moz.build
--- a/toolkit/modules/LightweightThemeConsumer.jsm
+++ b/toolkit/modules/LightweightThemeConsumer.jsm
@@ -6,18 +6,16 @@ var EXPORTED_SYMBOLS = ["LightweightThem
 
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const DEFAULT_THEME_ID = "default-theme@mozilla.org";
 const ICONS = Services.prefs.getStringPref("extensions.webextensions.themes.icons.buttons", "").split(",");
 
 ChromeUtils.defineModuleGetter(this, "AppConstants",
   "resource://gre/modules/AppConstants.jsm");
-ChromeUtils.defineModuleGetter(this, "LightweightThemeImageOptimizer",
-  "resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
 // Get the theme variables from the app resource directory.
 // This allows per-app variables.
 ChromeUtils.defineModuleGetter(this, "ThemeContentPropertyList",
   "resource:///modules/ThemeVariableMap.jsm");
 ChromeUtils.defineModuleGetter(this, "ThemeVariableMap",
   "resource:///modules/ThemeVariableMap.jsm");
 
 const toolkitVariableMap = [
@@ -194,22 +192,16 @@ LightweightThemeConsumer.prototype = {
     let theme = themeData.theme;
     if (themeData.darkTheme && this.darkMode) {
       theme = themeData.darkTheme;
     }
     if (!theme) {
       theme = { id: DEFAULT_THEME_ID };
     }
 
-    if (theme) {
-      theme = LightweightThemeImageOptimizer.optimize(theme, this._win.screen);
-    } else {
-      theme = {};
-    }
-
     let active = this._active = Object.keys(theme).length;
 
     let root = this._doc.documentElement;
 
     if (active && theme.headerURL) {
       root.setAttribute("lwtheme-image", "true");
     } else {
       root.removeAttribute("lwtheme-image");
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -1,28 +1,24 @@
 /* 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/. */
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["LightweightThemeManager"];
 
-ChromeUtils.defineModuleGetter(this, "LightweightThemeImageOptimizer",
-  "resource://gre/modules/addons/LightweightThemeImageOptimizer.jsm");
-
 // 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;
 
 var LightweightThemeManager = {
   set fallbackThemeData(data) {
     if (data && Object.getOwnPropertyNames(data).length) {
       _fallbackThemeData = Object.assign({}, data);
-      LightweightThemeImageOptimizer.purge();
     } else {
       _fallbackThemeData = null;
     }
   },
 
   /*
    * Returns the currently active theme, taking the fallback theme into account
    * if we'd be using the default theme otherwise.
deleted file mode 100644
--- a/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm
+++ /dev/null
@@ -1,179 +0,0 @@
-/* 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/. */
-
-"use strict";
-
-var EXPORTED_SYMBOLS = ["LightweightThemeImageOptimizer"];
-
-const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-
-ChromeUtils.defineModuleGetter(this, "Services",
-  "resource://gre/modules/Services.jsm");
-
-ChromeUtils.defineModuleGetter(this, "FileUtils",
-  "resource://gre/modules/FileUtils.jsm");
-
-const ORIGIN_TOP_RIGHT = 1;
-
-var LightweightThemeImageOptimizer = {
-  optimize(aThemeData, aScreen) {
-    let data = Object.assign({}, aThemeData);
-    if (!data.headerURL) {
-      return data;
-    }
-
-    data.headerURL = ImageCropper.getCroppedImageURL(
-      data.headerURL, aScreen, ORIGIN_TOP_RIGHT);
-
-    return data;
-  },
-
-  purge() {
-    let dir = FileUtils.getDir("ProfD", ["lwtheme"]);
-    dir.followLinks = false;
-    try {
-      dir.remove(true);
-    } catch (e) {}
-  },
-};
-
-Object.freeze(LightweightThemeImageOptimizer);
-
-var ImageCropper = {
-  _inProgress: {},
-
-  getCroppedImageURL(aImageURL, aScreen, aOrigin) {
-    // We can crop local files, only.
-    if (!aImageURL.startsWith("file://")) {
-      return aImageURL;
-    }
-
-    // Generate the cropped image's file name using its
-    // base name and the current screen size.
-    let uri = Services.io.newURI(aImageURL);
-    let file = uri.QueryInterface(Ci.nsIFileURL).file;
-
-    // Make sure the source file exists.
-    if (!file.exists()) {
-      return aImageURL;
-    }
-
-    let fileName = file.leafName + "-" + aScreen.width + "x" + aScreen.height;
-    let croppedFile = FileUtils.getFile("ProfD", ["lwtheme", fileName]);
-
-    // If we have a local file that is not in progress, return it.
-    if (croppedFile.exists() && !(croppedFile.path in this._inProgress)) {
-      let fileURI = Services.io.newFileURI(croppedFile);
-
-      // Copy the query part to avoid wrong caching.
-      fileURI = fileURI.mutate()
-                       .setQuery(uri.query)
-                       .finalize();
-      return fileURI.spec;
-    }
-
-    // Crop the given image in the background.
-    this._crop(uri, croppedFile, aScreen, aOrigin);
-
-    // Return the original image while we're waiting for the cropped version
-    // to be written to disk.
-    return aImageURL;
-  },
-
-  _crop(aURI, aTargetFile, aScreen, aOrigin) {
-    let inProgress = this._inProgress;
-    inProgress[aTargetFile.path] = true;
-
-    function resetInProgress() {
-      delete inProgress[aTargetFile.path];
-    }
-
-    ImageFile.read(aURI, function(aInputStream, aContentType) {
-      if (aInputStream && aContentType) {
-        ImageTools.decode(aInputStream, aContentType, function(aImage) {
-          if (aImage && aImage.width && aImage.height) {
-            let stream = ImageTools.encode(aImage, aScreen, aOrigin, aContentType);
-            if (stream) {
-              ImageFile.write(aTargetFile, stream, resetInProgress);
-            }
-          }
-        });
-      }
-
-      resetInProgress();
-    });
-  },
-};
-
-var ImageFile = {
-  read(aURI, aCallback) {
-    this._netUtil.asyncFetch({
-      uri: aURI,
-      loadUsingSystemPrincipal: true,
-      contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE,
-    }, function(aInputStream, aStatus, aRequest) {
-        if (Components.isSuccessCode(aStatus) && aRequest instanceof Ci.nsIChannel) {
-          let channel = aRequest.QueryInterface(Ci.nsIChannel);
-          aCallback(aInputStream, channel.contentType);
-        } else {
-          aCallback();
-        }
-      });
-  },
-
-  write(aFile, aInputStream, aCallback) {
-    let fos = FileUtils.openSafeFileOutputStream(aFile);
-    this._netUtil.asyncCopy(aInputStream, fos, function(aResult) {
-      FileUtils.closeSafeFileOutputStream(fos);
-
-      // Remove the file if writing was not successful.
-      if (!Components.isSuccessCode(aResult)) {
-        try {
-          aFile.remove(false);
-        } catch (e) {}
-      }
-
-      aCallback();
-    });
-  },
-};
-
-XPCOMUtils.defineLazyModuleGetter(ImageFile, "_netUtil",
-  "resource://gre/modules/NetUtil.jsm", "NetUtil");
-
-var ImageTools = {
-  decode(aInputStream, aContentType, aCallback) {
-    let callback = {
-      onImageReady(aImage, aStatus) {
-        aCallback(aImage);
-      },
-    };
-
-    try {
-      let threadManager = Cc["@mozilla.org/thread-manager;1"].getService();
-      this._imgTools.decodeImageAsync(aInputStream, aContentType, callback,
-                                      threadManager.currentThread);
-    } catch (e) {
-      aCallback(null);
-    }
-  },
-
-  encode(aImage, aScreen, aOrigin, aContentType) {
-    let stream;
-    let width = Math.min(aImage.width, aScreen.width);
-    let height = Math.min(aImage.height, aScreen.height);
-    let x = aOrigin == ORIGIN_TOP_RIGHT ? aImage.width - width : 0;
-
-    try {
-      stream = this._imgTools.encodeCroppedImage(aImage, aContentType, x, 0,
-                                                 width, height);
-    } catch (e) {}
-
-    return stream;
-  },
-};
-
-XPCOMUtils.defineLazyServiceGetter(ImageTools, "_imgTools",
-  "@mozilla.org/image/tools;1", "imgITools");
-
--- a/toolkit/mozapps/extensions/internal/moz.build
+++ b/toolkit/mozapps/extensions/internal/moz.build
@@ -5,17 +5,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXTRA_JS_MODULES.addons += [
     'AddonRepository.jsm',
     'AddonSettings.jsm',
     'AddonUpdateChecker.jsm',
     'Content.js',
     'GMPProvider.jsm',
-    'LightweightThemeImageOptimizer.jsm',
     'ProductAddonChecker.jsm',
     'XPIDatabase.jsm',
     'XPIInstall.jsm',
     'XPIProvider.jsm',
 ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     EXTRA_JS_MODULES.addons += [