зеркало из https://github.com/mozilla/pjs.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:
Коммит
963bb164d0
|
@ -40,31 +40,6 @@ const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
const MAX_USED_THEMES_COUNT = 8;
|
const MAX_USED_THEMES_COUNT = 8;
|
||||||
const MAX_PREVIEW_SECONDS = 30;
|
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 = {
|
var LightweightThemeManager = {
|
||||||
get usedThemes () {
|
get usedThemes () {
|
||||||
|
@ -78,22 +53,9 @@ var LightweightThemeManager = {
|
||||||
get currentTheme () {
|
get currentTheme () {
|
||||||
try {
|
try {
|
||||||
if (_prefs.getBoolPref("isThemeSelected"))
|
if (_prefs.getBoolPref("isThemeSelected"))
|
||||||
var data = this.usedThemes[0];
|
return this.usedThemes[0];
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
return null;
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
set currentTheme (aData) {
|
set currentTheme (aData) {
|
||||||
|
@ -122,9 +84,6 @@ var LightweightThemeManager = {
|
||||||
_prefs.setBoolPref("isThemeSelected", aData != null);
|
_prefs.setBoolPref("isThemeSelected", aData != null);
|
||||||
_notifyWindows(aData);
|
_notifyWindows(aData);
|
||||||
|
|
||||||
if (PERSIST_ENABLED && aData)
|
|
||||||
_persistImages(aData);
|
|
||||||
|
|
||||||
return aData;
|
return aData;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -198,66 +157,17 @@ var _previewTimerCallback = {
|
||||||
notify: function () {
|
notify: function () {
|
||||||
LightweightThemeManager.resetPreview();
|
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) {
|
__defineGetter__("_prefs", function () {
|
||||||
var localFile = Cc["@mozilla.org/file/directory_service;1"]
|
delete this._prefs;
|
||||||
.getService(Ci.nsIProperties)
|
return this._prefs =
|
||||||
.get("ProfD", Ci.nsILocalFile);
|
Cc["@mozilla.org/preferences-service;1"]
|
||||||
localFile.append(localFileName);
|
.getService(Ci.nsIPrefService).getBranch("lightweightThemes.");
|
||||||
return _ioService.newFileURI(localFile);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function _persistImage(sourceURL, localFileName, callback) {
|
__defineGetter__("_observerService", function () {
|
||||||
var targetURI = _getLocalImageURI(localFileName);
|
delete this._observerService;
|
||||||
var sourceURI = _ioService.newURI(sourceURL, null, null);
|
return this._observerService =
|
||||||
|
Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
||||||
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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче