зеркало из https://github.com/mozilla/gecko-dev.git
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.
This commit is contained in:
Коммит
a3b5235ddd
|
@ -40,31 +40,6 @@ 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 () {
|
||||
|
@ -78,22 +53,9 @@ var LightweightThemeManager = {
|
|||
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) {
|
||||
|
@ -122,9 +84,6 @@ var LightweightThemeManager = {
|
|||
_prefs.setBoolPref("isThemeSelected", aData != null);
|
||||
_notifyWindows(aData);
|
||||
|
||||
if (PERSIST_ENABLED && aData)
|
||||
_persistImages(aData);
|
||||
|
||||
return aData;
|
||||
},
|
||||
|
||||
|
@ -198,66 +157,17 @@ 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);
|
||||
}
|
||||
__defineGetter__("_prefs", function () {
|
||||
delete this._prefs;
|
||||
return this._prefs =
|
||||
Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService).getBranch("lightweightThemes.");
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче