Merge backout of changeset 5f03363ae12d (Bug 516013) due to xpcshell test failure (test_LightweightThemeManager) caused by exception thrown from the code added in that changeset.
authorL. David Baron <dbaron@dbaron.org>
Fri, 09 Oct 2009 13:31:39 -0700
changeset 33719 52fb6780a698bbe1523bb2db7f8d2e96d70eb384
parent 33717 2a6590861731ff469ac8fe7ef63e59808e6c7cff (current diff)
parent 33718 505a2a075e1125d4e22bd39de319aba6b75fd275 (diff)
child 33720 4859a803215c4add7df1ef2bedb138efa5b4944d
push id9647
push userdbaron@mozilla.com
push dateFri, 09 Oct 2009 20:32:36 +0000
treeherdermozilla-central@52fb6780a698 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs516013
milestone1.9.3a1pre
Merge backout of changeset 5f03363ae12d (Bug 516013) due to xpcshell test failure (test_LightweightThemeManager) caused by exception thrown from the code added in that changeset.
--- a/toolkit/mozapps/extensions/src/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/src/LightweightThemeManager.jsm
@@ -35,70 +35,32 @@
  * ***** END LICENSE BLOCK ***** */
 
 var EXPORTED_SYMBOLS = ["LightweightThemeManager"];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const MAX_USED_THEMES_COUNT = 8;
 const MAX_PREVIEW_SECONDS = 30;
-const PERSIST_ENABLED = true;
-const PERSIST_BYPASS_CACHE = false;
-const PERSIST_FILES = {
-  headerURL: "lightweighttheme-header",
-  footerURL: "lightweighttheme-footer"
-};
-
-__defineGetter__("_prefs", function () {
-  delete this._prefs;
-  return this._prefs =
-         Cc["@mozilla.org/preferences-service;1"]
-           .getService(Ci.nsIPrefService).getBranch("lightweightThemes.");
-});
-
-__defineGetter__("_observerService", function () {
-  delete this._observerService;
-  return this._observerService =
-         Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
-});
-
-__defineGetter__("_ioService", function () {
-  delete this._ioService;
-  return this._ioService =
-         Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-});
 
 var LightweightThemeManager = {
   get usedThemes () {
     try {
       return JSON.parse(_prefs.getCharPref("usedThemes"));
     } catch (e) {
       return [];
     }
   },
 
   get currentTheme () {
     try {
       if (_prefs.getBoolPref("isThemeSelected"))
-        var data = this.usedThemes[0];
+        return this.usedThemes[0];
     } catch (e) {}
-
-    if (!data)
-      return null;
-
-    if (PERSIST_ENABLED) {
-      for (let key in PERSIST_FILES) {
-        try {
-          if (data[key] && _prefs.getBoolPref("persisted." + key))
-            data[key] = _getLocalImageURI(PERSIST_FILES[key]).spec;
-        } catch (e) {}
-      }
-    }
-
-    return data;
+    return null;
   },
 
   set currentTheme (aData) {
     let cancel = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
     cancel.data = false;
     _observerService.notifyObservers(cancel, "lightweight-theme-change-requested",
                                      JSON.stringify(aData));
 
@@ -117,19 +79,16 @@ var LightweightThemeManager = {
     if (_previewTimer) {
       _previewTimer.cancel();
       _previewTimer = null;
     }
 
     _prefs.setBoolPref("isThemeSelected", aData != null);
     _notifyWindows(aData);
 
-    if (PERSIST_ENABLED && aData)
-      _persistImages(aData);
-
     return aData;
   },
 
   getUsedTheme: function (aId) {
     var usedThemes = this.usedThemes;
     for (let i = 0; i < usedThemes.length; i++) {
       if (usedThemes[i].id == aId)
         return usedThemes[i];
@@ -193,71 +152,22 @@ function _notifyWindows(aThemeData) {
                                    JSON.stringify(aThemeData));
 }
 
 var _previewTimer;
 var _previewTimerCallback = {
   notify: function () {
     LightweightThemeManager.resetPreview();
   }
-};
-
-function _persistImages(aData) {
-  function onSuccess(key) function () {
-    let current = LightweightThemeManager.currentTheme;
-    if (current && current.id == aData.id)
-      _prefs.setBoolPref("persisted." + key, true);
-  };
-
-  for (let key in PERSIST_FILES) {
-    _prefs.setBoolPref("persisted." + key, false);
-    if (aData[key])
-      _persistImage(aData[key], PERSIST_FILES[key], onSuccess(key));
-  }
-}
-
-function _getLocalImageURI(localFileName) {
-  var localFile = Cc["@mozilla.org/file/directory_service;1"]
-                     .getService(Ci.nsIProperties)
-                     .get("ProfD", Ci.nsILocalFile);
-  localFile.append(localFileName);
-  return _ioService.newFileURI(localFile);
 }
 
-function _persistImage(sourceURL, localFileName, callback) {
-  var targetURI = _getLocalImageURI(localFileName);
-  var sourceURI = _ioService.newURI(sourceURL, null, null);
-
-  var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
-                  .createInstance(Ci.nsIWebBrowserPersist);
-
-  persist.persistFlags =
-    Ci.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
-    Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION |
-    (PERSIST_BYPASS_CACHE ?
-       Ci.nsIWebBrowserPersist.PERSIST_FLAGS_BYPASS_CACHE :
-       Ci.nsIWebBrowserPersist.PERSIST_FLAGS_FROM_CACHE);
-
-  persist.progressListener = new _persistProgressListener(callback);
-
-  persist.saveURI(sourceURI, null, null, null, null, targetURI);
-}
+__defineGetter__("_prefs", function () {
+  delete this._prefs;
+  return this._prefs =
+         Cc["@mozilla.org/preferences-service;1"]
+           .getService(Ci.nsIPrefService).getBranch("lightweightThemes.");
+});
 
-function _persistProgressListener(callback) {
-  this.onLocationChange = function () {};
-  this.onProgressChange = function () {};
-  this.onStatusChange   = function () {};
-  this.onSecurityChange = function () {};
-  this.onStateChange    = function (aWebProgress, aRequest, aStateFlags, aStatus) {
-    if (aRequest &&
-        aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK &&
-        aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) {
-      try {
-        if (aRequest.QueryInterface(Ci.nsIHttpChannel).requestSucceeded) {
-          // success
-          callback();
-          return;
-        }
-      } catch (e) { }
-      // failure
-    }
-  };
-}
+__defineGetter__("_observerService", function () {
+  delete this._observerService;
+  return this._observerService =
+         Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
+});